Subject: getlogin(2)+setlogin(2) arrive,usleep(3)+sleep(3) fixed (#390 - 1 of 3) Index: sys/init_systent.c,lib/libc/{gen,pdp},many many more 2.11BSD Description: 1) getlogin() is slow (having to open /dev, /var/run/utmp, etc) and does not work when the system is in single user more (or if the utmp file is not publically readable). 2) many programs (incorrectly) declare the getlogin() function locally rather than (correctly) using '#include . 3) unistd.h has a bug and mistakenly declares access(2) as returning 'unsigned int' rather than 'int'. 4) usleep(3) is useless for two reasons: a) it uses alarm(2) and thus can only offer 1 second granularity and b) its parameter is an "unsigned int" which can only count 65535 microseconds (or about 3 clock ticks) maximum. 5) If sleep(3) is interrupted it does not return the amount of unslept time. Sleep(3) is expensive because it requires 9 system calls and uses signal(3)+alarm(2). Repeat-By: 1) While the system is in single user mode run a program which depends on getlogin(). In single user mode getlogin() returns NULL and programs which depend on getlogin() will either generate an error or a core dump. 2) Observation. 3) Recompile sendmail with the incorrect declaration of access() and note the inability of sendmail to create files in the queue directory. 4) Try to use usleep() to pause for 1/2 second (500000 microseconds). 5) Have a program which catches SIGINT (or perhaps SIGHUP) and then performs a "i = sleep(500);". Note that after the signal is handled that the return value is (likely) garbage _and_ that the program waits until the full sleep interval has elapsed rather than returning after the signal handler completes. Fix: 1) The 4.4BSD getlogin() and setlogin() system calls were ported. Only a 'root' process can issue setlogin(2) and at the present time only login(1) does this. The login name is inherited by child processes and thus remains the same even if 'su' is used to switch user identities. 2) There were many files which contained local declarations of the form "char *getlogin();" or "extern char *getlogin();". Replacing those references with "#include " in some cases required additional modifications to be made. 3) Misdeclaring access(2)'s return value breaks programs which use the idiom "if (access(foo, 0) < 0);". Sendmail was one of these programs. Arguably the correct usage of access() is "if (access(foo, 0) != 0);" (some folks would say using access() at all is bad). 4) Change usleep() to take a 'long' rather than an 'unsigned int'. Rewrite usleep() to use 'select()' rather than alarm + setitimer. 5) Write (from scratch) a new version of sleep(3) which uses 'select' rather than signal + alarm. Remove the logic which resumed the sleep in the event of a signal. Compute the amount of time left unslept. The new sleep(3) only requires 3 system calls (two gettimeofday(2) calls and 1 select(2)) instead of the 9 used by the previous version (which saved and restored the SIGALRM signal handles, set up the new signal catcher, etc). There are 3 parts (390, 391, 392) to this update kit. Make sure you have all of them. This is a moderately large update. A new kernel (two kernels if you rebuild the GENERIC one - always a good idea) has to be built. The C library (libc.a) is recompiled. Quite a few applications are remade (to use the new getlogin(2) syscall). No attempt has been made to recompile all programs which use sleep(3) - that will have to wait until the next "make world". A side benefit on these changes is that many programs experience a significant size reduction. The new 'sleep' and 'getlogin' routines are *MUCH* smaller than the old ones. Savings of over 1kb have been seen in programs which used both sleep and getlogin. The changes to the kernel are small - the two new system calls (kern_prot.c) added very little to the size of the kernel. It is probable that the kernel overlay structure will NOT have to be changed. In the C library the sleep, usleep, getlogin, and setlogin modules are added/replaced. New and updated manpages are provided. The debugger 'adb' was modified to know about the new system calls. Installation of the lint libraries (from /usr/src/share/lint) has been simplified - the Makefile now has the ability to create the "compiled" versions without requiring several manual steps. The 'MX' version of sendmail does not (as far as I know) run well but it was felt worth a little bit of time to at least keep the sources compileable to make life a little easier for the fellow who want to work on it in his copious free time. MANIFEST of New/Changed/Removed files. Files ending in ".RM" are being 'removed' from the system, files ending in ".NEW" are being added to the system, and files ending in ".old" are being patched. A number of files are in more than one catagory (a file being replaced would show up as a .RM and a .NEW): /usr/include/syscall.h.old /usr/include/unistd.h.old /usr/man/cat3/usleep.0.RM /usr/man/cat3/getlogin.0.RM /usr/src/sys/sys/syscalls.c.old /usr/src/sys/sys/init_main.c.old /usr/src/sys/sys/kern_prot.c.old /usr/src/sys/sys/init_sysent.c.old /usr/src/bin/adb/opset.c.old /usr/src/bin/login/login.c.old /usr/src/bin/su.c.old /usr/src/bin/mail.c.old /usr/src/games/warp/intrp.c.old /usr/src/games/boggle/boggle.c.old /usr/src/games/hack/hack.main.c.old /usr/src/games/hack/hack.mklev.c.old /usr/src/games/hack/hack.pager.c.old /usr/src/lib/libc/gen/usleep.c.RM /usr/src/lib/libc/gen/usleep.c.NEW /usr/src/lib/libc/gen/sleep.c.RM /usr/src/lib/libc/gen/sleep.c.NEW /usr/src/lib/libc/gen/getlogin.c.RM /usr/src/lib/libc/gen/getlogin.c.NEW /usr/src/lib/libc/net/rexec.c.old /usr/src/lib/libc/pdp/sys/Makefile.old /usr/src/lib/libc/pdp/sys/setlogin.s.NEW /usr/src/man/man2/getlogin.2.NEW /usr/src/man/man2/Makefile.old /usr/src/man/man3/Makefile.old /usr/src/man/man3/getlogin.3.RM /usr/src/man/man3/sleep.3.RM /usr/src/man/man3/sleep.3.NEW /usr/src/man/man3/usleep.3.RM /usr/src/new/rcs/src/rcsutil.c.old /usr/src/ucb/error/errorfilter.c.old /usr/src/ucb/ftp/ftp.c.old /usr/src/ucb/ftp/main.c.old /usr/src/ucb/ftp/cmds.c.old /usr/src/ucb/ftp/ruserpass.c.old /usr/src/ucb/talk/get_names.c.old /usr/src/ucb/logger.c.old /usr/src/ucb/sccs.c.old /usr/src/ucb/from.c.old /usr/src/usr.bin/learn/learn.c.old /usr/src/usr.bin/uucp/uucp.h.old /usr/src/usr.bin/uucp/getpwinfo.c.old /usr/src/usr.bin/uucp/cico.c.old /usr/src/usr.bin/uucp/conn.c.old /usr/src/usr.bin/uucp/condevs.c.old /usr/src/usr.bin/uucp/pk0.c.old /usr/src/usr.bin/uucp/pk1.c.old /usr/src/usr.bin/uucp/anlwrk.c.old /usr/src/usr.bin/uucp/chkpth.c.old /usr/src/usr.bin/uucp/ulockf.c.old /usr/src/usr.bin/uucp/versys.c.old /usr/src/usr.bin/uucp/uuxqt.c.old /usr/src/usr.bin/uucp/uuq.c.old /usr/src/usr.lib/libU77/getlog_.c.old /usr/src/share/lint/llib-lc.old /usr/src/share/lint/Makefile.old /usr/src/usr.sbin/sendmail/include/useful.h.old /usr/src/usr.sbin/sendmail/src/conf.c.old /usr/src/usr.sbin/sendmail/src/sendmail.h.old /usr/src/usr.sbin/sendmail/src/daemon.c.old /usr/src/usr.sbin/sendmail/src/util.c.old /usr/src/usr.sbin/sendmail/src/conf.h.old /usr/src/usr.sbin/sendmail/src/clock.c.old /usr/src/usr.sbin/sendmail/src/arpadate.c.old /usr/src/usr.sbin/sendmail.MX/include/useful.h.old /usr/src/usr.sbin/sendmail.MX/src/conf.c.old /usr/src/usr.sbin/sendmail.MX/src/sendmail.h.old /usr/src/usr.sbin/sendmail.MX/src/arpadate.c.old /usr/src/usr.sbin/sendmail.MX/src/clock.c.old /usr/src/usr.sbin/sendmail.MX/src/util.c.old /usr/src/usr.sbin/sendmail.MX/src/conf.h.old /usr/src/usr.sbin/sendmail.MX/src/daemon.c.old /usr/src/usr.sbin/sendmail.MX/src/Makefile.old /usr/src/usr.sbin/sendmail.MX/src/main.c.old /usr/src/usr.sbin/sendmail.MX/src/srvrsmtp.c.old /usr/src/usr.sbin/sendmail.MX/src/err.c.old /usr/src/usr.sbin/sendmail.MX/src/envelope.c.old /usr/src/usr.sbin/sendmail.MX/src/usersmtp.c.old /usr/src/sbin/shutdown/shutdown.c.old /usr/src/sbin/reboot/reboot.c.old /VERSION.old Update Part Content ------ ---- ------- 390 1 This file. Contains the description, MANIFEST, a shell script (/tmp/390.rm) to remove old files, a shell script (/tmp/390.sh) to compile/install the libraries and applications, and a shar file (/tmp/390.shar) of new files. 391 2 First of two patch files. 392 3 Second of two patch files. After gathering all 3 parts cut where indicated and save to files (/tmp/390, /tmp/391 and /tmp/392). Then: cd /tmp sh 390 sh -x 390.rm sh 390.shar patch -p0 < 391 patch -p0 < 392 Before compiling or installing any libraries/applications the new kernel (with the new system calls) must be in place. The overlay structure MAY need to be adjusted (hopefully not), keep a careful watch for "too big" messages from the linker: (IF you are not building a networking kernel then omit references to 'netnix' below) cd /sys/YOUR_KERNEL make mv /unix /ounix mv /netnix /onetnix install -m 744 unix netnix / reboot Optionally a new GENERIC kernel is made (this can be deferred until later): cd /sys/GENERIC make mv unix /genunix chmod 744 /genunix Included in the kit is a shell script which will perform all the necessary compilation and installation. THIS script can either be used as a GUIDE (with the steps being performed manually) or run directly. NOTE: 390.sh assumes that the system is completely in sync with the reference system. If you have removed or tar+compress'd directories to save space then the script will fail and it will be necessary to either edit the script or use it as a guide and perform the steps manually. If you are voyeuristic you can jot down the sizes of some programs before recompiling them (good ones would be 'login', 'su', 'ftp' and 'sendmail'). Then after the new versions are installed take a look at the sizes to see how much smaller the new programs are. cd /tmp sh -x 390.sh This will take a fairly long time - several hours (libc.a takes about 1.25 hours and several of the applications are large). Then log out and log back in to the system. This runs the new login program which properly initializes the login name used by the new system calls. As always this and previous updates to 2.11BSD are available via anonymous FTP to either FTP.IIPO.GTEGSC.COM or MOE.2BSD.COM in the directory /pub/2.11BSD. ---------------------------cut here---------------------------- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # 390.rm # 390.sh # 390.shar # This archive created: Wed Oct 8 13:30:38 1997 export PATH; PATH=/bin:/usr/bin:$PATH if test -f '390.rm' then echo shar: "will not over-write existing file '390.rm'" else sed 's/^V//' << \SHAR_EOF > '390.rm' V#!/bin/sh -x V Vrm -f /usr/man/cat3/usleep.0 Vrm -f /usr/man/cat3/getlogin.0 Vrm -f /usr/src/lib/libc/gen/usleep.c Vrm -f /usr/src/lib/libc/gen/sleep.c Vrm -f /usr/src/lib/libc/gen/getlogin.c Vrm -f /usr/src/man/man3/getlogin.3 Vrm -f /usr/src/man/man3/sleep.3 Vrm -f /usr/src/man/man3/usleep.3 SHAR_EOF chmod 755 '390.rm' fi if test -f '390.sh' then echo shar: "will not over-write existing file '390.sh'" else sed 's/^V//' << \SHAR_EOF > '390.sh' V#!/bin/sh -x V Vcd /usr/src/lib/libc Vmake clean Vmake install Vmake clean V Vcd /usr/src/bin/adb Vmake Vmake install Vmake clean V Vcd /usr/src/bin/login Vmake Vmake install Vmake clean V Vcd /usr/src/bin Vmake su mail Vinstall -s -m 4755 -o root su mail /bin V Vcd /usr/src/games/warp Vmake Vmake install Vmake clean V Vcd /usr/src/games/boggle Vmake Vmake install Vmake clean V Vcd /usr/src/games/hack Vmake Vmake install Vmake clean V Vcd /usr/src/man/man2 Vmake Vmake install Vmake clean V Vcd /usr/src/man/man3 Vmake Vmake install Vmake clean V Vcd /usr/src/new/rcs Vmake Vmake install Vmake clean V Vcd /usr/src/ucb/error Vmake Vmake install Vmake clean V Vcd /usr/src/ucb/ftp Vmake Vmake install Vmake clean V Vcd /usr/src/ucb/talk Vmake Vmake install Vmake clean V Vcd /usr/src/ucb Vmake sccs logger from Vinstall -s -m 755 -o root sccs logger from /usr/ucb V Vcd /usr/src/usr.bin/learn Vmake Vmake install Vmake clean V Vcd /usr/src/usr.bin/uucp Vmake Vmake install Vmake clean V Vcd /usr/src/usr.lib/libU77 Vmake Vmake install Vmake clean V Vcd /usr/src/share/lint Vmake install Vmake libs V Vcd /usr/src/usr.sbin/sendmail Vmake Vmake install Vmake clean V/usr/sbin/sendmail -bz V Vcd /usr/src/sbin/shutdown Vmake Vmake install Vmake clean V Vcd /usr/src/sbin/reboot Vmake Vmake install Vmake clean SHAR_EOF chmod 755 '390.sh' fi if test -f '390.shar' then echo shar: "will not over-write existing file '390.shar'" else sed 's/^V//' << \SHAR_EOF > '390.shar' V#! /bin/sh V# This is a shell archive, meaning: V# 1. Remove everything above the #! /bin/sh line. V# 2. Save the resulting text in a file. V# 3. Execute the file with /bin/sh (not csh) to create: V# /usr/src/lib/libc/gen/usleep.c V# /usr/src/lib/libc/gen/sleep.c V# /usr/src/lib/libc/gen/getlogin.c V# /usr/src/lib/libc/pdp/sys/setlogin.s V# /usr/src/man/man2/getlogin.2 V# /usr/src/man/man3/sleep.3 V# This archive created: Tue Oct 7 19:49:26 1997 Vexport PATH; PATH=/bin:/usr/bin:$PATH Vif test -f '/usr/src/lib/libc/gen/usleep.c' Vthen V echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/usleep.c'" Velse Vsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/usleep.c' VX/* VX * Program: sleep.c VX * Copyright: 1997, sms VX * Author: Steven M. Schultz VX * VX * Version Date Modification VX * 1.0 1997/9/26 1. Initial release. VX*/ VX VX#include /* For NULL */ VX#include VX#include VX VX/* VX * This implements the usleep(3) function using only 1 system call (select) VX * instead of the 9 that the old implementation required. Also this version VX * avoids using signals (with the attendant system overhead). VX * VX * Nothing is returned and if less than ~20000 microseconds is specified the VX * select will return without any delay at all. VX*/ VX VXusleep(micros) VX long micros; VX { VX struct timeval s; VX VX if (micros > 0) VX { VX s.tv_sec = micros / 1000000L; VX s.tv_usec = micros % 1000000L; VX select(0, NULL, NULL, NULL, &s); VX } VX } VSHAR_EOF Vchmod 644 '/usr/src/lib/libc/gen/usleep.c' Vfi Vif test -f '/usr/src/lib/libc/gen/sleep.c' Vthen V echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/sleep.c'" Velse Vsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/sleep.c' VX/* VX * Program: sleep.c VX * Copyright: 1997, sms VX * Author: Steven M. Schultz VX * VX * Version Date Modification VX * 1.0 1997/9/25 1. Initial release. VX*/ VX VX#include /* For NULL */ VX#include VX#include VX VX/* VX * This implements the sleep(3) function using only 3 system calls instead of VX * the 9 that the old implementation required. Also this version avoids using VX * signals (with the attendant system overhead) and returns the amount of VX * time left unslept if an interrupt occurs. VX * VX * The error status of gettimeofday is not checked because if that fails the VX * program has scrambled the stack so badly that a sleep() failure is the least VX * problem the program has. The select() call either completes successfully VX * or is interrupted - no errors to be checked for. VX*/ VX VXu_int VXsleep(seconds) VX u_int seconds; VX { VX struct timeval f, s; VX VX if (seconds) VX { VX gettimeofday(&f, NULL); VX s.tv_sec = seconds; VX s.tv_usec = 0; VX select(0, NULL, NULL, NULL, &s); VX gettimeofday(&s, NULL); VX seconds -= (s.tv_sec - f.tv_sec); VX/* VX * ONLY way this can happen is if the system time gets set back while we're VX * in the select() call. In this case return 0 instead of a bogus number. VX*/ VX if (seconds < 0) VX seconds = 0; VX } VX return(seconds); VX } VSHAR_EOF Vchmod 644 '/usr/src/lib/libc/gen/sleep.c' Vfi Vif test -f '/usr/src/lib/libc/gen/getlogin.c' Vthen V echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/getlogin.c'" Velse Vsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/getlogin.c' VX/* VX * Copyright (c) 1988, 1993 VX * The Regents of the University of California. All rights reserved. VX * VX * Redistribution and use in source and binary forms, with or without VX * modification, are permitted provided that the following conditions VX * are met: VX * 1. Redistributions of source code must retain the above copyright VX * notice, this list of conditions and the following disclaimer. VX * 2. Redistributions in binary form must reproduce the above copyright VX * notice, this list of conditions and the following disclaimer in the VX * documentation and/or other materials provided with the distribution. VX * 3. All advertising materials mentioning features or use of this software VX * must display the following acknowledgement: VX * This product includes software developed by the University of VX * California, Berkeley and its contributors. VX * 4. Neither the name of the University nor the names of its contributors VX * may be used to endorse or promote products derived from this software VX * without specific prior written permission. VX * VX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND VX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE VX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE VX * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE VX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL VX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS VX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) VX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT VX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY VX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF VX * SUCH DAMAGE. VX */ VX VX#if defined(LIBC_SCCS) && !defined(lint) VXstatic char sccsid[] = "@(#)getlogin.c 8.1.1 (2.11BSD) 1997.9.23"; VX#endif /* LIBC_SCCS and not lint */ VX VX#include VX#include VX#include VX#include VX#include VX#include VX VXint _logname_valid; /* known to setlogin() */ VX VXchar * VXgetlogin() VX{ VX static char logname[MAXLOGNAME + 1]; VX VX if (_logname_valid == 0) { VX if (_getlogin(logname, sizeof(logname) - 1) < 0) VX return ((char *)NULL); VX _logname_valid = 1; VX } VX return (*logname ? logname : (char *)NULL); VX} VSHAR_EOF Vchmod 644 '/usr/src/lib/libc/gen/getlogin.c' Vfi Vif test -f '/usr/src/lib/libc/pdp/sys/setlogin.s' Vthen V echo shar: "will not over-write existing file '/usr/src/lib/libc/pdp/sys/setlogin.s'" Velse Vsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/pdp/sys/setlogin.s' VX/*- VX * Copyright (c) 1991, 1993 VX * The Regents of the University of California. All rights reserved. VX * VX * This code is derived from software contributed to Berkeley by VX * William Jolitz. VX * VX * Redistribution and use in source and binary forms, with or without VX * modification, are permitted provided that the following conditions VX * are met: VX * 1. Redistributions of source code must retain the above copyright VX * notice, this list of conditions and the following disclaimer. VX * 2. Redistributions in binary form must reproduce the above copyright VX * notice, this list of conditions and the following disclaimer in the VX * documentation and/or other materials provided with the distribution. VX * 3. All advertising materials mentioning features or use of this software VX * must display the following acknowledgement: VX * This product includes software developed by the University of VX * California, Berkeley and its contributors. VX * 4. Neither the name of the University nor the names of its contributors VX * may be used to endorse or promote products derived from this software VX * without specific prior written permission. VX * VX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND VX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE VX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE VX * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE VX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL VX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS VX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) VX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT VX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY VX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF VX * SUCH DAMAGE. VX */ VX VX#if defined(LIBC_SCCS) && !defined(lint) VX .asciz "@(#)setlogin.s 8.1.1 (2.11BSD) 1997/9/23" VX#endif /* LIBC_SCCS and not lint */ VX VX#include "SYS.h" VX VX.globl __logname_valid /* in getlogin() */ VX VX/* VX * It simplifies the logic to always clear the valid flag. If the syscall VX * fails all that happens is that an extra getlogin() call is made later on. VX*/ VX VXENTRY(setlogin) VX clr __logname_valid VX SYS(setlogin) VX EXIT_norm VSHAR_EOF Vchmod 640 '/usr/src/lib/libc/pdp/sys/setlogin.s' Vfi Vif test -f '/usr/src/man/man2/getlogin.2' Vthen V echo shar: "will not over-write existing file '/usr/src/man/man2/getlogin.2'" Velse Vsed 's/^X//' << \SHAR_EOF > '/usr/src/man/man2/getlogin.2' VX.\" Copyright (c) 1989, 1991, 1993 VX.\" The Regents of the University of California. All rights reserved. VX.\" VX.\" Redistribution and use in source and binary forms, with or without VX.\" modification, are permitted provided that the following conditions VX.\" are met: VX.\" 1. Redistributions of source code must retain the above copyright VX.\" notice, this list of conditions and the following disclaimer. VX.\" 2. Redistributions in binary form must reproduce the above copyright VX.\" notice, this list of conditions and the following disclaimer in the VX.\" documentation and/or other materials provided with the distribution. VX.\" 3. All advertising materials mentioning features or use of this software VX.\" must display the following acknowledgement: VX.\" This product includes software developed by the University of VX.\" California, Berkeley and its contributors. VX.\" 4. Neither the name of the University nor the names of its contributors VX.\" may be used to endorse or promote products derived from this software VX.\" without specific prior written permission. VX.\" VX.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND VX.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE VX.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE VX.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE VX.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL VX.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS VX.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) VX.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT VX.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY VX.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF VX.\" SUCH DAMAGE. VX.\" VX.\" @(#)getlogin.2 8.1.1 (2.11BSD) 1997/9/23 VX.\" VX.TH GETLOGIN 2 "September 23, 1997" VX.UC 5 VX.SH NAME VX\fBgetlogin\fP, \fBsetlogin\fP \- get/set login name VX.SH SYNOPSIS VX.B #include VX.sp VX.nf VXchar * VXgetlogin() VX.sp VXint VXsetlogin(name) VX char *name; VX.fi VX.SH DESCRIPTION VXThe VX.B getlogin VXroutine VXreturns the login name of the user associated with the current session, VXas previously set by VX.BR setlogin . VXThe name is normally associated with a login shell VXat the time a session is created, VXand is inherited by all processes descended from the login shell. VX(This is true even if some of those processes assume another user ID, VXfor example when VX\fBsu\fP(1) VXis used.) VX.PP VX.B Setlogin VXsets the login name of the user associated with the current session to VX.IR name . VXThis call is restricted to the super-user, and VXis normally used only when a new session is being created on behalf VXof the named user VX(for example, at login time, or when a remote shell is invoked). VX.SH RETURN VALUES VXIf a call to VX.B getlogin VXsucceeds, it returns a pointer to a null-terminated string in a static buffer. VXIf the name has not been set, it returns VX.IR NULL . VXIf a call to VX.B setlogin VXsucceeds, a value of 0 is returned. If VX.B setlogin VXfails, a value of -1 is returned and an error code is VXplaced in the global location VX.IR errno . VX.SH ERRORS VXThe following errors may be returned by these calls: VX.TP 15 VXEFAULT VXThe VX.I name VXparameter gave an invalid address. VX.TP 15 VXEINVAL VXThe VX.I name VXparameter pointed to a string that was too long. VXLogin names are limited to VX.I MAXLOGNAME VX(from VX\fI\\fP) VXcharacters, currently 16. VX.TP 15 VXEPERM VXThe caller tried to set the login name and was not the super-user. VX.SH SEE ALSO VXsetsid(2) VX.SH BUGS VXLogin names are limited in length by VX.BR setlogin . VXHowever, lower limits are placed on login names elsewhere in the system VX(UT_NAMESIZE in VX\fI\\fP). VX.PP VXIn earlier versions of the system, VX.B getlogin VXfailed unless the process was associated with a login terminal. VXThe current implementation (using VX.BR setlogin ) VXallows getlogin to succeed even when the process has no controlling terminal. VXIn earlier versions of the system, the value returned by VX.B getlogin VXcould not be trusted without checking the user ID. VXPortable programs should probably still make this check. VX.SH HISTORY VXThe VX.B setlogin VXfunction first appeared in 4.4BSD. VXThe VX.B getlogin function was present in V7. VSHAR_EOF Vchmod 644 '/usr/src/man/man2/getlogin.2' Vfi Vif test -f '/usr/src/man/man3/sleep.3' Vthen V echo shar: "will not over-write existing file '/usr/src/man/man3/sleep.3'" Velse Vsed 's/^X//' << \SHAR_EOF > '/usr/src/man/man3/sleep.3' VX.\" Copyright (c) 1986, 1991, 1993 VX.\" The Regents of the University of California. All rights reserved. VX.\" VX.\" Redistribution and use in source and binary forms, with or without VX.\" modification, are permitted provided that the following conditions VX.\" are met: VX.\" 1. Redistributions of source code must retain the above copyright VX.\" notice, this list of conditions and the following disclaimer. VX.\" 2. Redistributions in binary form must reproduce the above copyright VX.\" notice, this list of conditions and the following disclaimer in the VX.\" documentation and/or other materials provided with the distribution. VX.\" 3. All advertising materials mentioning features or use of this software VX.\" must display the following acknowledgement: VX.\" This product includes software developed by the University of VX.\" California, Berkeley and its contributors. VX.\" 4. Neither the name of the University nor the names of its contributors VX.\" may be used to endorse or promote products derived from this software VX.\" without specific prior written permission. VX.\" VX.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND VX.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE VX.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE VX.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE VX.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL VX.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS VX.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) VX.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT VX.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY VX.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF VX.\" SUCH DAMAGE. VX.\" VX.\" @(#)sleep.3 8.1.1 (2.11BSD) 1997/9/26 VX.\" VX.TH SLEEP 3 "September 26,1997" VX.UC 3 VX.SH NAME VX\fBsleep\fP, usleep \- suspend process execution VX.SH SYNOPSIS VX.B #include VX.sp VX.nf VXunsigned int VXsleep(seconds) VX unsigned int seconds; VX.sp VXvoid VXusleep(microseconds) VX long microseconds; VX.fi VX.SH DESCRIPTION VXThe VX.B sleep VXfunction suspends execution of the calling process for VX.I seconds VXof clock time, or until interrupted by a signal. VX.PP VXThe VX.B usleep VXfunction suspends execution of the calling process for VX.I microseconds VXof clock time, or until interrupted by a signal. VX.PP VXSystem activity may lengthen the suspension. VX.SH RETURN VALUES VXThe VX.B sleep VXfunction returns 0, or if interrupted before VX.IR seconds, VXthe amount not slept (the requested time minus the time actually slept) VXin seconds. The VX.B usleep VXfunction does not return anything (meaningful). VX.SH SEE ALSO VXselect(2) VX.SH COMPATIBILITY VXPrevious implementations of VX.B sleep VXand VX.B usleep VXre-suspended the process if interrupted by a signal. VXThis implementation has been changed to return in that case, VXto conform to POSIX 1003.1-88. VX.PP VXOn the PDP-11 the previous version of \fBusleep\fP took a \fIu_int\fP as VXthe input parameter. This has been changed to be \fIlong\fP so that VX\fBusleep\fP can be used for more than 65 milliseconds (a u_int could only VXcount 65535 microseconds) of sleep. Thus it is now possible for VX\fBusleep\fP to handle longer sleep durations than \fBsleep\fP. VX.SH BUGS VXOn the PDP-11 the clock resolution is limited to the line frequency (usually VX60Hz in the U.S.A. and 50Hz elsewhere). VX.SH HISTORY VXA VX.B usleep VXfunction appeared in VX4.3BSD. VXA VX.B sleep VXfunction appeared in V7. VSHAR_EOF Vchmod 644 '/usr/src/man/man3/sleep.3' Vfi Vexit 0 V# End of shell archive SHAR_EOF chmod 644 '390.shar' fi exit 0 # End of shell archive