summaryrefslogtreecommitdiff
path: root/src/shutdown/hpr_wallv.c
blob: 083fa7f520124ecacaf6b73b67e8e8e4a42dd490 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ISC license. */

#include <string.h>
#include <sys/uio.h>
#include <utmpx.h>

#include <skalibs/allreadwrite.h>
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
#include <skalibs/posixishard.h>

#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() ;
}