aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-01-10 10:55:27 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-01-10 10:55:27 +0200
commit31b05ff79914a6903bda172af9580afc394e9271 (patch)
tree6a03395c4c70003287b080341856aba78229c13b /src
parentfc696a834573e65c184ecbcd78e70f67d78e861d (diff)
downloadpies-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.
Diffstat (limited to 'src')
-rw-r--r--src/progman.c55
-rw-r--r--src/sysvinit.c45
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
@@ -1935,52 +1935,55 @@ 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;
static void
propagate_child_exit (pid_t pid)
@@ -2428,13 +2431,13 @@ progman_cleanup (int expect_term)
int status;
while ((pid = waitpid (-1, &status, WNOHANG)) > 0)
{
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;
switch (prog->type)
{
case TYPE_COMPONENT:
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 965bce2..375a0d5 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -569,20 +569,65 @@ sysvinit_sigtrans (int sig, int *pact)
default:
return 0;
}
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 ()
{
int sigv[] = {
SIGINT,
SIGPWR,
SIGWINCH,
};
+
+ grecs_malloc_fun = sysvinit_malloc;
+ grecs_realloc_fun = sysvinit_realloc;
close (0);
close (1);
close (2);
set_console_dev ();
console_stty ();

Return to:

Send suggestions and report system problems to the System administrator.