blob: 0a2b89e5ece6d847a891b98d21b2b33cccce83fd [file] [log] [blame]
Bernhard Reutner-Fischere039e682009-10-26 23:29:03 +01001/* 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 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02006 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Bernhard Reutner-Fischere039e682009-10-26 23:29:03 +01007 */
8
9#include "libbb.h"
Bernhard Reutner-Fischere039e682009-10-26 23:29:03 +010010
11int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
12int 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}