diff --git a/src/openrc-shutdown/broadcast.c b/src/openrc-shutdown/broadcast.c index f21ee95c4..09d10632a 100644 --- a/src/openrc-shutdown/broadcast.c +++ b/src/openrc-shutdown/broadcast.c @@ -17,8 +17,6 @@ #include #include #include -#include -#include #include #include #include @@ -37,15 +35,6 @@ # define _PATH_DEV "/dev/" #endif -static sigjmp_buf jbuf; - -/* - * Alarm handler - */ -RC_NORETURN static void handler(int arg RC_UNUSED) -{ - siglongjmp(jbuf, 1); -} static void getuidtty(char **userp, char **ttyp) { @@ -123,16 +112,11 @@ void broadcast(char *text) char *date; char *p; char *line = NULL; - struct sigaction sa; int flags; char *term = NULL; struct utmpx *utmp; - /* - * These are set across the sigsetjmp call, so they can't be stored on - * the stack, otherwise they might be clobbered. - */ - static int fd; - static FILE *tp; + int fd; + FILE *tp; getuidtty(&user, &tty); @@ -159,11 +143,6 @@ void broadcast(char *text) if (fork() != 0) return; - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = handler; - sigemptyset(&sa.sa_mask); - sigaction(SIGALRM, &sa, NULL); - setutxent(); while ((utmp = getutxent()) != NULL) { @@ -178,25 +157,19 @@ void broadcast(char *text) continue; } - /* - * Open it non-delay - */ - if (sigsetjmp(jbuf, 1) == 0) { - alarm(2); - flags = O_WRONLY|O_NDELAY|O_NOCTTY; - if (file_isatty(term) && (fd = open(term, flags)) >= 0) { - if (isatty(fd) && (tp = fdopen(fd, "w")) != NULL) { - fputs(line, tp); - fputs(text, tp); - fflush(tp); - } + /* Request non-blocking I/O */ + flags = O_WRONLY|O_NONBLOCK|O_NOCTTY; + if (file_isatty(term) && (fd = open(term, flags)) >= 0) { + if (isatty(fd) && (tp = fdopen(fd, "w")) != NULL) { + alarm(2); /* Let the kernel kill us if write() blocks */ + fputs(line, tp); + fputs(text, tp); + fclose(tp); + alarm(0); } + else + close(fd); } - alarm(0); - if (fd >= 0) - close(fd); - if (tp != NULL) - fclose(tp); free(term); } endutxent();