diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-04-16 20:37:01 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-04-16 20:37:01 +0000 |
commit | 73cff35173dd75b0254ae7cf9098c32822859de0 (patch) | |
tree | fd1bb09611b2b7064967ca8d8b2aef98514e616b /src/shutdown/hpr_wall.c | |
parent | 5199738f4e32773f4f752a94998593e18e3af36f (diff) | |
download | s6-linux-init-73cff35173dd75b0254ae7cf9098c32822859de0.tar.xz |
It builds! Tomorrow: skeletons for stage2, stage3 and runlevel scripts.
Diffstat (limited to 'src/shutdown/hpr_wall.c')
-rw-r--r-- | src/shutdown/hpr_wall.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/shutdown/hpr_wall.c b/src/shutdown/hpr_wall.c new file mode 100644 index 0000000..cc6da5e --- /dev/null +++ b/src/shutdown/hpr_wall.c @@ -0,0 +1,47 @@ +/* ISC license. */ + +#include <string.h> +#include <errno.h> +#include <utmpx.h> + +#include <skalibs/posixishard.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/strerr2.h> +#include <skalibs/djbunix.h> + +#include "hpr.h" + +#ifndef UT_LINESIZE +#define UT_LINESIZE 32 +#endif + +void hpr_wall (char const *s) +{ + size_t n = strlen(s) ; + char tty[10 + UT_LINESIZE] = "/dev/" ; + char msg[n+1] ; + memcpy(msg, s, n) ; + msg[n++] = '\n' ; + setutxent() ; + for (;;) + { + size_t linelen, idlen ; + struct utmpx *utx ; + int fd ; + errno = 0 ; + utx = getutxent() ; + if (!utx) break ; + if (utx->ut_type != USER_PROCESS) continue ; + linelen = strnlen(utx->ut_line, UT_LINESIZE) ; + idlen = strnlen(utx->ut_id, 4) ; + memcpy(tty + 5, utx->ut_line, linelen) ; + memcpy(tty + 5 + linelen, utx->ut_id, idlen) ; + tty[5 + linelen + idlen] = 0 ; + fd = open_append(tty) ; + if (fd == -1) continue ; + allwrite(fd, msg, n) ; + fd_close(fd) ; + } + if (errno) strerr_warnwu1sys("getutxent") ; + endutxent() ; +} |