1 /* vi: set sw=4 ts=4: */
3 * mesg implementation for busybox
5 * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP))
12 //kbuild:lib-$(CONFIG_MESG) += mesg.o
18 //config: Mesg controls access to your terminal by others. It is typically
19 //config: used to allow or disallow other users to write to your terminal
21 //usage:#define mesg_trivial_usage
23 //usage:#define mesg_full_usage "\n\n"
24 //usage: "Control write access to your terminal\n"
25 //usage: " y Allow write access to your terminal\n"
26 //usage: " n Disallow write access to your terminal"
31 #define S_IWGRP_OR_S_IWOTH S_IWGRP
33 #define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
36 int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37 int mesg_main(int argc UNUSED_PARAM, char **argv)
46 || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n'))
48 tty = xmalloc_ttyname(STDERR_FILENO);
51 } else if (stat(tty, &sb) == 0) {
54 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
57 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
58 : sb.st_mode & ~(S_IWGRP|S_IWOTH);
59 if (chmod(tty, m) == 0) {
63 bb_simple_perror_msg_and_die(tty);