diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-01-10 10:55:27 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-01-10 10:55:27 +0200 |
commit | 31b05ff79914a6903bda172af9580afc394e9271 (patch) | |
tree | 6a03395c4c70003287b080341856aba78229c13b | |
parent | fc696a834573e65c184ecbcd78e70f67d78e861d (diff) | |
download | pies-31b05ff79914a6903bda172af9580afc394e9271.tar.gz pies-31b05ff79914a6903bda172af9580afc394e9271.tar.bz2 |
Improvements in init mode
* src/progman.c (print_status): Suppress output if running
as init process, unless in debug mode.
* src/sysvinit.c (sysvinit_begin): Set up "non-failing"
memory allocation.
-rw-r--r-- | src/progman.c | 55 | ||||
-rw-r--r-- | src/sysvinit.c | 45 |
2 files changed, 74 insertions, 26 deletions
diff --git a/src/progman.c b/src/progman.c index eb7b70f..81b97ff 100644 --- a/src/progman.c +++ b/src/progman.c @@ -1938,46 +1938,49 @@ progman_stop () static void print_status (const char *tag, pid_t pid, int status, int expect_term) { + int prio; + + if (init_process) + { + if (debug_level <= 1) + return; + prio = LOG_DEBUG; + } + else + prio = LOG_ERR; + if (WIFEXITED (status)) { if (WEXITSTATUS (status) == 0) debug (1, (_("%s (%lu) exited successfully"), tag, (unsigned long) pid)); else - logmsg (LOG_ERR, - _("%s (%lu) failed with status %d"), - tag, (unsigned long) pid, - WEXITSTATUS (status)); + logmsg (prio, _("%s (%lu) exited with status %d"), + tag, (unsigned long) pid, + WEXITSTATUS (status)); } else if (WIFSIGNALED (status)) { - int prio; - + char const *coremsg = ""; + if (expect_term && WTERMSIG (status) == SIGTERM) prio = LOG_DEBUG; - else - prio = LOG_ERR; - logmsg (prio, - _("%s (%lu) terminated on signal %d"), - tag, (unsigned long) pid, - WTERMSIG (status)); - } - else if (WIFSTOPPED (status)) - logmsg (LOG_ERR, - _("%s (%lu) stopped on signal %d"), - tag, (unsigned long) pid, - WSTOPSIG (status)); #ifdef WCOREDUMP - else if (WCOREDUMP (status)) - logmsg (LOG_ERR, - _("%s (%lu) dumped core"), - tag, (unsigned long) pid); + if (WCOREDUMP (status)) + coremsg = _(" (core dumped)"); #endif + logmsg (prio, _("%s (%lu) terminated on signal %d%s"), + tag, (unsigned long) pid, + WTERMSIG (status), coremsg); + } + else if (WIFSTOPPED (status)) + logmsg (prio, _("%s (%lu) stopped on signal %d"), + tag, (unsigned long) pid, + WSTOPSIG (status)); else - logmsg (LOG_ERR, - _("%s (%lu) terminated with unrecognized status"), - tag, (unsigned long) pid); + logmsg (prio, _("%s (%lu) terminated with unrecognized status: %d"), + tag, (unsigned long) pid, status); } static void propagate_child_exit (pid_t) ATTRIBUTE_NORETURN; @@ -2431,7 +2434,7 @@ progman_cleanup (int expect_term) struct prog *prog = prog_lookup_by_pid (pid); if (!prog) { - print_status (_("subprocess"), pid, status, expect_term); + print_status (_("unknown child"), pid, status, expect_term); continue; } prog->pid = 0; diff --git a/src/sysvinit.c b/src/sysvinit.c index 965bce2..375a0d5 100644 --- a/src/sysvinit.c +++ b/src/sysvinit.c @@ -572,6 +572,48 @@ sysvinit_sigtrans (int sig, int *pact) return 1; } +static void +unintr_sleep (unsigned n) +{ + struct timeval tv; + + tv.tv_sec = n; + tv.tv_usec = 0; + + while (select (0, NULL, NULL, NULL, &tv) < 0 && errno == EINTR) + ; +} + +/* Memory allocation functions for INIT. They may not fail, therefore + they just retry allocation until it eventually succeeds. +*/ + +static void * +sysvinit_malloc (size_t size) +{ + void *p; + + while (!(p = malloc (size))) + { + logmsg (LOG_ERR, _("out of memory")); + unintr_sleep (5); + } + return p; +} + +static void * +sysvinit_realloc (void *ptr, size_t size) +{ + void *p; + + while (!(p = realloc (ptr, size))) + { + logmsg (LOG_ERR, _("out of memory")); + unintr_sleep (5); + } + return p; +} + void sysvinit_begin () { @@ -580,6 +622,9 @@ sysvinit_begin () SIGPWR, SIGWINCH, }; + + grecs_malloc_fun = sysvinit_malloc; + grecs_realloc_fun = sysvinit_realloc; close (0); close (1); |