diff options
author | Karel Zak | 2006-12-07 00:25:34 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:34 +0100 |
commit | fd6b7a7ffc50400704beb41d5a23af5f9edb1eed (patch) | |
tree | 997c0ca2abc018369babd7da59bcd0afe492068e /misc-utils | |
parent | Imported from util-linux-2.5 tarball. (diff) | |
download | kernel-qcow2-util-linux-fd6b7a7ffc50400704beb41d5a23af5f9edb1eed.tar.gz kernel-qcow2-util-linux-fd6b7a7ffc50400704beb41d5a23af5f9edb1eed.tar.xz kernel-qcow2-util-linux-fd6b7a7ffc50400704beb41d5a23af5f9edb1eed.zip |
Imported from util-linux-2.7.1 tarball.
Diffstat (limited to 'misc-utils')
31 files changed, 544 insertions, 1251 deletions
diff --git a/misc-utils/Makefile b/misc-utils/Makefile index f69f0c1ef..1ae67df3f 100644 --- a/misc-utils/Makefile +++ b/misc-utils/Makefile @@ -1,6 +1,6 @@ # Makefile -- Makefile for util-linux Linux utilities # Created: Sat Dec 26 20:09:40 1992 -# Revised: Fri Oct 6 20:27:07 1995 by r.faith@ieee.org +# Revised: Mon Nov 11 10:12:16 1996 by faith@cs.unc.edu # Copyright 1992, 1993, 1994, 1995 Rickard E. Faith (faith@cs.unc.edu) # May be distirbuted under the GPL # @@ -9,35 +9,40 @@ include ../MCONFIG # Where to put man pages? -MAN1= cal.1 chkdupexe.1 ddate.1 dnsdomainname.1 domainname.1 \ - dsplit.1 hostid.1 hostname.1 kill.1 logger.1 look.1 mcookie.1 \ - namei.1 reset.1 script.1 setterm.1 tsort.1 \ - whereis.1 write.1 - -ifeq "$(HAVE_CLEAR)" "no" -MAN1:=$(MAN1) clear.1 -endif +MAN1= cal.1 chkdupexe.1 ddate.1 hostid.1 kill.1 \ + logger.1 look.1 mcookie.1 namei.1 script.1 \ + setterm.1 tsort.1 whereis.1 write.1 # Where to put binaries? # See the "install" rule for the links. . . -BIN= domainname hostname kill +BIN= kill -USRBIN= cal chkdupexe ddate dsplit hostid logger look mcookie \ - namei reset script setterm tsort whereis write +USRBIN= cal chkdupexe ddate hostid logger look mcookie \ + namei script setterm tsort whereis write ifeq "$(HAVE_CLEAR)" "no" USRBIN:=$(USRBIN) clear +MAN1:=$(MAN1) clear.1 +endif + +ifeq "$(HAVE_RESET)" "no" +USRBIN:=$(USRBIN) reset +MAN1:=$(MAN1) reset.1 endif +# ifeq "$(HAVE_SYSVINIT)" "no" +# USRBIN:=$(USRBIN) pidof +# endif + # Programs requiring special compilation -NEEDS_TERMCAP= setterm +NEEDS_CURSES= setterm all: $(BIN) $(USRBIN) $(USRBIN.NONSHADOW) $(USRGAMES) getoptprog -$(NEEDS_TERMCAP): - $(CC) $(LDFLAGS) $^ -o $@ -ltermcap +$(NEEDS_CURSES): + $(CC) $(LDFLAGS) $^ -o $@ $(LIBCURSES) %: %.sh cp $@.sh $@ @@ -52,28 +57,25 @@ $(NEEDS_TERMCAP): cal: cal.o $(BSD)/getopt.o $(BSD)/err.o chkdupexe: chkdupexe.pl clear: clear.sh -domainname: domainname.o -dsplit: dsplit.o getoptprog: getoptprog.o $(BSD)/getopt.o hostid: hostid.o -hostname: hostname.o kill: kill.o procs.o logger: logger.o $(BSD)/getopt.o mcookie: mcookie.o md5.o -md5sum: md5sum.o md5.o -md5.o: md5.h +mcookie.o: mcookie.c md5.h +md5.o: md5.c md5.h namei: namei.o reset: reset.sh script: script.o setterm: setterm.o tsort: tsort.o +# pidof: pidof.o procs.o install: all $(INSTALLDIR) $(BINDIR) $(USRBINDIR) $(INSTALLBIN) $(BIN) $(BINDIR) $(INSTALLBIN) $(USRBIN) $(USRBINDIR) $(INSTALLBIN) getoptprog $(USRBINDIR)/getopt - (cd $(BINDIR); ln -sf hostname dnsdomainname) $(INSTALLDIR) $(MAN1DIR) $(MAN8DIR) $(INSTALLMAN) $(MAN1) $(MAN1DIR) $(INSTALLMAN) getoptprog.1 $(MAN1DIR)/getopt.1 diff --git a/misc-utils/README.hostname b/misc-utils/README.hostname deleted file mode 100644 index 1e82b8cfe..000000000 --- a/misc-utils/README.hostname +++ /dev/null @@ -1,29 +0,0 @@ - -You may ask "Why another version of the hostname command?". The answer is -simple. A lot of people misuse the domainname command to get the DNS domain -name. Since the domainname command should ONLY be used to set/show the NIS -domain name (formerly known as Yellow Pages) there was no easy way to get -the FQDN (Fully Qualified Domain Name) or the DNS domainname from within a -shell script. - -This hostname command offers you some additional features: - -- show the FQDN (long host name) -- show the short host name -- show the DNS domain name -- read the host name from file - -For further informations simply type "hostname --help" or read the manual -page. - -If the program is called as dnsdomainname it will simply show the DNS domain -name. - -If you ONLY use the loopback mode you can only use the normal features -(set/show the host name) since you probably don't have a FQDN (Fully Qualified -Domain Name) in the /etc/hosts file. You can change this by either using -the dummy device or by changing the localhost line in /etc/hosts to -something like this (it will use localhost as an alias name): - -127.0.0.1 erdos.maths.groucho.edu localhost erdos - diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 87ab71df6..ecdc79987 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -34,15 +34,18 @@ * SUCH DAMAGE. */ -#ifndef lint static char copyright[] = "@(#) Copyright (c) 1989, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94"; -#endif /* not lint */ + + +/* This defines _LINUX_C_LIB_VERSION_MAJOR, dunno about gnulibc. We + don't want it to read /usr/i586-unknown-linux/include/_G_config.h + so we specify fill path. Were we got /usr/i586-unknown-linux from? + Dunno. */ + +#include "/usr/include/_G_config.h" #include <sys/types.h> @@ -55,7 +58,15 @@ static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94"; #include <unistd.h> #include <locale.h> -#if defined(__linux__) && _LINUX_C_LIB_VERSION_MAJOR > 4 +/* Test changes to deal with gnulibc, Linux libc 5. */ +/* #if defined(__linux__) && _LINUX_C_LIB_VERSION_MAJOR > 4 */ +#if _LINUX_C_LIB_VERSION_MAJOR - 0 > 4 || __GNU_LIBRARY__ - 0 >= 5 +# define LANGINFO 1 +#else +# define LANGINFO 0 +#endif + +#if LANGINFO # include <langinfo.h> #else # include <localeinfo.h> @@ -165,7 +176,7 @@ main(argc, argv) argc -= optind; argv += optind; - month = 0; + month = year = 0; switch(argc) { case 2: if ((month = atoi(*argv++)) < 1 || month > 12) @@ -210,7 +221,7 @@ void headers_init(void) strcpy(j_day_headings,""); for(i = 0 ; i < 7 ; i++ ) { -#if defined(__linux__) && _LINUX_C_LIB_VERSION_MAJOR > 4 +#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1) strncat(day_headings,nl_langinfo(ABDAY_1+i),2); strcat(j_day_headings,nl_langinfo(ABDAY_1+i)); #else @@ -222,7 +233,7 @@ void headers_init(void) } for (i = 0; i < 12; i++) { -#if defined(__linux__) && _LINUX_C_LIB_VERSION_MAJOR > 4 +#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1) full_month[i] = nl_langinfo(MON_1+i); #else full_month[i] = _time_info->full_month[i]; diff --git a/misc-utils/chkdupexe.pl b/misc-utils/chkdupexe.pl index 117d20fa5..f6111def1 100644 --- a/misc-utils/chkdupexe.pl +++ b/misc-utils/chkdupexe.pl @@ -1,44 +1,85 @@ -#!/usr/bin/perl +#!/usr/bin/perl5 -w # -# chkdupexe version 2.0 +# chkdupexe version 2.1.1 # # Simple script to look for and list duplicate executables and dangling # symlinks in the system executable directories. # -# Copyright 1993 Nicolai Langfeldt. Distribute under gnu copyleft -# (included in perl package) +# Copyright 1993 Nicolai Langfeldt. janl@math.uio.no +# Distribute under gnu copyleft (included in perl package) # # Modified 1995-07-04 Michael Shields <shields@tembel.org> # Don't depend on GNU ls. # Cleanups. # Merge together $ENV{'PATH'} and $execdirs. # Don't break if there are duplicates in $PATH. -# +# +# Modified 1996-02-16 Nicolai Langfeldt (janl@math.uio.no). +# I was thinking admins would edit the $execdirs list to suit their +# machine(s) when I wrote this. This is ofcourse not the case, thus +# Michaels fixes. And my fixes to his :-) +# - Working duplicate dirs detection. +# - Added more checks +# - Took out $PATH from the list of checked directories and added a +# check for $execdirs and $PATH consistency instead +# - Made it possible to run with perl -w + +$execdirs='/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin '. + '/usr/X11/bin /usr/bin/X11 /usr/local/X11/bin '. + '/usr/TeX/bin /usr/tex/bin /usr/games '. + '/usr/local/games /usr/intervies/bin/LINUX'; + +# Values from /usr/include/linux/errno.h. Existence of linux/errno.ph is not +# something to count on... :-( +$ENOENT=2; + +%didthis=(); -$execdirs='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/local/bin:/local/sbin:/usr/X11/bin:/usr/bin/X11:/usr/local/X11/bin:/local/X11/bin:/usr/TeX/bin:/usr/tex/bin:/usr/local/graph/bin:/usr/games:/usr/local/games:/usr/intervies/bin/LINUX'; +foreach $dir (split(/\s+/, "$execdirs")) { -DIRECTORY: -foreach $dir (split(/:/, "$execdirs:$ENV{'PATH'}")) { + # It's like this: One directory corresponds to one $device,$inode tuple + # If a symlink points to a directory we already checked that directory + # will have the same $device,$inode tuple. - # Follow symlinks and make sure we haven't scanned this directory already. - while (-l $dir) { - $newdir = readlink($dir); - print "Dangling symlink: $dir\n" unless $newdir; - $dir = $newdir; - next DIRECTORY if $seendir{$dir}++; + # Does this directory have any real exstence outside the ravings of + # symlinks pointing hither and dither? + ($device,$inode)=stat($dir); + if (!defined($device)) { + # Nonexistant directory, or dangling symlink? + ($dum)=lstat($dir); + next if $! == $ENOENT; + if (!$dum) { + print "Dangling symlink: $dir\n"; + next; + } + # warn "Nonexistent directory: $dir\n"; + next; } - opendir(DIR,$dir) || (warn "Couldn't opendir($dir): $!\n", next); + if (!-d _) { + print "Not a directory: $dir\n"; + next; + } + + next if defined($didthis{$device,$inode}); + + $didthis{$device,$inode}=1; + + chdir($dir) || die "Could not chdir $dir: $!\n"; +# This would give us the true directory name, do we want that? +# chop($dir=`pwd`); + opendir(DIR,".") || + die "NUTS! Personaly I think your perl or filesystem is broken.\n". + "I've done all sorts of checks on $dir, and now I can't open it!\n"; foreach $_ (readdir(DIR)) { - lstat("$dir/$_"); + lstat($_); if (-l _) { - ($dum)=stat("$dir/$_"); - # Might as well report these since we discover them anyway - print "Dangling symlink: $dir/$_\n" unless $dum; + ($dum)=stat($_); + print "Dangling symlink: $dir/$_\n" unless defined($dum); next; } next unless -f _ && -x _; # Only handle regular executable files - if ($count{$_}) { + if (defined($count{$_})) { $progs{$_}.=" $dir/$_"; $count{$_}++; } else { @@ -54,3 +95,19 @@ while (($prog,$paths)=each %progs) { print LS "$paths\n" if ($count{$prog}>1); } close(LS); + +@unchecked=(); +# Check if the users PATH contains something I've not checked. The site admin +# might want to know about inconsistencies in user PATHs and chkdupexec +# configuration +foreach $dir (split(/:/,$ENV{'PATH'})) { + ($device,$inode)=stat($dir); + next unless defined($device); + next if defined($didthis{$device,$inode}); + push(@unchecked,$dir); + $didthis{$device,$inode}=1; +} + +print "Warning: Your path contanis these directories which chkdupexe have not checked:\n",join(',',@unchecked), + ".\nPlease review the execdirs list in chkdupexe.\n" + if ($#unchecked>=$[); diff --git a/misc-utils/clear.1 b/misc-utils/clear.1 deleted file mode 100644 index 9d2082304..000000000 --- a/misc-utils/clear.1 +++ /dev/null @@ -1,31 +0,0 @@ -.\" Copyright 1992 Rickard E. Faith (faith@cs.unc.edu) -.\" May be distributed under the GNU General Public License -.TH CLEAR 1 "10 October 1993" "Linux 0.99" "Linux Programmer's Manual" -.SH NAME -clear \- clear terminal screen -.SH SYNOPSIS -.BR clear -.SH DESCRIPTION -.B clear -calls -.BR tput (1) -with the -.I clear -argument. This causes -.B tput -to attempt to clear the screen checking the data in -.I /etc/termcap -(for the GNU or BSD -.BR tput ) -or in the terminfo database -(for the -.B ncurses -.BR tput ) -and sending the appropriate sequence to the terminal. This command can be -redirected to clear the screen of some other terminal. -.SH "SEE ALSO" -.BR reset (1), -.BR stty (1), -.BR tput (1) -.SH AUTHOR -Rik Faith (faith@cs.unc.edu) diff --git a/misc-utils/clear.sh b/misc-utils/clear.sh deleted file mode 100644 index 73d1ebe1c..000000000 --- a/misc-utils/clear.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -tput clear diff --git a/misc-utils/ddate.c b/misc-utils/ddate.c index 96421d021..f838d1c63 100644 --- a/misc-utils/ddate.c +++ b/misc-utils/ddate.c @@ -53,14 +53,20 @@ /*#define PRAISE_BOB 13013*/ -#include <time.h> +#include <stdlib.h> #include <string.h> +#include <time.h> #include <stdio.h> #ifndef __GNUC__ #define inline /* foo */ #endif +#ifdef KILL_BOB +int xday_countdown(int yday, int year); +#endif + + /* string constants */ char *day_long[5] = { @@ -76,11 +82,11 @@ char *season_long[5] = { char *season_short[5] = {"Chs", "Dsc", "Cfn", "Bcy", "Afm"}; char *holyday[5][2] = { - "Mungday", "Chaoflux", - "Mojoday", "Discoflux", - "Syaday", "Confuflux", - "Zaraday", "Bureflux", - "Maladay", "Afflux" + { "Mungday", "Chaoflux" }, + { "Mojoday", "Discoflux" }, + { "Syaday", "Confuflux" }, + { "Zaraday", "Bureflux" }, + { "Maladay", "Afflux" } }; struct disc_time { @@ -131,6 +137,7 @@ int load_fortunes(char *fn, char *delim, char** result); struct disc_time convert(int,int); struct disc_time makeday(int,int,int); +int main (int argc, char *argv[]) { long t; @@ -298,7 +305,6 @@ struct disc_time convert(int nday, int nyear) } - #ifdef KILL_BOB /* Code for counting down to X-Day, X-Day being Cfn 40, 3164 */ diff --git a/misc-utils/dnsdomainname.1 b/misc-utils/dnsdomainname.1 deleted file mode 100644 index 1f45128b5..000000000 --- a/misc-utils/dnsdomainname.1 +++ /dev/null @@ -1 +0,0 @@ -.so man1/hostname.1 diff --git a/misc-utils/domainname.1 b/misc-utils/domainname.1 deleted file mode 100644 index 0a305ad1e..000000000 --- a/misc-utils/domainname.1 +++ /dev/null @@ -1,28 +0,0 @@ -.\" Copyright 1992 Rickard E. Faith (faith@cs.unc.edu) -.\" May be distributed under the GNU General Public License -.TH DOMAINNAME 1 "26 December 1992" "Linux 0.98" "Linux Programmer's Manual" -.SH NAME -domainname \- set or print domain of current host -.SH SYNOPSIS -.BR "domainname [ " name " ]" -.SH DESCRIPTION -.B domainname -prints the domainname of the current host, from the -.BR getdomainname (3) -library call. If an argument is present and the effective UID is 0, -.B domainname -changes the name of the host, with the -.BR setdomainname (2) -system call. This is usually done at boot time in the -.I /etc/rc.local -script. -.SH FILES -.I /etc/rc.local -.SH "SEE ALSO" -.BR getdomainname (3), -.BR setdomainname (2), -.BR uname (1), -.BR uname (2) -.SH AUTHOR -Lars Wirzenius by substituting in hostname.c - diff --git a/misc-utils/domainname.c b/misc-utils/domainname.c deleted file mode 100644 index 107091e87..000000000 --- a/misc-utils/domainname.c +++ /dev/null @@ -1,29 +0,0 @@ -/* domainname.c - poe@daimi.aau.dk */ - -#include <sys/types.h> -#include <sys/param.h> -#include <stdio.h> -#include <unistd.h> - -#define MAXDNAME 64 - -int main(int argc, char *argv[]) -{ - char hn[MAXDNAME + 1]; - - if(argc >= 2) { - if(geteuid() || getuid()) { - puts("You must be root to change the domainname"); - exit(1); - } - if(strlen(argv[1]) > MAXDNAME) { - puts("That name is too long."); - exit(1); - } - setdomainname(argv[1], strlen(argv[1])); - } else { - getdomainname(hn, MAXDNAME); - puts(hn); - } - exit(0); -} diff --git a/misc-utils/dsplit.1 b/misc-utils/dsplit.1 deleted file mode 100644 index f78f058fb..000000000 --- a/misc-utils/dsplit.1 +++ /dev/null @@ -1,46 +0,0 @@ -.\" Public Domain 1994 Rik Faith (faith@cs.unc.edu) -.TH DSPLIT 1 "5 July 1994" "Linux 1.1" "Linux Programmer's Manual" -.SH NAME -dsplit \- split a large file into pieces -.SH SYNOPSIS -.BI "dsplit [ \-size " nnn " ] [ " input_file " [ " output_base " ] ]" -.SH DESCRIPTION -.B dsplit -splits binary files into smaller chunks so that they may be placed on -floppy disks. -.SH OPTIONS -.TP -.BI \-size " nnn" -Specifies the size of each output file, in bytes. The default is 1457000, -which is enough to will a 1.44 MB floppy disk. -.TP -.I input_file -Specifies the name of the file to split up. A \- indicates standard input. -The default is standard input. -.TP -.I output_base -Specifies the name of the output files to be written. -.B dsplit -will append 000, 001, ..., to the -.IR output_base . -The default is "dsplit". -.SH "AUTHOR'S NOTES" -Submitted-by: arnstein@netcom.com (David Arnstein) -.br -Posting-number: Volume 40, Issue 51 -.br -Archive-name: dsplit/part01 -.br -Environment: MS-DOS, UNIX -.PP -Here is a portable binary file splitting program. It reads a binary file -and splits it into pieces. I use this program to put large binary files on -floppy disks. For this reason, the default size of the output files is -1,457,000 bytes, which just about fills up a 1.44 MB floppy disk. -.PP -Unlike other binary split programs I have seen, dsplit does not malloc a -huge block of memory. Dsplit is suitable for use under MSDOS and other -primitive operating systems. -.PP -(The program came from -gatekeeper.dec.com:/pub/usenet/comp.sources.misc/volume40/dsplit). diff --git a/misc-utils/dsplit.c b/misc-utils/dsplit.c deleted file mode 100644 index c3c22a305..000000000 --- a/misc-utils/dsplit.c +++ /dev/null @@ -1,271 +0,0 @@ -#ifdef lint - static char RCSid[] = "$RCSfile: dsplit.c,v $ $Revision: 1.9 $ $Date: 1995/03/12 01:31:03 $"; -#endif -/* - Program dsplit: Splits a large file into pieces. - - Usage: - dsplit [-size nnn] [input_file [output_base]] - Size is size of each output file, in bytes. The default is 1457000, - enough to fill a "1.44MB" diskette, save 152 bytes. - input_file is the name of the file to split up. A dash (-) indicates - standard input. Defaults to standard input. - output_base is the name of the output files to be written, minus the - extension. Dsplit adds suffixes 000, 001, ... - The default base name is dsplit. -*/ -#include <ctype.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#if (defined (__MSDOS__) || defined (WIN32)) -#include <io.h> -#include <fcntl.h> -#endif /* __MSDOS__ or WIN32 */ -#ifndef FILENAME_MAX -#define FILENAME_MAX 1024 -#endif - -#define DEFAULT_NAME "dsplit" -#define DEFAULT_SIZE 1457000L -#if (defined (__MSDOS__) || defined (WIN32)) -# define READ_OPTIONS "rb" -# define WRITE_OPTIONS "wb" -#else -# define READ_OPTIONS "r" -# define WRITE_OPTIONS "w" -#endif /* __MSDOS__ or WIN32 */ - -#ifndef MIN -#define MIN(a,b) (((a) <= (b)) ? (a) : (b)) -#endif - -static unsigned long output_size = DEFAULT_SIZE; -static char* base_name = DEFAULT_NAME; -static FILE* input_handle; -static char* input_name = "-"; - -#ifdef __STDC__ -static void init (int argc, char* argv[]); -static int write_one (int count); -static void ToLower (char* string); -static void usage_error (void); -#else /* not __STDC__ */ -static void init (/* int argc, char* argv[] */); -static int write_one (/* int count */); -static void ToLower (/* char* string */); -static void usage_error (/* void */); -#endif /* __STDC__ */ - - - -#ifdef __STDC__ -int main (int argc, char* argv[]) -#else -int main (argc, argv) -int argc; -char* argv[]; -#endif -{ - int count; - - /* Process command line arguments, open input file. */ - init (argc, argv); - - /* Write the output files */ - for (count = 0 ; write_one (count) ; ++count) - ; - - /* Close input file (a matter of style) */ - if (fclose (input_handle) != 0) - { - (void)fprintf (stderr, "Could not close file \"%s\" for input\n", - input_name); - return 1; - } - - /* Normal successful conclusion */ - return 0; -} - - - -#ifdef __STDC__ -static void init (int argc, char* argv[]) -#else -static void init (argc, argv) -int argc; -char* argv[]; -#endif -{ - int iarg; - int name_count; - - /* Initialize the input file handle to standard input. IBM's Toolset++ - won't let me do this statically, unfortunately. */ - input_handle = stdin; - - /* Initialize for following loop */ - name_count = 0; - - /* Loop over command line arguments */ - for (iarg = 1 ; iarg < argc ; ++iarg) - { - /* Point to argument,for convenience */ - char* arg = argv[iarg]; - - /* If this argument is an option */ - if (arg[0] == '-' && arg[1] != '\0') - { - /* Process option if recognized */ - ToLower (arg+1); - if (strcmp (arg+1, "size") != 0) - usage_error (); - ++iarg; - if (iarg >= argc) - usage_error (); - arg = argv[iarg]; - if (sscanf (arg, "%ld", &output_size) != 1) - { - (void)fprintf (stderr, "Illegal numeric expression \"%s\"\n", arg); - exit (1); - } - } - else /* argument is not an option */ - { - /* Argument is a name string. Determine which one. */ - switch (name_count) - { - case 0: - input_name = argv[iarg]; - break; - case 1: - base_name = argv[iarg]; - break; - default: - usage_error (); - break; - } - ++name_count; - - } /* End if this argument is an option */ - - } /* End loop over command line arguments */ - - /* Open the input file */ - if (strcmp (input_name, "-") == 0) - { -# if (defined (__MSDOS__) || defined (WIN32)) - if (setmode (0, O_BINARY) == -1) - { - perror ("dsplit: setmode"); - exit (1); - } -# endif - } - else - { - if ((input_handle = fopen (input_name, READ_OPTIONS)) == NULL) - { - (void)fprintf (stderr, "Could not open file \"%s\" for input\n", - input_name); - exit (1); - } - } -} - - - -#ifdef __STDC__ -static int write_one (int count) -#else -static int write_one (count) -int count; -#endif -{ - char output_name[FILENAME_MAX]; - int bytes_written; - unsigned long total_written; - FILE* output_handle; - - /* Read the first buffer full now, just to see if any data is left */ - static char buff[1024]; - int to_read = MIN (sizeof(buff), output_size); - int bytes_read = fread (buff, 1, to_read, input_handle); - if (bytes_read <= 0) - return 0; - - /* Open file for output */ - sprintf (output_name, "%s.%03d", base_name, count); - output_handle = fopen (output_name, WRITE_OPTIONS); - if (output_handle == NULL) - { - (void)fprintf (stderr, - "Could not open file \"%s\" for output\n", output_name); - exit (1); - } - - /* Write the first output buffer */ - bytes_written = fwrite (buff, 1, bytes_read, output_handle); - if (bytes_written != bytes_read) - { - (void)fprintf (stderr, "Error writing to file \"%s\"\n", output_name); - exit (1); - } - total_written = bytes_written; - - /* Write output file */ - while (total_written < output_size) - { - to_read = MIN (sizeof(buff), output_size-total_written); - bytes_read = fread (buff, 1, to_read, input_handle); - if (bytes_read <= 0) - break; - bytes_written = fwrite (buff, 1, bytes_read, output_handle); - if (bytes_written != bytes_read) - { - (void)fprintf (stderr, "Error writing to file \"%s\"\n", output_name); - exit (1); - } - total_written += bytes_written; - } - - /* Close the output file, it is complete */ - if (fclose (output_handle) != 0) - { - (void)fprintf (stderr, - "Could not close file \"%s\" for output\n", output_name); - exit (1); - } - - /* Indicate whether more data remains to be transferred */ - return (bytes_read == to_read); -} - - - -#ifdef __STDC__ -static void ToLower (char* string) -#else -static void ToLower (string) -char* string; -#endif -{ - - while (*string != '\0') - tolower (*string++); -} - - - -#ifdef __STDC__ -static void usage_error (void) -#else -static void usage_error () -#endif -{ - (void)fprintf (stderr, - "Usage: dsplit [-size nnn] [input_file [output_base]]\n"); - exit (1); -} - diff --git a/misc-utils/getoptprog.c b/misc-utils/getoptprog.c index 03b0987ef..94eac145a 100644 --- a/misc-utils/getoptprog.c +++ b/misc-utils/getoptprog.c @@ -1,5 +1,7 @@ #include <stdio.h> +#include <unistd.h> +int main(argc, argv) int argc; char *argv[]; @@ -26,5 +28,5 @@ char *argv[]; for (; optind < argc; optind++) printf(" %s", argv[optind]); printf("\n"); - exit(status); + return status; } diff --git a/misc-utils/hostid.c b/misc-utils/hostid.c index 829c5b672..211e4ce5a 100644 --- a/misc-utils/hostid.c +++ b/misc-utils/hostid.c @@ -6,7 +6,7 @@ #include <errno.h> #include <getopt.h> -void main (int argc, char **argv) +int main (int argc, char **argv) { int verbose = 0; @@ -32,5 +32,5 @@ void main (int argc, char **argv) printf("Usage: %s hostid_number\n",*argv); } } - exit(0); + return 0; } diff --git a/misc-utils/hostname.1 b/misc-utils/hostname.1 deleted file mode 100644 index 9efc07586..000000000 --- a/misc-utils/hostname.1 +++ /dev/null @@ -1,77 +0,0 @@ -.TH HOSTNAME 1 "28 July 1994" "Linux" "Linux Programmer's Manual" -.SH NAME -hostname \- show or set the system's host name -.br -dnsdomainname \- show the system's domain name -.SH SYNOPSIS -.B hostname -.RB [ \-d ] -.RB [ \-\-domain ] -.RB [ \-F\ filename ] -.RB [ \-\-file\ filename ] -.RB [ \-f ] -.RB [ \-\-fqdn ] -.RB [ \-h ] -.RB [ \-\-help ] -.RB [ \-\-long ] -.RB [ \-s ] -.RB [ \-\-short ] -.RB [ \-v ] -.RB [ \-\-version ] -.RB [ name ] -.br -.B dnsdomainname -.SH DESCRIPTION -.B Hostname -is the program that is used to either set the host name or display -the current host or domain name of the system. This name is used -by many of the networking programs to identify the machine. -.LP -When called without any arguments, the program displays the current -name as set by the -.B hostname -command. You can change the output format to display always the short -or the long host name (FQDN). When called with arguments, the program will -set the value of the host name to the value specified. This usually is -done only once, at system startup time, by the -.I /etc/rc.d/rc.inet1 -configuration script. -.LP -Note, that only the super-user can change the host name. -.LP -If the program was called as -.B dnsdomainname -it will show the DNS domain name. You can't change the DNS domain name with -.B dnsdomainname -(see below). -.SH OPTIONS -.TP -.I "\-d, \-\-domain" -Display the name of the DNS domain. Don't use the command -.B domainname -to get the DNS domain name because it will show the NIS domain name and -not the DNS domain name. -.TP -.I "\-F, \-\-file filename" -Read the host name from the specified file. Comments (lines starting with -a `#') are ignored. -.TP -.I "\-f, \-\-fqdn, \-\-long" -Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a -short host name and the DNS domain name. Unless you are using bind or NIS -for host lookups you can change the FQDN and the DNS domain name (which is -part of the FQDN) in the \fI/etc/hosts\fR file. -.TP -.I "\-h, \-\-help" -Print a usage message on standard output and exit successfully. -.TP -.I "\-s, \-\-short" -Display the short host name. -.TP -.I "\-v, \-\-version" -Print version information on standard output and exit successfully. -.SH FILES -.B /etc/hosts -.SH AUTHOR -Peter Tobias, <tobias@server.et-inf.fho-emden.de> - diff --git a/misc-utils/hostname.c b/misc-utils/hostname.c deleted file mode 100644 index 2ff915afe..000000000 --- a/misc-utils/hostname.c +++ /dev/null @@ -1,184 +0,0 @@ -/* hostname -- set the host name or show the host/domain name - - Copyright (C) 1994 Peter Tobias - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - - -#include <stdio.h> -#include <unistd.h> -#include <getopt.h> -#include <string.h> -#include <netdb.h> -#include <errno.h> -#include <sys/param.h> - -#define NO_OPT -1 - -static char *program_name; -static const char *version_string = "hostname 1.6"; - -static void sethname(char *); -static void showhname(char *, int); -static void usage(void); - -static void sethname(char *hname) -{ - if(sethostname(hname, strlen(hname))) { - switch(errno) { - case EPERM: - fprintf(stderr,"%s: you must be root to change the host name\n", program_name); - break; - case EINVAL: - fprintf(stderr,"%s: name too long\n", program_name); - break; - default: - } - exit(1); - }; -} - -static void showhname(char *hname, int c) -{ - struct hostent *hp; - register char *p; - - if (!(hp = gethostbyname(hname))) { - herror(program_name); - exit(1); - } - - if (!(p = strchr(hp->h_name, '.')) && (c == 'd')) return; - - switch(c) { - case 'd': - printf("%s\n", ++p); - break; - case 'f': - printf("%s\n", hp->h_name); - break; - case 's': - if (p != NULL) *p = '\0'; - printf("%s\n", hp->h_name); - break; - default: - } -} - -static void usage(void) -{ - printf("Usage: %s [OPTION]... [hostname]\n\n\ - -d, --domain display the DNS domain name\n\ - -F, --file filename read the host name from file\n\ - -f, --fqdn, --long display the long host name (FQDN)\n\ - -s, --short display the short host name\n\ - -h, --help display this help and exit\n\ - -v, --version output version information and exit\n\ -\n\ - When the program is called without any arguments, it displays the\n\ - current host name as set by the hostname command. If an argument\n\ - is given, the program will set the value of the host name to the\n\ - value specified.\n\ - Unless you are using bind or NIS for host lookups you can change the\n\ - FQDN (Fully Qualified Domain Name) and the DNS domain name (which is\n\ - part of the FQDN) in the /etc/hosts file.\n", program_name); -} - -int main(int argc, char **argv) -{ - int c; - int option_index = 0; - - char myname[MAXHOSTNAMELEN+1]; - - static const struct option long_options[] = - { - {"domain", no_argument, 0, 'd'}, - {"file", required_argument, 0, 'F'}, - {"fqdn", no_argument, 0, 'f'}, - {"help", no_argument, 0, 'h'}, - {"long", no_argument, 0, 'f'}, - {"short", no_argument, 0, 's'}, - {"version", no_argument, 0, 'v'}, - {0, 0, 0, 0} - }; - - program_name = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0]; - - if (strcmp(program_name, "dnsdomainname") == 0) { - if (argc > 1) { - fprintf(stderr,"%s: You can't change the DNS domainname with this command\n", program_name); - fprintf(stderr,"\nUnless you are using bind or NIS for host lookups you can change the DNS\n"); - fprintf(stderr,"domain name (which is part of the FQDN) in the /etc/hosts file.\n"); - exit(1); - } - c = 'd'; - } else - c = getopt_long(argc, argv, "dfF:hsv", long_options, &option_index); - - gethostname(myname, sizeof(myname)); - - switch(c) - { - case 'd': - case 'f': - case 's': - showhname(myname, c); - break; - case 'F': - { - register FILE *fd; - register char *p; - char fline[MAXHOSTNAMELEN]; - - if ((fd = fopen(optarg, "r")) != NULL) { - while (fgets(fline, sizeof(fline), fd) != NULL) - if ((p = index(fline, '\n')) != NULL) { - *p = '\0'; - if (fline[0] == '#') - continue; - sethname(fline); - } - (void) fclose(fd); - } else { - fprintf(stderr,"%s: can't open `%s'\n", - program_name, optarg); - exit(1); - } - } - break; - case 'h': - usage(); - break; - case 'v': - printf("%s\n", version_string); - break; - case '?': - fprintf(stderr,"Try `%s --help' for more information.\n", program_name); - exit(1); - break; - case NO_OPT: - if (optind < argc) { - sethname(argv[optind]); - exit(0); - } - default: - printf("%s\n", myname); - - }; - exit(0); -} diff --git a/misc-utils/kill.1 b/misc-utils/kill.1 index aad5c23ba..f4fd6436d 100644 --- a/misc-utils/kill.1 +++ b/misc-utils/kill.1 @@ -23,7 +23,26 @@ Specify the list of processes that .B kill should signal. Each .I pid -can be a process id, or a process name. +can be one of four things. A +.I "process name" +in which case processes called that will be signaled. +.I n +where +.I n +is larger than 0. The process with pid +.I n +will be signaled. +.I -1 +in which case all processes from MAX_INT to 2 will be signaled, +as allowed by the issuing user. +.I -n +where +.I n +is larger than 1, in which case processes in process group +.I n +are signaled. IFF a negative argument is given the signal +.I must +be specified first, otherwise it will be taken as the signal to send. .TP .BR \-s Specify the signal to send. diff --git a/misc-utils/kill.c b/misc-utils/kill.c index f89ff67c1..85911211a 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -59,7 +59,7 @@ char *sys_signame[NSIG] = { #endif int main (int argc, char *argv[]); -char *mybasename(char *pathname); +extern char *mybasename(char *); int signame_to_signum (char *sig); int arg_to_signum (char *arg); void nosig (char *name); @@ -144,8 +144,12 @@ int main (int argc, char *argv[]) continue; } /* `arg' begins with a dash but is not a known option. - so it's probably something like -HUP. - try to deal with it. */ + so it's probably something like -HUP, or -1/-n + try to deal with it. + -n could be signal n, or pid -n (i.e. process group n). + If a signal has been parsed, assume it's a pid, break */ + if (do_kill) + break; arg++; if ((numsig = arg_to_signum (arg)) < 0) { return usage (1); @@ -186,13 +190,6 @@ int main (int argc, char *argv[]) return (errors); } -char *mybasename (char *path) -{ - char *cp; - - cp = strrchr (path, '/'); - return (cp ? cp + 1 : path); -} int signame_to_signum (char *sig) { diff --git a/misc-utils/look.c b/misc-utils/look.c index 5a47970ed..13cb67872 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -92,6 +92,7 @@ void print_from __P((char *, char *, char *)); static void usage __P((void)); +void main(argc, argv) int argc; char *argv[]; @@ -102,6 +103,8 @@ main(argc, argv) file = _PATH_WORDS; termchar = '\0'; + string = NULL; /* just for gcc */ + while ((ch = getopt(argc, argv, "adft:")) != EOF) switch(ch) { case 'a': @@ -152,6 +155,7 @@ main(argc, argv) exit(look(string, front, back)); } +int look(string, front, back) char *string, *front, *back; { @@ -159,7 +163,7 @@ look(string, front, back) register char *readp, *writep; /* Reformat string string to avoid doing it multiple times later. */ - for (readp = writep = string; ch = *readp++;) { + for (readp = writep = string; (ch = *readp++) != 0;) { if (fflag) ch = FOLD(ch); if (dflag) diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c index a4c896075..05136190f 100644 --- a/misc-utils/mcookie.c +++ b/misc-utils/mcookie.c @@ -4,7 +4,7 @@ * Public Domain 1995 Rickard E. Faith (faith@cs.unc.edu) * This program comes with ABSOLUTELY NO WARRANTY. * - * $Id: mcookie.c,v 1.2 1995/10/07 01:32:00 faith Exp $ + * $Id: mcookie.c,v 1.5 1997/07/06 00:13:06 aebr Exp $ * * This program gathers some random bits of data and used the MD5 * message-digest algorithm to generate a 128-bit hexadecimal number for @@ -87,7 +87,7 @@ int main( int argc, char **argv ) if (file[0] == '-' && !file[1]) fd = fileno(stdin); else if ((fd = open( file, O_RDONLY )) <0) { - fprintf( stderr, "Could not open %s\n" ); + fprintf( stderr, "Could not open %s\n", file ); } while ((r = read( fd, buf, sizeof( buf ) )) > 0) { diff --git a/misc-utils/md5sum.1 b/misc-utils/md5sum.1 deleted file mode 100644 index 86094b27b..000000000 --- a/misc-utils/md5sum.1 +++ /dev/null @@ -1,64 +0,0 @@ -.\" md5sum.1 -- -.\" Public Domain 1995 Rik Faith (faith@cs.unc.edu) -.\" Revised: Sat Feb 11 12:16:48 1995 by faith@cs.unc.edu -.\" " -.TH MD5SUM 1 "11 February 1995" "Linux 1.0" "Linux Programmer's Manual" -.SH NAME -md5sum \- generate/check MD5 message digests -.SH SYNOPSIS -.BR "md5sum [" \-bv "] [" \-c -.BR "[ " file " ] ]" -.br -.BR "md5sum " file " ..." -.SH DESCRIPTION -.B md5sum -generates and checks MD5 message digests, as described in RFC-1321. The -"message digest" produced can be thought of as a 128-bit "signature" of the -input file. Typically, -.B md5sum -is used to verify the integrity of files made available for distribution -via anonymous ftp (for example, announcements for new versions of -.BR irc(1) -usually contain MD5 signatures). -.P -Message digests for a tree of files can be generated with a command similar -to the following: -.RS -.sp -find . -type f -print | xargs md5sum -.sp -.RE -The output of this command is suitable as input for the -.B \-c -option. -.SH OPTIONS -.TP -.BI "\-c [" file "]" -Check message digests. Input is taken from -.B stdin -or from the spcified -.IR file . -The input should be in the same format as the output generated by -.BR md5sum . -.TP -.B \-v -Verbose. Print file names when checking. -.TP -.B \-b -Read files in binary mode (otherwise, end-of-file conventions will be -ignored). -.SH HISTOY -The -.B md5sum -program was written by Branko Lankester and may be freely distributed. The -original source code is in the MIT PGP 2.6.2 distribution. Those concerned -about the integrity of this version should obtain the original sources and -compile their own version. -.PP -The underlying implementation of Ron Rivest's MD5 algorithm was written by -Colin Plumb and is in the Public Domain. (Equivalent code is also -available from RSA Data Security, Inc.) -.SH "SEE ALSO" -.BR sum (1), -.BR cksum (1), -.BR pgp (1) diff --git a/misc-utils/md5sum.c b/misc-utils/md5sum.c deleted file mode 100644 index e0b1dc9c0..000000000 --- a/misc-utils/md5sum.c +++ /dev/null @@ -1,243 +0,0 @@ -/*
- * md5sum.c - Generate/check MD5 Message Digests
- *
- * Compile and link with md5.c. If you don't have getopt() in your library
- * also include getopt.c. For MSDOS you can also link with the wildcard
- * initialization function (wildargs.obj for Turbo C and setargv.obj for MSC)
- * so that you can use wildcards on the commandline.
- *
- * Written March 1993 by Branko Lankester
- * Modified June 1993 by Colin Plumb for altered md5.c.
- */
-#include <stdio.h>
-#include <string.h>
-#include "md5.h"
-
-#ifdef UNIX
-#define FOPRTXT "r"
-#define FOPRBIN "r"
-#else
-#ifdef VMS
-#define FOPRTXT "r","ctx=stm"
-#define FOPRBIN "rb","ctx=stm"
-#else
-#define FOPRTXT "r"
-#define FOPRBIN "rb"
-#endif
-#endif
-
-extern char *optarg;
-extern int optind;
-
-void usage();
-void print_digest();
-int mdfile(FILE *fp, unsigned char *digest);
-int do_check(FILE *chkf);
-
-char *progname;
-int verbose = 0;
-int bin_mode = 0;
-
-void
-main(int argc, char **argv)
-{
- int opt, rc = 0;
- int check = 0;
- FILE *fp;
- unsigned char digest[16];
-
- progname = *argv;
- while ((opt = getopt(argc, argv, "cbvp:h")) != EOF) {
- switch (opt) {
- case 'c': check = 1; break;
- case 'v': verbose = 1; break;
- case 'b': bin_mode = 1; break;
- default: usage();
- }
- }
- argc -= optind;
- argv += optind;
- if (check) {
- switch (argc) {
- case 0: fp = stdin; break;
- case 1: if ((fp = fopen(*argv, FOPRTXT)) == NULL) {
- perror(*argv);
- exit(2);
- }
- break;
- default: usage();
- }
- exit(do_check(fp));
- }
- if (argc == 0) {
- if (mdfile(stdin, digest)) {
- fprintf(stderr, "%s: read error on stdin\n", progname);
- exit(2);
- }
- print_digest(digest);
- printf("\n");
- exit(0);
- }
- for ( ; argc > 0; --argc, ++argv) {
- if (bin_mode)
- fp = fopen(*argv, FOPRBIN);
- else
- fp = fopen(*argv, FOPRTXT);
- if (fp == NULL) {
- perror(*argv);
- rc = 2;
- continue;
- }
- if (mdfile(fp, digest)) {
- fprintf(stderr, "%s: error reading %s\n", progname, *argv);
- rc = 2;
- } else {
- print_digest(digest);
- printf(" %c%s\n", bin_mode ? '*' : ' ', *argv);
- }
- fclose(fp);
- }
- exit(rc);
-}
-
-void
-usage()
-{
- fprintf(stderr, "usage: md5sum [-bv] [-c [file]] | [file...]\n");
- fprintf(stderr, "Generates or checks MD5 Message Digests\n");
- fprintf(stderr, " -c check message digests (default is generate)\n");
- fprintf(stderr, " -v verbose, print file names when checking\n");
- fprintf(stderr, " -b read files in binary mode\n");
- fprintf(stderr, "The input for -c should be the list of message digests and file names\n");
- fprintf(stderr, "that is printed on stdout by this program when it generates digests.\n");
- exit(2);
-}
-
-int
-mdfile(FILE *fp, unsigned char *digest)
-{
- unsigned char buf[1024];
- MD5_CTX ctx;
- int n;
-
- MD5Init(&ctx);
- while ((n = fread(buf, 1, sizeof(buf), fp)) > 0)
- MD5Update(&ctx, buf, n);
- MD5Final(digest, &ctx);
- if (ferror(fp))
- return -1;
- return 0;
-}
-
-void
-print_digest(unsigned char *p)
-{
- int i;
-
- for (i = 0; i < 16; ++i)
- printf("%02x", *p++);
-}
-
-int
-hex_digit(int c)
-{
- if (c >= '0' && c <= '9')
- return c - '0';
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 10;
- return -1;
-}
-
-int
-get_md5_line(FILE *fp, unsigned char *digest, char *file)
-{
- char buf[1024];
- int i, d1, d2, rc;
- char *p = buf;
-
- if (fgets(buf, sizeof(buf), fp) == NULL)
- return -1;
-
- for (i = 0; i < 16; ++i) {
- if ((d1 = hex_digit(*p++)) == -1)
- return 0;
- if ((d2 = hex_digit(*p++)) == -1)
- return 0;
- *digest++ = d1*16 + d2;
- }
- if (*p++ != ' ')
- return 0;
- /*
- * next char is an attribute char, space means text file
- * if it's a '*' the file should be checked in binary mode.
- */
- if (*p == ' ')
- rc = 1;
- else if (*p == '*')
- rc = 2;
- else {
- fprintf(stderr, "%s: unrecognized line: %s", progname, buf);
- return 0;
- }
- ++p;
- i = strlen(p);
- if (i < 2 || i > 255)
- return 0;
- p[i-1] = '\0';
- strcpy(file, p);
- return rc;
-}
-
-int
-do_check(FILE *chkf)
-{
- int rc, ex = 0, failed = 0, checked = 0;
- unsigned char chk_digest[16], file_digest[16];
- char filename[256];
- FILE *fp;
- int flen = 14;
-
- while ((rc = get_md5_line(chkf, chk_digest, filename)) >= 0) {
- if (rc == 0) /* not an md5 line */
- continue;
- if (verbose) {
- if (strlen(filename) > flen)
- flen = strlen(filename);
- fprintf(stderr, "%-*s ", flen, filename);
- }
- if (bin_mode || rc == 2)
- fp = fopen(filename, FOPRBIN);
- else
- fp = fopen(filename, FOPRTXT);
- if (fp == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, filename);
- ex = 2;
- continue;
- }
- if (mdfile(fp, file_digest)) {
- fprintf(stderr, "%s: error reading %s\n", progname, filename);
- ex = 2;
- fclose(fp);
- continue;
- }
- fclose(fp);
- if (memcmp(chk_digest, file_digest, 16) != 0) {
- if (verbose)
- fprintf(stderr, "FAILED\n");
- else
- fprintf(stderr, "%s: MD5 check failed for '%s'\n", progname, filename);
- ++failed;
- } else if (verbose)
- fprintf(stderr, "OK\n");
- ++checked;
- }
- if (verbose && failed)
- fprintf(stderr, "%s: %d of %d file(s) failed MD5 check\n", progname, failed, checked);
- if (!checked) {
- fprintf(stderr, "%s: no files checked\n", progname);
- return 3;
- }
- if (!ex && failed)
- ex = 1;
- return ex;
-}
diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 750576187..2c9850028 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -42,15 +42,20 @@ chdir to /, or if it encounters an unknown file type. -------------------------------------------------------------*/ #ifndef lint -static char *RCSid = "$Id: namei.c,v 1.4 1995/03/12 01:35:45 faith Exp $"; +static char *RCSid = "$Id: namei.c,v 1.6 1997/07/06 00:13:09 aebr Exp $"; #endif #include <stdio.h> +#include <unistd.h> +#include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/param.h> +#ifndef __GNU_LIBRARY__ extern char *sys_errlist[]; +#endif + extern int errno; #define ERR sys_errlist[errno],errno @@ -64,6 +69,7 @@ int xflag = 0; static char *pperm(); +int main(argc, argv) int argc; char *argv[]; @@ -110,7 +116,7 @@ char *argv[]; exit(1); } } - exit(0); + return 0; } void diff --git a/misc-utils/procs.c b/misc-utils/procs.c index 4d0ea7aca..2ea3e098c 100644 --- a/misc-utils/procs.c +++ b/misc-utils/procs.c @@ -6,9 +6,9 @@ * modify it under the terms of the gnu general public license. * there is no warranty. * - * $Author: faith $ - * $Revision: 1.2 $ - * $Date: 1995/03/12 02:55:24 $ + * $Author: janl $ + * $Revision: 1.5 $ + * $Date: 1996/11/11 22:40:03 $ * */ @@ -111,3 +111,12 @@ static char *parse_parens (char *buf) } return cp; } + + +char *mybasename (char *path) +{ + char *cp; + + cp = strrchr (path, '/'); + return (cp ? cp + 1 : path); +} diff --git a/misc-utils/reset.1 b/misc-utils/reset.1 index 46aea01ee..c4a4de456 100644 --- a/misc-utils/reset.1 +++ b/misc-utils/reset.1 @@ -4,7 +4,7 @@ .SH NAME reset \- reset the terminal .SH SYNOPSIS -.BR clear +.BR reset .SH DESCRIPTION .B reset calls @@ -28,7 +28,7 @@ is called with the .I sane argument in an attempt to get cooked mode back. .SH "SEE ALSO" -.BR reset (1), +.BR clear (1), .BR stty (1), .BR tput (1) .SH AUTHOR diff --git a/misc-utils/script.c b/misc-utils/script.c index d1e8b1e94..ba322fe5c 100644 --- a/misc-utils/script.c +++ b/misc-utils/script.c @@ -54,11 +54,20 @@ static char sccsid[] = "@(#)script.c 5.13 (Berkeley) 3/5/91"; #include <stdio.h> #include <paths.h> -#ifdef linux +#ifdef __linux__ #include <unistd.h> #include <string.h> #endif +void done(void); +void fail(void); +void fixtty(void); +void getmaster(void); +void getslave(void); +void doinput(void); +void dooutput(void); +void doshell(void); + char *shell; FILE *fscript; int master; @@ -74,6 +83,7 @@ int l; char line[] = "/dev/ptyXX"; int aflg; +void main(argc, argv) int argc; char *argv[]; @@ -134,6 +144,7 @@ main(argc, argv) doinput(); } +void doinput() { register int cc; @@ -162,6 +173,7 @@ finish() done(); } +void dooutput() { register int cc; @@ -181,11 +193,12 @@ dooutput() done(); } +void doshell() { + /*** int t; - /*** t = open(_PATH_TTY, O_RDWR); if (t >= 0) { (void) ioctl(t, TIOCNOTTY, (char *)0); @@ -199,7 +212,7 @@ doshell() (void) dup2(slave, 1); (void) dup2(slave, 2); (void) close(slave); -#ifdef linux +#ifdef __linux__ execl(shell, strrchr(shell, '/') + 1, "-i", 0); #else execl(shell, "sh", "-i", 0); @@ -208,6 +221,7 @@ doshell() fail(); } +void fixtty() { struct termios rtt; @@ -218,6 +232,7 @@ fixtty() (void) tcsetattr(0, TCSAFLUSH, &rtt); } +void fail() { @@ -225,6 +240,7 @@ fail() done(); } +void done() { time_t tvec, time(); @@ -242,6 +258,7 @@ done() exit(0); } +void getmaster() { char *pty, *bank, *cp; @@ -278,6 +295,7 @@ getmaster() fail(); } +void getslave() { diff --git a/misc-utils/setterm.1 b/misc-utils/setterm.1 index 794fea7db..3853a7132 100644 --- a/misc-utils/setterm.1 +++ b/misc-utils/setterm.1 @@ -2,7 +2,7 @@ .\" Copyright 1992 Rickard E. Faith (faith@cs.unc.edu) .\" Most of this was copied from the source code. Do not restrict distribution. .\" May be distributed under the GNU General Public License -.TH SETTERM 1 "25 December 1992" "Linux 0.98" "Linux Programmer's Manual" +.TH SETTERM 1 "2 July 1996" "Util-Linux 2.6" "Linux Programmer's Manual" .SH NAME setterm \- set terminal attributes .SH SYNOPSIS @@ -36,21 +36,25 @@ setterm \- set terminal attributes .BR "setterm [ \-clrtabs [ tab1 tab2 tab3 ... ]" " where (tabn = 1-160)" .BR "setterm [ \-regtabs [" " 1-160 " "] ]" .BR "setterm [ \-blank [" " 0-60 " "] ]" +.BR "setterm [ \-powersave [ on|vsync|hsync|powerdown|off ] ]" +.BR "setterm [ \-powerdown [" " 0-60 " "] ]" .BR "setterm [ \-dump [" " 1-NR_CONS " "] ]" .BR "setterm [ \-append [" " 1-NR_CONS " "] ]" .BR "setterm [ \-file" " dumpfilename " ] .BR "setterm [ \-standout [" " attr " "] ]" +.BR "setterm [ \-blength [" " 0-2000 " "] ]" +.B "setterm [ \-bfreq freqnumber ]" .fi .SH DESCRIPTION .B setterm writes to standard output a character string that will invoke the specified terminal capabilities. Where possibile -.I /etc/termcap +.I terminfo is consulted to find the string to use. Some options however do not correspond to a -.BR termcap (5) -capability. In this case, if the terminal type is "minix-vc", or -"minix-vcam" the string that invokes the specified capabilities on the PC +.BR terminfo (5) +capability. In this case, if the terminal type is "con", or +"linux" the string that invokes the specified capabilities on the PC Minix virtual console driver is output. Options that are not implemented by the terminal are ignored. .SH OPTIONS @@ -76,13 +80,15 @@ stores the terminal's current rendering options as the default values. .SH "SEE ALSO" .BR tput (1), .BR stty (1), -.BR termcap (5), +.BR terminfo (5), .BR tty (4) .SH BUGS -Differences between the Minux and Linux versions are not documented. +Differences between the Minix and Linux versions are not documented. .SH AUTHORS Gordon Irlam (gordoni@cs.ua.oz.au) .br Adaption to Linux by Peter MacDonald .br Enhancements by Mika Liljeberg (liljeber@cs.Helsinki.FI) +.br +Beep patch by Christophe Jolif (cjolif@storm.gatelink.fr.net) diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c index e81fccc3b..60145d9fa 100644 --- a/misc-utils/setterm.c +++ b/misc-utils/setterm.c @@ -8,6 +8,13 @@ * * Enhancements by Mika Liljeberg (liljeber@cs.Helsinki.FI) * + * Beep modifications by Christophe Jolif (cjolif@storm.gatelink.fr.net) + * + * Sanity increases by Cafeine Addict [sic]. + * + * Powersave features by, todd j. derr <tjd@wordsmith.org> + * + * Converted to terminfo by Kars de Jong (jongk@cs.utwente.nl) * * Syntax: * @@ -47,18 +54,22 @@ * [ -standout [attr] ] * [ -msg [on|off] ] * [ -msglevel [0-8] ] - * [ -powersave [on|off] ] + * [ -powersave [on|vsync|hsync|powerdown|off] ] + * [ -powerdown [0-60] ] + * [ -blength [0-2000] ] + * [ -bfreq freq ] * * * Semantics: * - * Setterm writes to standard output a character string that will invoke the - * specified terminal capabilities. Where possibile termcap is consulted to - * find the string to use. Some options however do not correspond to a - * termcap capability. In this case if the terminal type is "con*", or - * "linux*" the string that invokes the specified capabilities on the PC - * Linux virtual console driver is output. Options that are not implemented - * by the terminal are ignored. + * Setterm writes to standard output a character string that will + * invoke the specified terminal capabilities. Where possibile + * terminfo is consulted to find the string to use. Some options + * however do not correspond to a terminfo capability. In this case if + * the terminal type is "con*", or "linux*" the string that invokes + * the specified capabilities on the PC Linux virtual console driver + * is output. Options that are not implemented by the terminal are + * ignored. * * The following options are non-obvious. * @@ -74,33 +85,47 @@ * -default sets the terminal's rendering options to the default values. * * -store stores the terminal's current rendering options as the default - * values. - */ + * values. */ #include <stdlib.h> #include <stdio.h> +#include <errno.h> #include <ctype.h> -#include <termcap.h> -#include <linux/config.h> -#include <sys/time.h> #include <unistd.h> #include <termios.h> #include <string.h> +#include <fcntl.h> +#include <term.h> +#if NCH +#include <ncurses.h> +#else +#include <curses.h> +#endif +#include <sys/ioctl.h> +#include <sys/time.h> -/* for syslog system call */ -#include <linux/unistd.h> -#include <errno.h> -_syscall3(int, syslog, int, type, char*, buf, int, len); +#ifndef TCGETS +/* TCGETS is either defined in termios.h, or here: */ +#include <asm/ioctls.h> +#endif -/* Constants. */ +#if __GNU_LIBRARY__ < 5 +#ifndef __alpha__ +# include <linux/unistd.h> +#define __NR_klogctl __NR_syslog +_syscall3(int, klogctl, int, type, char*, buf, int, len); +#else /* __alpha__ */ +#define klogctl syslog +#endif +#endif -/* Termcap constants. */ -#define TC_BUF_SIZE 1024 /* Size of termcap(3) buffer. */ -#define TC_ENT_SIZE 50 /* Size of termcap(3) entry buffer. */ +/* Constants. */ /* General constants. */ +#ifndef TRUE #define TRUE 1 #define FALSE 0 +#endif /* Keyboard types. */ #define PC 0 @@ -127,8 +152,6 @@ _syscall3(int, syslog, int, type, char*, buf, int, len); /* Static variables. */ -char tc_buf[TC_BUF_SIZE]; /* Termcap buffer. */ - /* Option flags. Set if the option is to be invoked. */ int opt_term, opt_reset, opt_initialize, opt_cursor, opt_keyboard; int opt_linewrap, opt_snow, opt_softscroll, opt_default, opt_foreground; @@ -136,7 +159,8 @@ int opt_background, opt_bold, opt_blink, opt_reverse, opt_underline; int opt_store, opt_clear, opt_blank, opt_snap, opt_snapfile, opt_standout; int opt_append, opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat; int opt_tabs, opt_clrtabs, opt_regtabs, opt_appcursorkeys, opt_inversescreen; -int opt_msg, opt_msglevel, opt_powersave; +int opt_msg, opt_msglevel, opt_powersave, opt_powerdown; +int opt_blength, opt_bfreq; /* Option controls. The variable names have been contracted to ensure * uniqueness. @@ -144,20 +168,25 @@ int opt_msg, opt_msglevel, opt_powersave; char *opt_te_terminal_name; /* Terminal name. */ int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on, opt_bl_on; int opt_re_on, opt_un_on, opt_rep_on, opt_appck_on, opt_invsc_on; -int opt_msg_on, opt_ps_on; /* Boolean switches. */ +int opt_msg_on; /* Boolean switches. */ int opt_ke_type; /* Keyboard type. */ int opt_fo_color, opt_ba_color; /* Colors. */ int opt_ul_color, opt_hb_color; int opt_cl_all; /* Clear all or rest. */ int opt_bl_min; /* Blank screen. */ +int opt_blength_l; +int opt_bfreq_f; int opt_sn_num = 0; /* Snap screen. */ int opt_st_attr; int opt_rt_len; /* regular tab length */ int opt_tb_array[161]; /* Array for tab list */ int opt_msglevel_num; +int opt_ps_mode, opt_pd_min; /* powersave mode/powerdown time */ char opt_sn_name[200] = "screen.dump"; +void screendump(int vcnum, FILE *F); + /* Command line parsing routines. * * Note that it is an error for a given option to be invoked more than once. @@ -253,30 +282,31 @@ int *bad_arg; /* Set to true if an error is detected. */ if (argc != 1 || *option) *bad_arg = TRUE; *option = TRUE; if (argc == 1) { - if (strcmp(argv[0], "black") == 0) - *opt_color = BLACK; - else if (strcmp(argv[0], "red") == 0) - *opt_color = RED; - else if (strcmp(argv[0], "green") == 0) - *opt_color = GREEN; - else if (strcmp(argv[0], "yellow") == 0) - *opt_color = YELLOW; - else if (strcmp(argv[0], "blue") == 0) - *opt_color = BLUE; - else if (strcmp(argv[0], "magenta") == 0) - *opt_color = MAGENTA; - else if (strcmp(argv[0], "cyan") == 0) - *opt_color = CYAN; - else if (strcmp(argv[0], "white") == 0) - *opt_color = WHITE; - else if (strcmp(argv[0], "default") == 0) - *opt_color = DEFAULT; - else if (isdigit(argv[0][0])) - *opt_color = atoi(argv[0]); - else - *bad_arg = TRUE; - if(*opt_color < 0 || *opt_color > 15) - *bad_arg = TRUE; + if (strcmp(argv[0], "black") == 0) + *opt_color = BLACK; + else if (strcmp(argv[0], "red") == 0) + *opt_color = RED; + else if (strcmp(argv[0], "green") == 0) + *opt_color = GREEN; + else if (strcmp(argv[0], "yellow") == 0) + *opt_color = YELLOW; + else if (strcmp(argv[0], "blue") == 0) + *opt_color = BLUE; + else if (strcmp(argv[0], "magenta") == 0) + *opt_color = MAGENTA; + else if (strcmp(argv[0], "cyan") == 0) + *opt_color = CYAN; + else if (strcmp(argv[0], "white") == 0) + *opt_color = WHITE; + else if (strcmp(argv[0], "default") == 0) + *opt_color = DEFAULT; + else if (isdigit(argv[0][0])) + *opt_color = atoi(argv[0]); + else + *bad_arg = TRUE; + + if(*opt_color < 0 || *opt_color > 7) + *bad_arg = TRUE; } } @@ -364,7 +394,7 @@ int *option; /* Clear flag to set. */ int *opt_all; /* Clear all switch to set or reset. */ int *bad_arg; /* Set to true if an error is detected. */ { -/* Parse a -clear specification. */ +/* Parse a -blank specification. */ if (argc > 1 || *option) *bad_arg = TRUE; *option = TRUE; @@ -377,6 +407,35 @@ int *bad_arg; /* Set to true if an error is detected. */ } } +void parse_powersave(argc, argv, option, opt_mode, bad_arg) +int argc; /* Number of arguments for this option. */ +char *argv[]; /* Arguments for this option. */ +int *option; /* powersave flag to set. */ +int *opt_mode; /* Powersaving mode, defined in vesa_blank.c */ +int *bad_arg; /* Set to true if an error is detected. */ +{ +/* Parse a -powersave mode specification. */ + + if (argc > 1 || *option) *bad_arg = TRUE; + *option = TRUE; + if (argc == 1) { + if (strcmp(argv[0], "on") == 0) + *opt_mode = 1; + else if (strcmp(argv[0], "vsync") == 0) + *opt_mode = 1; + else if (strcmp(argv[0], "hsync") == 0) + *opt_mode = 2; + else if (strcmp(argv[0], "powerdown") == 0) + *opt_mode = 3; + else if (strcmp(argv[0], "off") == 0) + *opt_mode = 0; + else + *bad_arg = TRUE; + } else { + *opt_mode = 0; + } +} + #if 0 void parse_standout(argc, argv, option, opt_all, bad_arg) int argc; /* Number of arguments for this option. */ @@ -385,7 +444,7 @@ int *option; /* Clear flag to set. */ int *opt_all; /* Clear all switch to set or reset. */ int *bad_arg; /* Set to true if an error is detected. */ { -/* Parse a -clear specification. */ +/* Parse a -standout specification. */ if (argc > 1 || *option) *bad_arg = TRUE; *option = TRUE; @@ -423,7 +482,7 @@ int *option; /* Clear flag to set. */ int *opt_all; /* Clear all switch to set or reset. */ int *bad_arg; /* Set to true if an error is detected. */ { -/* Parse a -clear specification. */ +/* Parse a -dump or -append specification. */ if (argc > 1 || *option) *bad_arg = TRUE; *option = TRUE; @@ -443,7 +502,7 @@ int *option; /* Clear flag to set. */ int *opt_all; /* Clear all switch to set or reset. */ int *bad_arg; /* Set to true if an error is detected. */ { -/* Parse a -clear specification. */ +/* Parse a -file specification. */ if (argc != 1 || *option) *bad_arg = TRUE; *option = TRUE; @@ -514,9 +573,49 @@ int *bad_arg; /* Set to true if an error is detected. */ } } + +void parse_blength(argc, argv, option, opt_all, bad_arg) +int argc; /* Number of arguments for this option. */ +char *argv[]; /* Arguments for this option. */ +int *option; /* Clear flag to set. */ +int *opt_all; +int *bad_arg; /* Set to true if an error is detected. */ +{ +/* Parse -blength specification. */ + + if (argc > 1 || *option) *bad_arg = TRUE; + *option = TRUE; + if (argc == 1) { + *opt_all = atoi(argv[0]); + if (*opt_all > 2000) + *bad_arg = TRUE; + } else { + *opt_all = 0; + } +} + +void parse_bfreq(argc, argv, option, opt_all, bad_arg) +int argc; /* Number of arguments for this option. */ +char *argv[]; /* Arguments for this option. */ +int *option; /* Clear flag to set. */ +int *opt_all; +int *bad_arg; /* Set to true if an error is detected. */ +{ +/* Parse -bfreq specification. */ + + if (argc > 1 || *option) *bad_arg = TRUE; + *option = TRUE; + if (argc == 1) { + *opt_all = atoi(argv[0]); + } else { + *opt_all = 0; + } +} + + void show_tabs() { - int i, co = tgetnum("co"); + int i, co = tigetnum("cols"); if(co > 0) { printf("\r "); @@ -612,7 +711,13 @@ int *bad_arg; /* Set to true if an error is detected. */ else if (STRCMP(option, "msglevel") == 0) parse_msglevel(argc, argv, &opt_msglevel, &opt_msglevel_num, bad_arg); else if (STRCMP(option, "powersave") == 0) - parse_switch(argc, argv, &opt_powersave, &opt_ps_on, bad_arg); + parse_powersave(argc, argv, &opt_powersave, &opt_ps_mode, bad_arg); + else if (STRCMP(option, "powerdown") == 0) + parse_blank(argc, argv, &opt_powerdown, &opt_pd_min, bad_arg); + else if (STRCMP(option, "blength") == 0) + parse_blength(argc, argv, &opt_blength, &opt_blength_l, bad_arg); + else if (STRCMP(option, "bfreq") == 0) + parse_bfreq(argc, argv, &opt_bfreq, &opt_bfreq_f, bad_arg); #if 0 else if (STRCMP(option, "standout") == 0) parse_standout(argc, argv, &opt_standout, &opt_st_attr, bad_arg); @@ -676,23 +781,23 @@ char *prog_name; /* Name of this program. */ fprintf(stderr, " [ -file dumpfilename ]\n"); fprintf(stderr, " [ -msg [on|off] ]\n"); fprintf(stderr, " [ -msglevel [0-8] ]\n"); - fprintf(stderr, " [ -powersave [on|off] ]\n"); + fprintf(stderr, " [ -powersave [on|vsync|hsync|powerdown|off] ]\n"); + fprintf(stderr, " [ -powerdown [0-60] ]\n"); + fprintf(stderr, " [ -blength [0-2000] ]\n"); + fprintf(stderr, " [ -bfreq freqnumber ]\n"); } -char tc_ent_buf[TC_ENT_SIZE]; /* Buffer for storing a termcap entry. */ - -char *tc_entry(name) -char *name; /* Termcap capability string to lookup. */ +char *ti_entry(name) +const char *name; /* Terminfo capability string to lookup. */ { -/* Return the specified termcap string, or an empty string if no such termcap +/* Return the specified terminfo string, or an empty string if no such terminfo * capability exists. */ char *buf_ptr; - buf_ptr = tc_ent_buf; - if (tgetstr(name, &buf_ptr) == NULL) tc_ent_buf[0] = '\0'; - return tc_ent_buf; + if ((buf_ptr = tigetstr(name)) == (char *)-1) buf_ptr = NULL; + return buf_ptr; } void perform_sequence(vcterm) @@ -703,20 +808,20 @@ int vcterm; /* Set if terminal is a virtual console. */ /* -reset. */ if (opt_reset) { - printf("%s", tc_entry("rs")); + putp(ti_entry("rs1")); } /* -initialize. */ if (opt_initialize) { - printf("%s", tc_entry("is")); + putp(ti_entry("is2")); } /* -cursor [on|off]. */ if (opt_cursor) { if (opt_cu_on) - printf("%s", tc_entry("ve")); + putp(ti_entry("cnorm")); else - printf("%s", tc_entry("vi")); + putp(ti_entry("civis")); } #if 0 @@ -788,7 +893,7 @@ int vcterm; /* Set if terminal is a virtual console. */ if (vcterm) printf("\033[0m"); else - printf("%s", tc_entry("me")); + putp(ti_entry("sgr0")); } /* -foreground black|red|green|yellow|blue|magenta|cyan|white|default. @@ -834,12 +939,12 @@ int vcterm; /* Set if terminal is a virtual console. */ */ if (opt_bold) { if (opt_bo_on) - printf("%s", tc_entry("md")); + putp(ti_entry("bold")); else { if (vcterm) printf("%s%s", ESC, "[22m"); else - printf("%s", tc_entry("me")); + putp(ti_entry("sgr0")); } } @@ -848,12 +953,12 @@ int vcterm; /* Set if terminal is a virtual console. */ */ if (opt_halfbright) { if (opt_hb_on) - printf("%s", tc_entry("mh")); + putp(ti_entry("dim")); else { if (vcterm) printf("%s%s", ESC, "[22m"); else - printf("%s", tc_entry("me")); + putp(ti_entry("sgr0")); } } @@ -862,12 +967,12 @@ int vcterm; /* Set if terminal is a virtual console. */ */ if (opt_blink) { if (opt_bl_on) - printf("%s", tc_entry("mb")); + putp(ti_entry("blink")); else { if (vcterm) printf("%s%s", ESC, "[25m"); else - printf("%s", tc_entry("me")); + putp(ti_entry("sgr0")); } } @@ -876,21 +981,21 @@ int vcterm; /* Set if terminal is a virtual console. */ */ if (opt_reverse) { if (opt_re_on) - printf("%s", tc_entry("mr")); + putp(ti_entry("rev")); else { if (vcterm) printf("%s%s", ESC, "[27m"); else - printf("%s", tc_entry("me")); + putp(ti_entry("sgr0")); } } /* -underline [on|off]. */ if (opt_underline) { if (opt_un_on) - printf("%s", tc_entry("us")); + putp(ti_entry("smul")); else - printf("%s", tc_entry("ue")); + putp(ti_entry("rmul")); } /* -store. Vc only. */ @@ -901,9 +1006,9 @@ int vcterm; /* Set if terminal is a virtual console. */ /* -clear [all|rest]. */ if (opt_clear) { if (opt_cl_all) - printf("%s", tc_entry("cl")); + putp(ti_entry("clear")); else - printf("%s", tc_entry("cd")); + putp(ti_entry("ed")); } /* -tabs Vc only. */ @@ -926,7 +1031,7 @@ int vcterm; /* Set if terminal is a virtual console. */ if (opt_tb_array[0] == -1) printf("\033[3g"); else - for(i=0; opt_tb_array[i]; i++) + for(i=0; opt_tb_array[i] > 0; i++) printf("\033[%dG\033[g", opt_tb_array[i]); putchar('\r'); } @@ -942,18 +1047,23 @@ int vcterm; /* Set if terminal is a virtual console. */ } /* -blank [0-60]. */ - if (opt_blank) + if (opt_blank && vcterm) printf("\033[9;%d]", opt_bl_min); - /* -powersave [on|off] (console) */ + /* -powersave [on|vsync|hsync|powerdown|off] (console) */ if (opt_powersave) { char ioctlarg[2]; ioctlarg[0] = 10; /* powersave */ - ioctlarg[1] = opt_ps_on; + ioctlarg[1] = opt_ps_mode; if (ioctl(0,TIOCLINUX,ioctlarg)) fprintf(stderr,"cannot (un)set powersave mode\n"); } + /* -powerdown [0-60]. */ + if (opt_powerdown) { + printf("\033[14;%d]", opt_pd_min); + } + #if 0 /* -standout [num]. */ if (opt_standout) @@ -979,26 +1089,38 @@ int vcterm; /* Set if terminal is a virtual console. */ if (opt_msg && vcterm) { if (opt_msg_on) /* 7 -- Enable printk's to console */ - result = syslog(7, NULL, 0); + result = klogctl(7, NULL, 0); else /* 6 -- Disable printk's to console */ - result = syslog(6, NULL, 0); + result = klogctl(6, NULL, 0); if (result != 0) - printf("syslog error: %s\n", strerror(result)); + printf("klogctl error: %s\n", strerror(result)); } /* -msglevel [0-8] */ if (opt_msglevel && vcterm) { /* 8 -- Set level of messages printed to console */ - result = syslog(8, NULL, opt_msglevel_num); + result = klogctl(8, NULL, opt_msglevel_num); if (result != 0) - printf("syslog error: %s\n", strerror(result)); + printf("klogctl error: %s\n", strerror(result)); } + + /* -blength [0-2000] */ + if (opt_blength && vcterm) { + printf("\033[11;%d]", opt_blength_l); + } + + /* -bfreq freqnumber */ + if (opt_bfreq && vcterm) { + printf("\033[10;%d]", opt_bfreq_f); + } + } extern char *malloc(); +void screendump(int vcnum, FILE *F){ #include <sys/param.h> char infile[MAXPATHLEN]; @@ -1069,7 +1191,7 @@ try_ioctl: } } -void main(int argc, char **argv) +int main(int argc, char **argv) { int bad_arg = FALSE; /* Set if error in arguments. */ int arg, modifier; @@ -1117,13 +1239,9 @@ void main(int argc, char **argv) } } - /* Find termcap entry. */ + /* Find terminfo entry. */ - if (tgetent(tc_buf, term) != 1) { - fprintf(stderr, "%s: Could not find termcap entry for %s.\n", - argv[0], term); - exit(1); - } + setupterm(term, 1, (int *)0); /* See if the terminal is a virtual console terminal. */ @@ -1133,5 +1251,5 @@ void main(int argc, char **argv) perform_sequence(vcterm); - exit(0); + return 0; } diff --git a/misc-utils/tsort.c b/misc-utils/tsort.c index 4ccfcd539..a5a44dae8 100644 --- a/misc-utils/tsort.c +++ b/misc-utils/tsort.c @@ -93,6 +93,7 @@ typedef struct _buf { NODE *add_node(), *find_node(); void add_arc(), no_memory(), remove_node(), tsort(); char *grow_buf(), *malloc(); +int find_cycle(NODE *, NODE *, int, int); extern int errno; NODE *graph; @@ -100,6 +101,7 @@ NODE *hashtable[HASHSIZE]; NODE **cycle_buf; NODE **longest_cycle; +int main(argc, argv) int argc; char **argv; @@ -158,7 +160,7 @@ main(argc, argv) /* do the sort */ tsort(); - exit(0); + return 0; } /* double the size of oldbuf and return a pointer to the new buffer. */ @@ -213,6 +215,7 @@ add_arc(s1, s2) ++n2->n_refcnt; } +int hash_string(s) char *s; { @@ -257,7 +260,7 @@ add_node(name) n->n_flags = 0; /* add to linked list */ - if (n->n_next = graph) + if ((n->n_next = graph) != NULL) graph->n_prevp = &n->n_next; n->n_prevp = &graph; graph = n; @@ -312,7 +315,7 @@ tsort() } for (n = graph; n; n = n->n_next) if (!(n->n_flags & NF_ACYCLIC)) { - if (cnt = find_cycle(n, n, 0, 0)) { + if ((cnt = find_cycle(n, n, 0, 0)) != 0) { register int i; (void)fprintf(stderr, @@ -353,6 +356,7 @@ remove_node(n) } /* look for the longest cycle from node from to node to. */ +int find_cycle(from, to, longest_len, depth) NODE *from, *to; int depth, longest_len; diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index f869040a9..841360116 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -44,8 +44,20 @@ static char sccsid[] = "@(#)whereis.c 5.5 (Berkeley) 4/18/91"; #include <sys/param.h> #include <sys/dir.h> #include <stdio.h> +#include <string.h> #include <ctype.h> +void zerof(void); +void getlist(int *, char ***, char ***, int *); +void lookup(char *); +void looksrc(char *); +void lookbin(char *); +void lookman(char *); +void findv(char **, int, char *); +void find(char **, char *); +void findin(char *, char *); +int itsit(char *, char *); + static char *bindirs[] = { #ifdef __linux__ "/bin", @@ -66,6 +78,8 @@ static char *bindirs[] = { "/usr/lib/emacs/19.28/etc", "/usr/lib/emacs/19.29/etc", "/usr/lib/emacs/19.30/etc", + "/usr/lib/emacs/19.31/etc", + "/usr/lib/emacs/19.32/etc", "/usr/TeX/bin", "/usr/tex/bin", "/usr/interviews/bin/LINUX", @@ -231,6 +245,7 @@ char uflag; * whereis name * look for source, documentation and binaries */ +int main(argc, argv) int argc; char *argv[]; @@ -288,9 +303,10 @@ usage: } else lookup(*argv++); while (--argc > 0); - exit(0); + return 0; } +void getlist(argcp, argvp, flagp, cntp) char ***argvp; int *argcp; @@ -308,16 +324,17 @@ getlist(argcp, argvp, flagp, cntp) } +void zerof() { - if (sflag && bflag && mflag) sflag = bflag = mflag = 0; } + int count; int print; - +void lookup(cp) register char *cp; { @@ -369,6 +386,7 @@ again: printf("\n"); } +void looksrc(cp) char *cp; { @@ -378,6 +396,7 @@ looksrc(cp) findv(Sflag, Scnt, cp); } +void lookbin(cp) char *cp; { @@ -387,6 +406,7 @@ lookbin(cp) findv(Bflag, Bcnt, cp); } +void lookman(cp) char *cp; { @@ -396,6 +416,7 @@ lookman(cp) findv(Mflag, Mcnt, cp); } +void findv(dirv, dirc, cp) char **dirv; int dirc; @@ -406,6 +427,7 @@ findv(dirv, dirc, cp) findin(*dirv++, cp), dirc--; } +void find(dirs, cp) char **dirs; char *cp; @@ -415,6 +437,7 @@ find(dirs, cp) findin(*dirs++, cp); } +void findin(dir, cp) char *dir, *cp; { @@ -434,6 +457,7 @@ findin(dir, cp) closedir(dirp); } +int itsit(cp, dp) register char *cp, *dp; { diff --git a/misc-utils/write.c b/misc-utils/write.c index a1865bd71..545404b48 100644 --- a/misc-utils/write.c +++ b/misc-utils/write.c @@ -36,7 +36,10 @@ * Modified for Linux, Mon Mar 8 18:16:24 1993, faith@cs.unc.edu * Wed Jun 22 21:41:56 1994, faith@cs.unc.edu: * Added fix from Mike Grupenhoff (kashmir@umiacs.umd.edu) - * + * Mon Jul 1 17:01:39 MET DST 1996, janl@math.uio.no: + * - Added fix from David.Chapell@mail.trincoll.edu enabeling daemons + * to use write. + * - ANSIed it since I was working on it anyway. */ #ifndef lint @@ -49,27 +52,35 @@ static char copyright[] = static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ -#include <sys/param.h> -#include <sys/signal.h> -#include <sys/stat.h> -#include <sys/file.h> -#include <sys/time.h> +#define _GNU_SOURCE /* for snprintf */ + +#include <unistd.h> #include <utmp.h> #include <ctype.h> #include <pwd.h> #include <stdio.h> #include <string.h> +#include <sys/param.h> +#include <sys/signal.h> +#include <sys/stat.h> +#include <sys/file.h> +#include <sys/time.h> #ifdef __linux__ #include <paths.h> #include "pathnames.h" #include <locale.h> #endif +void search_utmp(char *, char *, char *, uid_t); +void do_write(char *, char *, uid_t); +void wr_fputs(char *); +int term_chk(char *, int *, time_t *, int); +int utmp_chk(char *, char *); + extern int errno; -main(argc, argv) - int argc; - char **argv; +void +main(int argc, char **argv) { register char *cp; time_t atime; @@ -90,21 +101,25 @@ main(argc, argv) else if (isatty(fileno(stderr))) myttyfd = fileno(stderr); else { - (void)fprintf(stderr, "write: can't find your tty\n"); - exit(1); + myttyfd = -1; } - if (!(mytty = ttyname(myttyfd))) { + if (myttyfd != -1) { + if (!(mytty = ttyname(myttyfd))) { (void)fprintf(stderr, "write: can't find your tty's name\n"); exit(1); - } - if (cp = rindex(mytty, '/')) + } + if ((cp = rindex(mytty, '/')) != NULL) mytty = cp + 1; - if (term_chk(mytty, &msgsok, &atime, 1)) + if (term_chk(mytty, &msgsok, &atime, 1)) exit(1); - if (!msgsok) { + if (!msgsok) { (void)fprintf(stderr, "write: you have write permission turned off.\n"); exit(1); + } + + } else { + mytty = "<no tty>"; } myuid = getuid(); @@ -142,28 +157,32 @@ main(argc, argv) /* NOTREACHED */ } + /* * utmp_chk - checks that the given user is actually logged in on * the given tty */ -utmp_chk(user, tty) - char *user, *tty; +int utmp_chk(char *user, char *tty) + { struct utmp u; - int ufd; + struct utmp *uptr; + int res = 1; - if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0) - return(0); /* ignore error, shouldn't happen anyway */ + utmpname(_PATH_UTMP); + setutent(); - while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u)) + while ((uptr = getutent())) { + memcpy(&u, uptr, sizeof(u)); if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0 && strncmp(tty, u.ut_line, sizeof(u.ut_line)) == 0) { - (void)close(ufd); - return(0); + res = 0; + break; } + } - (void)close(ufd); - return(1); + endutent(); + return(res); } /* @@ -177,28 +196,27 @@ utmp_chk(user, tty) * Special case for writing to yourself - ignore the terminal you're * writing from, unless that's the only terminal with messages enabled. */ -search_utmp(user, tty, mytty, myuid) - char *user, *tty, *mytty; - uid_t myuid; +void search_utmp(char *user, char *tty, char *mytty, uid_t myuid) + { struct utmp u; + struct utmp *uptr; time_t bestatime, atime; - int ufd, nloggedttys, nttys, msgsok, user_is_me; + int nloggedttys, nttys, msgsok, user_is_me; #ifdef __linux__ char atty[sizeof(u.ut_line) + 1]; #else char atty[UT_LINESIZE + 1]; #endif - if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0) { - perror("utmp"); - exit(1); - } + utmpname(_PATH_UTMP); + setutent(); nloggedttys = nttys = 0; bestatime = 0; user_is_me = 0; - while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u)) + while ((uptr = getutent())) { + memcpy(&u, uptr, sizeof(u)); if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) { ++nloggedttys; #ifdef __linux__ @@ -226,8 +244,9 @@ search_utmp(user, tty, mytty, myuid) (void)strcpy(tty, atty); } } + } - (void)close(ufd); + endutent(); if (nloggedttys == 0) { (void)fprintf(stderr, "write: %s is not logged in\n", user); exit(1); @@ -251,15 +270,13 @@ search_utmp(user, tty, mytty, myuid) * term_chk - check that a terminal exists, and get the message bit * and the access time */ -term_chk(tty, msgsokP, atimeP, showerror) - char *tty; - int *msgsokP, showerror; - time_t *atimeP; +int term_chk(char *tty, int *msgsokP, time_t *atimeP, int showerror) + { struct stat s; char path[MAXPATHLEN]; - (void)sprintf(path, "/dev/%s", tty); + (void)snprintf(path, sizeof(path), "/dev/%s", tty); if (stat(path, &s) < 0) { if (showerror) (void)fprintf(stderr, @@ -274,9 +291,8 @@ term_chk(tty, msgsokP, atimeP, showerror) /* * do_write - actually make the connection */ -do_write(tty, mytty, myuid) - char *tty, *mytty; - uid_t myuid; +void do_write(char *tty, char *mytty, uid_t myuid) + { register char *login, *nows; register struct passwd *pwd; @@ -286,12 +302,12 @@ do_write(tty, mytty, myuid) /* Determine our login name before the we reopen() stdout */ if ((login = getlogin()) == NULL) - if (pwd = getpwuid(myuid)) + if ((pwd = getpwuid(myuid)) != NULL) login = pwd->pw_name; else login = "???"; - (void)sprintf(path, "/dev/%s", tty); + (void)snprintf(path, sizeof(path), "/dev/%s", tty); if ((freopen(path, "w", stdout)) == NULL) { (void)fprintf(stderr, "write: %s: %s\n", path, strerror(errno)); exit(1); @@ -316,8 +332,7 @@ do_write(tty, mytty, myuid) /* * done - cleanup and exit */ -void -done() +void done(void) { (void)printf("EOF\r\n"); exit(0); @@ -327,10 +342,10 @@ done() * wr_fputs - like fputs(), but makes control characters visible and * turns \n into \r\n */ -wr_fputs(s) - register char *s; +void wr_fputs(char *s) + { - register char c; + char c; #define PUTC(c) if (putchar(c) == EOF) goto err; |