From e039e689e3c4baefb4b62703429aaf86eef1bd99 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Mon, 26 Oct 2009 23:29:03 +0100 Subject: wall: new applet text data bss dec hex filename 81 0 0 81 51 miscutils/wall.o Signed-off-by: Bernhard Reutner-Fischer Signed-off-by: Denys Vlasenko --- miscutils/wall.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 miscutils/wall.c (limited to 'miscutils/wall.c') diff --git a/miscutils/wall.c b/miscutils/wall.c new file mode 100644 index 000000000..2dbab60b4 --- /dev/null +++ b/miscutils/wall.c @@ -0,0 +1,36 @@ +/* vi: set sw=4 ts=4: */ +/* + * wall - write a message to all logged-in users + * Copyright (c) 2009 Bernhard Reutner-Fischer + * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ + +#include "libbb.h" +#include + +int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int wall_main(int argc UNUSED_PARAM, char **argv) +{ + struct utmp *ut; + char *msg; + int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO; + + msg = xmalloc_read(fd, NULL); + if (ENABLE_FEATURE_CLEAN_UP && argv[1]) + close(fd); + setutent(); + while ((ut = getutent()) != NULL) { + char *line; + if (ut->ut_type != USER_PROCESS) + continue; + line = concat_path_file("/dev", ut->ut_line); + xopen_xwrite_close(line, msg); + free(line); + } + if (ENABLE_FEATURE_CLEAN_UP) { + endutent(); + free(msg); + } + return EXIT_SUCCESS; +} -- cgit v1.2.3