Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 2 | /* |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 3 | * mesg implementation for busybox |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 4 | * |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 5 | * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org> |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 6 | * |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 10 | #include "busybox.h" |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 11 | |
| 12 | #ifdef USE_TTY_GROUP |
| 13 | #define S_IWGRP_OR_S_IWOTH S_IWGRP |
| 14 | #else |
| 15 | #define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH) |
| 16 | #endif |
| 17 | |
Bernhard Reutner-Fischer | febe3c4 | 2007-04-04 20:52:03 +0000 | [diff] [blame] | 18 | int mesg_main(int argc, char **argv); |
| 19 | int mesg_main(int argc, char **argv) |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 20 | { |
| 21 | struct stat sb; |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 22 | const char *tty; |
Eric Andersen | 7850014 | 2004-08-27 19:55:28 +0000 | [diff] [blame] | 23 | char c = 0; |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 24 | |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 25 | if (--argc == 0 |
| 26 | || (argc == 1 && ((c = **++argv) == 'y' || c == 'n')) |
| 27 | ) { |
| 28 | tty = ttyname(STDERR_FILENO); |
| 29 | if (tty == NULL) { |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 30 | tty = "ttyname"; |
| 31 | } else if (stat(tty, &sb) == 0) { |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 32 | mode_t m; |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 33 | if (argc == 0) { |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 34 | puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 35 | return EXIT_SUCCESS; |
| 36 | } |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 37 | m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH |
| 38 | : sb.st_mode & ~(S_IWGRP|S_IWOTH); |
| 39 | if (chmod(tty, m) == 0) { |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 40 | return EXIT_SUCCESS; |
| 41 | } |
| 42 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 43 | bb_perror_msg_and_die("%s", tty); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 44 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 45 | bb_show_usage(); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 46 | } |