]>
Commit | Line | Data |
---|---|---|
726f69e2 KZ |
1 | /* |
2 | * mesg.c The "mesg" utility. Gives / restrict access to | |
3 | * your terminal by others. | |
4 | * | |
5 | * Usage: mesg [y|n]. | |
6 | * Without arguments prints out the current settings. | |
7 | */ | |
8 | #include <stdio.h> | |
9 | #include <sys/stat.h> | |
10 | #include <stdlib.h> | |
11 | #include <errno.h> | |
12 | #include <unistd.h> | |
13 | ||
14 | char *Version = "@(#) mesg 1.0 08-12-92 MvS"; | |
15 | ||
16 | int main(int argc, char **argv) | |
17 | { | |
18 | struct stat st; | |
19 | ||
20 | if (!isatty(0)) { | |
21 | /* Or should we look in /etc/utmp? */ | |
22 | fprintf(stderr, "stdin: is not a tty"); | |
23 | return(1); | |
24 | } | |
25 | ||
26 | if (fstat(0, &st) < 0) { | |
27 | perror("fstat"); | |
28 | return(1); | |
29 | } | |
30 | if (argc < 2) { | |
31 | printf("Is %s\n", ((st.st_mode & 022) == 022) ? "y" : "n"); | |
32 | return(0); | |
33 | } | |
34 | if (argc > 2 || (argv[1][0] != 'y' && argv[1][0] != 'n')) { | |
35 | fprintf(stderr, "Usage: mesg [y|n]\n"); | |
36 | return(1); | |
37 | } | |
38 | if (argv[1][0] == 'y') | |
39 | st.st_mode |= 022; | |
40 | else | |
41 | st.st_mode &= ~022; | |
42 | fchmod(0, st.st_mode); | |
43 | return(0); | |
44 | } |