@@ -48,7 +48,7 @@ int daemon_start(pid_t *pid)
48
48
asprintf (& env_armcap , "OPENSSL_armcap=%d" , 0 );
49
49
asprintf (& application_executable_path , "%s/hyperiond" , HYPERION_PATH );
50
50
51
- char * env_vars [] = {env_library_path , env_armcap , NULL };
51
+ char * env_vars [] = {env_library_path , env_armcap , "HOME=/home/root" , NULL };
52
52
char * argv [] = {application_executable_path , NULL };
53
53
54
54
res = posix_spawn (pid , application_executable_path , NULL , NULL , argv , env_vars );
@@ -66,6 +66,7 @@ void *execution_task(void *data)
66
66
{
67
67
int res = 0 ;
68
68
int status = 0 ;
69
+ bool run_loop = true;
69
70
70
71
service_t * service = (service_t * )data ;
71
72
@@ -75,26 +76,26 @@ void *execution_task(void *data)
75
76
break ;
76
77
}
77
78
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
- }
84
79
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
93
97
}
94
-
95
- usleep (200 * 1000 ); // 200ms
96
-
97
- } while (!WIFEXITED (status ) && !WIFSIGNALED (status ));
98
+ } while (run_loop );
98
99
99
100
service -> daemon_pid = 0 ;
100
101
return NULL ;
@@ -215,7 +216,7 @@ bool service_method_start(LSHandle* sh, LSMessage* msg, void* data)
215
216
jobject_set (jobj , j_cstr_to_buffer ("status" ), jstring_create ("Precondition fail: Not running elevated!" ));
216
217
break ;
217
218
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" ));
219
220
break ;
220
221
case 3 :
221
222
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)
250
251
jobject_set (jobj , j_cstr_to_buffer ("status" ), jstring_create ("Precondition fail: Not running elevated!" ));
251
252
break ;
252
253
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" ));
254
255
break ;
255
256
default :
256
257
jobject_set (jobj , j_cstr_to_buffer ("status" ), jstring_create ("Hyperion.NG failed to stop, reason: Unknown" ));
@@ -345,6 +346,7 @@ int main()
345
346
service .hyperiond_version = NULL ;
346
347
347
348
log_init ();
349
+ log_set_level (Debug );
348
350
LSErrorInit (& lserror );
349
351
350
352
// create a GMainLoop
@@ -359,7 +361,7 @@ int main()
359
361
}
360
362
361
363
if (!registered ) {
362
- ERR ("Failed luna-service registration!" );
364
+ ERR ("Unable to register on Luna bus: %s" , lserror . message );
363
365
LSErrorFree (& lserror );
364
366
return -1 ;
365
367
}
0 commit comments