summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer2009-10-26 23:29:03 +0100
committerDenys Vlasenko2009-10-27 17:34:36 +0100
commite039e689e3c4baefb4b62703429aaf86eef1bd99 (patch)
tree41d75770e7e1bb36a2662fa9c273ab4c806dc3c3 /miscutils
parenta48308701a4d89d7cc0d0557cfabaec94a0bb3b0 (diff)
downloadbusybox-e039e689e3c4baefb4b62703429aaf86eef1bd99.zip
busybox-e039e689e3c4baefb4b62703429aaf86eef1bd99.tar.gz
wall: new applet
text data bss dec hex filename 81 0 0 81 51 miscutils/wall.o Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/Config.in6
-rw-r--r--miscutils/Kbuild1
-rw-r--r--miscutils/wall.c36
3 files changed, 43 insertions, 0 deletions
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 9b80488..842f7f9 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -612,6 +612,12 @@ config VOLNAME
help
Prints a CD-ROM volume name.
+config WALL
+ bool "wall"
+ default n
+ help
+ Write a message to all users that are logged in.
+
config WATCHDOG
bool "watchdog"
default n
diff --git a/miscutils/Kbuild b/miscutils/Kbuild
index d88cb39..22a9adb 100644
--- a/miscutils/Kbuild
+++ b/miscutils/Kbuild
@@ -42,4 +42,5 @@ lib-$(CONFIG_TIME) += time.o
lib-$(CONFIG_TIMEOUT) += timeout.o
lib-$(CONFIG_TTYSIZE) += ttysize.o
lib-$(CONFIG_VOLNAME) += volname.o
+lib-$(CONFIG_WALL) += wall.o
lib-$(CONFIG_WATCHDOG) += watchdog.o
diff --git a/miscutils/wall.c b/miscutils/wall.c
new file mode 100644
index 0000000..2dbab60
--- /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 <utmp.h>
+
+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;
+}