diff options
author | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:39 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:39 +0100 |
commit | 7eda085c41faa3445b4b168ce78ab18dab87d98a (patch) | |
tree | eb8da4baebd0af68fa84818d3d51b4a3714667fc /sys-utils | |
parent | 5c36a0eb7cdb0360f9afd5d747c321f423b35984 (diff) | |
download | util-linux-old-7eda085c41faa3445b4b168ce78ab18dab87d98a.tar.gz |
Imported from util-linux-2.9v tarball.
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/Makefile | 42 | ||||
-rw-r--r-- | sys-utils/README.hwclock | 46 | ||||
-rw-r--r-- | sys-utils/README.linux68k | 11 | ||||
-rw-r--r-- | sys-utils/README.shhopt-1.1 | 155 | ||||
-rw-r--r-- | sys-utils/arch.1 | 3 | ||||
-rw-r--r-- | sys-utils/ctrlaltdel.c | 13 | ||||
-rw-r--r-- | sys-utils/cytune.c | 134 | ||||
-rw-r--r-- | sys-utils/dmesg.c | 10 | ||||
-rw-r--r-- | sys-utils/hwclock.8 | 451 | ||||
-rw-r--r-- | sys-utils/hwclock.c | 2151 | ||||
-rw-r--r-- | sys-utils/ipcrm.c | 18 | ||||
-rw-r--r-- | sys-utils/ipcs.c | 237 | ||||
-rw-r--r-- | sys-utils/kbdrate.8 | 64 | ||||
-rw-r--r-- | sys-utils/kbdrate.c | 205 | ||||
-rw-r--r-- | sys-utils/lp.h | 83 | ||||
-rw-r--r-- | sys-utils/rdev.c | 36 | ||||
-rw-r--r-- | sys-utils/readprofile.c | 30 | ||||
-rw-r--r-- | sys-utils/renice.c | 25 | ||||
-rw-r--r-- | sys-utils/setsid.c | 11 | ||||
-rw-r--r-- | sys-utils/shhopt-1.1.lsm | 17 | ||||
-rw-r--r-- | sys-utils/shhopt.c | 467 | ||||
-rw-r--r-- | sys-utils/shhopt.h | 33 | ||||
-rw-r--r-- | sys-utils/tunelp.8 | 135 | ||||
-rw-r--r-- | sys-utils/tunelp.c | 119 |
24 files changed, 588 insertions, 3908 deletions
diff --git a/sys-utils/Makefile b/sys-utils/Makefile index 91aa32d1..0109eb14 100644 --- a/sys-utils/Makefile +++ b/sys-utils/Makefile @@ -2,17 +2,16 @@ # Created: Sat Dec 26 20:09:40 1992 # Revised: Mon Aug 19 20:12:33 1996 by faith@cs.unc.edu # Copyright 1992, 1993, 1994, 1995 Rickard E. Faith (faith@cs.unc.edu) -# Copyright 1996 Nicolai Langfeldt (janl@math.uio.no)?? # - +include ../make_include include ../MCONFIG # Where to put man pages? MAN1= arch.1 readprofile.1 -MAN8= ctrlaltdel.8 cytune.8 dmesg.8 hwclock.8 \ - ipcrm.8 ipcs.8 kbdrate.8 ramsize.8 renice.8 \ +MAN8= ctrlaltdel.8 cytune.8 dmesg.8 \ + ipcrm.8 ipcs.8 ramsize.8 renice.8 \ rootflags.8 setsid.8 sln.8 swapdev.8 tunelp.8 \ vidmode.8 @@ -21,56 +20,65 @@ MAN8= ctrlaltdel.8 cytune.8 dmesg.8 hwclock.8 \ BIN= arch dmesg -USRBIN= cytune ipcrm ipcs renice readprofile setsid tunelp +USRBIN= cytune ipcrm ipcs renice setsid + +USRSBIN= readprofile tunelp + +SBIN= ctrlaltdel -SBIN= ctrlaltdel hwclock kbdrate +NOTMADE= ifeq "$(HAVE_SLN)" "no" +ifeq "$(CAN_DO_STATIC)" "no" +NOTMADE=nosln +else SBIN:=$(SBIN) sln endif +endif ifeq "$(CPU)" "intel" MAN8:=$(MAN8) rdev.8 -USRBIN:=$(USRBIN) rdev +USRSBIN:=$(USRSBIN) rdev endif # Where to put datebase files? USRINFO= ipc.info -all: $(SBIN) $(BIN) $(USRBIN) +all: $(SBIN) $(BIN) $(USRBIN) $(USRSBIN) $(NOTMADE) sln: sln.c $(CC) -static $(CFLAGS) $(LDFLAGS) $< -o $@ +nosln: + @echo sln not made since static compilation fails here + # Rules for everything else arch: arch.o -hwclock.o: hwclock.c shhopt.h -hwclock: hwclock.o shhopt.o ctrlaltdel.o: ctrlaltdel.c $(LIB)/linux_reboot.h ctrlaltdel: ctrlaltdel.o $(LIB)/my_reboot.o ipcrm: ipcrm.o ipcs: ipcs.o -kbdrate: kbdrate.o rdev: rdev.o renice: renice.o readprofile: readprofile.o setsid: setsid.o install: all - $(INSTALLDIR) $(SBINDIR) $(BINDIR) $(USRBINDIR) + $(INSTALLDIR) $(SBINDIR) $(BINDIR) $(USRBINDIR) $(USRSBINDIR) $(INSTALLBIN) $(SBIN) $(SBINDIR) $(INSTALLBIN) $(BIN) $(BINDIR) $(INSTALLBIN) $(USRBIN) $(USRBINDIR) - (cd $(USRBINDIR); ln -sf rdev swapdev) - (cd $(USRBINDIR); ln -sf rdev ramsize) - (cd $(USRBINDIR); ln -sf rdev vidmode) - (cd $(USRBINDIR); ln -sf rdev rootflags) + $(INSTALLBIN) $(USRSBIN) $(USRSBINDIR) + (cd $(USRSBINDIR); ln -sf rdev swapdev) + (cd $(USRSBINDIR); ln -sf rdev ramsize) + (cd $(USRSBINDIR); ln -sf rdev vidmode) + (cd $(USRSBINDIR); ln -sf rdev rootflags) $(INSTALLDIR) $(MAN1DIR) $(MAN8DIR) $(INFODIR) $(INSTALLMAN) $(MAN1) $(MAN1DIR) $(INSTALLMAN) $(MAN8) $(MAN8DIR) $(INSTALLMAN) $(USRINFO) $(INFODIR) clean: - -rm -f *.o *~ core $(SBIN) $(BIN) $(USRBIN) + -rm -f *.o *~ core $(SBIN) $(BIN) $(USRBIN) $(USRSBIN) diff --git a/sys-utils/README.hwclock b/sys-utils/README.hwclock deleted file mode 100644 index 7d2f460d..00000000 --- a/sys-utils/README.hwclock +++ /dev/null @@ -1,46 +0,0 @@ -Hwclock is a program that runs under Linux and sets and queries the -Hardware Clock, which is often called the Real Time Clock, RTC, or -CMOS clock. - -Hwclock is shipped with an ELF executable built for ISA (Intel) -machines. So there is nothing to build for those machines. Just -install the executable file "hwclock" and the man page file -"hwclock.8" in suitable directories (like /sbin/hwclock and -/usr/man/man8/hwclock.8) and you're ready to go. - -hwclock accesses platform-dependent hardware, so if you have something -other than an ISA machine, the shipped executable probably doesn't work, -and you have to compile hwclock yourself. - -Sometimes, you need to install hwclock setuid root. If you want users -other than the superuser to be able to display the clock value using the -direct ISA I/O method, install it setuid root. If you have the /dev/rtc -interface on your system or are on a non-ISA system, there's no need for -users to use the direct ISA I/O method, so don't bother. - -To install setuid root, do something like this: - - chmod a=rx,u=s /sbin/hwclock - -In any case, hwclock will not allow you to set anything unless you have -the superuser _real_ uid. (This is restriction is not necessary if you -haven't installed setuid root, but it's there for now). - -You may want to preformat and/or compress the man page before installing. - -If you want to build hwclock, just cd to the source directory and invoke -make with no parameters. - -hwclock calls option processing routines in the libsshopt library, -which is part of Sverre H. Huseby's "shhopt" package. An ELF -executable of this library is included in the package, but you can use -a copy that is already on your system by altering the make file. You -can find a more authoritative copy of this library, and its source -code, on sunsite (ftp://sunsite.unc.edu/pub/Linux/libs/shhopt-X.Y). - -As shipped, the routines are linked in statically, so you only need the -libsshopt.a file to build hwclock, not to run it. - - - - diff --git a/sys-utils/README.linux68k b/sys-utils/README.linux68k deleted file mode 100644 index ae636713..00000000 --- a/sys-utils/README.linux68k +++ /dev/null @@ -1,11 +0,0 @@ - -Here are the ports of the clock and kbdrate utilities that needed -/dev/port in their original implementation. /dev/port does not exist -under Linux/68k, so the needed functionalities are implemented as new -ioctls in the kernel. The modified sources (in src/) first test if the -kernel knows that ioctls. If it does, they are used. Else, /dev/port -is tried the old way. The kernel patch necessary for clock and kbdrate -is in kernel-patch/. (It is #14a of my patch list to 0.9pl4). - -Roman (Roman.Hodek@informatik.uni-erlangen.de) - diff --git a/sys-utils/README.shhopt-1.1 b/sys-utils/README.shhopt-1.1 deleted file mode 100644 index 766d6cbd..00000000 --- a/sys-utils/README.shhopt-1.1 +++ /dev/null @@ -1,155 +0,0 @@ -shhopt - library for parsing command line options. -================================================== - -This is a set of functions for parsing command line options. Both -traditional one-character options, and GNU-style --long-options are -supported. - - -What separates this from traditional getopt? --------------------------------------------- - -This library does more of the parsing for you. You set up a special -structure describing the names and types of the options you want your -program to support. In the structure you also give addresses of -variables to update or functions to call for the various -options. By calling optParseOptions, all options in argv are parsed -and removed from argv. What is left, are the non-optional arguments to -your program. - -The down-side of this, is that you won't be able to make a program -where the position of the options between the non-options are -significant. - - -Usage ------ - -To see how to use this library, take a look at the sample program -example.c. - -A brief explanation: - -To parse your command line, you need to create and initialize an array -of optStruct's. Each element in the array describes a long and short -version of an option and specifies what type of option it is and how -to handle it. - -The structure fields (see also shhopt.h): - - `shortName' is the short option name without the leading '-'. - - `longName' is the long option name without the leading "--". - - `type' specifies what type of option this is. (Does it expect an - argument? Is it a flag? If it takes an argument,what type should - it be?) - - `arg' is either a function to be called with the argument from - the commandline, or a pointer to a location in which to store - the value. - - `flags' indicates whether `arg' points to a function or a storage - location. - -The different argument types: - - `OPT_END' flags this as the last element in the options array. - - `OPT_FLAG' indicates an option that takes no arguments. If `arg' is - not a function pointer, the value of `arg' will be set to 1 if - this flag is found on the command line. - - `OPT_STRING' expects a string argument. - - `OPT_INT' expects an int argument. - - `OPT_UINT' expects an unsigned int argument. - - `OPT_LONG' expects a long argument. - - `OPT_ULONG' expects an unsigned long argument. - -The different flag types: - - `OPT_CALLFUNC' indicates that `arg' is a function pointer. If this - is not given, `arg' is taken as a pointer to a variable. - - -Notes ------ - -* A dash (`-') by itself is not taken as any kind of an option, as - several programs use this to indicate the special files stdin and - stdout. It is thus left as a normal argument to the program. - -* Two dashes (`--') as an argument, is taken to mean that the rest of - the arguments should not be scanned for options. This simplifies - giving names of files that start with a dash. - -* Short (one-character) options accept parameters in two ways, either - directly following the option in the same argv-entry, or in the next - argv-entry: - - -sPARAMETER - -s PARAMETER - -* Long options accept parameters in two ways: - - --long-option=PARAMETER - --long-option PARAMETER - - To follow the GNU-tradition, your program documentation should use - the first form. - -* Several one-character options may be combined after a single - dash. If any of the options requires a parameter, the rest of the - string is taken as this parameter. If there is no "rest of the - string", the next argument is taken as the parameter. - -* There is no support for floating point (double) arguments to - options. This is to avoid unnecessary linking with the math - library. See example.c for how to get around this by writing a - function converting a string argument to a double. - - -Portability ------------ - -If your libc lacks strtoul, you will need to link with GNU's -liberty, -that may be found by anonymous ftp to prep.ai.mit.edu:/pub/gnu - -The library has (more or less recently) been compiled and `tested' on -the following systems: - - IRIX Release 5.3 IP22 - Linux 1.2.9 - SunOS Release 4.1.3_U1 (-liberty needed) - ULTRIX V4.4 (Rev. 69) - -All compilations were done using GNU's gcc, and GNU's make. - - -Author ------- - -The program is written by - - Sverre H. Huseby - Maridalsvn. 122, leil. 101 - N-0461 Oslo - Norway - - sverrehu@ifi.uio.no - http://www.ifi.uio.no/~sverrehu/ - -You can use and copy this for free. If you decide to use it, please do -me three small favours: - - 1. Tell me! (E-mail, postcard, letter, whatever. If you wish - to give me something, please send a bottle of your - favourite beer (making this BeerWare)) - 2. Let your friends and favourite download site have a copy! - (with all files intact, please..) - 3. Report any bugs you find! - diff --git a/sys-utils/arch.1 b/sys-utils/arch.1 index 9ce88db5..3eaf4f38 100644 --- a/sys-utils/arch.1 +++ b/sys-utils/arch.1 @@ -16,7 +16,8 @@ On current Linux systems, prints things such as "i386", "i486", "i586", "alpha", "sparc", "arm", "m68k", "mips", "ppc". .SH SEE ALSO -.BR uname (1) ", " uname (2) +.BR uname (1), +.BR uname (2) .\" .\" Details: .\" arch prints the machine part of the system_utsname struct diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c index c754fd05..5a0ac9ff 100644 --- a/sys-utils/ctrlaltdel.c +++ b/sys-utils/ctrlaltdel.c @@ -2,19 +2,28 @@ * ctrlaltdel.c - Set the function of the Ctrl-Alt-Del combination * Created 4-Jul-92 by Peter Orbaek <poe@daimi.aau.dk> * ftp://ftp.daimi.aau.dk/pub/linux/poe/ + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ #include <stdio.h> #include <unistd.h> #include <string.h> #include "linux_reboot.h" +#include "nls.h" int main(int argc, char *argv[]) { + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + if(geteuid()) { fprintf(stderr, - "You must be root to set the Ctrl-Alt-Del behaviour.\n"); + _("You must be root to set the Ctrl-Alt-Del behaviour.\n")); exit(1); } @@ -29,7 +38,7 @@ main(int argc, char *argv[]) { exit(1); } } else { - fprintf(stderr, "Usage: ctrlaltdel hard|soft\n"); + fprintf(stderr, _("Usage: ctrlaltdel hard|soft\n")); exit(1); } exit(0); diff --git a/sys-utils/cytune.c b/sys-utils/cytune.c index 510703b9..a98b6a62 100644 --- a/sys-utils/cytune.c +++ b/sys-utils/cytune.c @@ -33,6 +33,13 @@ * */ + /* + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> + * - fixed strerr(errno) in gettext calls + */ + #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -42,14 +49,16 @@ #include <string.h> #include <fcntl.h> #include <errno.h> +#include <signal.h> #include <linux/tty.h> #include <termios.h> -#if 0 -#include <linux/tqueue.h> /* required for old kernels */ + +#include "../defines.h" /* for NEED_tqueue_h */ +#ifdef NEED_tqueue_h +#include <linux/tqueue.h> /* required for old kernels (for struct tq_struct) */ /* compilation errors on other kernels */ #endif #include <linux/cyclades.h> -#include <signal.h> #if 0 #ifndef XMIT @@ -59,6 +68,8 @@ # endif #endif #endif + +#include "nls.h" /* Until it gets put in the kernel, toggle by hand. */ #undef XMIT @@ -104,9 +115,7 @@ void summary(int signal) { for(i = optind; i < argc; i ++) { j = i - optind; cc = &cmon[cmon_index]; - fprintf(stderr, "File %s, For threshold value %lu, Maximum characters " - "in fifo were %d,\nand the maximum transfer rate in " - "characters/second was %f\n", + fprintf(stderr, _("File %s, For threshold value %lu, Maximum characters in fifo were %d,\nand the maximum transfer rate in characters/second was %f\n"), argv[i], cc->threshold_value, cc->maxmax, @@ -117,10 +126,7 @@ void summary(int signal) { } cc = &cmon[cmon_index]; if (cc->threshold_value > 0 && signal != -1) { - fprintf(stderr, "File %s, For threshold value %lu and timrout value %lu," - " Maximum characters " - "in fifo were %d,\nand the maximum transfer rate in " - "characters/second was %f\n", + fprintf(stderr, _("File %s, For threshold value %lu and timrout value %lu, Maximum characters in fifo were %d,\nand the maximum transfer rate in characters/second was %f\n"), argv[cmon_index+optind], cc->threshold_value, cc->timeout_value, @@ -174,6 +180,10 @@ int main(int argc, char *argv[]) { global_argc = argc; /* For signal routine. */ global_argv = &argv; /* For signal routine. */ + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + while (EOF != (i = getopt(argc, argv, "qs:S:t:T:gGi:"))) { switch (i) { @@ -183,7 +193,7 @@ int main(int argc, char *argv[]) { case 'i': interval = atoi(optarg); if(interval <= 0) { - fprintf(stderr, "Invalid interval value: %s\n",optarg); + fprintf(stderr, _("Invalid interval value: %s\n"),optarg); errflg ++; } break; @@ -191,7 +201,7 @@ int main(int argc, char *argv[]) { ++set; set_val = atoi(optarg); if(set_val <= 0 || set_val > 12) { - fprintf(stderr, "Invalid set value: %s\n",optarg); + fprintf(stderr, _("Invalid set value: %s\n"),optarg); errflg ++; } break; @@ -199,7 +209,7 @@ int main(int argc, char *argv[]) { ++set_def; set_def_val = atoi(optarg); if(set_def_val < 0 || set_def_val > 12) { - fprintf(stderr, "Invalid default value: %s\n",optarg); + fprintf(stderr, _("Invalid default value: %s\n"),optarg); errflg ++; } break; @@ -207,7 +217,7 @@ int main(int argc, char *argv[]) { ++set_time; set_time_val = atoi(optarg); if(set_time_val <= 0 || set_time_val > 255) { - fprintf(stderr, "Invalid set time value: %s\n",optarg); + fprintf(stderr, _("Invalid set time value: %s\n"),optarg); errflg ++; } break; @@ -215,7 +225,7 @@ int main(int argc, char *argv[]) { ++set_def_time; set_def_time_val = atoi(optarg); if(set_def_time_val < 0 || set_def_time_val > 255) { - fprintf(stderr, "Invalid default time value: %s\n",optarg); + fprintf(stderr, _("Invalid default time value: %s\n"),optarg); errflg ++; } break; @@ -232,9 +242,7 @@ int main(int argc, char *argv[]) { (set && set_def) || (set_time && set_def_time) || (get && get_def)) { fprintf(stderr, - "Usage: %s [-q [-i interval]]" - " ([-s value]|[-S value]) ([-t value]|[-T value])" - " [-g|-G] file [file...]\n", + _("Usage: %s [-q [-i interval]] ([-s value]|[-S value]) ([-t value]|[-T value]) [-g|-G] file [file...]\n"), argv[0]); exit(1); } @@ -245,14 +253,16 @@ int main(int argc, char *argv[]) { for(i = optind;i < argc;i ++) { file = open(argv[i],O_RDONLY); if(file == -1) { - fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv)); exit(1); } if(ioctl(file, set ? CYSETTHRESH : CYSETDEFTHRESH, set ? set_val : set_def_val)) { - fprintf(stderr, "Can't set %s to threshold %d: %s\n", - argv[i],set?set_val:set_def_val,strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't set %s to threshold %d: %s\n"), + argv[i],set?set_val:set_def_val,strerror(errsv)); exit(1); } } @@ -261,14 +271,16 @@ int main(int argc, char *argv[]) { for(i = optind;i < argc;i ++) { file = open(argv[i],O_RDONLY); if(file == -1) { - fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv)); exit(1); } if(ioctl(file, set_time ? CYSETTIMEOUT : CYSETDEFTIMEOUT, set_time ? set_time_val : set_def_time_val)) { - fprintf(stderr, "Can't set %s to time threshold %d: %s\n", - argv[i],set_time?set_time_val:set_def_time_val,strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't set %s to time threshold %d: %s\n"), + argv[i],set_time?set_time_val:set_def_time_val,strerror(errsv)); exit(1); } } @@ -278,24 +290,27 @@ int main(int argc, char *argv[]) { for(i = optind;i < argc;i ++) { file = open(argv[i],O_RDONLY); if(file == -1) { - fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv)); exit(1); } if(ioctl(file, get ? CYGETTHRESH : CYGETDEFTHRESH, &threshold_value)) { - fprintf(stderr, "Can't get threshold for %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't get threshold for %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } if(ioctl(file, get ? CYGETTIMEOUT : CYGETDEFTIMEOUT, &timeout_value)) { - fprintf(stderr, "Can't get timeout for %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't get timeout for %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } - printf("%s: %ld %s threshold and %ld %s timeout\n", + printf(_("%s: %ld %s threshold and %ld %s timeout\n"), argv[i], threshold_value, - get?"current":"default", + get?_("current"):_("default"), timeout_value, - get?"current":"default"); + get?_("current"):_("default")); } } @@ -306,40 +321,44 @@ int main(int argc, char *argv[]) { cmon = (struct cyclades_control *) malloc(sizeof (struct cyclades_control) * numfiles); if(!cmon) { - perror("malloc failed"); + perror(_("malloc failed")); exit(1); } if(signal(SIGINT, summary)|| signal(SIGQUIT, summary)|| signal(SIGTERM, summary)) { - perror("Can't set signal handler"); + perror(_("Can't set signal handler")); exit(1); } if(gettimeofday(&lasttime,&tz)) { - perror("gettimeofday failed"); + perror(_("gettimeofday failed")); exit(1); } for(i = optind; i < argc; i ++) { cmon_index = i - optind; cmon[cmon_index].cfile = open(argv[i], O_RDONLY); if(-1 == cmon[cmon_index].cfile) { - fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv)); exit(1); } if(ioctl(cmon[cmon_index].cfile, CYGETMON, &cmon[cmon_index].c)) { - fprintf(stderr, "Can't issue CYGETMON on %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't issue CYGETMON on %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } summary(-1); if(ioctl(cmon[cmon_index].cfile, CYGETTHRESH, &threshold_value)) { - fprintf(stderr, "Can't get threshold for %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't get threshold for %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } if(ioctl(cmon[cmon_index].cfile, CYGETTIMEOUT, &timeout_value)) { - fprintf(stderr, "Can't get timeout for %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't get timeout for %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } } @@ -347,7 +366,7 @@ int main(int argc, char *argv[]) { sleep(interval); if(gettimeofday(&thistime,&tz)) { - perror("gettimeofday failed"); + perror(_("gettimeofday failed")); exit(1); } diff = dtime(&thistime, &lasttime); @@ -356,18 +375,21 @@ int main(int argc, char *argv[]) { for(i = optind; i < argc; i ++) { cmon_index = i - optind; if(ioctl(cmon[cmon_index].cfile, CYGETMON, &cywork)) { - fprintf(stderr, "Can't issue CYGETMON on %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't issue CYGETMON on %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } if(ioctl(cmon[cmon_index].cfile, CYGETTHRESH, &threshold_value)) { - fprintf(stderr, "Can't get threshold for %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't get threshold for %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } if(ioctl(cmon[cmon_index].cfile, CYGETTIMEOUT, &timeout_value)) { - fprintf(stderr, "Can't get timeout for %s: %s\n", - argv[i],strerror(errno)); + int errsv = errno; + fprintf(stderr, _("Can't get timeout for %s: %s\n"), + argv[i],strerror(errsv)); exit(1); } @@ -396,26 +418,24 @@ int main(int argc, char *argv[]) { } #ifdef XMIT - printf("%s: %lu ints, %lu/%lu chars; " - "fifo: %lu thresh, %lu tmout, " - "%lu max, %lu now\n", + printf(_("%s: %lu ints, %lu/%lu chars; ") + _("fifo: %lu thresh, %lu tmout, ") + _("%lu max, %lu now\n"), argv[i], cywork.int_count,cywork.char_count,cywork.send_count, threshold_value,timeout_value, cywork.char_max,cywork.char_last); - printf(" %f int/sec; %f rec, %f send (char/sec)\n", + printf(_(" %f int/sec; %f rec, %f send (char/sec)\n"), cywork.int_count/diff, xfer_rate, xmit_rate); #else - printf("%s: %lu ints, %lu chars; " - "fifo: %lu thresh, %lu tmout, " - "%lu max, %lu now\n", + printf(_("%s: %lu ints, %lu chars; fifo: %lu thresh, %lu tmout, %lu max, %lu now\n"), argv[i], cywork.int_count,cywork.char_count, threshold_value,timeout_value, cywork.char_max,cywork.char_last); - printf(" %f int/sec; %f rec (char/sec)\n", + printf(_(" %f int/sec; %f rec (char/sec)\n"), cywork.int_count/diff, xfer_rate); #endif diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index bfb488f9..a1026af6 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -6,12 +6,16 @@ * Modifications by Rick Sladkey (jrs@world.std.com) * Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch * by Peeter Joot. This was also suggested by John Hudson. + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ #include <linux/unistd.h> #include <stdio.h> #include <getopt.h> #include <stdlib.h> +#include "nls.h" #if __GNU_LIBRARY__ < 5 @@ -31,7 +35,7 @@ static char *progname; void usage() { - fprintf( stderr, "Usage: %s [-c] [-n level] [-s bufsize]\n", progname ); + fprintf( stderr, _("Usage: %s [-c] [-n level] [-s bufsize]\n"), progname ); } int main( int argc, char *argv[] ) @@ -45,6 +49,10 @@ int main( int argc, char *argv[] ) int lastc; int cmd = 3; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + progname = argv[0]; while ((c = getopt( argc, argv, "cn:s:" )) != EOF) { switch (c) { diff --git a/sys-utils/hwclock.8 b/sys-utils/hwclock.8 deleted file mode 100644 index 58f4a259..00000000 --- a/sys-utils/hwclock.8 +++ /dev/null @@ -1,451 +0,0 @@ -.TH CLOCK 8 "02 March 1998" -.SH NAME -clock \- query and set the hardware clock (RTC) -.SH SYNOPSIS -.B "hwclock --show" -.br -.B "hwclock --set --date=newdate" -.br -.B "hwclock --systohc" -.br -.B "hwclock --hctosys" -.br -.B "hwclock --getepoch" -.br -.B "hwclock --setepoch --epoch=year" -.br -.B "hwclock --adjust" -.br -.B "hwclock --version" -.PP -other options: -.PP -.B "--utc --directisa --test --debug" -.PP -Minimum unique abbreviations of all options are acceptable. -.PP -Also, equivalent options -r, -w, -s, -a, -v, -u, and -D are accepted for -compatibility with the program "clock". - -.SH DESCRIPTION -.I hwclock -is a tool for accessing the Hardware Clock. You can display the -current time, set the Hardware Clock to a specified time, set the -Hardware Clock to the System Time, and set the System Time from the -Hardware Clock. -.PP -You can also run -.I hwclock -periodically to insert or remove time from the Hardware Clock to -compensate for systematic drift (where the clock consistently gains or -loses time at a certain rate if left to run). - -.SH OPTIONS -You need exactly one of the following options to tell -.I hwclock -what function to perform: -.PP -.TP -.B \-\-show -Read the Hardware Clock and print the time on Standard Output. -.TP -.B \-\-set -Set the Hardware Clock to the time given by the -.B \-\-date -option. -.TP -.B \-\-hctosys -Set the System Time from the Hardware Clock. - -Also set the kernel's timezone value to the local timezone as indicated by -the TZ environment variable and/or /usr/lib/zoneinfo, as tzset(3) would -interpret them. EXCEPT: always set the Daylight Savings Time part of -the kernel's timezone value to 0 ("not Daylight Savings Time"). If DST -is indicated, just add an hour to the base part. - -See the discussion of timezones below. - -This is a good option to use in one of the system startup scripts. -.TP -.B \-\-systohc -Set the Hardware Clock to the current System Time. -.TP -.B \-\-adjust -Add or subtract time from the Hardware Clock to account for systematic -drift since the last time the clock was set or adjusted. See discussion -below. -.TP -.B \-\-getepoch -Print out standard output the kernel's Hardware Clock epoch value. -This is the number of years into AD to which a zero year value in the -Hardware Clock refers. For example, if you are using the convention -that the year counter in your Hardware Clock contains the number of -full years since 1952, then the kernel's Hardware Counter epoch value -must be 1952. - -This epoch value is used whenever hwclock reads or sets the Hardware Clock. -.TP -.B \-\-setepoch -Set the kernel's Hardware Clock epoch value to the value specified by the -.B \-\-epoch -option. See the -.B \-\-getepoch -option for details. -.TP -.B \-\-version -Print the version of -.I hwclock -on Standard Output. -.br -You need the following option if you specify -.B \-\-set -option. Otherwise, it is ignored. -.TP -.B \-\-date=date_string -Specifies the time to which to set the Hardware Clock. The value of this -option is an argument to the -.I date(1) -program. For example, -.sp -.I hwclock --set --date="9/22/96 16:45:05" -.TP -.B \-\-epoch=year -Specifies the year which is the beginning of the Hardware Clock's -epoch. I.e. the number of years into AD to which a zero value in the -Hardware Clock's year counter refers. - -For example, -.sp -.I hwclock --setepoch --epoch=1952 - -.PP -The following options apply to most functions. -.TP -.B \-\-utc -Indicates that the Hardware Clock is kept in Coordinated Universal -Time. It is your choice whether to keep your clock in UTC or local -time, but nothing in the clock tells which you've chosen. So this -option is how you give that information to -.I hwclock. - -In order to avoid any possible misunderstandings: all conversation -with the program -.I hwclock -is done in local time. If you have your clock in UTC -(as is common on a Unix system) then the option -.B --utc -tells -.I hwclock -to do the appropriate conversions: `hwclock \-\-show \-\-utc' -will tell you the local time, assuming the hardware clock is in UTC, -and `hwclock \-\-set \-\-date="XXX" \-\-utc' will set the -hardware clock to the UTC equivalent of the local time XXX. -.TP -.B \-\-directisa -is meaningful only on an ISA machine. For all other machines, it has -no effect. This option tells -.I hwclock -to use explicit I/O instructions to access the Hardware Clock. -Without this option, -.I hwclock -will try to use the /dev/rtc device (which it assumes to be driven by the -rtc device driver). If it is unable to open the device (for read), it will -use the explicit I/O instructions anyway. - -The rtc device driver was new in Linux Release 2. -.TP -.B \-\-test -Do everything except actually updating the Hardware Clock or anything -else. This is useful, especially in conjunction with -.B \-\-debug, -in learning about -.I hwclock. -.TP -.B \-\-debug -Display a lot of information about what -.I hwclock -is doing internally. Some of its function is complex and this output -can help you understand how the program works. - - -.SH NOTES - - -.SH Clocks in a Linux System -.PP -There are two main clocks in a Linux system: -.PP -.B The Hardware Clock: -This is a clock that runs independently of any control program running -in the CPU and even when the machine is powered off. - -On an ISA system, this clock is specified as part of the ISA standard. -The control program can read or set this clock to a whole second, but -the control program can also detect the edges of the 1 second clock -ticks, so the clock actually has virtually infinite precision. -.PP -This clock is commonly called the hardware clock, the real time clock, -the RTC, the BIOS clock, and the CMOS clock. Hardware Clock, in its -capitalized form, was coined for use by -.I hwclock -because all of the other names are inappropriate to the point of being -misleading. -.PP -.B The System Time: -This is the time kept by a clock inside the Linux kernel and driven by -a timer interrupt. (On an ISA machine, the timer interrupt is part of -the ISA standard). It has meaning only while Linux is running on the -machine. The System Time is the number of seconds since 00:00:00 -January 1, 1970 UTC (or more succinctly, the number of seconds since -1969). The System Time is not an integer, though. It has virtually -infinite precision. -.PP -The System Time is the time that matters. The Hardware Clock's basic -purpose in a Linux system is to keep time when Linux is not running. You -initialize the System Time to the time from the Hardware Clock when Linux -starts up, and then never use the Hardware Clock again. Note that in DOS, -for which ISA was designed, the Hardware Clock is the only real time clock. -.PP -It is important that the System Time not have any discontinuities such as -would happen if you used the -.I date(1L) -program to set it while the system is running. You can, however, do whatever -you want to the Hardware Clock while the system is running, and the next -time Linux starts up, it will do so with the adjusted time from the Hardware -Clock. You can also use the program -.I adjtimex(8) -to smoothly adjust the System Time while the system runs. -.PP -A Linux kernel maintains a concept of a local timezone for the system. -But don't be misled -- almost nobody cares what timezone the kernel -thinks it is in. Instead, programs that care about the timezone -(perhaps because they want to display a local time for you) almost -always use a more traditional method of determining the timezone: They -use the TZ environment variable and/or the /usr/local/timezone -directory, as explained in the man page for tzset(3). However, some -programs and fringe parts of the Linux kernel such as filesystems use -the kernel timezone value. An example is the vfat filesystem. If the -kernel timezone value is wrong, the vfat filesystem will report and -set the wrong timestamps on files. -.PP -.I hwclock -sets the kernel timezone to the value indicated by TZ and/or -/usr/local/timezone when you set the System Time using the -.B \-\-hctosys -option. -.PP -A complication is that the timezone value actually consists of two -parts: 1) how far from the Standard Meridian the locality is -geographically, and 2) whether or not a Daylight Savings Time (DST) -convention is in effect in the locality at the present time. In -practice, the DST part of the timezone value is almost never used, so -if the geographical part were to be set to its correct value, the -users of the timezone value would actually compute the wrong local -time. -.PP -Therefore, -.I -hwclock -violates the definition of the kernel's timezone value and always sets -the DST part to zero. If DST is supposed to be in effect, -.I -hwclock -simply adds an hour to the geographical part. - -.SH How hwclock Accesses the Hardware Clock -.PP -.I -hwclock -Uses many different ways to get and set Hardware Clock values. -The most normal way is to do I/O to the device special file /dev/rtc, -which is presumed to be driven by the rtc device driver. However, -this method is not always available. For one thing, the rtc driver is -a relatively recent addition to Linux. Older systems don't have it. -.PP -On older systems, the method of accessing the Hardware Clock depends on -the system hardware. -.PP -On an ISA system, -.I -hwclock -can directly access the "CMOS memory" registers that constitute the clock, -by doing I/O to Ports 0x70 and 0x71. It can only do this if running with -superuser effective userid. - -This is a really poor method of accessing the clock, for all the -reasons that user space programs are generally not supposed to do -direct I/O and disable interrupts. Hwclock provides it because it is -the only method available with older Linux kernels for ISA machines. - -.PP -On an m68k system, -.I -hwclock -can access the clock via the console driver, via the device special -file /dev/tty1. -.PP -On an Alpha, -.I -/dev/rtc -is the only choice. - -There are or were some Alpha Linux systems that don't have /dev/rtc -and there are or were programs that accessed the clock via almost -direct I/O using /dev/port. However, this is not as good a method as -/dev/rtc and such programs were not widely enough used that hwclock -has any need to be backward compatible with them. So hwclock does not -provide the /dev/port method and consequently will not work on an -Alpha that doesn't have /dev/rtc. - -.PP -.I -hwclock -tries to use /dev/rtc. If it is compiled for a kernel that doesn't have -that function or it is unable to open /dev/rtc, -.I -hwclock -will fall back to another method, if available. On an ISA -machine, you can force -.I -hwclock -to use the direct manipulation of the CMOS registers without even trying -/dev/rtc by specifying the --directisa option. - - -.SH The Adjust Function -.PP -The Hardware Clock is usually not very accurate. However, much of its -inaccuracy is completely predictable -- it gains or loses the same amount -of time every day. This is called systematic drift. -.I Hwclock's -"adjust" function lets you make systematic corrections to correct the -systematic drift. -.PP -It works like this: -.I Hwclock -keeps a file, -.I /etc/adjtime, -that keeps some historical information. This is called the adjtime file. -.PP -Suppose you start with no adjtime file. You issue a -.I hwclock --set -command to set the Hardware Clock to the true current time. -.I Hwclock -creates the adjtime file and records in it the current time as the -last time the clock was calibrated. -5 days -later, the clock has gained 10 seconds, so you issue another -.I hwclock --set -command to set it back 10 seconds. -.I Hwclock -updates the adjtime file to show the current time as the last time the -clock was calibrated, and records 2 seconds per day as the systematic -drift rate. 24 hours go by, and then you issue a -.I hwclock --adjust -command. -.I Hwclock -consults the adjtime file and sees that the clock gains 2 seconds per -day when left alone and that it has been left alone for exactly one -day. So it subtracts 2 seconds from the Hardware Clock. It then -records the current time as the last time the clock was adjusted. -Another 24 hours goes by and you issue another -.I hwclock --adjust. -.I Hwclock -does the same thing: subtracts 2 seconds and updates the adjtime file -with the current time as the last time the clock was adjusted. -.PP -Every time you calibrate (set) the clock (using -.I --set -or -.I --systohc -), -.I hwclock -recalculates the systematic drift rate based on how long it has been -since the last calibration, how long it has been since the last -adjustment, what drift rate was assumed in any intervening -adjustments, and the amount by which the clock is presently off. -.PP -A small amount of error creeps in any time -.I hwclock -sets the clock, so it refrains from making an adjustment that would be -less than 1 second. Later on, when you request an adjustment again, -the accumulated drift will be more than a second and -.I hwclock -will do the adjustment then. -.PP -It is good to do a -.I hwclock --adjust -just before the -.I hwclock --hctosys -at system startup time, and maybe periodically while the system is -running via cron. -.PP -The format of the adjtime file is, in ASCII: -.PP -Line 1: 3 numbers, separated by blanks: 1) systematic drift rate in -seconds per day, floating point decimal; 2) Resulting number of -seconds since 1969 UTC of most recent adjustment or calibration, -decimal integer; 3) zero (for compatibility with -.I clock -). -.PP -Line 2: 1 number: Resulting number of seconds since 1969 UTC of most -recent calibration. -.PP -You can use an adjtime file that was previously used with the -.I clock -program with -.I hwclock. - - -.SH Automatic Hardware Clock Synchronization By the Kernel - -You should be aware of another way that the Hardware Clock is kept -synchronized in some systems. The Linux kernel has a mode wherein it -copies the System Time to the Hardware Clock every 11 minutes. -This is a good mode to use when you are using something sophisticated -like ntp to keep your System Time synchronized. (ntp is a way to keep -your System Time synchronized either to a time server somewhere on the -network or to a radio clock hooked up to your system. See RFC 1305). - -This mode (we'll call it "11 minute mode") is off until something -turns it on. The ntp daemon xntpd is one thing that turns it on. You -can turn it off by running anything, including -.I hwclock --hctosys -, that sets the System Time the old fashioned way. - -To see if it is on or -off, use the command -.I adjtimex --print -and look at the value of "status". If the "64" bit of this number -(expressed in binary) equal to 0, 11 minute mode is on. Otherwise, it -is off. - -If your system runs with 11 minute mode on, don't use -.I hwclock --adjust -or -.I hwclock --hctosys . -You'll just make a mess. It is acceptable to use a -.I hwclock --hctosys -at startup time to get a reasonable System Time until your system is -able to set the System Time from the external source and start 11 -minute mode. - - -.SH ENVIRONMENT VARIABLES -.I TZ - -.SH FILES -.I /etc/adjtime -.I /usr/lib/zoneinfo/ - -.SH SEE ALSO -adjtimex(8), date(1), gettimeofday(2), settimeofday(2), crontab(1), -tzset(3) - -.SH AUTHORS -Written By Bryan Henderson, September 1996 (bryanh@giraffe-data.com), -based on work done on the -.I clock -program by Charles Hedrick, Rob Hooft, and Harald Koenig. See the source -code for complete history and credits. diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c deleted file mode 100644 index 02302da2..00000000 --- a/sys-utils/hwclock.c +++ /dev/null @@ -1,2151 +0,0 @@ -/************************************************************************** - hwclock -*************************************************************************** - - This is a program for reading and setting the Hardware Clock on an ISA - family computer. This is the clock that is also known as the RTC, - real time clock, or, unfortunately, the CMOS clock. - - See man page for details. - - By Bryan Henderson, 96.09.19. bryanh@giraffe-data.com - - Based on work by others; see history at end of source code. - -**************************************************************************/ -/************************************************************************** - Maintenance notes - - To compile this, you must use GNU compiler optimization (-O option) - in order to make the "extern inline" functions from asm/io.h (inb(), - etc.) compile. If you don't optimize, which means the compiler - will generate no inline functions, the references to these functions - in this program will be compiled as external references. Since you - probably won't be linking with any functions by these names, you will - have unresolved external references when you link. - - The program is designed to run setuid superuser, since we need to be - able to do direct I/O. (More to the point: we need permission to - execute the iopl() system call). (However, if you use one of the - methods other than direct ISA I/O to access the clock, no setuid is - required). - - Here's some info on how we must deal with the time that elapses while - this program runs: There are two major delays as we run: - - 1) Waiting up to 1 second for a transition of the Hardware Clock so - we are synchronized to the Hardware Clock. - - 2) Running the "date" program to interpret the value of our --date - option. - - Reading the /etc/adjtime file is the next biggest source of delay and - uncertainty. - - The user wants to know what time it was at the moment he invoked us, - not some arbitrary time later. And in setting the clock, he is - giving us the time at the moment we are invoked, so if we set the - clock some time later, we have to add some time to that. - - So we check the system time as soon as we start up, then run "date" - and do file I/O if necessary, then wait to synchronize with a - Hardware Clock edge, then check the system time again to see how - much time we spent. We immediately read the clock then and (if - appropriate) report that time, and additionally, the delay we measured. - - If we're setting the clock to a time given by the user, we wait some - more so that the total delay is an integral number of seconds, then - set the Hardware Clock to the time the user requested plus that - integral number of seconds. N.B. The Hardware Clock can only be set - in integral seconds. - - If we're setting the clock to the system clock value, we wait for - the system clock to reach the top of a second, and then set the - Hardware Clock to the system clock's value. - - Here's an interesting point about setting the Hardware Clock: On my - machine, when you set it, it sets to that precise time. But one can - imagine another clock whose update oscillator marches on a steady one - second period, so updating the clock between any two oscillator ticks - is the same as updating it right at the earlier tick. To avoid any - complications that might cause, we set the clock as soon as possible - after an oscillator tick. - - - About synchronizing to the Hardware Clock when reading the time: The - precision of the Hardware Clock counters themselves is one second. - You can't read the counters and find out that is 12:01:02.5. But if - you consider the location in time of the counter's ticks as part of - its value, then its precision is as infinite as time is continuous! - What I'm saying is this: To find out the _exact_ time in the - hardware clock, we wait until the next clock tick (the next time the - second counter changes) and measure how long we had to wait. We - then read the value of the clock counters and subtract the wait time - and we know precisely what time it was when we set out to query the - time. - - hwclock uses this method, and considers the Hardware Clock to have - infinite precision. - - - Enhancements needed: - - - When waiting for whole second boundary in set_hardware_clock_exact, - fail if we miss the goal by more than .1 second, as could happen if - we get pre-empted (by the kernel dispatcher). - -****************************************************************************/ - -#include <string.h> -#include <stdio.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#include <time.h> -#include <sys/time.h> -#include <sys/stat.h> -#ifdef __i386__ -#include <asm/io.h> /* for inb, outb */ -#endif -#include <shhopt.h> -#include "../version.h" - -#define MYNAME "hwclock" -#define VERSION "2.4" - -#define FLOOR(arg) ((arg >= 0 ? (int) arg : ((int) arg) - 1)); - -/* Here the information for time adjustments is kept. */ -#define ADJPATH "/etc/adjtime" - -/* Note that we must define the boolean type as int because we use the - shhopt option processing library which, unfortunately, returns flag - options as integers. It is customary to define bool as char, but - then we would have to do a lot of conversion in order to interface - with shhopt. -*/ -typedef int bool; -#define TRUE 1 -#define FALSE 0 - -struct adjtime { - /* This is information we keep in the adjtime file that tells us how - to do drift corrections. Elements are all straight from the - adjtime file, so see documentation of that file for details. - Exception is <dirty>, which is an indication that what's in this - structure is not what's in the disk file (because it has been - updated since read from the disk file). - */ - bool dirty; - float drift_factor; - time_t last_adj_time; - float not_adjusted; - time_t last_calib_time; -}; - - -enum clock_access_method {ISA, RTC_IOCTL, KD, NOCLOCK}; - /* A method for accessing (reading, writing) the hardware clock: - - ISA: - via direct CPU I/O instructions that work on an ISA family - machine (IBM PC compatible). - - RTC_IOCTL: - via the rtc device driver, using device special file /dev/rtc. - - KD: - via the console driver, using device special file /dev/tty1. - This is the m68k ioctl interface, known as KDGHWCLK. - - NO_CLOCK: - Unable to determine a usable access method for the system clock. - */ - -#ifdef __i386__ -/* The following are just constants. Oddly, this program will not - compile if the inb() and outb() functions use something even - slightly different from these variables. This is probably at least - partially related to the fact that __builtin_constant_p() doesn't - work (is never true) in an inline function. See comment to this - effect in asm/io.h. -*/ -static unsigned short clock_ctl_addr = 0x70; -static unsigned short clock_data_addr = 0x71; -#endif - -bool debug; - /* We are running in debug mode, wherein we put a lot of information about - what we're doing to standard output. Because of the pervasive and yet - background nature of this value, this is a global variable. */ - -bool interrupts_enabled; - /* Interrupts are enabled as normal. We, unfortunately, turn interrupts - on the machine off in some places where we do the direct ISA accesses - to the Hardware Clock. It is in extremely poor form for a user space - program to do this, but that's the price we have to pay to run on an - ISA machine without the rtc driver in the kernel. - - Code which turns interrupts off uses this value to determine if they - need to be turned back on. - */ - -#include <linux/version.h> -/* Check if the /dev/rtc interface is available in this version of - the system headers. 131072 is linux 2.0.0. Might need to make - it conditional on i386 or something too -janl */ -#if LINUX_VERSION_CODE >= 131072 -#include <linux/mc146818rtc.h> -#include <linux/kd.h> -static const bool got_rtc = TRUE; -#else -static const bool got_rtc = FALSE; -/* Dummy definitions to make it compile. If any lines containing these - macros ever execute, there is a bug in the code. - */ -#define RTC_SET_TIME -1 -#define RTC_RD_TIME -1 -#define RTC_UIE_ON -1 -#define RTC_UIE_OFF -1 -#endif - -/* The RTC_EPOCH_READ and RTC_EPOCH_SET macros are supposed to be - defined by linux/mc146818rtc.h, included above. However, these are - recent inventions and at the time of this writing, not in any - official Linux. Since these values aren't even necessary for most - uses of hwclock, we don't want compilation to depend on the user - having some arcane version of this header file on his system. Thus, - we define the macros ourselves if the header file failed to do so. - 98.03.03. -*/ - -#ifndef RTC_EPOCH_READ -#define RTC_EPOCH_READ _IOR('p', 0x0d, unsigned long) /* Read epoch */ - /* Not all kernels have this ioctl */ -#endif - -#ifndef RTC_EPOCH_SET -#define RTC_EPOCH_SET _IOW('p', 0x0e, unsigned long) /* Set epoch */ - /* Not all kernels have this ioctl */ -#endif - - -#if defined(KDGHWCLK) -static const bool got_kdghwclk = TRUE; -static const int kdghwclk_ioctl = KDGHWCLK; -static const int kdshwclk_ioctl = KDSHWCLK; -#else -static const bool got_kdghwclk = FALSE; -static const int kdghwclk_ioctl; /* Never used; just to make compile work */ -struct hwclk_time {int sec;}; - /* Never used; just to make compile work */ -#endif - - -/* We're going to assume that if the CPU is in the Intel x86 family, - this is an ISA family machine. For all practical purposes, this is - the case at the time of this writing, especially after we assume a - Linux kernel is running on it. - */ -const bool isa_machine = -#ifdef __i386__ -TRUE -#else -FALSE; -#endif -; - -const bool alpha_machine = -#ifdef __alpha__ -TRUE -#else -FALSE; -#endif -; - - - -static int -i386_iopl(const int level) { -/*---------------------------------------------------------------------------- - When compiled for an Intel target, this is just the iopl() kernel call. - When compiled for any other target, this is a dummy function. - - We do it this way in order to keep the conditional compilation stuff - out of the way so it doesn't mess up readability of the code. ------------------------------------------------------------------------------*/ -#ifdef __i386__ - extern int iopl(const int level); - return iopl(level); -#else - return -1; -#endif -} - - - -static float -time_diff(struct timeval subtrahend, struct timeval subtractor) { -/*--------------------------------------------------------------------------- - The difference in seconds between two times in "timeval" format. -----------------------------------------------------------------------------*/ - return( (subtrahend.tv_sec - subtractor.tv_sec) - + (subtrahend.tv_usec - subtractor.tv_usec) / 1E6 ); -} - - -static struct timeval -time_inc(struct timeval addend, float increment) { -/*---------------------------------------------------------------------------- - The time, in "timeval" format, which is <increment> seconds after - the time <addend>. Of course, <increment> may be negative. ------------------------------------------------------------------------------*/ - struct timeval newtime; - - newtime.tv_sec = addend.tv_sec + (int) increment; - newtime.tv_usec = addend.tv_usec + (increment - (int) increment) * 1E6; - - /* Now adjust it so that the microsecond value is between 0 and 1 million */ - if (newtime.tv_usec < 0) { - newtime.tv_usec += 1E6; - newtime.tv_sec -= 1; - } else if (newtime.tv_usec >= 1E6) { - newtime.tv_usec -= 1E6; - newtime.tv_sec += 1; - } - return(newtime); -} - - - -static inline unsigned char -hclock_read(unsigned char reg) { -/*--------------------------------------------------------------------------- - Relative byte <reg> of the Hardware Clock value. - - On non-ISA machine, just return 0. ----------------------------------------------------------------------------*/ - register unsigned char ret; -#ifdef __i386__ - const bool interrupts_were_enabled = interrupts_enabled; - - __asm__ volatile ("cli"); - interrupts_enabled = FALSE; - /* & 0x7f ensures that we are not disabling NMI while we read. - Setting on Bit 7 here would disable NMI - */ - outb(reg & 0x7f, clock_ctl_addr); - ret = inb(clock_data_addr); - if (interrupts_were_enabled) { - __asm__ volatile ("sti"); - interrupts_enabled = TRUE; - } -#else - ret = 0; -#endif - return ret; -} - - - -static inline void -hclock_write(unsigned char reg, unsigned char val) { -/*---------------------------------------------------------------------------- - Set relative byte <reg> of the Hardware Clock value to <val>. - - On non-ISA machine, do nothing. -----------------------------------------------------------------------------*/ -#ifdef __i386__ - /* & 0x7f ensures that we are not disabling NMI while we read. - Setting on Bit 7 here would disable NMI - */ - outb(reg & 0x7f, clock_ctl_addr); - outb(val, clock_data_addr); -#endif -} - - - -static inline int -hclock_read_bcd (int addr) { - int b; - b = hclock_read(addr); - return (b & 15) + (b >> 4) * 10; -} - -static inline void -hclock_write_bcd(int addr, int value) { - hclock_write(addr, ((value / 10) << 4) + value % 10); -} - - -static void -read_adjtime(struct adjtime *adjtime_p, int *rc_p) { -/*---------------------------------------------------------------------------- - Read the adjustment parameters out of the /etc/adjtime file. - - Return them as the adjtime structure <*adjtime_p>. - - If there is no /etc/adjtime file, return defaults. - If values are missing from the file, return defaults for them. - - return *rc_p = 0 if all OK, !=0 otherwise. - ------------------------------------------------------------------------------*/ - FILE *adjfile; - int rc; /* local return code */ - struct stat statbuf; /* We don't even use the contents of this. */ - - rc = stat(ADJPATH, &statbuf); - if (rc < 0 && errno == ENOENT) { - /* He doesn't have a adjtime file, so we'll use defaults. */ - adjtime_p->drift_factor = 0; - adjtime_p->last_adj_time = 0; - adjtime_p->not_adjusted = 0; - adjtime_p->last_calib_time = 0; - - *rc_p = 0; - } else { - adjfile = fopen(ADJPATH, "r"); /* open file for reading */ - if (adjfile == NULL) { - const int fopen_errno = errno; - fprintf(stderr, MYNAME " is unable to open file " ADJPATH ". " - "fopen() errno=%d:%s", fopen_errno, strerror(fopen_errno)); - *rc_p = 2; - } else { - char line1[81]; /* String: first line of adjtime file */ - char line2[81]; /* String: second line of adjtime file */ - - line1[0] = '\0'; /* In case fgets fails */ - fgets(line1, sizeof(line1), adjfile); - line2[0] = '\0'; /* In case fgets fails */ - fgets(line2, sizeof(line2), adjfile); - - fclose(adjfile); - - /* Set defaults in case values are missing from file */ - adjtime_p->drift_factor = 0; - adjtime_p->last_adj_time = 0; - adjtime_p->not_adjusted = 0; - adjtime_p->last_calib_time = 0; - - sscanf(line1, "%f %d %f", - &adjtime_p->drift_factor, - (int *) &adjtime_p->last_adj_time, - &adjtime_p->not_adjusted); - - sscanf(line2, "%d", (int *) &adjtime_p->last_calib_time); - - *rc_p = 0; - } - adjtime_p->dirty = FALSE; - - if (debug) { - printf("Last drift adjustment done at %d seconds after 1969\n", - (int) adjtime_p->last_adj_time); - printf("Last calibration done at %d seconds after 1969\n", - (int) adjtime_p->last_calib_time); - } - } -} - - - -static void -synchronize_to_clock_tick_ISA(int *retcode_p) { -/*---------------------------------------------------------------------------- - Same as synchronize_to_clock_tick(), but just for ISA. ------------------------------------------------------------------------------*/ - int i; /* local loop index */ - - /* Wait for rise. Should be within a second, but in case something - weird happens, we have a limit on this loop to reduce the impact - of this failure. - */ - for (i = 0; !(hclock_read(10) & 0x80) && (i < 10000000); i++); - if (i >= 10000000) *retcode_p = 1; - else { - /* Wait for fall. Should be within 2.228 ms. */ - for (i = 0; (hclock_read(10) & 0x80) && (i < 1000000); i++); - if (i >= 10000000) *retcode_p = 1; - else *retcode_p = 0; - } -} - - - -static void -busywait_for_rtc_clock_tick(const int rtc_fd, int *retcode_p) { -/*---------------------------------------------------------------------------- - Wait for the top of a clock tick by reading /dev/rtc in a busy loop until - we see it. ------------------------------------------------------------------------------*/ - struct tm start_time; - /* The time when we were called (and started waiting) */ - int rc; - - if (debug) - printf("Waiting in loop for time from /dev/rtc to change\n"); - - rc = ioctl(rtc_fd, RTC_RD_TIME, &start_time); - if (rc == -1) { - fprintf(stderr, "ioctl() to /dev/rtc to read time failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 1; - } else { - /* Wait for change. Should be within a second, but in case something - weird happens, we have a limit on this loop to reduce the impact - of this failure. - */ - struct tm nowtime; - int i; /* local loop index */ - int rc; /* Return code from ioctl */ - - for (i = 0; - (rc = ioctl(rtc_fd, RTC_RD_TIME, &nowtime)) != -1 - && start_time.tm_sec == nowtime.tm_sec && i < 1000000; - i++); - if (i >= 1000000) { - fprintf(stderr, "Timed out waiting for time change.\n"); - *retcode_p = 2; - } else if (rc == -1) { - fprintf(stderr, "ioctl() to /dev/rtc to read time failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 3; - } else *retcode_p = 0; - } -} - - - -static void -synchronize_to_clock_tick_RTC(int *retcode_p) { -/*---------------------------------------------------------------------------- - Same as synchronize_to_clock_tick(), but just for /dev/rtc. ------------------------------------------------------------------------------*/ -int rtc_fd; /* File descriptor of /dev/rtc */ - - rtc_fd = open("/dev/rtc",O_RDONLY); - if (rtc_fd == -1) { - fprintf(stderr, "open() of /dev/rtc failed, errno = %s (%d).\n", - strerror(errno), errno); - *retcode_p = 1; - } else { - int rc; /* Return code from ioctl */ - /* Turn on update interrupts (one per second) */ - rc = ioctl(rtc_fd, RTC_UIE_ON, 0); - if (rc == -1 && errno == EINVAL) { - /* This rtc device doesn't have interrupt functions. This is typical - on an Alpha, where the Hardware Clock interrupts are used by the - kernel for the system clock, so aren't at the user's disposal. - */ - if (debug) printf("/dev/rtc does not have interrupt functions. "); - busywait_for_rtc_clock_tick(rtc_fd, retcode_p); - } else if (rc != -1) { - int rc; /* return code from ioctl */ - unsigned long dummy; - - /* this blocks until the next update interrupt */ - rc = read(rtc_fd, &dummy, sizeof(dummy)); - if (rc == -1) { - fprintf(stderr, "read() to /dev/rtc to wait for clock tick failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 1; - } else { - *retcode_p = 0; - } - /* Turn off update interrupts */ - rc = ioctl(rtc_fd, RTC_UIE_OFF, 0); - if (rc == -1) { - fprintf(stderr, "ioctl() to /dev/rtc to turn off update interrupts " - "failed, errno = %s (%d).\n", strerror(errno), errno); - } - } else { - fprintf(stderr, "ioctl() to /dev/rtc to turn on update interrupts " - "failed unexpectedly, errno = %s (%d).\n", - strerror(errno), errno); - *retcode_p = 1; - } - close(rtc_fd); - } -} - - - -static void -synchronize_to_clock_tick_KD(int *retcode_p) { -/*---------------------------------------------------------------------------- - Wait for the top of a clock tick by calling KDGHWCLK in a busy loop until - we see it. ------------------------------------------------------------------------------*/ - int con_fd; - - if (debug) - printf("Waiting in loop for time from KDGHWCLK to change\n"); - - con_fd = open("/dev/tty1", O_RDONLY); - if (con_fd < 0) { - fprintf(stderr, "open() failed to open /dev/tty1, errno = %s (%d).\n", - strerror(errno), errno); - *retcode_p = 1; - } else { - int rc; /* return code from ioctl() */ - int i; /* local loop index */ - /* The time when we were called (and started waiting) */ - struct hwclk_time start_time, nowtime; - - rc = ioctl(con_fd, kdghwclk_ioctl, &start_time); - if (rc == -1) { - fprintf(stderr, "KDGHWCLK to read time failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 3; - } - - for (i = 0; - (rc = ioctl(con_fd, kdghwclk_ioctl, &nowtime)) != -1 - && start_time.sec == nowtime.sec && i < 1000000; - i++); - if (i >= 1000000) { - fprintf(stderr, "Timed out waiting for time change.\n"); - *retcode_p = 2; - } else if (rc == -1) { - fprintf(stderr, "KDGHWCLK to read time failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 3; - } else *retcode_p = 0; - close(con_fd); - } -} - - - -static void -synchronize_to_clock_tick(enum clock_access_method clock_access, - int *retcode_p) { -/*----------------------------------------------------------------------------- - Wait until the falling edge of the Hardware Clock's update flag so - that any time that is read from the clock immediately after we - return will be exact. - - The clock only has 1 second precision, so it gives the exact time only - once per second, right on the falling edge of the update flag. - - We wait (up to one second) either blocked waiting for an rtc device - or in a CPU spin loop. The former is probably not very accurate. - - For the KD clock access method, we have no way to synchronize, so we - just return immediately. This will mess some things up, but it's the - best we can do. - - Return *retcode_p == 0 if it worked, nonzero if it didn't. - ------------------------------------------------------------------------------*/ - if (debug) printf("Waiting for clock tick...\n"); - - switch (clock_access) { - case ISA: synchronize_to_clock_tick_ISA(retcode_p); break; - case RTC_IOCTL: synchronize_to_clock_tick_RTC(retcode_p); break; - case KD: synchronize_to_clock_tick_KD(retcode_p); break; - default: - fprintf(stderr, "Internal error in synchronize_to_clock_tick. Invalid " - "value for clock_access argument.\n"); - *retcode_p = 1; - } - if (debug) printf("...got clock tick\n"); - return; -} - - - -static void -mktime_tz(struct tm tm, const bool universal, - bool *valid_p, time_t *systime_p) { -/*----------------------------------------------------------------------------- - Convert a time in broken down format (hours, minutes, etc.) into standard - unix time (seconds into epoch). Return it as *systime_p. - - The broken down time is argument <tm>. This broken down time is either in - local time zone or UTC, depending on value of logical argument "universal". - True means it is in UTC. - - If the argument contains values that do not constitute a valid time, - and mktime() recognizes this, return *valid_p == false and - *systime_p undefined. However, mktime() sometimes goes ahead and - computes a fictional time "as if" the input values were valid, - e.g. if they indicate the 31st day of April, mktime() may compute - the time of May 1. In such a case, we return the same fictional - value mktime() does as *systime_p and return *valid_p == true. - ------------------------------------------------------------------------------*/ - time_t mktime_result; /* The value returned by our mktime() call */ - char *zone; /* Local time zone name */ - - /* We use the C library function mktime(), but since it only works on - local time zone input, we may have to fake it out by temporarily - changing the local time zone to UTC. - */ - zone = (char *) getenv("TZ"); /* remember original time zone */ - - if (universal) { - /* Set timezone to UTC */ - setenv("TZ", "", TRUE); - /* Note: tzset() gets called implicitly by the time code, but only the - first time. When changing the environment variable, better call - tzset() explicitly. - */ - tzset(); - } - mktime_result = mktime(&tm); - if (mktime_result == -1) { - /* This apparently (not specified in mktime() documentation) means - the 'tm' structure does not contain valid values (however, not - containing valid values does _not_ imply mktime() returns -1). - */ - *valid_p = FALSE; - *systime_p = 0; - if (debug) - printf("Invalid values in hardware clock: " - "%2d/%.2d/%.2d %.2d:%.2d:%.2d\n", - tm.tm_year, tm.tm_mon+1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec - ); - } else { - *valid_p = TRUE; - *systime_p = mktime_result; - if (debug) - printf("Hw clock time : %.2d:%.2d:%.2d = %d seconds since 1969\n", - tm.tm_hour, tm.tm_min, tm.tm_sec, (int) *systime_p); - } - /* now put back the original zone. */ - if (zone) setenv("TZ", zone, TRUE); - else unsetenv("TZ"); - tzset(); -} - - - -static void -read_hardware_clock_kd(struct tm *tm) { -/*---------------------------------------------------------------------------- - Read the hardware clock and return the current time via <tm> - argument. Use ioctls to /dev/tty1 on what we assume is an m68k - machine. - - Note that we don't use /dev/console here. That might be a serial - console. ------------------------------------------------------------------------------*/ -#ifdef KDGHWCLK - int con_fd; - struct hwclk_time t; - - con_fd = open("/dev/tty1", O_RDONLY); - if (con_fd < 0) { - fprintf(stderr, "open() failed to open /dev/tty1, errno = %s (%d).\n", - strerror(errno), errno); - exit(5); - } else { - int rc; /* return code from ioctl() */ - - rc = ioctl(con_fd, kdghwclk_ioctl, &t); - if (rc == -1) { - fprintf(stderr, "ioctl() failed to read time from /dev/tty1, " - "errno = %s (%d).\n", - strerror(errno), errno); - exit(5); - } - close(con_fd); - } - - tm->tm_sec = t.sec; - tm->tm_min = t.min; - tm->tm_hour = t.hour; - tm->tm_mday = t.day; - tm->tm_mon = t.mon; - tm->tm_year = t.year; - tm->tm_wday = t.wday; - tm->tm_isdst = -1; /* Don't know if it's Daylight Savings Time */ -#else - /* This routine should never be invoked. It is here just to make the - program compile. - */ -#endif -} - - - -static void -read_hardware_clock_rtc_ioctl(struct tm *tm) { -/*---------------------------------------------------------------------------- - Read the hardware clock and return the current time via <tm> - argument. Use ioctls to "rtc" device /dev/rtc. ------------------------------------------------------------------------------*/ -#if defined(_MC146818RTC_H) - int rc; /* Local return code */ - int rtc_fd; /* File descriptor of /dev/rtc */ - - rtc_fd = open("/dev/rtc",O_RDONLY); - if (rtc_fd == -1) { - fprintf(stderr, "open() of /dev/rtc failed, errno = %s (%d).\n", - strerror(errno), errno); - exit(5); - } else { - /* Read the RTC time/date */ - rc = ioctl(rtc_fd, RTC_RD_TIME, tm); - if (rc == -1) { - fprintf(stderr, "ioctl() to /dev/rtc to read the time failed, " - "errno = %s (%d).\n", strerror(errno), errno); - exit(5); - } - close(rtc_fd); - } - tm->tm_isdst = -1; /* don't know whether it's daylight */ -#else - /* This function should never be called. It exists just to make the - program compile. - */ -#endif -} - - - -static void -read_hardware_clock_isa(struct tm *tm) { -/*---------------------------------------------------------------------------- - Read the hardware clock and return the current time via <tm> argument. - Assume we have an ISA machine and read the clock directly with CPU I/O - instructions. - - This function is not totally reliable. It takes a finite and - unpredictable amount of time to execute the code below. During that - time, the clock may change and we may even read an invalid value in - the middle of an update. We do a few checks to minimize this - possibility, but only the kernel can actually read the clock - properly, since it can execute code in a short and predictable - amount of time (by turning of interrupts). - - In practice, the chance of this function returning the wrong time is - extremely remote. - ------------------------------------------------------------------------------*/ - bool got_time; - /* We've successfully read a time from the Hardware Clock */ - - got_time = FALSE; - while (!got_time) { - /* Bit 7 of Byte 10 of the Hardware Clock value is the Update In Progress - (UIP) bit, which is on while and 244 uS before the Hardware Clock - updates itself. It updates the counters individually, so reading - them during an update would produce garbage. The update takes 2mS, - so we could be spinning here that long waiting for this bit to turn - off. - - Furthermore, it is pathologically possible for us to be in this - code so long that even if the UIP bit is not on at first, the - clock has changed while we were running. We check for that too, - and if it happens, we start over. - */ - - if ((hclock_read(10) & 0x80) == 0) { - /* No clock update in progress, go ahead and read */ - tm->tm_sec = hclock_read_bcd(0); - tm->tm_min = hclock_read_bcd(2); - tm->tm_hour = hclock_read_bcd(4); - tm->tm_wday = hclock_read_bcd(6) - 3; - tm->tm_mday = hclock_read_bcd(7); - tm->tm_mon = hclock_read_bcd(8) - 1; - tm->tm_year = hclock_read_bcd(9); - /* We don't use the century byte (Byte 50) of the Hardware Clock. - Here's why: On older machines, it isn't defined. In at least - one reported case, a machine puts some arbitrary value in that - byte. Furthermore, the Linux standard time data structure doesn't - allow for times beyond about 2037 and no Linux systems were - running before 1937. Therefore, all the century byte could tell - us is that the clock is wrong or this whole program is obsolete! - - So we just say if the year of century is less than 37, it's the - 21st century, otherwise it's the 20th. - */ - - if (hclock_read_bcd(9) >= 37) tm->tm_year = hclock_read_bcd(9); - else tm->tm_year = hclock_read_bcd(9) + 100; - } - /* Unless the clock changed while we were reading, consider this - a good clock read . - */ - if (tm->tm_sec == hclock_read_bcd (0)) got_time = TRUE; - /* Yes, in theory we could have been running for 60 seconds and - the above test wouldn't work! - */ - } - tm->tm_isdst = -1; /* don't know whether it's daylight */ -} - - - -static void -read_hardware_clock(const enum clock_access_method method, - const bool universal, bool *valid_p, time_t *systime_p){ -/*---------------------------------------------------------------------------- - Read the hardware clock and return the current time via <tm> argument. - - Use the method indicated by <method> argument to access the hardware clock. ------------------------------------------------------------------------------*/ - struct tm tm; - - - switch (method) { - case ISA: - read_hardware_clock_isa(&tm); - break; - case RTC_IOCTL: - read_hardware_clock_rtc_ioctl(&tm); - break; - case KD: - read_hardware_clock_kd(&tm); - break; - default: - fprintf(stderr, - "Internal error: invalid value for clock access method.\n"); - exit(5); - } - if (debug) - printf ("Time read from Hardware Clock: %02d:%02d:%02d\n", - tm.tm_hour, tm.tm_min, tm.tm_sec); - mktime_tz(tm, universal, valid_p, systime_p); -} - - - -static void -set_hardware_clock_kd(const struct tm new_broken_time, - const bool testing) { -/*---------------------------------------------------------------------------- - Set the Hardware Clock to the time <new_broken_time>. Use ioctls to - /dev/tty1 on what we assume is an m68k machine. - - Note that we don't use /dev/console here. That might be a serial console. -----------------------------------------------------------------------------*/ -#ifdef KDGHWCLK - int con_fd; /* File descriptor of /dev/tty1 */ - struct hwclk_time t; - - con_fd = open("/dev/tty1", O_RDONLY); - if (con_fd < 0) { - fprintf(stderr, "Error opening /dev/tty1. Errno: %s (%d)\n", - strerror(errno), errno); - exit(1); - } else { - int rc; /* locally used return code */ - - t.sec = new_broken_time.tm_sec; - t.min = new_broken_time.tm_min; - t.hour = new_broken_time.tm_hour; - t.day = new_broken_time.tm_mday; - t.mon = new_broken_time.tm_mon; - t.year = new_broken_time.tm_year; - t.wday = new_broken_time.tm_wday; - - if (testing) - printf("Not setting Hardware Clock because running in test mode.\n"); - else { - rc = ioctl(con_fd, kdshwclk_ioctl, &t ); - if (rc < 0) { - fprintf(stderr, "ioctl() to open /dev/tty1 failed. " - "Errno: %s (%d)\n", - strerror(errno), errno); - exit(1); - } - } - close(con_fd); - } -#else - /* This function should never be invoked. It is here just to make the - program compile. - */ -#endif -} - - - -static void -set_hardware_clock_rtc_ioctl(const struct tm new_broken_time, - const bool testing) { -/*---------------------------------------------------------------------------- - Set the Hardware Clock to the broken down time <new_broken_time>. - Use ioctls to "rtc" device /dev/rtc. -----------------------------------------------------------------------------*/ - int rc; - int rtc_fd; - - rtc_fd = open("/dev/rtc", O_RDONLY); - if (rtc_fd < 0) { - fprintf(stderr, "Unable to open /dev/rtc, open() errno = %s (%d)\n", - strerror(errno), errno); - exit(5); - } else { - if (testing) - printf("Not setting Hardware Clock because running in test mode.\n"); - else { - rc = ioctl(rtc_fd, RTC_SET_TIME, &new_broken_time); - if (rc == -1) { - fprintf(stderr, - "ioctl() (RTC_SET_TIME) to /dev/rtc to set time failed, " - "errno = %s (%d).\n", strerror(errno), errno); - exit(5); - } else { - if (debug) - printf("ioctl(RTC_SET_TIME) was successful.\n"); - } - } - close(rtc_fd); - } -} - - - -static void -set_hardware_clock_isa(const struct tm new_broken_time, - const bool testing) { -/*---------------------------------------------------------------------------- - Set the Hardware Clock to the time (in broken down format) - new_broken_time. Use direct I/O instructions to what we assume is - an ISA Hardware Clock. -----------------------------------------------------------------------------*/ - unsigned char save_control, save_freq_select; - - if (testing) - printf("Not setting Hardware Clock because running in test mode.\n"); - else { -#ifdef __i386__ - const bool interrupts_were_enabled = interrupts_enabled; - - __asm__ volatile ("cli"); - interrupts_enabled = FALSE; -#endif - save_control = hclock_read(11); /* tell the clock it's being set */ - hclock_write(11, (save_control | 0x80)); - save_freq_select = hclock_read(10); /* stop and reset prescaler */ - hclock_write (10, (save_freq_select | 0x70)); - - hclock_write_bcd(0, new_broken_time.tm_sec); - hclock_write_bcd(2, new_broken_time.tm_min); - hclock_write_bcd(4, new_broken_time.tm_hour); - hclock_write_bcd(6, new_broken_time.tm_wday + 3); - hclock_write_bcd(7, new_broken_time.tm_mday); - hclock_write_bcd(8, new_broken_time.tm_mon + 1); - hclock_write_bcd(9, new_broken_time.tm_year%100); - hclock_write_bcd(50, (1900+new_broken_time.tm_year)/100); - - /* The kernel sources, linux/arch/i386/kernel/time.c, have the - following comment: - - The following flags have to be released exactly in this order, - otherwise the DS12887 (popular MC146818A clone with integrated - battery and quartz) will not reset the oscillator and will not - update precisely 500 ms later. You won't find this mentioned - in the Dallas Semiconductor data sheets, but who believes data - sheets anyway ... -- Markus Kuhn - - Hence, they will also be done in this order here. - faith@cs.unc.edu, Thu Nov 9 08:26:37 1995 - */ - - hclock_write (11, save_control); - hclock_write (10, save_freq_select); -#ifdef __i386__ - if (interrupts_were_enabled) { - __asm__ volatile ("sti"); - interrupts_enabled = TRUE; - } -#endif - } -} - - -static void -set_hardware_clock(const enum clock_access_method method, - const time_t newtime, - const bool universal, - const bool testing) { -/*---------------------------------------------------------------------------- - Set the Hardware Clock to the time <newtime>, in local time zone or UTC, - according to <universal>. - - Use the method indicated by the <method> argument. -----------------------------------------------------------------------------*/ - - struct tm new_broken_time; - /* Time to which we will set Hardware Clock, in broken down format, in - the time zone of caller's choice - */ - - if (universal) new_broken_time = *gmtime(&newtime); - else new_broken_time = *localtime(&newtime); - - if (debug) - printf("Setting Hardware Clock to %.2d:%.2d:%.2d " - "= %d seconds since 1969\n", - new_broken_time.tm_hour, new_broken_time.tm_min, - new_broken_time.tm_sec, (int) newtime); - - switch (method) { - case ISA: - set_hardware_clock_isa(new_broken_time, testing); - break; - case RTC_IOCTL: - set_hardware_clock_rtc_ioctl(new_broken_time, testing); - break; - case KD: - set_hardware_clock_kd(new_broken_time, testing); - break; - default: - fprintf(stderr, - "Internal error: invalid value for clock access method.\n"); - exit(5); - } -} - - - -static void -set_hardware_clock_exact(const time_t settime, - const struct timeval ref_time, - const enum clock_access_method clock_access, - const bool universal, - const bool testing) { -/*---------------------------------------------------------------------------- - Set the Hardware Clock to the time "settime", in local time zone or UTC, - according to "universal". - - But correct "settime" and wait for a fraction of a second so that - "settime" is the value of the Hardware Clock as of system time - "ref_time", which is in the past. For example, if "settime" is - 14:03:05 and "ref_time" is 12:10:04.5 and the current system - time is 12:10:06.0: Wait .5 seconds (to make exactly 2 seconds since - "ref_time") and then set the Hardware Clock to 14:03:07, thus - getting a precise and retroactive setting of the clock. - - (Don't be confused by the fact that the system clock and the Hardware - Clock differ by two hours in the above example. That's just to remind - you that there are two independent time scales here). - - This function ought to be able to accept set times as fractional times. - Idea for future enhancement. - ------------------------------------------------------------------------------*/ - time_t newtime; /* Time to which we will set Hardware Clock */ - struct timeval now_time; /* locally used time */ - - gettimeofday(&now_time, NULL); - newtime = settime + (int) time_diff(now_time, ref_time) + 1; - if (debug) - printf("Time elapsed since reference time has been %.6f seconds.\n" - "Delaying further to reach the next full second.\n", - time_diff(now_time, ref_time)); - - /* Now delay some more until Hardware Clock time newtime arrives */ - do gettimeofday(&now_time, NULL); - while (time_diff(now_time, ref_time) < newtime - settime); - - set_hardware_clock(clock_access, newtime, universal, testing); -} - - - -static void -get_epoch(unsigned long *epoch_p, int *retcode_p) { -/*---------------------------------------------------------------------------- - Get the Hardware Clock epoch setting from the kernel. -----------------------------------------------------------------------------*/ - int rtc_fd; - - rtc_fd = open("/dev/rtc", O_RDONLY); - if (rtc_fd < 0) { - if (errno == ENOENT) - fprintf(stderr, "To manipulate the epoch value in the kernel, we must " - "access the Linux 'rtc' device driver via the device special " - "file /dev/rtc. This file does not exist on this system.\n"); - else - fprintf(stderr, "Unable to open /dev/rtc, open() errno = %s (%d)\n", - strerror(errno), errno); - *retcode_p = 1; - } else { - int rc; /* return code from ioctl */ - rc = ioctl(rtc_fd, RTC_EPOCH_READ, epoch_p); - if (rc == -1) { - fprintf(stderr, "ioctl(RTC_EPOCH_READ) to /dev/rtc failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 1; - } else { - *retcode_p = 0; - if (debug) printf("we have read epoch %ld from /dev/rtc " - "with RTC_EPOCH_READ ioctl.\n", *epoch_p); - } - close(rtc_fd); - } - return; -} - - - -static void -set_epoch(unsigned long epoch, const bool testing, int *retcode_p) { -/*---------------------------------------------------------------------------- - Set the Hardware Clock epoch in the kernel. -----------------------------------------------------------------------------*/ - if (epoch < 1900) - /* kernel would not accept this epoch value */ - fprintf(stderr, "The epoch value may not be less than 1900. " - "You requested %ld\n", epoch); - else { - int rtc_fd; - - rtc_fd = open("/dev/rtc", O_RDONLY); - if (rtc_fd < 0) { - if (errno == ENOENT) - fprintf(stderr, "To manipulate the epoch value in the kernel, we must " - "access the Linux 'rtc' device driver via the device special " - "file /dev/rtc. This file does not exist on this system.\n"); - fprintf(stderr, "Unable to open /dev/rtc, open() errno = %s (%d)\n", - strerror(errno), errno); - *retcode_p = 1; - } else { - if (debug) printf("setting epoch to %ld " - "with RTC_EPOCH_SET ioctl to /dev/rtc.\n", epoch); - if (testing) { - printf("Not setting epoch because running in test mode.\n"); - *retcode_p = 0; - } else { - int rc; /* return code from ioctl */ - rc = ioctl(rtc_fd, RTC_EPOCH_SET, epoch); - if (rc == -1) { - if (errno == EINVAL) - fprintf(stderr, "The kernel (specifically, the device driver " - "for /dev/rtc) does not have the RTC_EPOCH_SET ioctl. " - "Get a newer driver.\n"); - else - fprintf(stderr, "ioctl(RTC_EPOCH_SET) to /dev/rtc failed, " - "errno = %s (%d).\n", strerror(errno), errno); - *retcode_p = 1; - } else *retcode_p = 0; - } - close(rtc_fd); - } - } -} - - - -static void -display_time(const bool hclock_valid, const time_t systime, - const float sync_duration) { -/*---------------------------------------------------------------------------- - Put the time "systime" on standard output in display format. - Except if hclock_valid == false, just tell standard output that we don't - know what time it is. - - Include in the output the adjustment "sync_duration". ------------------------------------------------------------------------------*/ - if (!hclock_valid) - fprintf(stderr, "The Hardware Clock registers contain values that are " - "either invalid (e.g. 50th day of month) or beyond the range " - "we can handle (e.g. Year 2095).\n"); - else { - char *ctime_now; /* Address of static storage containing time string */ - - /* For some strange reason, ctime() is designed to include a newline - character at the end. We have to remove that. - */ - ctime_now = ctime(&systime); /* Compute display value for time */ - *(ctime_now+strlen(ctime_now)-1) = '\0'; /* Cut off trailing newline */ - - printf("%s %.6f seconds\n", ctime_now, -(sync_duration)); - } -} - - - -static int -interpret_date_string(const char *date_opt, time_t * const time_p) { -/*---------------------------------------------------------------------------- - Interpret the value of the --date option, which is something like - "13:05:01". In fact, it can be any of the myriad ASCII strings that specify - a time which the "date" program can understand. The date option value in - question is our "dateopt" argument. - - The specified time is in the local time zone. - - Our output, "*time_p", is a seconds-into-epoch time. - - We use the "date" program to interpret the date string. "date" must be - runnable by issuing the command "date" to the /bin/sh shell. That means - in must be in the current PATH. - - If anything goes wrong (and many things can), we return return code - 10 and arbitrary *time_p. Otherwise, return code is 0 and *time_p - is valid. -----------------------------------------------------------------------------*/ - FILE *date_child_fp; - char date_resp[100]; - const char magic[]="seconds-into-epoch="; - char date_command[100]; - int retcode; /* our eventual return code */ - int rc; /* local return code */ - - if (date_opt == NULL) { - fprintf(stderr, "No --date option specified.\n"); - retcode = 14; - } else if (strchr(date_opt, '"') != NULL) { - /* Quotation marks in date_opt would ruin the date command we construct. - */ - fprintf(stderr, "The value of the --date option is not a valid date.\n" - "In particular, it contains quotation marks.\n"); - retcode = 12; - } else { - sprintf(date_command, "date --date=\"%s\" +seconds-into-epoch=%%s", - date_opt); - if (debug) printf("Issuing date command: %s\n", date_command); - - date_child_fp = popen(date_command, "r"); - if (date_child_fp == NULL) { - fprintf(stderr, "Unable to run 'date' program in /bin/sh shell. " - "popen() failed with errno=%d:%s\n", errno, strerror(errno)); - retcode = 10; - } else { - date_resp[0] = '\0'; /* in case fgets fails */ - fgets(date_resp, sizeof(date_resp), date_child_fp); - if (debug) printf("response from date command = %s\n", date_resp); - if (strncmp(date_resp, magic, sizeof(magic)-1) != 0) { - fprintf(stderr, "The date command issued by " MYNAME " returned " - "unexpected results.\n" - "The command was:\n %s\nThe response was:\n %s\n", - date_command, date_resp); - retcode = 8; - } else { - int seconds_since_epoch; - rc = sscanf(date_resp + sizeof(magic)-1, "%d", &seconds_since_epoch); - if (rc < 1) { - fprintf(stderr, "The date command issued by " MYNAME " returned" - "something other than an integer where the converted" - "time value was expected.\n" - "The command was:\n %s\nThe response was:\n %s\n", - date_command, date_resp); - retcode = 6; - } else { - retcode = 0; - *time_p = seconds_since_epoch; - if (debug) - printf("date string %s equates to %d seconds since 1969.\n", - date_opt, (int) *time_p); - } - } - fclose(date_child_fp); - } - } - return(retcode); -} - - - -static int -set_system_clock(const bool hclock_valid, const time_t newtime, - const bool testing) { -/*---------------------------------------------------------------------------- - Set the System Clock to time 'newtime'. - - Also set the kernel time zone value to the value indicated by the - TZ environment variable and/or /usr/lib/zoneinfo/, interpreted as - tzset() would interpret them. Except: do not consider Daylight - Savings Time to be a separate component of the time zone. Include - any effect of DST in the basic timezone value and set the kernel - DST value to 0. - - EXCEPT: if hclock_valid is false, just issue an error message - saying there is no valid time in the Hardware Clock to which to set - the system time. - - If 'testing' is true, don't actually update anything -- just say we - would have. ------------------------------------------------------------------------------*/ - int retcode; /* our eventual return code */ - - if (!hclock_valid) { - fprintf(stderr,"The Hardware Clock does not contain a valid time, so " - "we cannot set the System Time from it.\n"); - retcode = 1; - } else { - struct timeval tv; - int rc; /* local return code */ - - tv.tv_sec = newtime; - tv.tv_usec = 0; - - tzset(); /* init timezone, daylight from TZ or ...zoneinfo/localtime */ - /* An undocumented function of tzset() is to set global variabales - 'timezone' and 'daylight' - */ - - if (debug) { - printf( "Calling settimeofday:\n" ); - printf( "\ttv.tv_sec = %ld, tv.tv_usec = %ld\n", - (long) tv.tv_sec, (long) tv.tv_usec ); - } - if (testing) { - printf("Not setting system clock because running in test mode.\n"); - retcode = 0; - } else { - /* For documentation of settimeofday(), in addition to its man page, - see kernel/time.c in the Linux source code. - */ - const struct timezone tz = { timezone/60 - 60*daylight, 0 }; - /* put daylight in minuteswest rather than dsttime, - since the latter is mostly ignored ... */ - rc = settimeofday(&tv, &tz); - if (rc != 0) { - if (errno == EPERM) - fprintf(stderr, "Must be superuser to set system clock.\n"); - else - fprintf(stderr, - "settimeofday() failed, errno=%d:%s\n", - errno, strerror(errno)); - retcode = 1; - } else retcode = 0; - } - } - return(retcode); -} - - -static void -adjust_drift_factor(struct adjtime *adjtime_p, - const time_t nowtime, - const bool hclock_valid, const time_t hclocktime ) { -/*--------------------------------------------------------------------------- - Update the drift factor in <*adjtime_p> to reflect the fact that the - Hardware Clock was calibrated to <nowtime> and before that was set - to <hclocktime>. - - We assume that the user has been doing regular drift adjustments - using the drift factor in the adjtime file, so if <nowtime> and - <clocktime> are different, that means the adjustment factor isn't - quite right. - - We record in the adjtime file the time at which we last calibrated - the clock so we can compute the drift rate each time we calibrate. - - EXCEPT: if <hclock_valid> is false, assume Hardware Clock was not set - before to anything meaningful and regular adjustments have not been - done, so don't adjust the drift factor. - -----------------------------------------------------------------------------*/ - if (!hclock_valid) { - if (debug) - printf("Not adjusting drift factor because the Hardware Clock " - "previously contained garbage.\n"); - } else if ((hclocktime - adjtime_p->last_calib_time) < 23 * 60 * 60) { - if (debug) - printf("Not adjusting drift factor because it has been less than a " - "day since the last calibration.\n"); - } else { - const float factor_adjust = - ((float) (nowtime - hclocktime) - / (hclocktime - adjtime_p->last_calib_time)) - * 24 * 60 * 60; - - if (debug) - printf("Clock drifted %d seconds in the past %d seconds " - "in spite of a drift factor of %f seconds/day.\n" - "Adjusting drift factor by %f seconds/day\n", - (int) (nowtime - hclocktime), - (int) (hclocktime - adjtime_p->last_calib_time), - adjtime_p->drift_factor, - factor_adjust ); - - adjtime_p->drift_factor += factor_adjust; - } - adjtime_p->last_calib_time = nowtime; - - adjtime_p->last_adj_time = nowtime; - - adjtime_p->not_adjusted = 0; - - adjtime_p->dirty = TRUE; -} - - - -static void -calculate_adjustment( - const float factor, - const time_t last_time, - const float not_adjusted, - const time_t systime, - int *adjustment_p, - float *retro_p, - const int debug ) { -/*---------------------------------------------------------------------------- - Do the drift adjustment calculation. - - The way we have to set the clock, we need the adjustment in two parts: - - 1) an integer number of seconds (return as *adjustment_p) - - 2) a positive fraction of a second (less than 1) (return as *retro_p) - - The sum of these two values is the adjustment needed. Positive means to - advance the clock or insert seconds. Negative means to retard the clock - or remove seconds. -----------------------------------------------------------------------------*/ - float exact_adjustment; - - exact_adjustment = ((float) (systime - last_time)) * factor / (24 * 60 * 60) - + not_adjusted; - *adjustment_p = FLOOR(exact_adjustment); - - *retro_p = exact_adjustment - (float) *adjustment_p; - if (debug) { - printf ("Time since last adjustment is %d seconds\n", - (int) (systime - last_time)); - printf ("Need to insert %d seconds and refer time back " - "%.6f seconds ago\n", - *adjustment_p, *retro_p); - } -} - - - -static void -save_adjtime(const struct adjtime adjtime, const bool testing) { -/*----------------------------------------------------------------------------- - Write the contents of the <adjtime> structure to its disk file. - - But if the contents are clean (unchanged since read from disk), don't - bother. ------------------------------------------------------------------------------*/ - FILE *adjfile; - char newfile[405]; /* Stuff to write to disk file */ - - int rc; /* locally used: return code from a function */ - - if (adjtime.dirty) { - /* snprintf is not always available, but this is safe - as long as libc does not use more than 100 positions for %ld or %f */ - sprintf(newfile, "%f %ld %f\n%ld\n", - adjtime.drift_factor, - (long) adjtime.last_adj_time, - adjtime.not_adjusted, - (long) adjtime.last_calib_time ); - - if (testing) { - printf("Not updating adjtime file because of testing mode.\n"); - printf("Would have written the following to %s:\n%s", - ADJPATH, newfile); - } else { - adjfile = fopen(ADJPATH, "w"); - if (adjfile == NULL) { - const int fopen_errno = errno; - printf("Could not open file with the clock adjustment parameters " - "in it (%s) for output.\n" - "fopen() returned errno %d: %s.\n" - "Drift adjustment parameters not updated.\n", - ADJPATH, fopen_errno, strerror(errno)); - } else { - rc = fprintf(adjfile, newfile); - if (rc < 0) { - const int fprintf_errno = errno; - printf("Could not update file with the clock adjustment parameters " - "(%s) in it.\n" - "fprintf() returned errno %d: %s.\n" - "Drift adjustment parameters not updated.\n", - ADJPATH, fprintf_errno, strerror(errno)); - } - rc = fclose(adjfile); - if (rc < 0) { - const int fclose_errno = errno; - printf("Could not update file with the clock adjustment parameters " - "(%s) in it.\n" - "fclose() returned errno %d: %s.\n" - "Drift adjustment parameters not updated.\n", - ADJPATH, fclose_errno, strerror(errno)); - } - } - } - } -} - - - -static void -do_adjustment(struct adjtime *adjtime_p, - const bool hclock_valid, const time_t hclocktime, - const struct timeval read_time, - const enum clock_access_method clock_access, - const bool universal, const bool testing) { -/*--------------------------------------------------------------------------- - Do the adjustment requested, by 1) setting the Hardware Clock (if - necessary), and 2) updating the last-adjusted time in the adjtime - structure. - - Do not update anything if the Hardware Clock does not currently present - a valid time. - - arguments <factor> and <last_time> are current values from the adjtime - file. - - <hclock_valid> means the Hardware Clock contains a valid time, and that - time is <hclocktime>. - - <read_time> is the current system time (to be precise, it is the system - time at the time <hclocktime> was read, which due to computational delay - could be a short time ago). - - <universal>: the Hardware Clock is kept in UTC. - - <testing>: We are running in test mode (no updating of clock). - - We do not bother to update the clock if the adjustment would be less than - one second. This is to avoid cumulative error and needless CPU hogging - (remember we use an infinite loop for some timing) if the user runs us - frequently. - -----------------------------------------------------------------------------*/ - if (!hclock_valid) { - fprintf(stderr, "The Hardware Clock does not contain a valid time, " - "so we cannot adjust it.\n"); - } else { - int adjustment; - /* Number of seconds we must insert in the Hardware Clock */ - float retro; - /* Fraction of second we have to remove from clock after inserting - <adjustment> whole seconds. - */ - calculate_adjustment(adjtime_p->drift_factor, - adjtime_p->last_adj_time, - adjtime_p->not_adjusted, - hclocktime, - &adjustment, &retro, - debug ); - if (adjustment > 0 || adjustment < -1) { - set_hardware_clock_exact(hclocktime + adjustment, - time_inc(read_time, -retro), - clock_access, universal, testing); - adjtime_p->last_adj_time = hclocktime + adjustment; - adjtime_p->not_adjusted = 0; - adjtime_p->dirty = TRUE; - } else - if (debug) - printf("Needed adjustment is less than one second, " - "so not setting clock.\n"); - } -} - - - -static void -determine_clock_access_method(const bool user_requests_ISA, - enum clock_access_method *clock_access_p) { -/*---------------------------------------------------------------------------- - Figure out how we're going to access the hardware clock, by seeing - what facilities are available, looking at invocation options, and - using compile-time constants. - - <user_requests_ISA> means the user explicitly asked for the ISA method. - Even if he did, we will not select the ISA method if this is not an - ISA machine. ------------------------------------------------------------------------------*/ - bool rtc_works; - /* The /dev/rtc method is available and seems to work on this machine */ - - if (got_rtc) { - int rtc_fd = open("/dev/rtc", O_RDONLY); - if (rtc_fd > 0) { - rtc_works = TRUE; - close(rtc_fd); - } else { - rtc_works = FALSE; - if (debug) - printf("Open of /dev/rtc failed, errno = %s (%d). " - "falling back to more primitive clock access method.\n", - strerror(errno), errno); - } - } else { - if (debug) - printf("The Linux kernel for which this copy of hwclock() was built " - "is too old to have /dev/rtc\n"); - rtc_works = FALSE; - } - - if (user_requests_ISA && isa_machine) *clock_access_p = ISA; - else if (rtc_works) *clock_access_p = RTC_IOCTL; - else if (got_kdghwclk) { - int con_fd; - struct hwclk_time t; - - con_fd = open("/dev/tty1", O_RDONLY); - if (con_fd >= 0) { - if (ioctl( con_fd, kdghwclk_ioctl, &t ) >= 0) - *clock_access_p = KD; - else { - if (errno == EINVAL) { - /* KDGHWCLK not implemented in this kernel... */ - *clock_access_p = ISA; - } else { - *clock_access_p = KD; - fprintf(stderr, - "KDGHWCLK ioctl failed, errno = %s (%d).\n", - strerror(errno), errno); - } - } - } else { - *clock_access_p = KD; - fprintf(stderr, - "Can't open /dev/tty1. open() errno = %s (%d).\n", - strerror(errno), errno); - } - close(con_fd); - } else if (isa_machine) { - *clock_access_p = ISA; - } else - *clock_access_p = NOCLOCK; - if (debug) { - switch (*clock_access_p) { - case ISA: printf("Using direct I/O instructions to ISA clock.\n"); break; - case KD: printf("Using KDGHWCLK interface to m68k clock.\n"); break; - case RTC_IOCTL: printf("Using /dev/rtc interface to clock.\n"); break; - default: - printf("determine_clock_access_method() returned invalid value: %d.\n", - *clock_access_p); - } - } -} - - - -static void -manipulate_clock(const bool show, const bool adjust, - const bool set, const time_t set_time, - const bool hctosys, const bool systohc, - const struct timeval startup_time, - const enum clock_access_method clock_access, - const bool universal, const bool testing, - int *retcode_p - ) { -/*--------------------------------------------------------------------------- - Do all the normal work of hwclock - read, set clock, etc. - - Issue output to stdout and error message to stderr where appropriate. - - Return rc == 0 if everything went OK, rc != 0 if not. -----------------------------------------------------------------------------*/ - struct adjtime adjtime; - /* Contents of the adjtime file, or what they should be. */ - int rc; /* local return code */ - bool no_auth; /* User lacks necessary authorization to access the clock */ - - if (clock_access == ISA) { - rc = i386_iopl(3); - if (rc != 0) { - fprintf(stderr, MYNAME " is unable to get I/O port access. " - "I.e. iopl(3) returned nonzero return code %d.\n" - "This is often because the program isn't running " - "with superuser privilege, which it needs.\n", - rc); - no_auth = TRUE; - } else no_auth = FALSE; - } else no_auth = FALSE; - - if (no_auth) *retcode_p = 1; - else { - if (adjust || set || systohc) - read_adjtime(&adjtime, &rc); - else { - /* A little trick to avoid reading the file if we don't have to */ - adjtime.dirty = FALSE; - rc = 0; - } - if (rc != 0) *retcode_p = 2; - else { - synchronize_to_clock_tick(clock_access, retcode_p); - /* this takes up to 1 second */ - if (*retcode_p == 0) { - struct timeval read_time; - /* The time at which we read the Hardware Clock */ - - bool hclock_valid; - /* The Hardware Clock gives us a valid time, or at least something - close enough to fool mktime(). - */ - - time_t hclocktime; - /* The time the hardware clock had just after we - synchronized to its next clock tick when we started up. - Defined only if hclock_valid is true. - */ - - gettimeofday(&read_time, NULL); - read_hardware_clock(clock_access, universal, &hclock_valid, - &hclocktime); - - if (show) { - display_time(hclock_valid, hclocktime, - time_diff(read_time, startup_time)); - *retcode_p = 0; - } else if (set) { - set_hardware_clock_exact(set_time, startup_time, - clock_access, universal, testing); - adjust_drift_factor(&adjtime, set_time, hclock_valid, hclocktime); - *retcode_p = 0; - } else if (adjust) { - do_adjustment(&adjtime, hclock_valid, hclocktime, - read_time, clock_access, - universal, testing); - *retcode_p = 0; - } else if (systohc) { - struct timeval nowtime, reftime; - /* We can only set_hardware_clock_exact to a whole seconds - time, so we set it with reference to the most recent - whole seconds time. - */ - gettimeofday(&nowtime, NULL); - reftime.tv_sec = nowtime.tv_sec; - reftime.tv_usec = 0; - - set_hardware_clock_exact((time_t) reftime.tv_sec, reftime, - clock_access, universal, testing); - *retcode_p = 0; - adjust_drift_factor(&adjtime, (time_t) reftime.tv_sec, hclock_valid, - hclocktime); - } else if (hctosys) { - rc = set_system_clock(hclock_valid, hclocktime, testing); - if (rc != 0) { - printf("Unable to set system clock.\n"); - *retcode_p = 1; - } else *retcode_p = 0; - } - save_adjtime(adjtime, testing); - } - } - } -} - - - -static void -manipulate_epoch(const bool getepoch, const bool setepoch, - const int epoch_opt, const bool testing) { -/*---------------------------------------------------------------------------- - Get or set the Hardware Clock epoch value in the kernel, as appropriate. - <getepoch>, <setepoch>, and <epoch> are hwclock invocation options. - - <epoch> == -1 if the user did not specify an "epoch" option. - ------------------------------------------------------------------------------*/ - /* - Maintenance note: This should work on non-Alpha machines, but the - evidence today (98.03.04) indicates that the kernel only keeps the - epoch value on Alphas. If that is ever fixed, this function should be - changed. - */ - - if (!alpha_machine) - fprintf(stderr, "The kernel keeps an epoch value for the Hardware Clock " - "only on an Alpha machine.\nThis copy of hwclock was built for " - "a machine other than Alpha\n(and thus is presumably not running " - "on an Alpha now). No action taken.\n"); - else { - if (getepoch) { - unsigned long epoch; - int retcode; - - get_epoch(&epoch, &retcode); - if (retcode != 0) - printf("Unable to get the epoch value from the kernel.\n"); - else - printf("Kernel is assuming an epoch value of %lu\n", epoch); - } else if (setepoch) { - if (epoch_opt == -1) - fprintf(stderr, "To set the epoch value, you must use the 'epoch' " - "option to tell to what value to set it.\n"); - else { - int rc; - set_epoch(epoch_opt, testing, &rc); - if (rc != 0) - printf("Unable to set the epoch value in the kernel.\n"); - } - } - } -} - - - -int -main(int argc, char **argv, char **envp) { -/*---------------------------------------------------------------------------- - MAIN ------------------------------------------------------------------------------*/ - struct timeval startup_time; - /* The time we started up, in seconds into the epoch, including fractions. - */ - time_t set_time; /* Time to which user said to set Hardware Clock */ - - enum clock_access_method clock_access; - /* The method that we determine is best for accessing Hardware Clock - on this system. - */ - - bool permitted; /* User is permitted to do the function */ - int retcode; /* Our eventual return code */ - - int rc; /* local return code */ - - /* option_def is the control table for the option parser. These other - variables are the results of parsing the options and their meanings - are given by the option_def. The only exception is <show>, which - may be modified after parsing is complete to effect an implied option. - */ - bool show, set, systohc, hctosys, adjust, getepoch, setepoch, version; - bool universal, testing, directisa; - char *date_opt; - int epoch_opt; - - const optStruct option_def[] = { - { 'r', (char *) "show", OPT_FLAG, &show, 0 }, - { 0, (char *) "set", OPT_FLAG, &set, 0 }, - { 'w', (char *) "systohc", OPT_FLAG, &systohc, 0 }, - { 's', (char *) "hctosys", OPT_FLAG, &hctosys, 0 }, - { 0, (char *) "getepoch", OPT_FLAG, &getepoch, 0 }, - { 0, (char *) "setepoch", OPT_FLAG, &setepoch, 0 }, - { 'a', (char *) "adjust", OPT_FLAG, &adjust, 0 }, - { 'v', (char *) "version", OPT_FLAG, &version, 0 }, - { 0, (char *) "date", OPT_STRING, &date_opt, 0 }, - { 0, (char *) "epoch", OPT_UINT, &epoch_opt, 0 }, - { 'u', (char *) "utc", OPT_FLAG, &universal, 0 }, - { 0, (char *) "directisa", OPT_FLAG, &directisa, 0 }, - { 0, (char *) "test", OPT_FLAG, &testing, 0 }, - { 'D', (char *) "debug", OPT_FLAG, &debug, 0 }, - { 0, (char *) NULL, OPT_END, NULL, 0 } - }; - int argc_parse; /* argc, except we modify it as we parse */ - char **argv_parse; /* argv, except we modify it as we parse */ - - interrupts_enabled = TRUE; /* Since we haven't messed with them yet */ - - gettimeofday(&startup_time, NULL); /* Remember what time we were invoked */ - - /* set option defaults */ - show = set = systohc = hctosys = adjust = getepoch = setepoch = - version = universal = - directisa = testing = debug = FALSE; - date_opt = NULL; - epoch_opt = -1; - - argc_parse = argc; argv_parse = argv; - optParseOptions(&argc_parse, argv_parse, option_def, 0); - /* Uses and sets argc_parse, argv_parse. - Sets show, systohc, hctosys, adjust, universal, version, testing, - debug, set, date_opt, getepoch, setepoch, epoch_opt - */ - - if (argc_parse - 1 > 0) { - fprintf(stderr, MYNAME " takes no non-option arguments. " - "You supplied %d.\n", - argc_parse - 1); - exit(100); - } - - if (show + set + systohc + hctosys + adjust + - getepoch + setepoch + version > 1) { - fprintf(stderr, "You have specified multiple function options.\n" - "You can only perform one function at a time.\n"); - exit(100); - } - - if (set) { - rc = interpret_date_string(date_opt, &set_time); /* (time-consuming) */ - if (rc != 0) { - fprintf(stderr, "No usable set-to time. Cannot set clock.\n"); - exit(100); - } - } - - if (directisa && !isa_machine) { - fprintf(stderr, "You have requested direct access to the ISA Hardware " - "Clock using machine instructions from the user process. " - "But this method only works on an ISA machine with an x86 " - "CPU, and this is not one!\n"); - exit(100); - } - - if (!(show | set | systohc | hctosys | adjust | getepoch | setepoch | - version)) - show = 1; /* default to show */ - - - if (getuid() == 0) permitted = TRUE; - else { - /* program is designed to run setuid (in some situations) -- be secure! */ - if (set || hctosys || systohc || adjust) { - fprintf(stderr, - "Sorry, only the superuser can change the Hardware Clock.\n"); - permitted = FALSE; - } else if (setepoch) { - fprintf(stderr, - "Sorry, only the superuser can change " - "the Hardware Clock epoch in the kernel.\n"); - permitted = FALSE; - } else permitted = TRUE; - } - - if (!permitted) retcode = 2; - else { - retcode = 0; - if (version) { - printf(MYNAME " " VERSION "/%s\n",util_linux_version); - } else if (getepoch || setepoch) { - manipulate_epoch(getepoch, setepoch, epoch_opt, testing); - } else { - determine_clock_access_method(directisa, &clock_access); - if (clock_access == NOCLOCK) - fprintf(stderr, "Cannot access the Hardware Clock via any known " - "method. Use --debug option to see the details of our " - "search for an access method.\n"); - else - manipulate_clock(show, adjust, set, set_time, hctosys, systohc, - startup_time, clock_access, universal, testing, &rc); - } - } - exit(retcode); -} - - -/**************************************************************************** - - History of this program: - - 98.08.12 BJH Version 2.4 - - Don't use century byte from Hardware Clock. Add comments telling why. - - - 98.06.20 BJH Version 2.3. - - Make --hctosys set the kernel timezone from TZ environment variable - and/or /usr/lib/zoneinfo. From Klaus Ripke (klaus@ripke.com). - - 98.03.05 BJH. Version 2.2. - - Add --getepoch and --setepoch. - - Fix some word length things so it works on Alpha. - - Make it work when /dev/rtc doesn't have the interrupt functions. - In this case, busywait for the top of a second instead of blocking and - waiting for the update complete interrupt. - - Fix a bunch of bugs too numerous to mention. - - 97.06.01: BJH. Version 2.1. Read and write the century byte (Byte - 50) of the ISA Hardware Clock when using direct ISA I/O. Problem - discovered by job (jei@iclnl.icl.nl). - - Use the rtc clock access method in preference to the KDGHWCLK method. - Problem discovered by Andreas Schwab <schwab@LS5.informatik.uni-dortmund.de>. - - November 1996: Version 2.0.1. Modifications by Nicolai Langfeldt - (janl@math.uio.no) to make it compile on linux 1.2 machines as well - as more recent versions of the kernel. Introduced the NO_CLOCK - access method and wrote feature test code to detect absense of rtc - headers. - - - Bryan Henderson based hwclock on the program "clock", in September - 1996. While remaining mostly backward compatible with clock, - hwclock added the following: - - - You can set the hardware clock without also modifying the Linux - system clock. - - - You can read and set the clock with finer than 1 second precision. - - - When you set the clock, hwclock automatically refigures the drift - rate, based on how far off the clock was before you set it. (This - is the drift rate that is used with the --adjust function to - automatically adjust the clock periodically to compensate for drift). - - - More mnemonic GNU-style command line options. - - - Comments describing how the clock and program work to improve - maintainability. - - - Removed the old dead I/O code that worked without the inb/outb - instructions and without the asm/io.h definitions. - - The first version of hwclock was Version 2. - - Here is the history section from the "clock" program at the time it was - used as a basis for hwclock: - - V1.0 - - - V1.0 by Charles Hedrick, hedrick@cs.rutgers.edu, April 1992. - - ******************** - V1.1 - Modified for clock adjustments - Rob Hooft, hooft@chem.ruu.nl, Nov 1992 - Also moved error messages to stderr. The program now uses getopt. - Changed some exit codes. Made 'gcc 2.3 -Wall' happy. - - ***** - V1.2 - - Applied patches by Harald Koenig (koenig@nova.tat.physik.uni-tuebingen.de) - Patched and indented by Rob Hooft (hooft@EMBL-Heidelberg.DE) - - A free quote from a MAIL-message (with spelling corrections): - - "I found the explanation and solution for the CMOS reading 0xff problem - in the 0.99pl13c (ALPHA) kernel: the RTC goes offline for a small amount - of time for updating. Solution is included in the kernel source - (linux/kernel/time.c)." - - "I modified clock.c to fix this problem and added an option (now default, - look for USE_INLINE_ASM_IO) that I/O instructions are used as inline - code and not via /dev/port (still possible via #undef ...)." - - With the new code, which is partially taken from the kernel sources, - the CMOS clock handling looks much more "official". - Thanks Harald (and Torsten for the kernel code)! - - ***** - V1.3 - Canges from alan@spri.levels.unisa.edu.au (Alan Modra): - a) Fix a few typos in comments and remove reference to making - clock -u a cron job. The kernel adjusts cmos time every 11 - minutes - see kernel/sched.c and kernel/time.c set_rtc_mmss(). - This means we should really have a cron job updating - /etc/adjtime every 11 mins (set last_time to the current time - and not_adjusted to ???). - b) Swapped arguments of outb() to agree with asm/io.h macro of the - same name. Use outb() from asm/io.h as it's slightly better. - c) Changed CMOS_READ and CMOS_WRITE to inline functions. Inserted - cli()..sti() pairs in appropriate places to prevent possible - errors, and changed ioperm() call to iopl() to allow cli. - d) Moved some variables around to localise them a bit. - e) Fixed bug with clock -ua or clock -us that cleared environment - variable TZ. This fix also cured the annoying display of bogus - day of week on a number of machines. (Use mktime(), ctime() - rather than asctime() ) - f) Use settimeofday() rather than stime(). This one is important - as it sets the kernel's timezone offset, which is returned by - gettimeofday(), and used for display of MSDOS and OS2 file - times. - g) faith@cs.unc.edu added -D flag for debugging - - V1.4: alan@SPRI.Levels.UniSA.Edu.Au (Alan Modra) - Wed Feb 8 12:29:08 1995, fix for years > 2000. - faith@cs.unc.edu added -v option to print version. */ - - diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c index c04b7fd4..4dcd081b 100644 --- a/sys-utils/ipcrm.c +++ b/sys-utils/ipcrm.c @@ -1,5 +1,9 @@ /* * krishna balasubramanian 1993 + * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ #include <stdio.h> @@ -12,6 +16,8 @@ #include <sys/shm.h> #include <sys/msg.h> #include <sys/sem.h> +#include "nls.h" + #if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) /* union semun is defined by including <sys/sem.h> */ #else @@ -30,10 +36,14 @@ int main(int argc, char **argv) int id; union semun arg; - arg.val = 0; + arg.val = 0; + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); if (argc != 3 || strlen(argv[1]) < 3) { - printf ("usage: %s [shm | msg | sem] id\n", argv[0]); + printf (_("usage: %s [shm | msg | sem] id\n"), argv[0]); exit (1); } id = atoi (argv[2]); @@ -57,10 +67,10 @@ int main(int argc, char **argv) exit (1); default: - printf ("usage: %s [-shm | -msg | -sem] id\n", argv[0]); + printf (_("usage: %s [-shm | -msg | -sem] id\n"), argv[0]); exit (1); } - printf ("resource deleted\n"); + printf (_("resource deleted\n")); return 0; } diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index 975bfd1a..e628ce87 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -13,6 +13,10 @@ Patched to display the key field -- hy@picksys.com 12/18/96 + 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + - added Native Language Support + + */ #include <stdio.h> @@ -22,9 +26,12 @@ #include <time.h> #include <pwd.h> #include <grp.h> -#if 0 -#define __KERNEL__ /* yuk */ -#include <linux/linkage.h> +#include "nls.h" + +#include "../defines.h" /* for NEED_linkage_h */ +#ifdef NEED_linkage_h +#define __KERNEL__ /* required for SHM_DEST etc. */ +#include <linux/linkage.h> /* required for the keyword asmlinkage */ #endif /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */ /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */ @@ -34,6 +41,10 @@ #include <sys/sem.h> #include <sys/msg.h> #include <sys/shm.h> +#ifdef NEED_linkage_h +#undef __KERNEL__ +#endif + /* The last arg of semctl is a union semun, but where is it defined? X/OPEN tells us to define it ourselves, but until recently Linux include files would also define it. */ @@ -77,21 +88,21 @@ static char *progname; void usage(void) { - printf ("usage : %s -asmq -tclup \n", progname); - printf ("\t%s [-s -m -q] -i id\n", progname); - printf ("\t%s -h for help.\n", progname); + printf (_("usage : %s -asmq -tclup \n"), progname); + printf (_("\t%s [-s -m -q] -i id\n"), progname); + printf (_("\t%s -h for help.\n"), progname); return; } void help (void) { - printf ("%s provides information on ipc facilities for", progname); - printf (" which you have read access.\n"); - printf ("Resource Specification:\n\t-m : shared_mem\n\t-q : messages\n"); - printf ("\t-s : semaphores\n\t-a : all (default)\n"); - printf ("Output Format:\n\t-t : time\n\t-p : pid\n\t-c : creator\n"); - printf ("\t-l : limits\n\t-u : summary\n"); - printf ("-i id [-s -q -m] : details on resource identified by id\n"); + printf (_("%s provides information on ipc facilities for"), progname); + printf (_(" which you have read access.\n")); + printf (_("Resource Specification:\n\t-m : shared_mem\n\t-q : messages\n")); + printf (_("\t-s : semaphores\n\t-a : all (default)\n")); + printf (_("Output Format:\n\t-t : time\n\t-p : pid\n\t-c : creator\n")); + printf (_("\t-l : limits\n\t-u : summary\n")); + printf (_("-i id [-s -q -m] : details on resource identified by id\n")); usage(); return; } @@ -102,6 +113,10 @@ int main (int argc, char **argv) char format = 0; char options[] = "atcluphsmqi:"; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + progname = argv[0]; while ((opt = getopt (argc, argv, options)) != EOF) { switch (opt) { @@ -219,52 +234,52 @@ void do_shm (char format) maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) &shm_info); if (maxid < 0) { - printf ("kernel not configured for shared memory\n"); + printf (_("kernel not configured for shared memory\n")); return; } switch (format) { case LIMITS: - printf ("------ Shared Memory Limits --------\n"); + printf (_("------ Shared Memory Limits --------\n")); if ((shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo)) < 0 ) return; - printf ("max number of segments = %d\n", shminfo.shmmni); - printf ("max seg size (kbytes) = %d\n", shminfo.shmmax >> 10); - printf ("max total shared memory (kbytes) = %d\n", shminfo.shmall << 2); - printf ("min seg size (bytes) = %d\n", shminfo.shmmin); + printf (_("max number of segments = %d\n"), shminfo.shmmni); + printf (_("max seg size (kbytes) = %d\n"), shminfo.shmmax >> 10); + printf (_("max total shared memory (kbytes) = %d\n"), shminfo.shmall << 2); + printf (_("min seg size (bytes) = %d\n"), shminfo.shmmin); return; case STATUS: - printf ("------ Shared Memory Status --------\n"); - printf ("segments allocated %d\n", shm_info.used_ids); - printf ("pages allocated %ld\n", shm_info.shm_tot); - printf ("pages resident %ld\n", shm_info.shm_rss); - printf ("pages swapped %ld\n", shm_info.shm_swp); - printf ("Swap performance: %ld attempts\t %ld successes\n", + printf (_("------ Shared Memory Status --------\n")); + printf (_("segments allocated %d\n"), shm_info.used_ids); + printf (_("pages allocated %ld\n"), shm_info.shm_tot); + printf (_("pages resident %ld\n"), shm_info.shm_rss); + printf (_("pages swapped %ld\n"), shm_info.shm_swp); + printf (_("Swap performance: %ld attempts\t %ld successes\n"), shm_info.swap_attempts, shm_info.swap_successes); return; case CREATOR: - printf ("------ Shared Memory Segment Creators/Owners --------\n"); - printf ("%-10s%-10s%-10s%-10s%-10s%-10s\n", - "shmid","perms","cuid","cgid","uid","gid"); + printf (_("------ Shared Memory Segment Creators/Owners --------\n")); + printf (_("%-10s%-10s%-10s%-10s%-10s%-10s\n"), + _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid")); break; case TIME: - printf ("------ Shared Memory Attach/Detach/Change Times --------\n"); - printf ("%-10s%-10s %-20s%-20s%-20s\n", - "shmid","owner","attached","detached","changed"); + printf (_("------ Shared Memory Attach/Detach/Change Times --------\n")); + printf (_("%-10s%-10s %-20s%-20s%-20s\n"), + _("shmid"),_("owner"),_("attached"),_("detached"),_("changed")); break; case PID: - printf ("------ Shared Memory Creator/Last-op --------\n"); - printf ("%-10s%-10s%-10s%-10s\n","shmid","owner","cpid","lpid"); + printf (_("------ Shared Memory Creator/Last-op --------\n")); + printf (_("%-10s%-10s%-10s%-10s\n"),_("shmid"),_("owner"),_("cpid"),_("lpid")); break; default: - printf ("------ Shared Memory Segments --------\n"); - printf ("%-10s%-10s%-10s%-10s%-10s%-10s%-12s\n", "key","shmid", - "owner","perms","bytes","nattch","status"); + printf (_("------ Shared Memory Segments --------\n")); + printf (_("%-10s%-10s%-10s%-10s%-10s%-10s%-12s\n"), _("key"),_("shmid"), + _("owner"),_("perms"),_("bytes"),_("nattch"),_("status")); break; } @@ -284,9 +299,9 @@ void do_shm (char format) else printf ("%-10d%-10d", shmid, ipcp->uid); printf(" %-20.16s%-20.16s%-20.16s\n", - shmseg.shm_atime ? ctime(&shmseg.shm_atime) + 4 : "Not set", - shmseg.shm_dtime ? ctime(&shmseg.shm_dtime) + 4 : "Not set", - shmseg.shm_ctime ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); + shmseg.shm_atime ? ctime(&shmseg.shm_atime) + 4 : _("Not set"), + shmseg.shm_dtime ? ctime(&shmseg.shm_dtime) + 4 : _("Not set"), + shmseg.shm_ctime ? ctime(&shmseg.shm_ctime) + 4 : _("Not set")); break; case PID: if (pw) @@ -306,8 +321,8 @@ void do_shm (char format) printf ("%-10o%-10d%-10d%-6s%-6s\n", ipcp->mode & 0777, shmseg.shm_segsz, shmseg.shm_nattch, - ipcp->mode & SHM_DEST ? "dest" : " ", - ipcp->mode & SHM_LOCKED ? "locked" : " "); + ipcp->mode & SHM_DEST ? _("dest") : " ", + ipcp->mode & SHM_LOCKED ? _("locked") : " "); break; } } @@ -327,48 +342,48 @@ void do_sem (char format) arg.array = (ushort *) &seminfo; maxid = semctl (0, 0, SEM_INFO, arg); if (maxid < 0) { - printf ("kernel not configured for semaphores\n"); + printf (_("kernel not configured for semaphores\n")); return; } switch (format) { case LIMITS: - printf ("------ Semaphore Limits --------\n"); + printf (_("------ Semaphore Limits --------\n")); arg.array = (ushort *) &seminfo; /* damn union */ if ((semctl (0, 0, IPC_INFO, arg)) < 0 ) return; - printf ("max number of arrays = %d\n", seminfo.semmni); - printf ("max semaphores per array = %d\n", seminfo.semmsl); - printf ("max semaphores system wide = %d\n", seminfo.semmns); - printf ("max ops per semop call = %d\n", seminfo.semopm); - printf ("semaphore max value = %d\n", seminfo.semvmx); + printf (_("max number of arrays = %d\n"), seminfo.semmni); + printf (_("max semaphores per array = %d\n"), seminfo.semmsl); + printf (_("max semaphores system wide = %d\n"), seminfo.semmns); + printf (_("max ops per semop call = %d\n"), seminfo.semopm); + printf (_("semaphore max value = %d\n"), seminfo.semvmx); return; case STATUS: - printf ("------ Semaphore Status --------\n"); - printf ("used arrays = %d\n", seminfo.semusz); - printf ("allocated semaphores = %d\n", seminfo.semaem); + printf (_("------ Semaphore Status --------\n")); + printf (_("used arrays = %d\n"), seminfo.semusz); + printf (_("allocated semaphores = %d\n"), seminfo.semaem); return; case CREATOR: - printf ("------ Semaphore Arrays Creators/Owners --------\n"); - printf ("%-10s%-10s%-10s%-10s%-10s%-10s\n", - "semid","perms","cuid","cgid","uid","gid"); + printf (_("------ Semaphore Arrays Creators/Owners --------\n")); + printf (_("%-10s%-10s%-10s%-10s%-10s%-10s\n"), + _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),("gid")); break; case TIME: - printf ("------ Shared Memory Operation/Change Times --------\n"); - printf ("%-8s%-10s %-26.24s %-26.24s\n", - "shmid","owner","last-op","last-changed"); + printf (_("------ Shared Memory Operation/Change Times --------\n")); + printf (_("%-8s%-10s %-26.24s %-26.24s\n"), + _("shmid"),_("owner"),_("last-op"),_("last-changed")); break; case PID: break; default: - printf ("------ Semaphore Arrays --------\n"); - printf ("%-10s%-10s%-10s%-10s%-10s%-12s\n", - "key","semid","owner","perms","nsems","status"); + printf (_("------ Semaphore Arrays --------\n")); + printf (_("%-10s%-10s%-10s%-10s%-10s%-12s\n"), + _("key"),_("semid"),_("owner"),_("perms"),_("nsems"),_("status")); break; } @@ -389,8 +404,8 @@ void do_sem (char format) else printf ("%-8d%-10d", semid, ipcp->uid); printf (" %-26.24s %-26.24s\n", - semary.sem_otime ? ctime(&semary.sem_otime) : "Not set", - semary.sem_ctime ? ctime(&semary.sem_ctime) : "Not set"); + semary.sem_otime ? ctime(&semary.sem_otime) : _("Not set"), + semary.sem_ctime ? ctime(&semary.sem_ctime) : _("Not set")); break; case PID: break; @@ -421,7 +436,7 @@ void do_msg (char format) maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) &msginfo); if (maxid < 0) { - printf ("kernel not configured for shared memory\n"); + printf (_("kernel not configured for shared memory\n")); return; } @@ -429,40 +444,40 @@ void do_msg (char format) case LIMITS: if ((msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo)) < 0 ) return; - printf ("------ Messages: Limits --------\n"); - printf ("max queues system wide = %d\n", msginfo.msgmni); - printf ("max size of message (bytes) = %d\n", msginfo.msgmax); - printf ("default max size of queue (bytes) = %d\n", msginfo.msgmnb); + printf (_("------ Messages: Limits --------\n")); + printf (_("max queues system wide = %d\n"), msginfo.msgmni); + printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax); + printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb); return; case STATUS: - printf ("------ Messages: Status --------\n"); - printf ("allocated queues = %d\n", msginfo.msgpool); - printf ("used headers = %d\n", msginfo.msgmap); - printf ("used space = %d bytes\n", msginfo.msgtql); + printf (_("------ Messages: Status --------\n")); + printf (_("allocated queues = %d\n"), msginfo.msgpool); + printf (_("used headers = %d\n"), msginfo.msgmap); + printf (_("used space = %d bytes\n"), msginfo.msgtql); return; case CREATOR: - printf ("------ Message Queues: Creators/Owners --------\n"); - printf ("%-10s%-10s%-10s%-10s%-10s%-10s\n", - "msqid","perms","cuid","cgid","uid","gid"); + printf (_("------ Message Queues: Creators/Owners --------\n")); + printf (_("%-10s%-10s%-10s%-10s%-10s%-10s\n"), + _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid")); break; case TIME: - printf ("------ Message Queues Send/Recv/Change Times --------\n"); - printf ("%-8s%-10s %-20s%-20s%-20s\n", - "msqid","owner","send","recv","change"); + printf (_("------ Message Queues Send/Recv/Change Times --------\n")); + printf (_("%-8s%-10s %-20s%-20s%-20s\n"), + _("msqid"),_("owner"),_("send"),_("recv"),_("change")); break; case PID: - printf ("------ Message Queues PIDs --------\n"); - printf ("%-10s%-10s%-10s%-10s\n","msqid","owner","lspid","lrpid"); + printf (_("------ Message Queues PIDs --------\n")); + printf (_("%-10s%-10s%-10s%-10s\n"),_("msqid"),_("owner"),_("lspid"),_("lrpid")); break; default: - printf ("------ Message Queues --------\n"); - printf ("%-10s%-10s%-10s%-10s%-12s%-12s\n", "key","msqid", - "owner", "perms", "used-bytes", "messages"); + printf (_("------ Message Queues --------\n")); + printf (_("%-10s%-10s%-10s%-10s%-12s%-12s\n"), _("key"),_("msqid"), + _("owner"), _("perms"), _("used-bytes"), _("messages")); break; } @@ -482,9 +497,9 @@ void do_msg (char format) else printf ("%-8d%-10d", msqid, ipcp->uid); printf (" %-20.16s%-20.16s%-20.16s\n", - msgque.msg_stime ? ctime(&msgque.msg_stime) + 4 : "Not set", - msgque.msg_rtime ? ctime(&msgque.msg_rtime) + 4 : "Not set", - msgque.msg_ctime ? ctime(&msgque.msg_ctime) + 4 : "Not set"); + msgque.msg_stime ? ctime(&msgque.msg_stime) + 4 : _("Not set"), + msgque.msg_rtime ? ctime(&msgque.msg_rtime) + 4 : _("Not set"), + msgque.msg_ctime ? ctime(&msgque.msg_ctime) + 4 : _("Not set")); break; case PID: if (pw) @@ -521,18 +536,18 @@ void print_shm (int shmid) return; } - printf ("\nShared memory Segment shmid=%d\n", shmid); - printf ("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n", + printf (_("\nShared memory Segment shmid=%d\n"), shmid); + printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"), ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); - printf ("mode=%#o\taccess_perms=%#o\n", ipcp->mode, ipcp->mode & 0777); - printf ("bytes=%d\tlpid=%d\tcpid=%d\tnattch=%d\n", + printf (_("mode=%#o\taccess_perms=%#o\n"), ipcp->mode, ipcp->mode & 0777); + printf (_("bytes=%d\tlpid=%d\tcpid=%d\tnattch=%d\n"), shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, shmds.shm_nattch); - printf ("att_time=%s", shmds.shm_atime ? ctime (&shmds.shm_atime) : - "Not set\n"); - printf ("det_time=%s", shmds.shm_dtime ? ctime (&shmds.shm_dtime) : - "Not set\n"); - printf ("change_time=%s", ctime (&shmds.shm_ctime)); + printf (_("att_time=%s"), shmds.shm_atime ? ctime (&shmds.shm_atime) : + _("Not set\n")); + printf (_("det_time=%s"), shmds.shm_dtime ? ctime (&shmds.shm_dtime) : + _("Not set\n")); + printf (_("change_time=%s"), ctime (&shmds.shm_ctime)); printf ("\n"); return; } @@ -548,16 +563,16 @@ void print_msg (int msqid) perror ("msgctl "); return; } - printf ("\nMessage Queue msqid=%d\n", msqid); - printf ("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n", + printf (_("\nMessage Queue msqid=%d\n"), msqid); + printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"), ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode); - printf ("cbytes=%d\tqbytes=%d\tqnum=%d\tlspid=%d\tlrpid=%d\n", + printf (_("cbytes=%d\tqbytes=%d\tqnum=%d\tlspid=%d\tlrpid=%d\n"), buf.msg_cbytes, buf.msg_qbytes, buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); - printf ("send_time=%srcv_time=%schange_time=%s", - buf.msg_rtime? ctime (&buf.msg_rtime) : "Not Set\n", - buf.msg_stime? ctime (&buf.msg_stime) : "Not Set\n", - buf.msg_ctime? ctime (&buf.msg_ctime) : "Not Set\n"); + printf (_("send_time=%srcv_time=%schange_time=%s"), + buf.msg_rtime? ctime (&buf.msg_rtime) : _("Not Set\n"), + buf.msg_stime? ctime (&buf.msg_stime) : _("Not Set\n"), + buf.msg_ctime? ctime (&buf.msg_ctime) : _("Not Set\n")); printf ("\n"); return; } @@ -574,17 +589,17 @@ void print_sem (int semid) perror ("semctl "); return; } - printf ("\nSemaphore Array semid=%d\n", semid); - printf ("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n", + printf (_("\nSemaphore Array semid=%d\n"), semid); + printf (_("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"), ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); - printf ("mode=%#o, access_perms=%#o\n", ipcp->mode, ipcp->mode & 0777); - printf ("nsems = %d\n", semds.sem_nsems); - printf ("otime = %s", semds.sem_otime ? ctime (&semds.sem_otime) : - "Not set\n"); - printf ("ctime = %s", ctime (&semds.sem_ctime)); - - printf ("%-10s%-10s%-10s%-10s%-10s\n", "semnum","value","ncount", - "zcount","pid"); + printf (_("mode=%#o, access_perms=%#o\n"), ipcp->mode, ipcp->mode & 0777); + printf (_("nsems = %d\n"), semds.sem_nsems); + printf (_("otime = %s"), semds.sem_otime ? ctime (&semds.sem_otime) : + _("Not set\n")); + printf (_("ctime = %s"), ctime (&semds.sem_ctime)); + + printf (_("%-10s%-10s%-10s%-10s%-10s\n"), _("semnum"),_("value"),_("ncount"), + _("zcount"),_("pid")); arg.val = 0; for (i=0; i< semds.sem_nsems; i++) { int val, ncnt, zcnt, pid; diff --git a/sys-utils/kbdrate.8 b/sys-utils/kbdrate.8 deleted file mode 100644 index 88c6cbc1..00000000 --- a/sys-utils/kbdrate.8 +++ /dev/null @@ -1,64 +0,0 @@ -.\" Copyright 1992, 1994 Rickard E. Faith (faith@cs.unc.edu) -.\" May be distributed under the GNU General Public License -.\" Updated Wed Jun 22 21:09:43 1994, faith@cs.unc.edu -.TH KBDRATE 8 "22 June 1994" "Linux 1.1.19" "Linux Programmer's Manual" -.SH NAME -kbdrate \- reset the keyboard repeat rate and delay time -.SH SYNOPSIS -.B "kbdrate [ \-s ] [ \-r" -rate -.B "] [ \-d" -delay -.B ] -.SH DESCRIPTION -.B kbdrate -is used to change the IBM keyboard repeat rate and delay time. The delay -is the amount of time that a key must be depressed before it will start to -repeat. - -Using -.B kbdrate -without any options will reset the rate to 10.9 characters per second (cps) -and the delay to 250 milliseconds (mS). These are the IBM defaults. -.SH OPTIONS -.TP -.B \-s -Silent. No messages are printed. -.TP -.BI \-r " rate" -Change the keyboard repeat rate to -.I rate -cps. The allowable range is from 2.0 to 30.0 cps. Only certain, specific -values are possible, and the program will select the nearest possible value -to the one specified. The possible values are given, in characters per -second, as follows: 2.0, 2.1, 2.3, 2.5, 2.7, 3.0, 3.3, 3.7, 4.0, 4.3, 4.6, -5.0, 5.5, 6.0, 6.7, 7.5, 8.0, 8.6, 9.2, 10.0, 10.9, 12.0, 13.3, 15.0, 16.0, -17.1, 18.5, 20.0, 21.8, 24.0, 26.7, 30.0. -.TP -.BI \-d " delay" -Change the delay to -.I delay -milliseconds. The allowable range is from 250 to 1000 mS, but the only -possible values (based on hardware restrictions) are: 250mS, 500mS, 750mS, -and 1000mS. -.SH BUGS -Not all keyboards support all rates. -.PP -Not all keyboards have the rates mapped in the same way. -.PP -Setting the repeat rate on the Gateway AnyKey keyboard does not work. If -someone with a Gateway figures out how to program the keyboard, please send -mail to faith@cs.unc.edu. -.PP -The above description is for i386 machines, and writing to some io port -won't work on other architectures. Nowadays -.B kbdrate -first tries if the KDKBDREP ioctl is available. If it is, it is used, -otherwise the old method is applied. - -.SH FILES -.I /etc/rc.local -.br -.I /dev/port -.SH AUTHOR -Rik Faith (faith@cs.unc.edu) diff --git a/sys-utils/kbdrate.c b/sys-utils/kbdrate.c deleted file mode 100644 index 50442945..00000000 --- a/sys-utils/kbdrate.c +++ /dev/null @@ -1,205 +0,0 @@ -/* -From: faith@cs.unc.edu (Rik Faith) -Subject: User mode keyboard rate changer -Date: 27 Apr 92 13:44:26 GMT - -I put together this program, called kbdrate.c, which will reset the keyboard -repeat rate and delay in user mode. The program must have read/write -access to /dev/port, so if /dev/port is only read/writeable by group port, -then kbdrate must run setgid to group port (for example). - -The "rate" is the rate in characters per second - -The "delay" is the amount of time the key must remain depressed before it -will start to repeat. - -Usage examples: - -kbdrate set rate to IBM default (10.9 cps, 250mS delay) -kbdrate -r 30.0 set rate to 30 cps and delay to 250mS -kbdrate -r 20.0 -s set rate to 20 cps (delay 250mS) -- don't print message -kbdrate -r 0 -d 0 set rate to 2.0 cps and delay to 250 mS - -I find it useful to put kbdrate in my /etc/rc file so that the keyboard -rate is set to something that I find comfortable at boot time. This sure -beats rebuilding the kernel! - - - kbdrate.c -- Set keyboard typematic rate (and delay) - Created: Thu Apr 23 12:24:30 1992 - Author: Rickard E. Faith, faith@cs.unc.edu - - Copyright 1992 Rickard E. Faith. Distributed under the GPL. - This program comes with ABSOLUTELY NO WARRANTY. - Usage: kbdrate [-r rate] [-d delay] [-s] - Rate can range from 2.0 to 30.0 (units are characters per second) - Delay can range from 250 to 1000 (units are milliseconds) - -s suppressed message - Compiles under gcc 2.1 for Linux (tested with the pre-0.96 kernel) - - Wed Jun 22 21:35:43 1994, faith@cs.unc.edu: - Changed valid_rates per suggestion by Andries.Brouwer@cwi.nl. - Wed Jun 22 22:18:29 1994, faith@cs.unc.edu: - Added patch for AUSTIN notebooks from John Bowman - (bowman@hagar.ph.utexas.edu) - - Linux/68k modifications by Roman Hodek - (Roman.Hodek@informatik.uni-erlangen.de): - - Reading/writing the Intel I/O ports via /dev/port is not the - English way... Such hardware dependant stuff can never work on - other architectures. - - Linux/68k has an new ioctl for setting the keyboard repeat rate - and delay. Both values are counted in msecs, the kernel will do - any rounding to values possible with the underlying hardware. - - kbdrate now first tries if the KDKBDREP ioctl is available. If it - is, it is used, else the old method is applied. - -*/ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#include <linux/version.h> -#if LINUX_VERSION_CODE >= 131072 -/* kd.h is not available with all linux versions. 131072 is equivalent - to linux 2.0.0 */ -#include <linux/kd.h> -#endif - -#define VERSION "1.3" - -static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150, - 133, 120, 109, 100, 92, 86, 80, 75, 67, - 60, 55, 50, 46, 43, 40, 37, 33, 30, 27, - 25, 23, 21, 20 }; -#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int )) - -static int valid_delays[] = { 250, 500, 750, 1000 }; -#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int )) - -#ifdef KDKBDREP -static int ioctl_possible = 0; -struct kbd_repeat kbdrep_s; -#endif - -int main( int argc, char **argv ) -{ - double rate = 10.9; /* Default rate */ - int delay = 250; /* Default delay */ - int value = 0x7f; /* Maximum delay with slowest rate */ - /* DO NOT CHANGE this value */ - int silent = 0; - int fd; - char data; - int c; - int i; - extern char *optarg; - - while ( (c = getopt( argc, argv, "r:d:sv" )) != EOF ) - switch (c) { - case 'r': - rate = atof( optarg ); - break; - case 'd': - delay = atoi( optarg ); - break; - case 's': - silent = 1; - break; - case 'v': - fprintf( stderr, "util-linux kbdrate " VERSION "\n"); - exit(0); - } - -#ifdef KDKBDREP - kbdrep_s.rate = -1; /* don't change, just test */ - kbdrep_s.delay = -1; - if (ioctl( 0, KDKBDREP, &kbdrep_s )) { - if (errno == EINVAL) - ioctl_possible = 0; - else { - perror( "ioctl(KDKBDREP)" ); - exit( 1 ); - } - } else ioctl_possible = 1; - - if (ioctl_possible) { - if (rate == 0) /* switch repeat off */ - kbdrep_s.rate = 0; - else - kbdrep_s.rate = 1000.0 / rate; /* convert cps to msec */ - if (kbdrep_s.rate < 1) - kbdrep_s.rate = 1; - kbdrep_s.delay = delay; - if (kbdrep_s.delay < 1) - kbdrep_s.delay = 1; - - if (ioctl( 0, KDKBDREP, &kbdrep_s )) { - perror( "ioctl(KDKBDREP)" ); - exit( 1 ); - } - - if (!silent) - printf( "Typematic Rate set to %.1f cps (delay = %d mS)\n", - 1000.0 / (double)kbdrep_s.rate, kbdrep_s.delay ); - } else { -#endif - - /* The ioport way */ - - for (i = 0; i < RATE_COUNT; i++) - if (rate * 10 >= valid_rates[i]) { - value &= 0x60; - value |= i; - break; - } - - - for (i = 0; i < DELAY_COUNT; i++) - if (delay <= valid_delays[i]) { - value &= 0x1f; - value |= i << 5; - break; - } - - if ( (fd = open( "/dev/port", O_RDWR )) < 0) { - perror( "Cannot open /dev/port" ); - exit( 1 ); - } - - do { - lseek( fd, 0x64, 0 ); - read( fd, &data, 1 ); - } while ((data & 2) == 2 ); /* wait */ - - lseek( fd, 0x60, 0 ); - data = 0xf3; /* set typematic rate */ - write( fd, &data, 1 ); - - do { - lseek( fd, 0x64, 0 ); - read( fd, &data, 1 ); - } while ((data & 2) == 2 ); /* wait */ - - lseek( fd, 0x60, 0 ); - sleep( 1 ); - write( fd, &value, 1 ); - - close( fd ); - - if (!silent) printf( "Typematic Rate set to %.1f cps (delay = %d mS)\n", - valid_rates[value & 0x1f] / 10.0, - valid_delays[ (value & 0x60) >> 5 ] ); - -#ifdef KDKBDREP - } -#endif - - return 0; -} diff --git a/sys-utils/lp.h b/sys-utils/lp.h new file mode 100644 index 00000000..7fa83dde --- /dev/null +++ b/sys-utils/lp.h @@ -0,0 +1,83 @@ +/* Line printer stuff mostly follows the original Centronics printers. See + IEEE Std.1284-1994 Standard Signaling Method for a Bi-directional Parallel + Peripheral Interface for Personal Computers for 5 modes of data transfer. */ + +/* Parallel port registers: data (0x3bc, 0x378, 0x278), status=data+1, control=data+2 */ + +/* Parallel port status register (read only): +bit 7: NBSY (1: ready, 0: busy or error or off-line) +bit 6: NACK (if NBSY=1, then 1; if NBSY=0 then 1: sending data, 0: ready with data) +bit 5: PAP (1: out-of-paper) +bit 4: OFON (1: on-line) +bit 3: NFEH (1: OK, 0: printer error) +bits 2-0: 07 + +On out-of-paper: PAP=1, OFON=0, NFEH=1. + +"When reading the busy status, read twice in a row and use the value +obtained from the second read. This improves the reliability on some +parallel ports when the busy line may not be connected and is floating." +"On some Okidata printers when the busy signal switches from high to low, +the printer sends a 50 ns glitch on the paper out signal line. Before +declaring a paper out condition, check the status again." +(The Undocumented PC, F. van Gilluwe, p. 711) +*/ + +/* Parallel port control register (read/write): +bit 4: IRQ (1: we want an interrupt when NACK goes from 1 to 0) +bit 3: DSL (1: activate printer) +bit 2: NINI (0: initialise printer) +bit 1: ALF (1: printer performs automatic linefeed after each line) +bit 0: STR (0->1: generate a Strobe pulse: transport data to printer) +*/ + +/* Parallel port timing: + 1. wait for NBSY=1 + 2. outb(data byte, data port) + 3. wait for at least 0.5us + 4. read control port, OR with STR=0x1, output to control port - purpose: + generate strobe pulse; this will make the busy line go high + 5. wait for at least 0.5us + 6. read control port, AND with !STR, output to control port + 7. wait for at least 0.5us + 8. in a loop: read status register until NACK bit is 0 or NBSY=1 + (the printer will keep NACK=0 for at least 0.5us, then NACK=NBSY=1). +*/ + + +/* lp ioctls */ +#define LPCHAR 0x0601 /* specify the number of times we ask for the status + (waiting for ready) before giving up with a timeout + The duration may mainly depend on the timing of an inb. */ +#define LPTIME 0x0602 /* time to sleep after each timeout (in units of 0.01 sec) */ +#define LPABORT 0x0604 /* call with TRUE arg to abort on error, + FALSE to retry. Default is retry. */ +#define LPSETIRQ 0x0605 /* call with new IRQ number, + or 0 for polling (no IRQ) */ +#define LPGETIRQ 0x0606 /* get the current IRQ number */ +#define LPWAIT 0x0608 /* #of loops to wait before taking strobe high */ +#define LPCAREFUL 0x0609 /* call with TRUE arg to require out-of-paper, off- + line, and error indicators good on all writes, + FALSE to ignore them. Default is ignore. */ +#define LPABORTOPEN 0x060a /* call with TRUE arg to abort open() on error, + FALSE to ignore error. Default is ignore. */ +#define LPGETSTATUS 0x060b /* return LP_S(minor) */ +#define LPRESET 0x060c /* reset printer */ +#define LPGETFLAGS 0x060e /* get status flags */ + +#define LPSTRICT 0x060f /* enable/disable strict compliance (2.0.36) */ + /* Strict: wait until !READY before taking strobe low; + this may be bad for the Epson Stylus 800. + Not strict: wait a constant time as given by LPWAIT */ +#define LPTRUSTIRQ 0x060f /* set/unset the LP_TRUST_IRQ flag (2.1.131) */ + +/* + * bit defines for 8255 status port + * base + 1 + * accessed with LP_S(minor), which gets the byte... + */ +#define LP_PBUSY 0x80 /* inverted input, active high */ +#define LP_PACK 0x40 /* unchanged input, active low */ +#define LP_POUTPA 0x20 /* unchanged input, active high */ +#define LP_PSELECD 0x10 /* unchanged input, active high */ +#define LP_PERRORP 0x08 /* unchanged input, active low */ diff --git a/sys-utils/rdev.c b/sys-utils/rdev.c index 77e1a58f..434784b8 100644 --- a/sys-utils/rdev.c +++ b/sys-utils/rdev.c @@ -49,12 +49,15 @@ Tue Mar 30 09:31:52 1993: rdev -Rn to set root readonly flag, sct@dcs.ed.ac.uk Wed Jun 22 21:12:29 1994: Applied patches from Dave (gentzel@nova.enet.dec.com) to prevent dereferencing the NULL pointer, faith@cs.unc.edu +1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> +- added Native Language Support ------------------------------------------------------------------------- */ #include <stdio.h> +#include "nls.h" /* rdev.c - query/set root device. */ @@ -62,20 +65,20 @@ void usage() { - puts("usage: rdev [ -rsv ] [ -o OFFSET ] [ IMAGE [ VALUE [ OFFSET ] ] ]"); - puts(" rdev /dev/fd0 (or rdev /linux, etc.) displays the current ROOT device"); - puts(" rdev /dev/fd0 /dev/hda2 sets ROOT to /dev/hda2"); - puts(" rdev -R /dev/fd0 1 set the ROOTFLAGS (readonly status)"); - puts(" rdev -s /dev/fd0 /dev/hda2 set the SWAP device"); - puts(" rdev -r /dev/fd0 627 set the RAMDISK size"); - puts(" rdev -v /dev/fd0 1 set the bootup VIDEOMODE"); - puts(" rdev -o N ... use the byte offset N"); - puts(" rootflags ... same as rdev -R"); - puts(" swapdev ... same as rdev -s"); - puts(" ramsize ... same as rdev -r"); - puts(" vidmode ... same as rdev -v"); - puts("Note: video modes are: -3=Ask, -2=Extended, -1=NormalVga, 1=key1, 2=key2,..."); - puts(" use -R 1 to mount root readonly, -R 0 for read/write."); + puts(_("usage: rdev [ -rsv ] [ -o OFFSET ] [ IMAGE [ VALUE [ OFFSET ] ] ]")); + puts(_(" rdev /dev/fd0 (or rdev /linux, etc.) displays the current ROOT device")); + puts(_(" rdev /dev/fd0 /dev/hda2 sets ROOT to /dev/hda2")); + puts(_(" rdev -R /dev/fd0 1 set the ROOTFLAGS (readonly status)")); + puts(_(" rdev -s /dev/fd0 /dev/hda2 set the SWAP device")); + puts(_(" rdev -r /dev/fd0 627 set the RAMDISK size")); + puts(_(" rdev -v /dev/fd0 1 set the bootup VIDEOMODE")); + puts(_(" rdev -o N ... use the byte offset N")); + puts(_(" rootflags ... same as rdev -R")); + puts(_(" swapdev ... same as rdev -s")); + puts(_(" ramsize ... same as rdev -r")); + puts(_(" vidmode ... same as rdev -v")); + puts(_("Note: video modes are: -3=Ask, -2=Extended, -1=NormalVga, 1=key1, 2=key2,...")); + puts(_(" use -R 1 to mount root readonly, -R 0 for read/write.")); exit(-1); } @@ -90,7 +93,6 @@ usage() #include <sys/types.h> #include <sys/stat.h> - #define DEFAULT_OFFSET 508 @@ -135,6 +137,10 @@ int main(int argc,char **argv) struct stat s; int cmd = 0; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + device = NULL; if ((ptr = strrchr(argv[0],'/')) != NULL) ptr++; diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c index 4462a811..ba982f7c 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -18,6 +18,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + */ + #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -26,6 +31,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include "nls.h" #define RELEASE "2.0, May 1996" @@ -41,14 +47,14 @@ static char optstring[]="m:p:itvarV"; void usage() { fprintf(stderr, - "%s: Usage: \"%s [options]\n" + _("%s: Usage: \"%s [options]\n" "\t -m <mapfile> (default = \"%s\")\n" "\t -p <pro-file> (default = \"%s\")\n" "\t -i print only info about the sampling step\n" "\t -v print verbose data\n" "\t -a print all symbols, even if count is 0\n" "\t -r reset all the counters (root only)\n" - "\t -V print version and exit\n" + "\t -V print version and exit\n") ,prgname,prgname,defaultmap,defaultpro); exit(1); } @@ -73,7 +79,7 @@ FILE *pro; FILE *map; int proFd; char *mapFile, *proFile; -unsigned int len, add0=0, step, index=0; +unsigned int len=0, add0=0, step, index=0; unsigned int *buf, total, fn_len; unsigned int fn_add, next_add; /* current and next address */ char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */ @@ -86,6 +92,10 @@ int popenMap; /* flag to tell if popen() has been used */ #define next (current^1) + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + prgname=argv[0]; proFile=defaultpro; mapFile=defaultmap; @@ -100,7 +110,7 @@ int popenMap; /* flag to tell if popen() has been used */ case 'i': optInfo++; break; case 'r': optReset++; break; case 'v': optVerbose++; break; - case 'V': printf("%s Version %s\n",prgname,RELEASE); exit(0); + case 'V': printf(_("%s Version %s\n"),prgname,RELEASE); exit(0); default: usage(); } } @@ -112,7 +122,7 @@ int popenMap; /* flag to tell if popen() has been used */ pro=fopen(defaultpro,"w"); if (!pro) {perror(proFile); exit(1);} - fprintf(pro,"anything\n"); + fprintf(pro,_("anything\n")); fclose(pro); exit(0); } @@ -141,7 +151,7 @@ int popenMap; /* flag to tell if popen() has been used */ step=buf[0]; if (optInfo) { - printf("Sampling_step: %i\n",step); + printf(_("Sampling_step: %i\n"),step); exit(0); } @@ -154,7 +164,7 @@ int popenMap; /* flag to tell if popen() has been used */ { if (sscanf(mapline,"%x %s %s",&fn_add,mode,fn_name)!=3) { - fprintf(stderr,"%s: %s(%i): wrong map line\n", + fprintf(stderr,_("%s: %s(%i): wrong map line\n"), prgname,mapFile, maplineno); exit(1); } @@ -167,7 +177,7 @@ int popenMap; /* flag to tell if popen() has been used */ if (!add0) { - fprintf(stderr,"%s: can't find \"_stext\" in %s\n",prgname, mapFile); + fprintf(stderr,_("%s: can't find \"_stext\" in %s\n"),prgname, mapFile); exit(1); } @@ -180,7 +190,7 @@ int popenMap; /* flag to tell if popen() has been used */ if (sscanf(mapline,"%x %s %s",&next_add,mode,next_name)!=3) { - fprintf(stderr,"%s: %s(%i): wrong map line\n", + fprintf(stderr,_("%s: %s(%i): wrong map line\n"), prgname,mapFile, maplineno); exit(1); } @@ -208,7 +218,7 @@ int popenMap; /* flag to tell if popen() has been used */ 0,"total",total,total/(double)(fn_add-add0)); else printf("%6i %-40s %8.4f\n", - total,"total",total/(double)(fn_add-add0)); + total,_("total"),total/(double)(fn_add-add0)); popenMap ? pclose(map) : fclose(map); exit(0); diff --git a/sys-utils/renice.c b/sys-utils/renice.c index 8867d002..6bc83f99 100644 --- a/sys-utils/renice.c +++ b/sys-utils/renice.c @@ -31,6 +31,10 @@ * SUCH DAMAGE. */ + /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + */ + #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> @@ -38,6 +42,8 @@ #include <stdio.h> #include <pwd.h> #include <stdlib.h> +#include <errno.h> +#include "nls.h" int donice(int,int,int); @@ -52,10 +58,14 @@ main(int argc, char **argv) int which = PRIO_PROCESS; int who = 0, prio, errs = 0; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + argc--, argv++; if (argc < 2) { - fprintf(stderr, "usage: renice priority [ [ -p ] pids ] "); - fprintf(stderr, "[ [ -g ] pgrps ] [ [ -u ] users ]\n"); + fprintf(stderr, _("usage: renice priority [ [ -p ] pids ] " + "[ [ -g ] pgrps ] [ [ -u ] users ]\n")); exit(1); } prio = atoi(*argv); @@ -81,7 +91,7 @@ main(int argc, char **argv) register struct passwd *pwd = getpwnam(*argv); if (pwd == NULL) { - fprintf(stderr, "renice: %s: unknown user\n", + fprintf(stderr, _("renice: %s: unknown user\n"), *argv); continue; } @@ -89,7 +99,7 @@ main(int argc, char **argv) } else { who = atoi(*argv); if (who < 0) { - fprintf(stderr, "renice: %s: bad value\n", + fprintf(stderr, _("renice: %s: bad value\n"), *argv); continue; } @@ -104,19 +114,18 @@ donice(which, who, prio) int which, who, prio; { int oldprio; - extern int errno; errno = 0, oldprio = getpriority(which, who); if (oldprio == -1 && errno) { fprintf(stderr, "renice: %d: ", who); - perror("getpriority"); + perror(_("getpriority")); return (1); } if (setpriority(which, who, prio) < 0) { fprintf(stderr, "renice: %d: ", who); - perror("setpriority"); + perror(_("setpriority")); return (1); } - printf("%d: old priority %d, new priority %d\n", who, oldprio, prio); + printf(_("%d: old priority %d, new priority %d\n"), who, oldprio, prio); return (0); } diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c index 10f1501d..7aeb2de8 100644 --- a/sys-utils/setsid.c +++ b/sys-utils/setsid.c @@ -2,16 +2,25 @@ * setsid.c -- execute a command in a new session * Rick Sladkey <jrs@world.std.com> * In the public domain. + * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> +#include "nls.h" int main(int argc, char *argv[]) { + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + if (argc < 2) { - fprintf(stderr, "usage: %s program [arg ...]\n", + fprintf(stderr, _("usage: %s program [arg ...]\n"), argv[0]); exit(1); } diff --git a/sys-utils/shhopt-1.1.lsm b/sys-utils/shhopt-1.1.lsm deleted file mode 100644 index a61a2696..00000000 --- a/sys-utils/shhopt-1.1.lsm +++ /dev/null @@ -1,17 +0,0 @@ -Begin3 -Title: shhopt - library for parsing command line options. -Version: 1.1 -Entered-date: 06JUN96 -Description: C-functions for parsing command line options, both - traditional one-character options, and GNU'ish - --long-options. -Keywords: programming, library, lib, commandline -Author: sverrehu@ifi.uio.no (Sverre H. Huseby) -Primary-site: sunsite.unc.edu /pub/Linux/libs - shhopt-1.1.tar.gz -Platforms: Requires ANSI C-compiler. -Copying-policy: BeerWare: If you have the time and money, send me a bottle - of your favourite beer. If not, just send me a mail or - something. Copy and use as you wish; just leave the - author's name where you find it. -End diff --git a/sys-utils/shhopt.c b/sys-utils/shhopt.c deleted file mode 100644 index 6d31225c..00000000 --- a/sys-utils/shhopt.c +++ /dev/null @@ -1,467 +0,0 @@ -/* $Id: shhopt.c,v 2.2 1997/07/06 23:11:55 aebr Exp $ */ -/************************************************************************** - * - * FILE shhopt.c - * - * DESCRIPTION Functions for parsing command line arguments. Values - * of miscellaneous types may be stored in variables, - * or passed to functions as specified. - * - * REQUIREMENTS Some systems lack the ANSI C -function strtoul. If your - * system is one of those, you'll ned to write one yourself, - * or get the GNU liberty-library (from prep.ai.mit.edu). - * - * WRITTEN BY Sverre H. Huseby <sverrehu@ifi.uio.no> - * - **************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <ctype.h> -#include <limits.h> -#include <errno.h> - -#include "shhopt.h" - -/************************************************************************** - * * - * P R I V A T E D A T A * - * * - **************************************************************************/ - -static void optFatalFunc(const char *, ...); -static void (*optFatal)(const char *format, ...) = optFatalFunc; - - - -/************************************************************************** - * * - * P R I V A T E F U N C T I O N S * - * * - **************************************************************************/ - -/*------------------------------------------------------------------------- - * - * NAME optFatalFunc - * - * FUNCTION Show given message and abort the program. - * - * INPUT format, ... - * Arguments used as with printf(). - * - * RETURNS Never returns. The program is aborted. - * - */ -void optFatalFunc(const char *format, ...) -{ - va_list ap; - - fflush(stdout); - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - exit(99); -} - - - -/*------------------------------------------------------------------------- - * - * NAME optStructCount - * - * FUNCTION Get number of options in a optStruct. - * - * INPUT opt array of possible options. - * - * RETURNS Number of options in the given array. - * - * DESCRIPTION Count elements in an optStruct-array. The strcture must - * be ended using an element of type OPT_END. - * - */ -static int optStructCount(const optStruct opt[]) -{ - int ret = 0; - - while (opt[ret].type != OPT_END) - ++ret; - return ret; -} - - - -/*------------------------------------------------------------------------- - * - * NAME optMatch - * - * FUNCTION Find a matching option. - * - * INPUT opt array of possible options. - * s string to match, without `-' or `--'. - * lng match long option, otherwise short. - * - * RETURNS Index to the option if found, -1 if not found. - * - * DESCRIPTION Short options are matched from the first character in - * the given string. - * - */ -static int optMatch(const optStruct opt[], const char *s, int lng) -{ - int nopt, q, matchlen = 0; - char *p; - - nopt = optStructCount(opt); - if (lng) { - if ((p = strchr(s, '=')) != NULL) - matchlen = p - s; - else - matchlen = strlen(s); - } - for (q = 0; q < nopt; q++) { - if (lng) { - if (!opt[q].longName) - continue; - if (strncmp(s, opt[q].longName, matchlen) == 0) - return q; - } else { - if (!opt[q].shortName) - continue; - if (*s == opt[q].shortName) - return q; - } - } - return -1; -} - - - -/*------------------------------------------------------------------------- - * - * NAME optString - * - * FUNCTION Return a (static) string with the option name. - * - * INPUT opt the option to stringify. - * lng is it a long option? - * - * RETURNS Pointer to static string. - * - */ -static char *optString(const optStruct *opt, int lng) -{ - static char ret[31]; - - if (lng) { - strcpy(ret, "--"); - strncpy(ret + 2, opt->longName, 28); - } else { - ret[0] = '-'; - ret[1] = opt->shortName; - ret[2] = '\0'; - } - return ret; -} - - - -/*------------------------------------------------------------------------- - * - * NAME optNeedsArgument - * - * FUNCTION Check if an option requires an argument. - * - * INPUT opt the option to check. - * - * RETURNS Boolean value. - * - */ -static int optNeedsArgument(const optStruct *opt) -{ - return opt->type == OPT_STRING - || opt->type == OPT_INT - || opt->type == OPT_UINT - || opt->type == OPT_LONG - || opt->type == OPT_ULONG; -} - - - -/*------------------------------------------------------------------------- - * - * NAME argvRemove - * - * FUNCTION Remove an entry from an argv-array. - * - * INPUT argc pointer to number of options. - * argv array of option-/argument-strings. - * i index of option to remove. - * - * OUTPUT argc new argument count. - * argv array with given argument removed. - * - */ -static void argvRemove(int *argc, char *argv[], int i) -{ - if (i >= *argc) - return; - while (i++ < *argc) - argv[i - 1] = argv[i]; - --*argc; -} - - - -/*------------------------------------------------------------------------- - * - * NAME optExecute - * - * FUNCTION Perform the action of an option. - * - * INPUT opt array of possible options. - * arg argument to option, if it applies. - * lng was the option given as a long option? - * - * RETURNS Nothing. Aborts in case of error. - * - */ -void optExecute(const optStruct *opt, char *arg, int lng) -{ - switch (opt->type) { - case OPT_FLAG: - if (opt->flags & OPT_CALLFUNC) - ((void (*)(void)) opt->arg)(); - else - *((int *) opt->arg) = 1; - break; - - case OPT_STRING: - if (opt->flags & OPT_CALLFUNC) - ((void (*)(char *)) opt->arg)(arg); - else - *((char **) opt->arg) = arg; - break; - - case OPT_INT: - case OPT_LONG: { - long tmp; - char *e; - - tmp = strtol(arg, &e, 10); - if (*e) - optFatal("invalid number `%s'\n", arg); - if (errno == ERANGE - || (opt->type == OPT_INT && (tmp > INT_MAX || tmp < INT_MIN))) - optFatal("number `%s' to `%s' out of range\n", - arg, optString(opt, lng)); - if (opt->type == OPT_INT) { - if (opt->flags & OPT_CALLFUNC) - ((void (*)(int)) opt->arg)((int) tmp); - else - *((int *) opt->arg) = (int) tmp; - } else /* OPT_LONG */ { - if (opt->flags & OPT_CALLFUNC) - ((void (*)(long)) opt->arg)(tmp); - else - *((long *) opt->arg) = tmp; - } - break; - } - - case OPT_UINT: - case OPT_ULONG: { - unsigned long tmp; - char *e; - - tmp = strtoul(arg, &e, 10); - if (*e) - optFatal("invalid number `%s'\n", arg); - if (errno == ERANGE - || (opt->type == OPT_UINT && tmp > UINT_MAX)) - optFatal("number `%s' to `%s' out of range\n", - arg, optString(opt, lng)); - if (opt->type == OPT_UINT) { - if (opt->flags & OPT_CALLFUNC) - ((void (*)(unsigned)) opt->arg)((unsigned) tmp); - else - *((unsigned *) opt->arg) = (unsigned) tmp; - } else /* OPT_ULONG */ { - if (opt->flags & OPT_CALLFUNC) - ((void (*)(unsigned long)) opt->arg)(tmp); - else - *((unsigned long *) opt->arg) = tmp; - } - break; - } - - default: - break; - } -} - - - -/************************************************************************** - * * - * P U B L I C F U N C T I O N S * - * * - **************************************************************************/ - -/*------------------------------------------------------------------------- - * - * NAME optSetFatalFunc - * - * FUNCTION Set function used to display error message and exit. - * - * SYNOPSIS #include "shhmsg.h" - * void optSetFatalFunc(void (*f)(const char *, ...)); - * - * INPUT f function accepting printf()'like parameters, - * that _must_ abort the program. - * - */ -void optSetFatalFunc(void (*f)(const char *, ...)) -{ - optFatal = f; -} - - - -/*------------------------------------------------------------------------- - * - * NAME optParseOptions - * - * FUNCTION Parse commandline options. - * - * SYNOPSIS #include "shhopt.h" - * void optParseOptions(int *argc, char *argv[], - * const optStruct opt[], int allowNegNum); - * - * INPUT argc Pointer to number of options. - * argv Array of option-/argument-strings. - * opt Array of possible options. - * allowNegNum - * a negative number is not to be taken as - * an option. - * - * OUTPUT argc new argument count. - * argv array with arguments removed. - * - * RETURNS Nothing. Aborts in case of error. - * - * DESCRIPTION This function checks each option in the argv-array - * against strings in the opt-array, and `executes' any - * matching action. Any arguments to the options are - * extracted and stored in the variables or passed to - * functions pointed to by entries in opt. - * - * Options and arguments used are removed from the argv- - * array, and argc is decreased accordingly. - * - * Any error leads to program abortion. - * - */ -void optParseOptions(int *argc, char *argv[], - const optStruct opt[], int allowNegNum) -{ - int ai, /* argv index. */ - optarg, /* argv index of option argument, or -1 if none. */ - mi, /* Match index in opt. */ - done; - char *arg, /* Pointer to argument to an option. */ - *o, /* pointer to an option character */ - *p; - - /* - * Loop through all arguments. - */ - for (ai = 0; ai < *argc; ) { - /* - * "--" indicates that the rest of the argv-array does not - * contain options. - */ - if (strcmp(argv[ai], "--") == 0) { - argvRemove(argc, argv, ai); - break; - } - - if (allowNegNum && argv[ai][0] == '-' && isdigit(argv[ai][1])) { - ++ai; - continue; - } else if (strncmp(argv[ai], "--", 2) == 0) { - /* long option */ - /* find matching option */ - if ((mi = optMatch(opt, argv[ai] + 2, 1)) < 0) - optFatal("unrecognized option `%s'\n", argv[ai]); - - /* possibly locate the argument to this option. */ - arg = NULL; - if ((p = strchr(argv[ai], '=')) != NULL) - arg = p + 1; - - /* does this option take an argument? */ - optarg = -1; - if (optNeedsArgument(&opt[mi])) { - /* option needs an argument. find it. */ - if (!arg) { - if ((optarg = ai + 1) == *argc) - optFatal("option `%s' requires an argument\n", - optString(&opt[mi], 1)); - arg = argv[optarg]; - } - } else { - if (arg) - optFatal("option `%s' doesn't allow an argument\n", - optString(&opt[mi], 1)); - } - /* perform the action of this option. */ - optExecute(&opt[mi], arg, 1); - /* remove option and any argument from the argv-array. */ - if (optarg >= 0) - argvRemove(argc, argv, ai); - argvRemove(argc, argv, ai); - } else if (*argv[ai] == '-') { - /* A dash by itself is not considered an option. */ - if (argv[ai][1] == '\0') { - ++ai; - continue; - } - /* Short option(s) following */ - o = argv[ai] + 1; - done = 0; - optarg = -1; - while (*o && !done) { - /* find matching option */ - if ((mi = optMatch(opt, o, 0)) < 0) - optFatal("unrecognized option `-%c'\n", *o); - - /* does this option take an argument? */ - optarg = -1; - arg = NULL; - if (optNeedsArgument(&opt[mi])) { - /* option needs an argument. find it. */ - arg = o + 1; - if (!*arg) { - if ((optarg = ai + 1) == *argc) - optFatal("option `%s' requires an argument\n", - optString(&opt[mi], 0)); - arg = argv[optarg]; - } - done = 1; - } - /* perform the action of this option. */ - optExecute(&opt[mi], arg, 0); - ++o; - } - /* remove option and any argument from the argv-array. */ - if (optarg >= 0) - argvRemove(argc, argv, ai); - argvRemove(argc, argv, ai); - } else { - /* a non-option argument */ - ++ai; - } - } -} diff --git a/sys-utils/shhopt.h b/sys-utils/shhopt.h deleted file mode 100644 index ca8501ef..00000000 --- a/sys-utils/shhopt.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $Id: shhopt.h,v 2.2 1997/07/06 23:11:58 aebr Exp $ */ -#ifndef SHHOPT_H -#define SHHOPT_H - -/* constants for recognized option types. */ -typedef enum { - OPT_END, /* nothing. used as ending element. */ - OPT_FLAG, /* no argument following. sets variable to 1. */ - OPT_STRING, /* string argument. */ - OPT_INT, /* signed integer argument. */ - OPT_UINT, /* unsigned integer argument. */ - OPT_LONG, /* signed long integer argument. */ - OPT_ULONG, /* unsigned long integer argument. */ -} optArgType; - -/* flags modifying the default way options are handeled. */ -#define OPT_CALLFUNC 1 /* pass argument to a function. */ - -typedef struct { - char shortName; /* Short option name. */ - char *longName; /* Long option name, no including '--'. */ - optArgType type; /* Option type. */ - void *arg; /* Pointer to variable to fill with argument, - * or pointer to function if Type == OPT_FUNC. */ - int flags; /* Modifier flags. */ -} optStruct; - - -void optSetFatalFunc(void (*f)(const char *, ...)); -void optParseOptions(int *argc, char *argv[], - const optStruct opt[], int allowNegNum); - -#endif diff --git a/sys-utils/tunelp.8 b/sys-utils/tunelp.8 index 8b148f20..ac01ed40 100644 --- a/sys-utils/tunelp.8 +++ b/sys-utils/tunelp.8 @@ -1,32 +1,47 @@ .\" This file Copyright (C) 1992-1997 Michael K. Johnson <johnsonm@redhat.com> +.\" This file Copyright (C) 1998 Andrea Arcangeli <andrea@e-mind.com> .\" It may be distributed under the terms of the GNU General Public License, .\" version 2, or any higher version. See section COPYING of the GNU General .\" Public license for conditions under which this file may be redistributed. -.\" $Id: tunelp.8,v 1.6 1997/06/20 16:10:35 janl Exp $ -.TH tunelp 8 "26 August 1992" "Cohesive Systems" "Linux Programmer's Manual" +.\" +.\" Polished a bit - aeb +.TH tunelp 8 "7 May 1999" "tunelp" "Linux Programmer's Manual" .SH NAME tunelp \- set various parameters for the lp device .SH SYNOPSIS -\fBtunelp\fP \fI<device>\fP [-i \fI<IRQ>\fP | -t \fI<TIME>\fP | -c \fI<CHARS>\fP | -w \fI<WAIT>\fP | -a [on|off] | -o [on|off] | -C [on|off] | -r | -s | -q [on|off] ] +\fBtunelp\fP \fI<device>\fP [-i \fI<IRQ>\fP | -t \fI<TIME>\fP | -c \fI<CHARS>\fP | -w \fI<WAIT>\fP | -a [on|off] | -o [on|off] | -C [on|off] | -r | -s | -q [on|off] | - T [on|off] ] .SH DESCRIPTION \fBtunelp\fP sets several parameters for the /dev/lp\fI?\fP devices, for better performance (or for any performance at all, if your printer won't work -without it...) Without parameters, tells whether the device is using -interrups, and if so, which one. With parameters, sets the device +without it...) Without parameters, it tells whether the device is using +interrupts, and if so, which one. With parameters, it sets the device characteristics accordingly. The parameters are as follows: --i \fI<IRQ>\fP is the IRQ to use for the parallel port in question. If this -is set to something non-zero, -t and -c have no effect. If your port +.TP +.BI \-i " <IRQ>" +specifies the IRQ to use for the parallel port in question. If this +is set to something non-zero, \-t and \-c have no effect. If your port does not use interrupts, this option will make printing stop. +The command .B tunelp -i 0 restores non-interrupt driven (polling) action, and your printer should work again. If your parallel port does support interrupts, interrupt-driven printing should be somewhat faster and efficient, and -will probably be desireable. +will probably be desirable. --t \fI<TIME>\fP is the amount of time in jiffies that the driver waits if the +NOTE: This option will have no effect with kernel 2.1.131 or later since +the irq is handled by the parport driver. You can change +the parport irq for example via +.IR /proc/parport/*/irq . +Read +.I /usr/src/linux/Documentation/parport.txt +for more details on parport. + +.TP +.BI \-t " <TIME>" +is the amount of time in jiffies that the driver waits if the printer doesn't take a character for the number of tries dictated by -the -c parameter. 10 is the default value. If you want fastest +the \-c parameter. 10 is the default value. If you want fastest possible printing, and don't care about system load, you may set this to 0. If you don't care how fast your printer goes, or are printing text on a slow printer with a buffer, then 500 (5 seconds) should be @@ -34,51 +49,105 @@ fine, and will give you very low system load. This value generally should be lower for printing graphics than text, by a factor of approximately 10, for best performance. --c \fI<CHARS>\fP is the number of times to try to output a character to the -printer before sleeping for -t \fI<TIME>\fP. It is the number of times around +.TP +.BI \-c " <CHARS>" +is the number of times to try to output a character to the +printer before sleeping for \-t \fI<TIME>\fP. It is the number of times around a loop that tries to send a character to the printer. 120 appears to -be a good value for most printers. 250 is the default, because there -are some printers that require a wait this long, but feel free to -change this. If you have a very fast printer like an HP laserjet 4, a -value of 10 might make more sense. If you have a \fIreally\fP old -printer, you can increase this farther. +be a good value for most printers in polling mode. 1000 is the default, +because there are some printers that become jerky otherwise, but you \fImust\fP +set this to `1' to handle the maximal CPU efficiency if you are using +interrupts. If you have a very fast printer, a value of 10 might make more +sense even if in polling mode. +If you have a \fIreally\fP old printer, you can increase this further. -Setting -t \fI<TIME>\fP to 0 is equivalent to setting -c \fI<CHARS>\fP +Setting \-t \fI<TIME>\fP to 0 is equivalent to setting \-c \fI<CHARS>\fP to infinity. --w \fI<WAIT>\fP is the a busy loop counter for the strobe signal. While most -printers appear to be able to deal with an extremely short strobe, -some printers demand a longer one. Increasing this from the default -0 may make it possible to print with those printers. This may also -make it possible to use longer cables. +.TP +.BI \-w " <WAIT>" +is the number of usec we wait while playing with the strobe signal. +While most printers appear to be able to deal with an extremely +short strobe, some printers demand a longer one. Increasing this from +the default 1 may make it possible to print with those printers. This may also +make it possible to use longer cables. It's also possible to decrease this +value to 0 if your printer is fast enough or your machine is slow enough. --a [on|off] This is whether to abort on printer error -- the default +.TP +.B \-a [on|off] +This is whether to abort on printer error - the default is not to. If you are sitting at your computer, you probably want to be able to see an error and fix it, and have the printer go on printing. On the other hand, if you aren't, you might rather that your printer spooler find out that the printer isn't ready, quit trying, and send you mail about it. The choice is yours. --o [on|off] This option is much like -a. It makes any open() of this -device check to see that the device is on-line and not reporting any +.TP +.B \-o [on|off] +This option is much like \-a. It makes any +.I open() +of this device check to see that the device is on-line and not reporting any out of paper or other errors. This is the correct setting for most versions of lpd. --C [on|off] This option adds extra ("careful") error checking. When +.TP +.B \-C [on|off] +This option adds extra ("careful") error checking. When this option is on, the printer driver will ensure that the printer is on-line and not reporting any out of paper or other errors before sending data. This is particularly useful for printers that normally appear to accept data when turned off. --s This option returns the current printer status, both as a +NOTE: This option is obsolete because it's the default in 2.1.131 kernel +or later. + +.TP +.B \-s +This option returns the current printer status, both as a decimal number from 0..255, and as a list of active flags. When -this option is specified, -q off, turning off the display of the +this option is specified, \-q off, turning off the display of the current IRQ, is implied. --o, -C, and -s all require a Linux kernel version of 1.1.76 or later. +.TP +.B \-T [on|off] +This option tell the lp driver to trust or not the IRQ. +This option makes sense only if you are using interrupts. +If you tell the lp driver to trust the irq, then, when the lp driver will +get an irq, it will send the next pending character to the printer +unconditionally, even if the printer still claims to be BUSY. +This is the only way to sleep on interrupt (and so the handle the irq +printing efficiently) at least on Epson Stylus Color Printers. +The lp driver automagically detects if you could get improved +performance by setting this flag, and in such case it will warn you +with a kernel message. + +NOTE: Trusting the irq is reported to corrupt the printing on some hardware, +you must try to know if your printer will work or not... --r This option resets the port. It requires a Linux kernel version of +.TP +.B \-r +This option resets the port. It requires a Linux kernel version of 1.1.80 or later. --q [on|off] This option sets printing the display of the current IRQ -setting. +.TP +.B \-q [on|off] +This option sets printing the display of the current IRQ setting. + + +.SH NOTES +\-o, \-C, and \-s all require a Linux kernel version of 1.1.76 or later. + +\-C requires a Linux version prior to 2.1.131. + +\-T requires a Linux version of 2.1.131 or later. + +.SH BUGS +By some unfortunate coincidence the ioctl LPSTRICT of 2.0.36 has the same +number as the ioctl LPTRUSTIRQ introduced in 2.1.131. So, use of the \-T option +on a 2.0.36 kernel with an tunelp compiled under 2.1.131 or later may have +unexpected effects. + +.SH FILES +.I /dev/lp? +.br +.I /proc/parport/*/* diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c index e3b015ba..dfb30aa6 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -42,22 +42,26 @@ * Revision 1.2 1995/01/03 07:33:44 johnsonm * revisions for lp driver updates in Linux 1.1.76 * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * + * 1999-05-07 Merged LPTRUSTIRQ patch by Andrea Arcangeli (1998/11/29), aeb * */ -#include<unistd.h> -#include<stdio.h> -#include<fcntl.h> -/* This is for (some) 2.1 kernels */ -#define LP_NEED_CAREFUL -#include<linux/lp.h> -#include<linux/fs.h> -#include<sys/ioctl.h> -#include<sys/stat.h> -#include<sys/types.h> -#include<malloc.h> -#include<string.h> -#include<errno.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +/* #include <linux/fs.h> */ +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <malloc.h> +#include <string.h> +#include <errno.h> +#include "lp.h" +#include "nls.h" +#include "../version.h" struct command { long op; @@ -69,19 +73,23 @@ struct command { void print_usage(char *progname) { - printf("Usage: %s <device> [ -i <IRQ> | -t <TIME> | -c <CHARS> | -w <WAIT> | \n" - " -a [on|off] | -o [on|off] | -C [on|off] | -q [on|off] | -s ]\n", progname); + printf(_("Usage: %s <device> [ -i <IRQ> | -t <TIME> | -c <CHARS> | -w <WAIT> | \n" + " -a [on|off] | -o [on|off] | -C [on|off] | -q [on|off] | -s | \n" + " -T [on|off] ]\n"), + progname); exit (1); } - +void print_version(char *progname) { + printf("%s %s\n", progname, UTIL_LINUX_VERSION); +} void *mylloc(long size) { void *ptr; if(!(ptr = (void*)malloc(size))) { - perror("malloc error"); + perror(_("malloc error")); exit(2); } return ptr; @@ -92,7 +100,7 @@ void *mylloc(long size) { long get_val(char *val) { long ret; if (!(sscanf(val, "%ld", &ret) == 1)) { - perror("sscanf error"); + perror(_("sscanf error")); exit(3); } return ret; @@ -114,33 +122,14 @@ int main (int argc, char ** argv) { struct stat statbuf; struct command *cmds, *cmdst; - progname = argv[0]; if (argc < 2) print_usage(progname); - filename = strdup(argv[1]); - fd = open(filename, O_WRONLY|O_NONBLOCK, 0); - /* Need to open O_NONBLOCK in case ABORTOPEN is already set and - printer is off or off-line or in an error condition. Otherwise - we would abort... */ - if (fd < 0) { - perror(argv[1]); - return -1; - } - - fstat(fd, &statbuf); - - if((!S_ISCHR(statbuf.st_mode)) || (MAJOR(statbuf.st_rdev) != 6 ) - || (MINOR(statbuf.st_rdev) > 3)) { - printf("%s: %s not an lp device.\n", argv[0], argv[1]); - print_usage(progname); - } - cmdst = cmds = mylloc(sizeof(struct command)); cmds->next = 0; show_irq = 1; - while ((c = getopt(argc, argv, "t:c:w:a:i:ho:C:sq:r")) != EOF) { + while ((c = getopt(argc, argv, "t:c:w:a:i:ho:C:sq:rT:vV")) != EOF) { switch (c) { case 'h': print_usage(progname); @@ -210,10 +199,44 @@ int main (int argc, char ** argv) { cmds = cmds->next; cmds->next = 0; break; #endif - default: print_usage(progname); +#ifdef LPTRUSTIRQ + case 'T': + /* Note: this will do the wrong thing on 2.0.36 when compiled under 2.2.x */ + cmds->op = LPTRUSTIRQ; + cmds->val = get_onoff(optarg); + cmds->next = mylloc(sizeof(struct command)); + cmds = cmds->next; cmds->next = 0; + break; +#endif + case 'v': + case 'V': + print_version(progname); + exit(0); + default: + print_usage(progname); } } + if (optind != argc-1) + print_usage(progname); + + filename = strdup(argv[optind]); + fd = open(filename, O_WRONLY|O_NONBLOCK, 0); + /* Need to open O_NONBLOCK in case ABORTOPEN is already set and + printer is off or off-line or in an error condition. Otherwise + we would abort... */ + if (fd < 0) { + perror(filename); + return -1; + } + + fstat(fd, &statbuf); + + if(!S_ISCHR(statbuf.st_mode)) { + printf(_("%s: %s not an lp device.\n"), argv[0], filename); + print_usage(progname); + } + /* Allow for binaries compiled under a new kernel to work on the old ones */ /* The irq argument to ioctl isn't touched by the old kernels, but we don't */ /* want to cause the kernel to complain if we are using a new kernel */ @@ -231,12 +254,12 @@ int main (int argc, char ** argv) { else { if (status == 0xdeadbeef) /* a few 1.1.7x kernels will do this */ status = retval; - printf("%s status is %d", filename, status); - if (!(status & LP_PBUSY)) printf(", busy"); - if (!(status & LP_PACK)) printf(", ready"); - if ((status & LP_POUTPA)) printf(", out of paper"); - if ((status & LP_PSELECD)) printf(", on-line"); - if (!(status & LP_PERRORP)) printf(", error"); + printf(_("%s status is %d"), filename, status); + if (!(status & LP_PBUSY)) printf(_(", busy")); + if (!(status & LP_PACK)) printf(_(", ready")); + if ((status & LP_POUTPA)) printf(_(", out of paper")); + if ((status & LP_PSELECD)) printf(_(", on-line")); + if (!(status & LP_PERRORP)) printf(_(", error")); printf("\n"); } } else @@ -253,15 +276,15 @@ int main (int argc, char ** argv) { irq = 0xdeadbeef; retval = ioctl(fd, LPGETIRQ - offset, &irq); if (retval == -1) { - perror("LPGETIRQ error"); + perror(_("LPGETIRQ error")); exit(4); } if (irq == 0xdeadbeef) /* up to 1.1.77 will do this */ irq = retval; if (irq) - printf("%s using IRQ %d\n", filename, irq); + printf(_("%s using IRQ %d\n"), filename, irq); else - printf("%s using polling\n", filename); + printf(_("%s using polling\n"), filename); } close(fd); |