Rev | Line | |
---|
[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 | *
|
---|
| 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
---|
| 8 | */
|
---|
| 9 |
|
---|
[1765] | 10 | #include "libbb.h"
|
---|
[821] | 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 |
|
---|
[1765] | 18 | int mesg_main(int argc, char **argv);
|
---|
| 19 | int mesg_main(int argc, char **argv)
|
---|
[821] | 20 | {
|
---|
| 21 | struct stat sb;
|
---|
[1765] | 22 | const char *tty;
|
---|
[821] | 23 | char c = 0;
|
---|
| 24 |
|
---|
[1765] | 25 | if (--argc == 0
|
---|
| 26 | || (argc == 1 && ((c = **++argv) == 'y' || c == 'n'))
|
---|
| 27 | ) {
|
---|
| 28 | tty = ttyname(STDERR_FILENO);
|
---|
| 29 | if (tty == NULL) {
|
---|
[821] | 30 | tty = "ttyname";
|
---|
| 31 | } else if (stat(tty, &sb) == 0) {
|
---|
[1765] | 32 | mode_t m;
|
---|
[821] | 33 | if (argc == 0) {
|
---|
[1765] | 34 | puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
|
---|
[821] | 35 | return EXIT_SUCCESS;
|
---|
| 36 | }
|
---|
[1765] | 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) {
|
---|
[821] | 40 | return EXIT_SUCCESS;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | bb_perror_msg_and_die("%s", tty);
|
---|
| 44 | }
|
---|
| 45 | bb_show_usage();
|
---|
| 46 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.