wall: new applet
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Mon, 26 Oct 2009 22:29:03 +0000 (23:29 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 27 Oct 2009 16:34:36 +0000 (17:34 +0100)
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>
include/applets.h
include/usage.h
miscutils/Config.in
miscutils/Kbuild
miscutils/wall.c [new file with mode: 0644]
scripts/defconfig

index 134f21e2fc253faead4a4a4fc41b0babe3911dd8..9683f1ec81bd2b219eff226909b412444f20532e 100644 (file)
@@ -417,6 +417,7 @@ IF_VCONFIG(APPLET(vconfig, _BB_DIR_SBIN, _BB_SUID_DROP))
 IF_VI(APPLET(vi, _BB_DIR_BIN, _BB_SUID_DROP))
 IF_VLOCK(APPLET(vlock, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
 IF_VOLNAME(APPLET(volname, _BB_DIR_USR_BIN, _BB_SUID_DROP))
+IF_WALL(APPLET(wall, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
 IF_WATCH(APPLET(watch, _BB_DIR_BIN, _BB_SUID_DROP))
 IF_WATCHDOG(APPLET(watchdog, _BB_DIR_SBIN, _BB_SUID_DROP))
 IF_WC(APPLET(wc, _BB_DIR_USR_BIN, _BB_SUID_DROP))
index 93eb2f6ba94c510744a33be60f56eec72fb547ad..72b6acc47b200c0aacd764eb6a40157ef6a24356 100644 (file)
 #define volname_full_usage "\n\n" \
        "Show CD volume name of the DEVICE (default /dev/cdrom)"
 
+#define wall_trivial_usage \
+       "[file]"
+#define wall_full_usage "\n\n" \
+       "Write content of file or standard-input to all logged-in users"
+#define wall_sample_usage \
+       "echo foo | wall\n" \
+       "wall ./mymessage"
+
 #define watch_trivial_usage \
        "[-n seconds] [-t] PROG [ARGS]"
 #define watch_full_usage "\n\n" \
index 9b804889bad73e28c3161ce200cf1709b348cba7..842f7f9d2178f962bbc4ccbb7b9003a36da29973 100644 (file)
@@ -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
index d88cb39ac05a361f2e9b73be8fa9cd2eefa19885..22a9adb347d4793db931256826d27a6217ec379e 100644 (file)
@@ -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 (file)
index 0000000..2dbab60
--- /dev/null
@@ -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;
+}
index 797f275d1929736a90cb208d0924ad852c1163fb..f8a92d4c30a0d6857d507a580f570585c27fd0fd 100644 (file)
@@ -638,6 +638,7 @@ CONFIG_TIME=y
 CONFIG_TIMEOUT=y
 CONFIG_TTYSIZE=y
 CONFIG_VOLNAME=y
+CONFIG_WALL=y
 CONFIG_WATCHDOG=y
 
 #