source: MondoRescue/branches/2.2.9/mindi-busybox/init/mesg.c@ 2729

Last change on this file since 2729 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.6 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * mesg implementation for busybox
4 *
5 * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
6 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]8 */
9
[2725]10//applet:IF_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
11
12//kbuild:lib-$(CONFIG_MESG) += mesg.o
13
14//config:config MESG
15//config: bool "mesg"
16//config: default y
17//config: help
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
20
21//usage:#define mesg_trivial_usage
22//usage: "[y|n]"
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"
27
[1765]28#include "libbb.h"
[821]29
30#ifdef USE_TTY_GROUP
[2725]31#define S_IWGRP_OR_S_IWOTH S_IWGRP
[821]32#else
[2725]33#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
[821]34#endif
35
[2725]36int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37int mesg_main(int argc UNUSED_PARAM, char **argv)
[821]38{
39 struct stat sb;
[1765]40 const char *tty;
[821]41 char c = 0;
42
[2725]43 argv++;
44
45 if (!argv[0]
46 || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n'))
[1765]47 ) {
[2725]48 tty = xmalloc_ttyname(STDERR_FILENO);
[1765]49 if (tty == NULL) {
[821]50 tty = "ttyname";
51 } else if (stat(tty, &sb) == 0) {
[1765]52 mode_t m;
[2725]53 if (c == 0) {
[1765]54 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
[821]55 return EXIT_SUCCESS;
56 }
[1765]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) {
[821]60 return EXIT_SUCCESS;
61 }
62 }
[2725]63 bb_simple_perror_msg_and_die(tty);
[821]64 }
65 bb_show_usage();
66}
Note: See TracBrowser for help on using the repository browser.