From 6dbe3af945a63f025561abb83275cee9ff06c57b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Dec 2006 00:25:32 +0100 Subject: Imported from util-linux-2.2 tarball. --- login-utils/mesg.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 login-utils/mesg.c (limited to 'login-utils/mesg.c') diff --git a/login-utils/mesg.c b/login-utils/mesg.c new file mode 100644 index 000000000..07c5fad1f --- /dev/null +++ b/login-utils/mesg.c @@ -0,0 +1,44 @@ +/* + * mesg.c The "mesg" utility. Gives / restrict access to + * your terminal by others. + * + * Usage: mesg [y|n]. + * Without arguments prints out the current settings. + */ +#include +#include +#include +#include +#include + +char *Version = "@(#) mesg 1.0 08-12-92 MvS"; + +int main(int argc, char **argv) +{ + struct stat st; + + if (!isatty(0)) { + /* Or should we look in /etc/utmp? */ + fprintf(stderr, "stdin: is not a tty"); + return(1); + } + + if (fstat(0, &st) < 0) { + perror("fstat"); + return(1); + } + if (argc < 2) { + printf("Is %s\n", ((st.st_mode & 022) == 022) ? "y" : "n"); + return(0); + } + if (argc > 2 || (argv[1][0] != 'y' && argv[1][0] != 'n')) { + fprintf(stderr, "Usage: mesg [y|n]\n"); + return(1); + } + if (argv[1][0] == 'y') + st.st_mode |= 022; + else + st.st_mode &= ~022; + fchmod(0, st.st_mode); + return(0); +} -- cgit v1.2.3-55-g7522