[BusyBox] added command "mesg" to busybox
Da Chen
dchen at ayrnetworks.com
Tue Apr 30 13:03:03 UTC 2002
Hi,
I added linux command "mesg" to busybox to enable or disable
your terminal to receive message. Here is the patch and file mesg.c.
mesg.c is in directory "shellutils". I will add command "write" next
time.
Please review it. Thanks.
Da Chen
-------------- next part --------------
/* vi: set sw=4 ts=4: */
/*
* Mini mesg -- control write access to terminal.
*
* Ported to busybox by Da Chen <dchen at ayrnetworks.com>
* Copyright (c) 2002 AYR Networks, Inc.
*
* This is a free document; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation:
* http://www.gnu.org/copyleft/gpl.html
*
* Modified Fri Mar 10 20:27:19 1995, faith at cs.unc.edu, for Linux
* Modified Mon Jul 1 18:14:10 1996, janl at ifi.uio.no, writing to stdout
* as suggested by Michael Meskes <meskes at Informatik.RWTH-Aachen.DE>
*
* 1999-02-22 Arkadiusz Mi?kiewicz <misiek at pld.ORG.PL>
* - added Native Language Support
*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "busybox.h"
extern int mesg_main(int argc, char *argv[])
{
struct stat sb;
char *tty;
int ch;
while ((ch = getopt(argc, argv, "")) != EOF)
switch (ch) {
case '?':
default: show_usage();
}
argc -= optind;
argv += optind;
if ((tty = ttyname(STDERR_FILENO)) == NULL)
perror_msg("ttyname");
if (stat(tty, &sb) < 0)
perror_msg("%s", tty);
if (*argv == NULL) {
if (sb.st_mode & (S_IWGRP | S_IWOTH)) {
fprintf(stdout, "is y\n");
exit (1);
} else {
fprintf(stdout,"is n\n");
exit (2);
}
}
switch (*argv[0]) {
case 'y':
#ifdef USE_TTY_GROUP
if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
perror_msg("%s", tty);
#else
if (chmod(tty, sb.st_mode | S_IWGRP | S_IWOTH) < 0)
perror_msg("%s", tty);
#endif
exit(0);
case 'n':
if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0)
perror_msg("%s", tty);
exit(1);
default: show_usage();
}
return (0);
}
-------------- next part --------------
? ID
? mesg.patch
? shellutils/mesg.c
Index: include/applets.h
===================================================================
RCS file: /var/cvs/busybox/include/applets.h,v
retrieving revision 1.56
diff -b -w -u -r1.56 applets.h
--- include/applets.h 26 Apr 2002 23:53:08 -0000 1.56
+++ include/applets.h 30 Apr 2002 18:44:12 -0000
@@ -284,6 +284,9 @@
#ifdef CONFIG_MD5SUM
APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN)
#endif
+#ifdef CONFIG_MESG
+ APPLET(mesg, mesg_main, _BB_DIR_BIN)
+#endif
#ifdef CONFIG_MKDIR
APPLET(mkdir, mkdir_main, _BB_DIR_BIN)
#endif
Index: include/usage.h
===================================================================
RCS file: /var/cvs/busybox/include/usage.h,v
retrieving revision 1.90
diff -b -w -u -r1.90 usage.h
--- include/usage.h 27 Apr 2002 01:31:43 -0000 1.90
+++ include/usage.h 30 Apr 2002 18:44:13 -0000
@@ -1114,6 +1114,11 @@
"busybox: OK\n" \
"^D\n"
+#define mesg_trivial_usage \
+ "[y | n]"
+#define mesg_full_usage \
+ "\tcontrol write access to your terminal"
+
#define mkdir_trivial_usage \
"[OPTION] DIRECTORY..."
#define mkdir_full_usage \
Index: shellutils/Makefile.in
===================================================================
RCS file: /var/cvs/busybox/shellutils/Makefile.in,v
retrieving revision 1.2
diff -b -w -u -r1.2 Makefile.in
--- shellutils/Makefile.in 26 Apr 2002 23:53:09 -0000 1.2
+++ shellutils/Makefile.in 30 Apr 2002 18:44:13 -0000
@@ -36,6 +36,7 @@
SHELLUTILS-$(CONFIG_HOSTID) += hostid.o
SHELLUTILS-$(CONFIG_ID) += id.o
SHELLUTILS-$(CONFIG_LOGNAME) += logname.o
+SHELLUTILS-$(CONFIG_MESG) += mesg.o
SHELLUTILS-$(CONFIG_PRINTF) += printf.o
SHELLUTILS-$(CONFIG_PWD) += pwd.o
SHELLUTILS-$(CONFIG_SLEEP) += sleep.o
Index: shellutils/config.in
===================================================================
RCS file: /var/cvs/busybox/shellutils/config.in,v
retrieving revision 1.5
diff -b -w -u -r1.5 config.in
--- shellutils/config.in 26 Apr 2002 23:53:10 -0000 1.5
+++ shellutils/config.in 30 Apr 2002 18:44:13 -0000
@@ -19,6 +19,7 @@
bool 'hostid' CONFIG_HOSTID
bool 'id' CONFIG_ID
bool 'logname' CONFIG_LOGNAME
+bool 'mesg' CONFIG_MESG
bool 'printf' CONFIG_PRINTF
bool 'pwd' CONFIG_PWD
bool 'sleep' CONFIG_SLEEP
More information about the busybox
mailing list