Skip to content

Commit d9a235a

Browse files
committed
feat: More granular error logging
1 parent 8c0cc4b commit d9a235a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

service/src/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ int hyperiond_start(service_t* service)
114114
{
115115
int res = 0;
116116
if (!is_elevated()) {
117+
ERR("hyperiond_start: Not elevated");
117118
return 1;
118119
} else if (is_running(service->daemon_pid)) {
120+
ERR("hyperiond_start: Daemon already running");
119121
return 2;
120122
}
121123

@@ -141,8 +143,10 @@ int hyperiond_stop(service_t* service)
141143
int res = 0;
142144

143145
if (!is_elevated()) {
146+
ERR("hyperiond_stop: Not elevated");
144147
return 1;
145148
} else if (!is_running(service->daemon_pid)) {
149+
ERR("hyperiond_stop: Daemon not running");
146150
return 2;
147151
}
148152

@@ -169,20 +173,20 @@ int hyperiond_version(service_t* service)
169173
if (service->hyperiond_version == NULL) {
170174
service->hyperiond_version = (char *)calloc(FILENAME_MAX, 1);
171175
if (service->hyperiond_version == NULL) {
172-
// Buffer allocation failed
176+
ERR("hyperiond_version: Failed version buf allocation");
173177
return 1;
174178
}
175179

176180
char *command = hyperiond_version_cmdline();
177181
// Spawn process with read-only pipe
178182
FILE *fp = popen(command, "r");
179183
if (fp == NULL) {
180-
// Opening process failed
184+
ERR("hyperiond_version: popen failed");
181185
res = 2;
182186
} else {
183187
int bytes_read = fread(service->hyperiond_version, 1, FILENAME_MAX, fp);
184188
if (bytes_read == 0) {
185-
// Reading process' stdout failed
189+
ERR("hyperiond_version: Reading process' stdout failed");
186190
res = 3;
187191
}
188192

@@ -306,6 +310,8 @@ bool service_method_terminate(LSHandle* sh, LSMessage* msg, void* data __attribu
306310
LSError lserror;
307311
LSErrorInit(&lserror);
308312

313+
WARN("service_method_terminate: Terminating");
314+
309315
jvalue_ref jobj = jobject_create();
310316
jobject_set(jobj, j_cstr_to_buffer("returnValue"), jboolean_create(true));
311317

@@ -352,6 +358,7 @@ int main()
352358
}
353359

354360
if (!registered) {
361+
ERR("Failed luna-service registration!");
355362
LSErrorFree(&lserror);
356363
return -1;
357364
}

0 commit comments

Comments
 (0)