mirror of
https://github.com/troglobit/finit.git
synced 2026-10-26 12:14:37 +00:00
Log execution order at bootstrap to /run/finit/exec.order
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
0d70023bfe
commit
1889b88aab
3 files changed
+59
-1
No files matched your search
+48
@@ -414,6 +414,54 @@ void conf_saverc(void)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called at bootstrap to log execution order (for debug)
|
||||
*/
|
||||
void conf_save_exec_order(svc_t *svc, char *cmdline, int result)
|
||||
{
|
||||
const char *fn = _PATH_VARRUN "finit/exec.order";
|
||||
const char *ststr = !result ? "[ OK ]" : "[FAIL]";
|
||||
static char *prepared = NULL;
|
||||
int first = !fexist(fn);
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(fn, "a+");
|
||||
if (!fp) {
|
||||
err(1, "failed writing to %s", fn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (first) {
|
||||
fprintf(fp, "# Execution order of run/task/services at bootstrap\n");
|
||||
fprintf(fp, "# ST TYPE COMMAND LINE (DESC)\n");
|
||||
}
|
||||
|
||||
if (result == -1) {
|
||||
int len;
|
||||
|
||||
len = snprintf(NULL, 0, " %-7s %-64s (%s)", svc_typestr(svc), cmdline, svc->desc);
|
||||
if (len > 0) {
|
||||
if (prepared)
|
||||
free(prepared);
|
||||
prepared = malloc(++len);
|
||||
if (!prepared)
|
||||
return;
|
||||
snprintf(prepared, len, " %-7s %-64s (%s)", svc_typestr(svc), cmdline, svc->desc);
|
||||
}
|
||||
} else {
|
||||
if (prepared) {
|
||||
memcpy(prepared, ststr, strlen(ststr));
|
||||
fprintf(fp, "%s\n", prepared);
|
||||
free(prepared);
|
||||
prepared = NULL;
|
||||
} else {
|
||||
fprintf(fp, "%s %-7s %-64s (%s)\n", ststr, svc_typestr(svc), cmdline, svc->desc);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets, and makes a note of, all KEY=VALUE lines in a given .conf line
|
||||
* from finit.conf, or other .conf file. Note, PATH is always reset in
|
||||
|
||||
@@ -44,6 +44,7 @@ int conf_monitor (void);
|
||||
|
||||
void conf_reset_env (void);
|
||||
void conf_saverc (void);
|
||||
void conf_save_exec_order (svc_t *svc, char *cmdline, int result);
|
||||
void conf_parse_cmdline (int argc, char *argv[]);
|
||||
int conf_parse_runlevels (char *runlevels);
|
||||
void conf_parse_cond (svc_t *svc, char *cond);
|
||||
|
||||
+10
-1
@@ -629,6 +629,9 @@ static int service_start(svc_t *svc)
|
||||
}
|
||||
|
||||
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
||||
if (bootstrap)
|
||||
conf_save_exec_order(svc, cmdline, -1);
|
||||
|
||||
if (svc_is_sysv(svc))
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", cmdline);
|
||||
|
||||
@@ -838,6 +841,8 @@ fail:
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
if (do_progress && !run_block_pid)
|
||||
print_result(result);
|
||||
if (bootstrap && !run_block_pid)
|
||||
conf_save_exec_order(svc, NULL, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1896,10 +1901,14 @@ done:
|
||||
svc->start_time = svc->pid = 0;
|
||||
cont:
|
||||
if (lost == run_block_pid) {
|
||||
int result = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
|
||||
|
||||
svc_mark_clean(svc); /* done, regardless of exit status */
|
||||
run_block_pid = 0;
|
||||
if (svc->desc[0])
|
||||
print_result(WIFEXITED(status) ? WEXITSTATUS(status) : 1);
|
||||
print_result(result);
|
||||
if (bootstrap)
|
||||
conf_save_exec_order(svc, NULL, result);
|
||||
}
|
||||
|
||||
if (!service_step(svc)) {
|
||||
|
||||
Reference in new issue
Block a user