aboutsummaryrefslogtreecommitdiff
path: root/util-linux/wall.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-12 13:58:40 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-12 13:58:40 +0200
commit783d57af7bb2b851c16cf87df848e0365e5052da (patch)
tree71bb23e51b9cb40eac4a6fb831383134c1fc45a0 /util-linux/wall.c
parentac47a00e2ec398b04c3141cd3434a6e4b95740b1 (diff)
downloadbusybox-783d57af7bb2b851c16cf87df848e0365e5052da.tar.gz
Sort some miscutils/ applets into coreutils or util-linux
No code changes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/wall.c')
-rw-r--r--util-linux/wall.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/util-linux/wall.c b/util-linux/wall.c
new file mode 100644
index 000000000..50658f457
--- /dev/null
+++ b/util-linux/wall.c
@@ -0,0 +1,63 @@
+/* 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 source tree.
+ */
+
+//config:config WALL
+//config: bool "wall"
+//config: default y
+//config: depends on FEATURE_UTMP
+//config: help
+//config: Write a message to all users that are logged in.
+
+/* Needs to be run by root or be suid root - needs to write to /dev/TTY: */
+//applet:IF_WALL(APPLET(wall, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
+
+//kbuild:lib-$(CONFIG_WALL) += wall.o
+
+//usage:#define wall_trivial_usage
+//usage: "[FILE]"
+//usage:#define wall_full_usage "\n\n"
+//usage: "Write content of FILE or stdin to all logged-in users"
+//usage:
+//usage:#define wall_sample_usage
+//usage: "echo foo | wall\n"
+//usage: "wall ./mymessage"
+
+#include "libbb.h"
+
+int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int wall_main(int argc UNUSED_PARAM, char **argv)
+{
+ struct utmpx *ut;
+ char *msg;
+ int fd;
+
+ fd = STDIN_FILENO;
+ if (argv[1]) {
+ /* The applet is setuid.
+ * Access to the file must be under user's uid/gid.
+ */
+ fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid());
+ }
+ msg = xmalloc_read(fd, NULL);
+ if (ENABLE_FEATURE_CLEAN_UP && argv[1])
+ close(fd);
+ setutxent();
+ while ((ut = getutxent()) != 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) {
+ endutxent();
+ free(msg);
+ }
+ return EXIT_SUCCESS;
+}