runlevel/wall: depend on utmp feature
[platform/upstream/busybox.git] / miscutils / wall.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * wall - write a message to all logged-in users
4  * Copyright (c) 2009 Bernhard Reutner-Fischer
5  *
6  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7  */
8
9 #include "libbb.h"
10
11 int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
12 int wall_main(int argc UNUSED_PARAM, char **argv)
13 {
14         struct utmp *ut;
15         char *msg;
16         int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
17
18         msg = xmalloc_read(fd, NULL);
19         if (ENABLE_FEATURE_CLEAN_UP && argv[1])
20                 close(fd);
21         setutent();
22         while ((ut = getutent()) != NULL) {
23                 char *line;
24                 if (ut->ut_type != USER_PROCESS)
25                         continue;
26                 line = concat_path_file("/dev", ut->ut_line);
27                 xopen_xwrite_close(line, msg);
28                 free(line);
29         }
30         if (ENABLE_FEATURE_CLEAN_UP) {
31                 endutent();
32                 free(msg);
33         }
34         return EXIT_SUCCESS;
35 }