Skip to content

Commit d0a1873

Browse files
committed
fix: Signaling
1 parent af5a9e9 commit d0a1873

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

service/src/main.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int daemon_start(pid_t *pid)
4848
asprintf(&env_armcap, "OPENSSL_armcap=%d", 0);
4949
asprintf(&application_executable_path, "%s/hyperiond", HYPERION_PATH);
5050

51-
char *env_vars[] = {env_library_path, env_armcap, NULL};
51+
char *env_vars[] = {env_library_path, env_armcap, "HOME=/home/root", NULL};
5252
char *argv[] = {application_executable_path, NULL};
5353

5454
res = posix_spawn(pid, application_executable_path, NULL, NULL, argv, env_vars);
@@ -66,6 +66,7 @@ void *execution_task(void *data)
6666
{
6767
int res = 0;
6868
int status = 0;
69+
bool run_loop = true;
6970

7071
service_t *service = (service_t *)data;
7172

@@ -75,26 +76,26 @@ void *execution_task(void *data)
7576
break;
7677
}
7778
res = waitpid(service->daemon_pid, &status, WNOHANG);
78-
DBG("waitpid: pid=%d, status=%d, res=%d", service->daemon_pid, status, res);
79-
80-
if (res == -1) {
81-
ERR("waitpid: res=%d", res);
82-
break;
83-
}
8479

85-
if (WIFEXITED(status)) {
86-
INFO("Child status: exited, status=%d\n", WEXITSTATUS(status));
87-
} else if (WIFSIGNALED(status)) {
88-
INFO("Child status: killed by signal %d\n", WTERMSIG(status));
89-
} else if (WIFSTOPPED(status)) {
90-
INFO("Child status: stopped by signal %d\n", WSTOPSIG(status));
91-
} else if (WIFCONTINUED(status)) {
92-
INFO("Child status: continued\n");
80+
if (res == service->daemon_pid) {
81+
if (WIFEXITED(status)) {
82+
INFO("Child status: exited, status=%d\n", WEXITSTATUS(status));
83+
run_loop = false;
84+
} else if (WIFSIGNALED(status)) {
85+
INFO("Child status: killed by signal %d\n", WTERMSIG(status));
86+
run_loop = false;
87+
} else if (WIFSTOPPED(status)) {
88+
INFO("Child status: stopped by signal %d\n", WSTOPSIG(status));
89+
} else if (WIFCONTINUED(status)) {
90+
INFO("Child status: continued\n");
91+
}
92+
} else if (res == -1) {
93+
ERR("waitpid: res=%d", res);
94+
run_loop = false;
95+
} else {
96+
usleep(500 * 1000); // 500ms
9397
}
94-
95-
usleep(200 * 1000); // 200ms
96-
97-
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
98+
} while (run_loop);
9899

99100
service->daemon_pid = 0;
100101
return NULL;
@@ -215,7 +216,7 @@ bool service_method_start(LSHandle* sh, LSMessage* msg, void* data)
215216
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Precondition fail: Not running elevated!"));
216217
break;
217218
case 2:
218-
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Hyperion.NG was already running"));
219+
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Hyperion.NG is already running"));
219220
break;
220221
case 3:
221222
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Hyperion.NG failed to start, posix_spawn failed"));
@@ -250,7 +251,7 @@ bool service_method_stop(LSHandle* sh, LSMessage* msg, void* data)
250251
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Precondition fail: Not running elevated!"));
251252
break;
252253
case 2:
253-
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Hyperion.NG was not running"));
254+
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Hyperion.NG is not running"));
254255
break;
255256
default:
256257
jobject_set(jobj, j_cstr_to_buffer("status"), jstring_create("Hyperion.NG failed to stop, reason: Unknown"));
@@ -345,6 +346,7 @@ int main()
345346
service.hyperiond_version = NULL;
346347

347348
log_init();
349+
log_set_level(Debug);
348350
LSErrorInit(&lserror);
349351

350352
// create a GMainLoop
@@ -359,7 +361,7 @@ int main()
359361
}
360362

361363
if (!registered) {
362-
ERR("Failed luna-service registration!");
364+
ERR("Unable to register on Luna bus: %s", lserror.message);
363365
LSErrorFree(&lserror);
364366
return -1;
365367
}

0 commit comments

Comments
 (0)