Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * mesg implementation for busybox |
| 3 | * |
| 4 | * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <unistd.h> |
| 22 | #include <stdlib.h> |
"Vladimir N. Oleynik" | ba24820 | 2005-10-06 15:18:09 +0000 | [diff] [blame] | 23 | #include "busybox.h" |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 24 | |
| 25 | #ifdef USE_TTY_GROUP |
| 26 | #define S_IWGRP_OR_S_IWOTH S_IWGRP |
| 27 | #else |
| 28 | #define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH) |
| 29 | #endif |
| 30 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 31 | int mesg_main(int argc, char *argv[]) |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 32 | { |
| 33 | struct stat sb; |
| 34 | char *tty; |
Eric Andersen | 7850014 | 2004-08-27 19:55:28 +0000 | [diff] [blame] | 35 | char c = 0; |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 36 | |
| 37 | if ((--argc == 0) |
| 38 | || ((argc == 1) && (((c = **++argv) == 'y') || (c == 'n')))) { |
| 39 | if ((tty = ttyname(STDERR_FILENO)) == NULL) { |
| 40 | tty = "ttyname"; |
| 41 | } else if (stat(tty, &sb) == 0) { |
| 42 | if (argc == 0) { |
| 43 | puts(((sb.st_mode & (S_IWGRP | S_IWOTH)) == |
| 44 | 0) ? "is n" : "is y"); |
| 45 | return EXIT_SUCCESS; |
| 46 | } |
| 47 | if (chmod |
| 48 | (tty, |
| 49 | (c == |
| 50 | 'y') ? sb.st_mode | (S_IWGRP_OR_S_IWOTH) : sb. |
| 51 | st_mode & ~(S_IWGRP | S_IWOTH)) == 0) { |
| 52 | return EXIT_SUCCESS; |
| 53 | } |
| 54 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 55 | bb_perror_msg_and_die("%s", tty); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 56 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 57 | bb_show_usage(); |
Glenn L McGrath | 061c900 | 2002-09-16 04:21:46 +0000 | [diff] [blame] | 58 | } |