blob: 7e47644c3e0c24dbaa8e1aba80c7760c040a9be8 [file] [log] [blame]
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath061c9002002-09-16 04:21:46 +00002/*
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +00003 * mesg implementation for busybox
Glenn L McGrath061c9002002-09-16 04:21:46 +00004 *
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +00005 * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
Glenn L McGrath061c9002002-09-16 04:21:46 +00006 *
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +00007 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Glenn L McGrath061c9002002-09-16 04:21:46 +00008 */
9
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000010#include "busybox.h"
Glenn L McGrath061c9002002-09-16 04:21:46 +000011#include <unistd.h>
12#include <stdlib.h>
Glenn L McGrath061c9002002-09-16 04:21:46 +000013
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 Landleydfba7412006-03-06 20:47:33 +000020int mesg_main(int argc, char *argv[])
Glenn L McGrath061c9002002-09-16 04:21:46 +000021{
22 struct stat sb;
23 char *tty;
Eric Andersen78500142004-08-27 19:55:28 +000024 char c = 0;
Glenn L McGrath061c9002002-09-16 04:21:46 +000025
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 cad53642003-03-19 09:13:01 +000044 bb_perror_msg_and_die("%s", tty);
Glenn L McGrath061c9002002-09-16 04:21:46 +000045 }
Manuel Novoa III cad53642003-03-19 09:13:01 +000046 bb_show_usage();
Glenn L McGrath061c9002002-09-16 04:21:46 +000047}