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 | #include <unistd.h> |
| 12 | #include <stdlib.h> |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 13 | |
| 14 | #ifdef USE_TTY_GROUP |
| 15 | #define S_IWGRP_OR_S_IWOTH S_IWGRP |
| 16 | #else |
| 17 | #define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH) |
| 18 | #endif |
| 19 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 20 | int mesg_main(int argc, char *argv[]) |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 21 | { |
| 22 | struct stat sb; |
| 23 | char *tty; |
Eric Andersen | 7850014 | 2004-08-27 19:55:28 +0000 | [diff] [blame] | 24 | char c = 0; |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 25 | |
| 26 | if ((--argc == 0) |
| 27 | || ((argc == 1) && (((c = **++argv) == 'y') || (c == 'n')))) { |
| 28 | if ((tty = ttyname(STDERR_FILENO)) == NULL) { |
| 29 | tty = "ttyname"; |
| 30 | } else if (stat(tty, &sb) == 0) { |
| 31 | if (argc == 0) { |
| 32 | puts(((sb.st_mode & (S_IWGRP | S_IWOTH)) == |
| 33 | 0) ? "is n" : "is y"); |
| 34 | return EXIT_SUCCESS; |
| 35 | } |
| 36 | if (chmod |
| 37 | (tty, |
| 38 | (c == |
| 39 | 'y') ? sb.st_mode | (S_IWGRP_OR_S_IWOTH) : sb. |
| 40 | st_mode & ~(S_IWGRP | S_IWOTH)) == 0) { |
| 41 | return EXIT_SUCCESS; |
| 42 | } |
| 43 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 44 | bb_perror_msg_and_die("%s", tty); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 45 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 46 | bb_show_usage(); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 47 | } |