From f94e976efbdfdd885ecc81745542bedf315768fd Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 12 Feb 2021 18:17:50 +0000 Subject: bugfix: wall message on non-immediate shutdown(8) --- src/shutdown/hpr_wallv.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/shutdown/hpr_wallv.c (limited to 'src/shutdown/hpr_wallv.c') diff --git a/src/shutdown/hpr_wallv.c b/src/shutdown/hpr_wallv.c new file mode 100644 index 0000000..50523c5 --- /dev/null +++ b/src/shutdown/hpr_wallv.c @@ -0,0 +1,38 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include + +#include "hpr.h" + +#ifndef UT_LINESIZE +#define UT_LINESIZE 32 +#endif + +void hpr_wallv (struct iovec const *v, unsigned int n) +{ + char tty[10 + UT_LINESIZE] = "/dev/" ; + setutxent() ; + for (;;) + { + size_t linelen ; + int fd ; + struct utmpx *utx = getutxent() ; + if (!utx) break ; + if (utx->ut_type != USER_PROCESS) continue ; + linelen = strnlen(utx->ut_line, UT_LINESIZE) ; + memcpy(tty + 5, utx->ut_line, linelen) ; + tty[5 + linelen] = 0 ; + fd = open_append(tty) ; + if (fd == -1) continue ; + allwritev(fd, v, n) ; + fd_close(fd) ; + } + endutxent() ; +} -- cgit v1.2.3