From 23fba266a9454ee6ca095b7f6eccf523f6526607 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 2 Mar 2019 09:41:24 +0000 Subject: Save pending changes in 1.0.0.0 branch --- src/state/hpr_wall.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/state/hpr_wall.c (limited to 'src/state/hpr_wall.c') diff --git a/src/state/hpr_wall.c b/src/state/hpr_wall.c new file mode 100644 index 0000000..cc6da5e --- /dev/null +++ b/src/state/hpr_wall.c @@ -0,0 +1,47 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include + +#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() ; +} -- cgit v1.2.3