From 009d7247e4a491f6f3324d3f99e4198d92ef64c7 Mon Sep 17 00:00:00 2001 From: Werner Fink Date: Tue, 23 Feb 2010 12:26:26 +0000 Subject: [PATCH] * Set SHELL to /bin/sh in the environmant of shutdown. * Retry to write out shutdown messages if interrupted. --- doc/Changelog | 2 ++ src/shutdown.c | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 858471b..e800bea 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -9,6 +9,8 @@ to flush data and send them the ATA standby command. This should avoid data loss on USB sticks and other removable block devices. * Flush block devices on halt/reboot if not done by the kernel. + * Set SHELL to /bin/sh in the environmant of shutdown. + * Retry to write out shutdown messages if interrupted. sysvinit (2.88dsf) UNRELEASED; urgency=low diff --git a/src/shutdown.c b/src/shutdown.c index 84f99f1..3ec0341 100644 --- a/src/shutdown.c +++ b/src/shutdown.c @@ -71,6 +71,7 @@ char *clean_env[] = { "HOME=/", "PATH=/bin:/usr/bin:/sbin:/usr/sbin", "TERM=dumb", + "SHELL=/bin/sh", NULL, }; @@ -166,22 +167,34 @@ int init_setenv(char *name, char *value) sa.sa_handler = alrm_handler; sigaction(SIGALRM, &sa, NULL); got_alrm = 0; - alarm(3); - if ((fd = open(INIT_FIFO, O_WRONLY)) >= 0 && - write(fd, &request, sizeof(request)) == sizeof(request)) { - close(fd); - alarm(0); - return 0; - } + alarm(3); + if ((fd = open(INIT_FIFO, O_WRONLY)) >= 0) { && + ssize_t p = 0; + size_t s = sizeof(request); + void *ptr = &request; + while (s > 0) { + p = write(fd, ptr, s); + if (p < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + break; + } + ptr += p; + s -= p; + } + close(fd); + alarm(0); + return 0; + } - fprintf(stderr, "shutdown: "); - if (got_alrm) { - fprintf(stderr, "timeout opening/writing control channel %s\n", - INIT_FIFO); - } else { - perror(INIT_FIFO); - } - return -1; + fprintf(stderr, "shutdown: "); + if (got_alrm) { + fprintf(stderr, "timeout opening/writing control channel %s\n", + INIT_FIFO); + } else { + perror(INIT_FIFO); + } + return -1; }