diff options
Diffstat (limited to 'lib/libc/sys')
144 files changed, 21430 insertions, 127 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc new file mode 100644 index 0000000..8576ef6 --- /dev/null +++ b/lib/libc/sys/Makefile.inc @@ -0,0 +1,151 @@ +# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 +# $FreeBSD$ + +# sys sources +.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/sys ${.CURDIR}/../libc/sys + +# Include the generated makefile containing the *complete* list +# of syscall names in MIASM. +.include "${.CURDIR}/../../sys/sys/syscall.mk" + +# Include machine dependent definitions. +# +# MDASM names override the default syscall names in MIASM. +# NOASM will prevent the default syscall code from being generated. +# +.include "${.CURDIR}/../libc/${MACHINE_ARCH}/sys/Makefile.inc" + +# Sources common to both syscall interfaces: +SRCS+= ftruncate.c lseek.c mmap.c pread.c pwrite.c truncate.c + +# Build __error() into libc, but not libc_r which has its own: +.if ${LIB} == "c" +SRCS+= __error.c +.endif + +# Add machine dependent asm sources: +SRCS+=${MDASM} + +# Look though the complete list of syscalls (MIASM) for names that are +# not defined with machine dependent implementations (MDASM) and are +# not declared for no generation of default code (NOASM). If the +# syscall is not hidden, add it to the ASM list, otherwise add it +# to the ASMR list. +.for _asm in ${MIASM} +.if (${MDASM:R:M${_asm:R}} == "") +.if (${NOASM:R:M${_asm:R}} == "") +.if (${HIDDEN_SYSCALLS:R:M${_asm:R}} == "") +ASM+=$(_asm) +.else +ASMR+=$(_asm) +.endif +.endif +.endif +.endfor + +OBJS+= ${ASM} ${ASMR} ${PSEUDO} ${PSEUDOR} + +SASM= ${ASM:S/.o/.S/} + +SASMR= ${ASMR:S/.o/.S/} + +SPSEUDO= ${PSEUDO:S/.o/.S/} + +SPSEUDOR= ${PSEUDOR:S/.o/.S/} + +SRCS+= ${SASM} ${SASMR} ${SPSEUDO} ${SPSEUDOR} + +# Generated files +CLEANFILES+= ${SASM} ${SASMR} ${SPSEUDO} ${SPSEUDOR} + +${SASM}: + printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' > ${.TARGET} + +${SASMR}: + printf '#include "SYS.h"\nPRSYSCALL(${.PREFIX})\n' > ${.TARGET} + +${SPSEUDO}: + printf '#include "SYS.h"\nPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n' \ + > ${.TARGET} + +${SPSEUDOR}: + printf '#include "SYS.h"\nPPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n' \ + > ${.TARGET} + +.if ${LIB} == "c" +MAN2+= _exit.2 accept.2 access.2 acct.2 adjtime.2 \ + aio_cancel.2 aio_error.2 aio_read.2 aio_return.2 \ + aio_suspend.2 aio_write.2 \ + bind.2 brk.2 chdir.2 chflags.2 \ + chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 \ + connect.2 dup.2 execve.2 \ + fcntl.2 fhopen.2 flock.2 fork.2 fsync.2 \ + getdirentries.2 getdtablesize.2 \ + getfh.2 getfsstat.2 getgid.2 getgroups.2 getitimer.2 getlogin.2 \ + getpeername.2 getpgrp.2 getpid.2 getpriority.2 getrlimit.2 \ + getrusage.2 getsid.2 getsockname.2 \ + getsockopt.2 gettimeofday.2 getuid.2 \ + intro.2 ioctl.2 issetugid.2 jail.2 kill.2 \ + kldfind.2 kldfirstmod.2 kldload.2 kldnext.2 kldstat.2 kldunload.2 \ + ktrace.2 link.2 listen.2 lseek.2 \ + madvise.2 mincore.2 minherit.2 mkdir.2 mkfifo.2 mknod.2 mlock.2 mmap.2 \ + mount.2 mprotect.2 msync.2 munmap.2 nanosleep.2 \ + nfssvc.2 open.2 pathconf.2 pipe.2 poll.2 profil.2 ptrace.2 quotactl.2 \ + read.2 readlink.2 reboot.2 recv.2 rename.2 revoke.2 rfork.2 rmdir.2 \ + rtprio.2 select.2 semctl.2 semget.2 semop.2 send.2 sendfile.2 \ + setgroups.2 setpgid.2 setregid.2 setreuid.2 setsid.2 setuid.2 \ + shmat.2 shmctl.2 shmget.2 shutdown.2 \ + sigaction.2 sigaltstack.2 sigpending.2 sigprocmask.2 sigreturn.2 \ + sigstack.2 sigsuspend.2 socket.2 socketpair.2 stat.2 statfs.2 \ + swapon.2 symlink.2 sync.2 sysarch.2 syscall.2 \ + truncate.2 umask.2 undelete.2 \ + unlink.2 utimes.2 vfork.2 wait.2 write.2 +.if !defined(NO_P1003_1B) +MAN2+= sched_get_priority_max.2 sched_setparam.2 \ + sched_setscheduler.2 sched_yield.2 +.endif + +MLINKS+=brk.2 sbrk.2 +MLINKS+=chdir.2 fchdir.2 +MLINKS+=chflags.2 fchflags.2 +MLINKS+=chmod.2 fchmod.2 chmod.2 lchmod.2 +MLINKS+=chown.2 fchown.2 chown.2 lchown.2 +MLINKS+=clock_gettime.2 clock_getres.2 clock_gettime.2 clock_settime.2 +MLINKS+=dup.2 dup2.2 +MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatfs.2 +MLINKS+=getdirentries.2 getdents.2 +MLINKS+=getgid.2 getegid.2 +MLINKS+=getitimer.2 setitimer.2 +MLINKS+=getlogin.2 setlogin.2 +MLINKS+=getpgrp.2 getpgid.2 +MLINKS+=getpid.2 getppid.2 +MLINKS+=getpriority.2 setpriority.2 +MLINKS+=getrlimit.2 setrlimit.2 +MLINKS+=getsockopt.2 setsockopt.2 +MLINKS+=gettimeofday.2 settimeofday.2 +MLINKS+=getuid.2 geteuid.2 +MLINKS+=intro.2 errno.2 +MLINKS+=lseek.2 seek.2 +MLINKS+=mlock.2 munlock.2 +MLINKS+=mount.2 unmount.2 +MLINKS+=pathconf.2 fpathconf.2 +MLINKS+=read.2 pread.2 read.2 readv.2 +MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 +MLINKS+=send.2 sendmsg.2 send.2 sendto.2 +MLINKS+=setpgid.2 setpgrp.2 +MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2 +MLINKS+=shmat.2 shmdt.2 +MLINKS+=stat.2 fstat.2 stat.2 lstat.2 +MLINKS+=statfs.2 fstatfs.2 +MLINKS+=syscall.2 __syscall.2 +MLINKS+=truncate.2 ftruncate.2 +MLINKS+=utimes.2 futimes.2 utimes.2 lutimes.2 +MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 +MLINKS+=write.2 pwrite.2 write.2 writev.2 +.if !defined(NO_P1003_1B) +MLINKS+=sched_get_priority_max.2 sched_get_priority_min.2 \ + sched_get_priority_max.2 sched_rr_get_interval.2 +MLINKS+=sched_setparam.2 sched_getparam.2 +MLINKS+=sched_setscheduler.2 sched_getscheduler.2 +.endif +.endif diff --git a/lib/libc/sys/__error.c b/lib/libc/sys/__error.c new file mode 100644 index 0000000..9b0c25f --- /dev/null +++ b/lib/libc/sys/__error.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <sys/cdefs.h> + +extern int errno; + +/* + * Declare a weak reference in case the application is not linked + * with libpthread. + */ +#pragma weak __error=__error_unthreaded + +int * __error_unthreaded() +{ + return(&errno); +} diff --git a/lib/libc/sys/_exit.2 b/lib/libc/sys/_exit.2 new file mode 100644 index 0000000..a7d282d --- /dev/null +++ b/lib/libc/sys/_exit.2 @@ -0,0 +1,120 @@ +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)_exit.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt EXIT 2 +.Os BSD 4 +.Sh NAME +.Nm _exit +.Nd terminate the calling process +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft void +.Fn _exit "int status" +.Sh DESCRIPTION +The +.Fn _exit +function +terminates a process with the following consequences: +.Bl -bullet +.It +All of the descriptors open in the calling process are closed. +This may entail delays, for example, waiting for output to drain; +a process in this state may not be killed, as it is already dying. +.It +If the parent process of the calling process has an outstanding +.Xr wait 2 +call +or catches the +.Dv SIGCHLD +signal, +it is notified of the calling process's termination and +the +.Em status +is set as defined by +.Xr wait 2 . +.It +The parent process-ID of all of the calling process's existing child +processes are set to 1; the initialization process +(see the +.Sx DEFINITIONS +section of +.Xr intro 2 ) +inherits each of these processes. +.It +If the termination of the process causes any process group +to become orphaned (usually because the parents of all members +of the group have now exited; see +.Dq orphaned process group +in +.Xr intro 2 ) , +and if any member of the orphaned group is stopped, +the +.Dv SIGHUP +signal and the +.Dv SIGCONT +signal are sent to all members of the newly-orphaned process group. +.It +If the process is a controlling process (see +.Xr intro 2 ) , +the +.Dv SIGHUP +signal is sent to the foreground process group of the controlling terminal, +and all current access to the controlling terminal is revoked. +.El +.Pp +Most C programs call the library routine +.Xr exit 3 , +which flushes buffers, closes streams, unlinks temporary files, etc., +before +calling +.Fn _exit . +.Sh RETURN VALUES +.Fn _exit +can never return. +.Sh SEE ALSO +.Xr fork 2 , +.Xr sigaction 2 , +.Xr wait 2 , +.Xr exit 3 +.Sh STANDARDS +The +.Fn _exit +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +An +.Fn _exit +function call appeared in +.At v7 . diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2 new file mode 100644 index 0000000..384823e --- /dev/null +++ b/lib/libc/sys/accept.2 @@ -0,0 +1,201 @@ +.\" Copyright (c) 1983, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)accept.2 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD$ +.\" +.Dd December 11, 1993 +.Dt ACCEPT 2 +.Os BSD 4.2 +.Sh NAME +.Nm accept +.Nd accept a connection on a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn accept "int s" "struct sockaddr *addr" "socklen_t *addrlen" +.Sh DESCRIPTION +The argument +.Fa s +is a socket that has been created with +.Xr socket 2 , +bound to an address with +.Xr bind 2 , +and is listening for connections after a +.Xr listen 2 . +The +.Fn accept +argument +extracts the first connection request +on the queue of pending connections, creates +a new socket with the same properties of +.Fa s +and allocates a new file descriptor +for the socket. If no pending connections are +present on the queue, and the socket is not marked +as non-blocking, +.Fn accept +blocks the caller until a connection is present. +If the socket is marked non-blocking and no pending +connections are present on the queue, +.Fn accept +returns an error as described below. +The accepted socket +may not be used +to accept more connections. The original socket +.Fa s +remains open. +.Pp +The argument +.Fa addr +is a result parameter that is filled in with +the address of the connecting entity, +as known to the communications layer. +The exact format of the +.Fa addr +parameter is determined by the domain in which the communication +is occurring. +The +.Fa addrlen +is a value-result parameter; it should initially contain the +amount of space pointed to by +.Fa addr ; +on return it will contain the actual length (in bytes) of the +address returned. +This call +is used with connection-based socket types, currently with +.Dv SOCK_STREAM . +.Pp +It is possible to +.Xr select 2 +a socket for the purposes of doing an +.Fn accept +by selecting it for read. +.Pp +For certain protocols which require an explicit confirmation, +such as +.Tn ISO +or +.Tn DATAKIT , +.Fn accept +can be thought of +as merely dequeueing the next connection +request and not implying confirmation. +Confirmation can be implied by a normal read or write on the new +file descriptor, and rejection can be implied by closing the +new socket. +.Pp +One can obtain user connection request data without confirming +the connection by issuing a +.Xr recvmsg 2 +call with an +.Fa msg_iovlen +of 0 and a non-zero +.Fa msg_controllen , +or by issuing a +.Xr getsockopt 2 +request. +Similarly, one can provide user connection rejection information +by issuing a +.Xr sendmsg 2 +call with providing only the control information, +or by calling +.Xr setsockopt 2 . +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn accept +is implemented as the +.Va accept +syscall. +.Pp +In the threaded library, the +.Va accept +syscall is assembled to +.Fn _thread_sys_accept +and +.Fn accept +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_accept . +If the call to +.Fn _thread_sys_accept +would block, a context switch is performed. Before returning, +.Fn accept +unlocks +.Va s . +.Pp +.Sh RETURN VALUES +The call returns \-1 on error. If it succeeds, it returns a non-negative +integer that is a descriptor for the accepted socket. +.Sh ERRORS +The +.Fn accept +will fail if: +.Bl -tag -width EWOULDBLOCK +.It Bq Er EBADF +The descriptor is invalid. +.It Bq Er EINTR +The +.Fn accept +operation was interrupted. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENOTSOCK +The descriptor references a file, not a socket. +.It Bq Er EINVAL +.Xr listen 2 +has not been called on the socket descriptor. +.It Bq Er EFAULT +The +.Fa addr +parameter is not in a writable part of the +user address space. +.It Bq Er EWOULDBLOCK +The socket is marked non-blocking and no connections +are present to be accepted. +.El +.Sh SEE ALSO +.Xr bind 2 , +.Xr connect 2 , +.Xr getpeername 2 , +.Xr listen 2 , +.Xr select 2 , +.Xr socket 2 +.Sh HISTORY +The +.Fn accept +function appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/access.2 b/lib/libc/sys/access.2 new file mode 100644 index 0000000..9b1c036 --- /dev/null +++ b/lib/libc/sys/access.2 @@ -0,0 +1,135 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)access.2 8.2 (Berkeley) 4/1/94 +.\" $FreeBSD$ +.\" +.Dd April 1, 1994 +.Dt ACCESS 2 +.Os BSD 4 +.Sh NAME +.Nm access +.Nd check access permissions of a file or pathname +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn access "const char *path" "int mode" +.Sh DESCRIPTION +The +.Fn access +function checks the accessibility of the +file named by +.Fa path +for the access permissions indicated by +.Fa mode . +The value of +.Fa mode +is the bitwise inclusive OR of the access permissions to be +checked +.Pf ( Dv R_OK +for read permission, +.Dv W_OK +for write permission and +.Dv X_OK +for execute/search permission) or the existence test, +.Dv F_OK . +All components of the pathname +.Fa path +are checked for access permissions (including +.Dv F_OK ) . +.Pp +The real user ID is used in place of the effective user ID +and the real group access list +(including the real group ID) are +used in place of the effective ID for verifying permission. +.Pp +Even if a process has appropriate privileges and indicates success for +.Dv X_OK , +the file may not actually have execute permission bits set. +Likewise for +.Dv R_OK +and +.Dv W_OK . +.Sh RETURN VALUES +If +.Fa path +cannot be found or if any of the desired access modes would +not be granted, then a -1 value is returned; otherwise +a 0 value is returned. +.Sh ERRORS +Access to the file is denied if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EROFS +Write access is requested for a file on a read-only file system. +.It Bq Er ETXTBSY +Write access is requested for a pure procedure (shared text) +file presently being executed. +.It Bq Er EACCES +Permission bits of the file mode do not permit the requested +access, or search permission is denied on a component of the +path prefix. The owner of a file has permission checked with +respect to the ``owner'' read, write, and execute mode bits, +members of the file's group other than the owner have permission +checked with respect to the ``group'' mode bits, and all +others have permissions checked with respect to the ``other'' +mode bits. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr stat 2 +.Sh STANDARDS +The +.Fn access +function call is expected to conform to +.St -p1003.1-90 . +.Sh CAVEAT +.Fn Access +is a potential security hole and +should never be used. +.Sh HISTORY +An +.Fn access +function call appeared in +.At v7 . diff --git a/lib/libc/sys/acct.2 b/lib/libc/sys/acct.2 new file mode 100644 index 0000000..e0d93ae --- /dev/null +++ b/lib/libc/sys/acct.2 @@ -0,0 +1,115 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)acct.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt ACCT 2 +.Os BSD 4 +.Sh NAME +.Nm acct +.Nd enable or disable process accounting +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn acct "const char *file" +.Sh DESCRIPTION +The +.Fn acct +call enables or disables the collection of system accounting +records. +If the argument +.Fa file +is a nil pointer, accounting is disabled. +If +.Fa file +is an +.Em existing +pathname (null-terminated), record collection is enabled and for +every process initiated which terminates under normal +conditions an accounting record is appended to +.Fa file . +Abnormal conditions of termination are reboots +or other fatal system problems. +Records for processes which never terminate can not be +produced by +.Fn acct . +.Pp +For more information on the record structure used by +.Fn acct , +see +.Pa /usr/include/sys/acct.h +and +.Xr acct 5 . +.Pp +This call is permitted only to the super-user. +.Sh NOTES +Accounting is automatically disabled when the file system the +accounting file resides on runs out of space; it is enabled when +space once again becomes available. +.Sh RETURN VALUES +On error -1 is returned. +The file must exist and the call may be exercised only by the super-user. +.Sh ERRORS +.Fn Acct +will fail if one of the following is true: +.Bl -tag -width Er +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix, +or the path name is not a regular file. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EFAULT +.Fa File +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr acct 5 , +.Xr sa 8 +.Sh HISTORY +An +.Fn acct +function call appeared in +.At v7 . diff --git a/lib/libc/sys/adjtime.2 b/lib/libc/sys/adjtime.2 new file mode 100644 index 0000000..03f1b58 --- /dev/null +++ b/lib/libc/sys/adjtime.2 @@ -0,0 +1,112 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)adjtime.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt ADJTIME 2 +.Os BSD 4.3 +.Sh NAME +.Nm adjtime +.Nd "correct the time to allow synchronization of the system clock" +.Sh SYNOPSIS +.Fd #include <sys/time.h> +.Ft int +.Fn adjtime "const struct timeval *delta" "struct timeval *olddelta" +.Sh DESCRIPTION +.Fn Adjtime +makes small adjustments to the system time, as returned by +.Xr gettimeofday 2 , +advancing or retarding it +by the time specified by the timeval +.Fa delta . +If +.Fa delta +is negative, the clock is +slowed down by incrementing it more slowly than normal until +the correction is complete. +If +.Fa delta +is positive, a larger increment than normal +is used. +The skew used to perform the correction is generally a fraction of one percent. +Thus, the time is always +a monotonically increasing function. +A time correction from an earlier call to +.Fn adjtime +may not be finished when +.Fn adjtime +is called again. +If +.Fa olddelta +is non-nil, +the structure pointed to will contain, upon return, the +number of microseconds still to be corrected +from the earlier call. +.Pp +This call may be used by time servers that synchronize the clocks +of computers in a local area network. +Such time servers would slow down the clocks of some machines +and speed up the clocks of others to bring them to the average network time. +.Pp +The call +.Fn adjtime +is restricted to the super-user. +.Sh RETURN VALUES +A return value of 0 indicates that the call succeeded. +A return value of -1 indicates that an error occurred, and in this +case an error code is stored in the global variable +.Va errno . +.Sh ERRORS +.Fn Adjtime +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +An argument points outside the process's allocated address space. +.It Bq Er EPERM +The process's effective user ID is not that of the super-user. +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr gettimeofday 2 , +.Xr timed 8 , +.Xr timedc 8 +.Rs +.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD" +.%A R. Gusella +.%A S. Zatti +.Re +.Sh HISTORY +The +.Fn adjtime +function call appeared in +.Bx 4.3 . diff --git a/lib/libc/sys/aio_cancel.2 b/lib/libc/sys/aio_cancel.2 new file mode 100644 index 0000000..275c3eb --- /dev/null +++ b/lib/libc/sys/aio_cancel.2 @@ -0,0 +1,78 @@ +.\" Copyright (c) 1999 Softweyr LLC. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Softweyr LLC AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL Softweyr LLC OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd June 2, 1999 +.Dt AIO_CANCEL 2 +.Os +.Sh NAME +.Nm aio_cancel +.Nd cancel an outstanding asynchronous I/O operation (REALTIME) +.Sh SYNOPSIS +.Fd #include <aio.h> +.Ft int +.Fn aio_cancel "int something" "struct aiocb * iocb" +.Sh DESCRIPTION +The +.Fn aio_cancel +function is supposed to cancel the specified outstanding asynchronous +I/O request. +.Fn aio_cancel +is not implemented at this time, and always fails returning +.Dv ENOSYS . +.Sh RETURN VALUES +When +.Fn aio_cancel +inevitably fails, it returns +.Dv ENOSYS +to signify it is not supported. +.Sh SEE ALSO +.Xr aio_error 2 , +.Xr aio_read 2 , +.Xr aio_return 2 , +.Xr aio_suspend 2 , +.Xr aio_write 2 . +.Sh ERRORS +The +.Fn aio_cancel +function currently always fails, due to: +.Bl -tag -width Er +.It Bq Er ENOSYS +this operation is not implemented at this time. +.El +.Sh STANDARDS +.Nm +fails to conform to the +.St -p1003.2 +standard. +.Sh HISTORY +The +.Nm +function first appeared in +.Fx 3.0 . +.Sh AUTHORS +This +manual page was written by +.An Wes Peters Aq wes@softweyr.com . diff --git a/lib/libc/sys/aio_error.2 b/lib/libc/sys/aio_error.2 new file mode 100644 index 0000000..ae959ab --- /dev/null +++ b/lib/libc/sys/aio_error.2 @@ -0,0 +1,93 @@ +.\" Copyright (c) 1999 Softweyr LLC. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Softweyr LLC AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL Softweyr LLC OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd June 2, 1999 +.Dt AIO_ERROR 2 +.Os +.Sh NAME +.Nm aio_error +.Nd retrieve error status of asynchronous I/O operation (REALTIME) +.Sh SYNOPSIS +.Fd #include <aio.h> +.Ft int +.Fn aio_error "struct aiocb *iocb" +.Sh DESCRIPTION +The +.Fn aio_error +function returns the error status of the asynchronous I/O request +associated with the structure pointed to by +.Ar iocb . +.Sh RETURN VALUES +If the asynchronous I/O request has completed successfully, +.Fn aio_error +returns 0. If the request has not yet completed, +.Dv EINPROGRESS +is returned. If the request has completed unsuccessfully the error +status is returned as described in +.Xr read 2 , +.Xr write 2 , +or +.Xr fsync 2 +is returned. +On failure, +.Fn aio_error +returns +.Dv -1 +and sets +.Dv errno +to indicate the error condition. +.Sh ERRORS +The +.Fn aio_error +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Ar iocb +does not reference an outstanding asynchronous I/O request. +.El +.Sh SEE ALSO +.Xr aio_cancel 2 , +.Xr aio_read 2 , +.Xr aio_return 2 , +.Xr aio_suspend 2 , +.Xr aio_write 2 , +.Xr fsync 2 , +.Xr read 2 , +.Xr write 2 . +.Sh STANDARDS +.Fn aio_error +is expected to conform to the +.St -p1003.2 +standard. +.Sh HISTORY +The +.Nm +function first appeared in +.Fx 3.0 . +.Sh AUTHORS +This +manual page was written by +.An Wes Peters Aq wes@softweyr.com . diff --git a/lib/libc/sys/aio_read.2 b/lib/libc/sys/aio_read.2 new file mode 100644 index 0000000..438b647 --- /dev/null +++ b/lib/libc/sys/aio_read.2 @@ -0,0 +1,200 @@ +.\" Copyright (c) 1998 Terry Lambert +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd November 17, 1998 +.Dt AIO_READ 2 +.Os +.Sh NAME +.Nm aio_read +.Nd asynchronous read from a file (REALTIME) +.Sh SYNOPSIS +.Fd #include <time.h> +.Fd #include <aio.h> +.Ft int +.Fn aio_read "struct aiocb *iocb" +.Sh DESCRIPTION +The +.Fn aio_read +function allows the calling process to read +.Ar iocb->aio_nbytes +from the descriptor +.Ar iocb->aio_fildes +beginning at the offset +.Ar iocb->aio_offset +into the buffer pointed to by +.Ar iocb->aio_buf . +The call returns immediately after the read request has +been enqueued to the descriptor; the read may or may not have +completed at the time the call returns. +.Pp +If _POSIX_PRIORITIZED_IO is defined, and the descriptor supports it, +then the enqueued operation is submitted at a priority equal to that +of the calling process minus +.Ar iocb->aio_reqprio . +.Pp +The +.Ar iocb->aio_lio_opcode +is ignored by the +.Fn aio_read +call. +.Pp +The +.Ar iocb +pointer may be subsequently used as an argument to +.Fn aio_return +and +.Fn aio_error +in order to determine return or error status for the enqueued operation +while it is in progress. +.Pp +If the request could not be enqueued (generally due to invalid arguments), +then the call returns without having enqueued the request. +.Pp +If the request is successfully enqueued, the value of +.Ar iocb->aio_offset +can be modified during the request as context, so this value must +not be referenced after the request is enqueued. +.Sh RESTRICTIONS +The Asynchronous I/O Control Block structure pointed to by +.Ar iocb +and the buffer that the +.Ar iocb->aio_buf +member of that structure references must remain valid until the +operation has completed. For this reason, use of auto (stack) variables +for these objects is discouraged. +.Pp +The asynchronous I/O control buffer +.Ar iocb +should be zeroed before the +.Fn aio_read +call to avoid passing bogus context information to the kernel. +.Pp +Modifications of the Asynchronous I/O Control Block structure or the +buffer contents after the request has been enqueued, but before the +request has completed, are not allowed. +.Pp +If the file offset in +.Ar iocb->aio_offset +is past the offset maximum for +.Ar iocb->aio_fildes , +no I/O will occur. +.Sh RETURN VALUES +.Rv -std aio_read +.Sh DIAGNOSTICS +None. +.Sh ERRORS +The +.Fn aio_read +function will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The request was not queued because of system resource limitations. +.It Bq Er ENOSYS +The +.Fn aio_read +call is not supported. +.El +.Pp +The following conditions may be synchronously detected when the +.Fn aio_read +call is made, or asynchronously, at any time thereafter. If they +are detected at call time, +.Fn aio_read +returns -1 and sets +.Ar errno +appropriately; otherwise the +.Fn aio_return +function must be called, and will return -1, and +.Fn aio_error +must be called to determine the actual calue that would have been +returned in +.Ar errno . +.Pp +.Bl -tag -width Er +.It Bq Er EBADF +.Ar iocb->aio_fildes +is invalid. +.It Bq Er EINVAL +The offset +.Ar iocb->aio_offset +is not valid, the priority specified by +.Ar iocb->aio_reqprio +is not a valid priority, or the number of bytes specified by +.Ar iocb->aio_nbytes +is not valid. +.It Bq Er EOVERFLOW +The file is a regular file, +.Ar iocb->aio_nbytes +is greater than zero, the starting offset in +.Ar iocb->aio_offset +is before the end of the file, but is at or beyond the +.Ar iocb->aio_fildes +offset maximum. +.El +.Pp +If the request is successfully enqueued, but subsequently cancelled +or an error occurs, the value returned by the +.Fn aio_return +function is per the +.Xr read 2 +call, and the value returned by the +.Fn aio_error +function is either one of the error returns from the +.Xr read 2 +call, or one of: +.Bl -tag -width Er +.It Bq Er EBADF +.Ar iocb->aio_fildes +is invalid for reading. +.It Bq Er ECANCELED +The request was explicitly cancelled via a call to +.Fn aio_cancel . +.It Bq Er EINVAL +The offset +.Ar iocb->aio_offset +would be invalid. +.El +.Sh STANDARDS +The +.Fn aio_read +call is expected to conform to the +.St -p1003.2 +standard. +.Sh HISTORY +The +.Nm +function first appeared in +.Fx 3.0 . +.Sh AUTHORS +This +manual page was written by +.An Terry Lambert Aq terry@whistle.com . +.Sh BUGS +The value of +.Ar iocb->aio_offset +is ignored. Invalid information in +.Ar iocb->_aiocb_private +may confuse the kernel. diff --git a/lib/libc/sys/aio_return.2 b/lib/libc/sys/aio_return.2 new file mode 100644 index 0000000..7f70fc3 --- /dev/null +++ b/lib/libc/sys/aio_return.2 @@ -0,0 +1,95 @@ +.\" Copyright (c) 1999 Softweyr LLC. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Softweyr LLC AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL Softweyr LLC OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd June 2, 1999 +.Dt AIO_RETURN 2 +.Os +.Sh NAME +.Nm aio_return +.Nd retrieve return status of asynchronous I/O operation (REALTIME) +.Sh SYNOPSIS +.Fd #include <aio.h> +.Ft int +.Fn aio_return "struct aiocb *iocb" +.Sh DESCRIPTION +The +.Fn aio_return +function returns the final status of the asynchronous I/O request +associated with the structure pointed to by +.Ar iocb . +.Pp +.Fn aio_return +should only be called once, to obtain the final status of an asynchronous +I/O operation once +.Xr aio_error 2 +returns something other than +.Dv EINPROGRESS . +.Sh RETURN VALUES +If the asynchronous I/O request has completed, the status is returned +as described in +.Xr read 2 , +.Xr write 2 , +or +.Xr fsync 2 . +On failure, +.Fn aio_return +returns +.Dv -1 +and sets +.Dv errno +to indicate the error condition. +.Sh SEE ALSO +.Xr aio_cancel 2 , +.Xr aio_error 2 , +.Xr aio_read 2 , +.Xr aio_suspend 2 , +.Xr aio_write 2 , +.Xr fsync 2 , +.Xr read 2 , +.Xr write 2 . +.Sh ERRORS +The +.Fn aio_return +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Ar iocb +does not reference an outstanding asynchronous I/O request. +.El +.Sh STANDARDS +.Fn aio_return +is expected to conform to the +.St -p1003.2 +standard. +.Sh HISTORY +The +.Nm +function first appeared in +.Fx 3.0 . +.Sh AUTHORS +This +manual page was written by +.An Wes Peters Aq wes@softweyr.com . diff --git a/lib/libc/sys/aio_suspend.2 b/lib/libc/sys/aio_suspend.2 new file mode 100644 index 0000000..908492b --- /dev/null +++ b/lib/libc/sys/aio_suspend.2 @@ -0,0 +1,105 @@ +.\" Copyright (c) 1999 Softweyr LLC. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Softweyr LLC AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL Softweyr LLC OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd June 2, 1999 +.Dt AIO_SUSPEND 2 +.Os +.Sh NAME +.Nm aio_suspend +.Nd suspend until asynchronous I/O operations or timeout complete (REALTIME) +.Sh SYNOPSIS +.Fd #include <aio.h> +.Ft int +.Fn aio_suspend "const struct aiocb * const iocbs[]" "int niocb" "const struct timespec * timeout" +.Sh DESCRIPTION +The +.Fn aio_suspend +function suspends the calling process until at least one of the +specified asynchronous I/O requests have completed, a signal is +delivered, or the +.Ar timeout +has passed. +.Pp +.Ar iocbs +is an array of +.Ar niocb +pointers to asynchronous I/O requests. Array members containing +NULL will be silently ignored. +.Pp +If +.Ar timeout +is a non-nil pointer, it specifies a maximum interval to suspend. +If +.Ar timeout +is a nil pointer, the suspend blocks indefinitely. To effect a +poll, the +.Ar timeout +should point to a zero-value timespec structure. +.Sh RETURN VALUES +If one or more of the specified asynchronous I/O requests have +completed, +.Fn aio_suspend +returns 0. Otherwise it returns -1 and sets +.Va errno +to indicate the error, as enumerated below. +.Sh SEE ALSO +.Xr aio_cancel 2 , +.Xr aio_error 2 , +.Xr aio_read 2 , +.Xr aio_suspend 2 , +.Xr aio_write 2 . +.Sh ERRORS +The +.Fn aio_suspend +function will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +the +.Ar timeout +expired before any I/O requests completed. +.It Bq Er EINVAL +.Ar iocbs +contains more than +.Dv AIO_LISTIO_MAX +asynchronous I/O requests, or at least one of the requests is not +valid. +.It Bq Er EINTR +the suspend was interrupted by a signal. +.El +.Sh STANDARDS +.Fn aio_suspend +is expected to conform to the +.St -p1003.2 +standard. +.Sh HISTORY +The +.Nm +function first appeared in +.Fx 3.0 . +.Sh AUTHORS +This +manual page was written by +.An Wes Peters Aq wes@softweyr.com . diff --git a/lib/libc/sys/aio_write.2 b/lib/libc/sys/aio_write.2 new file mode 100644 index 0000000..8e55423 --- /dev/null +++ b/lib/libc/sys/aio_write.2 @@ -0,0 +1,192 @@ +.\" Copyright (c) 1999 Softweyr LLC. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Softweyr LLC AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL Softweyr LLC OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd June 2, 1999 +.Dt AIO_WRITE 2 +.Os +.Sh NAME +.Nm aio_write +.Nd asynchronous write to a file (REALTIME) +.Sh SYNOPSIS +.Fd #include <aio.h> +.Ft int +.Fn aio_write "struct aiocb *iocb" +.Sh DESCRIPTION +The +.Fn aio_write +function allows the calling process to write +.Ar iocb->aio_nbytes +from the buffer pointed to by +.Ar iocb->aio_buf +to the descriptor +.Ar iocb->aio_fildes . +The call returns immediately after the write request has been enqueued +to the descriptor; the write may or may not have completed at the time +the call returns. If the request could not be enqueued, generally due +to invalid arguments, the call returns without having enqueued the +request. +.Pp +If +.Dv O_APPEND +is set for +.Ar iocb->aio_fildes , +.Fn aio_write +operations append to the file in the same order as the calls were +made. If +.Dv O_APPEND +is not set for the file descriptor, the write operation will occur at +the absolute position from the beginning of the file plus +.Ar iocb->aio_offset . +.Pp +If +.Dv _POSIX_PRIORITIZED_IO +is defined, and the descriptor supports it, then the enqueued +operation is submitted at a priority equal to that of the calling +process minus +.Ar iocb->aio_reqprio . +.Pp +The +.Ar iocb +pointer may be subsequently used as an argument to +.Fn aio_return +and +.Fn aio_error +in order to determine return or error status for the enqueued operation +while it is in progress. +.Pp +If the request is successfully enqueued, the value of +.Ar iocb->aio_offset +can be modified during the request as context, so this value must not +be referenced after the request is enqueued. +.Sh RESTRICTIONS +The Asynchronous I/O Control Block structure pointed to by +.Ar iocb +and the buffer that the +.Ar iocb->aio_buf +member of that structure references must remain valid until the +operation has completed. For this reason, use of auto (stack) variables +for these objects is discouraged. +.Pp +The asynchronous I/O control buffer +.Ar iocb +should be zeroed before the +.Fn aio_read +call to avoid passing bogus context information to the kernel. +.Pp +Modifications of the Asynchronous I/O Control Block structure or the +buffer contents after the request has been enqueued, but before the +request has completed, are not allowed. +.Pp +If the file offset in +.Ar iocb->aio_offset +is past the offset maximum for +.Ar iocb->aio_fildes , +no I/O will occur. +.Sh RETURN VALUES +.Rv -std aio_write +.Sh ERRORS +The +.Fn aio_write +function will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The request was not queued because of system resource limitations. +.It Bq Er ENOSYS +The +.Fn aio_write +call is not supported. +.El +.Pp +The following conditions may be synchronously detected when the +.Fn aio_write +call is made, or asynchronously, at any time thereafter. If they +are detected at call time, +.Fn aio_write +returns -1 and sets +.Ar errno +appropriately; otherwise the +.Fn aio_return +function must be called, and will return -1, and +.Fn aio_error +must be called to determine the actual value that would have been +returned in +.Ar errno . +.Pp +.Bl -tag -width Er +.It Bq Er EBADF +.Ar iocb->aio_fildes +is invalid, or is not opened for writing. +.It Bq Er EINVAL +The offset +.Ar iocb->aio_offset +is not valid, the priority specified by +.Ar iocb->aio_reqprio +is not a valid priority, or the number of bytes specified by +.Ar iocb->aio_nbytes +is not valid. +.El +.Pp +If the request is successfully enqueued, but subsequently canceled +or an error occurs, the value returned by the +.Fn aio_return +function is per the +.Xr write 2 +call, and the value returned by the +.Fn aio_error +function is either one of the error returns from the +.Xr write 2 +call, or one of: +.Bl -tag -width Er +.It Bq Er EBADF +.Ar iocb->aio_fildes +is invalid for writing. +.It Bq Er ECANCELED +The request was explicitly canceled via a call to +.Fn aio_cancel . +.It Bq Er EINVAL +The offset +.Ar iocb->aio_offset +would be invalid. +.El +.Sh STANDARDS +.Fn aio_write +is expected to conform to the +.St -p1003.2 +standard. +.Sh HISTORY +The +.Nm +Function first appeared in +.Fx 3.0 . +.Sh AUTHORS +This manual page was written by +.An Wes Peters Aq wes@softweyr.com . +.Sh BUGS +Asynchronous I/O operations cannot be canceled in this implementation. +Invalid information in +.Ar iocb->_aiocb_private +may confuse the kernel. + diff --git a/lib/libc/sys/bind.2 b/lib/libc/sys/bind.2 new file mode 100644 index 0000000..316ed18 --- /dev/null +++ b/lib/libc/sys/bind.2 @@ -0,0 +1,147 @@ +.\" Copyright (c) 1983, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)bind.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt BIND 2 +.Os BSD 4.2 +.Sh NAME +.Nm bind +.Nd assign a local protocol address to a socket. +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn bind "int s" "const struct sockaddr *addr" "socklen_t addrlen" +.Sh DESCRIPTION +.Fn Bind +assigns the local protocol address to a socket. +When a socket is created +with +.Xr socket 2 +it exists in an address family space but has no protocol address assigned. +.Fn Bind +requests that +.Fa addr +be assigned to the socket. +.Sh NOTES +Binding an address in the UNIX domain creates a socket in the file +system that must be deleted by the caller when it is no longer +needed (using +.Xr unlink 2 ) . +.Pp +The rules used in address binding vary between communication domains. +Consult the manual entries in section 4 for detailed information. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn bind +is implemented as the +.Va bind +syscall. +.Pp +In the threaded library, the +.Va bind +syscall is assembled to +.Fn _thread_sys_bind +and +.Fn bind +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_bind . +Before returning, +.Fn bind +unlocks +.Va s . +.Sh RETURN VALUES +If the bind is successful, a 0 value is returned. +A return value of -1 indicates an error, which is +further specified in the global +.Va errno . +.Sh ERRORS +The +.Fn bind +call will fail if: +.Bl -tag -width EADDRNOTAVA +.It Bq Er EAGAIN +Kernel resources to complete the request are +temporarily unavilable. +.It Bq Er EBADF +.Fa S +is not a valid descriptor. +.It Bq Er ENOTSOCK +.Fa S +is not a socket. +.It Bq Er EADDRNOTAVAIL +The specified address is not available from the local machine. +.It Bq Er EADDRINUSE +The specified address is already in use. +.It Bq Er EACCES +The requested address is protected, and the current user +has inadequate permission to access it. +.It Bq Er EFAULT +The +.Fa addr +parameter is not in a valid part of the user +address space. +.El +.Pp +The following errors are specific to binding addresses in the UNIX domain. +.Bl -tag -width EADDRNOTAVA +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +A prefix component of the path name does not exist. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EIO +An I/O error occurred while making the directory entry or allocating the inode. +.It Bq Er EROFS +The name would reside on a read-only file system. +.It Bq Er EISDIR +An empty pathname was specified. +.El +.Sh SEE ALSO +.Xr connect 2 , +.Xr getsockname 2 , +.Xr listen 2 , +.Xr socket 2 +.Sh HISTORY +The +.Fn bind +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/brk.2 b/lib/libc/sys/brk.2 new file mode 100644 index 0000000..4db6072 --- /dev/null +++ b/lib/libc/sys/brk.2 @@ -0,0 +1,150 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)brk.2 8.4 (Berkeley) 5/1/95 +.\" $FreeBSD$ +.\" +.Dd May 1, 1995 +.Dt BRK 2 +.Os BSD 4 +.Sh NAME +.Nm brk , +.Nm sbrk +.Nd change data segment size +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft char * +.Fn brk "const char *addr" +.Ft char * +.Fn sbrk "int incr" +.Sh DESCRIPTION +.Bf -symbolic +The brk and sbrk functions are historical curiosities +left over from earlier days before the advent of virtual memory management. +.Ef +The +.Fn brk +function +sets the break or lowest address +of a process's data segment (uninitialized data) to +.Fa addr +(immediately above bss). +Data addressing is restricted between +.Fa addr +and the lowest stack pointer to the stack segment. +Memory is allocated by +.Fa brk +in page size pieces; +if +.Fa addr +is not evenly divisible by the system page size, it is +increased to the next page boundary. +.Pp +.\" The +.\" .Nm sbrk +.\" function +.\" allocates chunks of +.\" .Fa incr +.\" bytes +.\" to the process's data space +.\" and returns an address pointer. +.\" The +.\" .Xr malloc 3 +.\" function utilizes +.\" .Nm sbrk . +.\" .Pp +The current value of the program break is reliably returned by +.Dq Li sbrk(0) +(see also +.Xr end 3 ) . +The +.Xr getrlimit 2 +system call may be used to determine +the maximum permissible size of the +.Em data +segment; +it will not be possible to set the break +beyond the +.Em rlim_max +value returned from a call to +.Xr getrlimit 2 , +e.g. +.Dq etext + rlp\(->rlim_max. +(see +.Xr end 3 +for the definition of +.Em etext ) . +.Sh RETURN VALUES +.Fn Brk +returns 0 if successful; +otherwise -1 with +.Va errno +set to indicate why the allocation failed. +The +.Fn sbrk +function returns a pointer to the base of the new storage if successful; +otherwise -1 with +.Va errno +set to indicate why the allocation failed. +.Sh ERRORS +.Fn Brk +or +.Fn sbrk +will fail and no additional memory will be allocated if +one of the following are true: +.Bl -tag -width [ENOMEM] +.It Bq Er ENOMEM +The limit, as set by +.Xr setrlimit 2 , +was exceeded. +.It Bq Er ENOMEM +The maximum possible size of a data segment (compiled into the +system) was exceeded. +.It Bq Er ENOMEM +Insufficient space existed in the swap area +to support the expansion. +.El +.Sh SEE ALSO +.Xr execve 2 , +.Xr getrlimit 2 , +.Xr end 3 , +.Xr malloc 3 +.Sh BUGS +Setting the break may fail due to a temporary lack of +swap space. It is not possible to distinguish this +from a failure caused by exceeding the maximum size of +the data segment without consulting +.Xr getrlimit 2 . +.Sh HISTORY +A +.Fn brk +function call appeared in +.At v7 . diff --git a/lib/libc/sys/chdir.2 b/lib/libc/sys/chdir.2 new file mode 100644 index 0000000..51622f8 --- /dev/null +++ b/lib/libc/sys/chdir.2 @@ -0,0 +1,133 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)chdir.2 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD$ +.\" +.Dd December 11, 1993 +.Dt CHDIR 2 +.Os BSD 4 +.Sh NAME +.Nm chdir , +.Nm fchdir +.Nd change current working directory +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn chdir "const char *path" +.Ft int +.Fn fchdir "int fd" +.Sh DESCRIPTION +The +.Fa path +argument points to the pathname of a directory. +The +.Fn chdir +function +causes the named directory +to become the current working directory, that is, +the starting point for path searches of pathnames not beginning with +a slash, +.Ql / . +.Pp +The +.Fn fchdir +function +causes the directory referenced by +.Fa fd +to become the current working directory, +the starting point for path searches of pathnames not beginning with +a slash, +.Ql / . +.Pp +In order for a directory to become the current directory, +a process must have execute (search) access to the directory. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate +the error. +.Sh ERRORS +.Fn Chdir +will fail and the current working directory will be unchanged if +one or more of the following are true: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named directory does not exist. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EACCES +Search permission is denied for any component of +the path name. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Pp +.Fn Fchdir +will fail and the current working directory will be unchanged if +one or more of the following are true: +.Bl -tag -width Er +.It Bq Er EACCES +Search permission is denied for the directory referenced by the +file descriptor. +.It Bq Er ENOTDIR +The file descriptor does not reference a directory. +.It Bq Er EBADF +The argument +.Fa fd +is not a valid file descriptor. +.El +.Sh SEE ALSO +.Xr chroot 2 +.Sh STANDARDS +The +.Fn chdir +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn chdir +function call appeared in +.At v7 . +The +.Fn fchdir +function call +appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/chflags.2 b/lib/libc/sys/chflags.2 new file mode 100644 index 0000000..9325686 --- /dev/null +++ b/lib/libc/sys/chflags.2 @@ -0,0 +1,169 @@ +.\" Copyright (c) 1989, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)chflags.2 8.3 (Berkeley) 5/2/95 +.\" $FreeBSD$ +.\" +.Dd May 2, 1995 +.Dt CHFLAGS 2 +.Os +.Sh NAME +.Nm chflags , +.Nm fchflags +.Nd set file flags +.Sh SYNOPSIS +.Fd #include <sys/stat.h> +.Fd #include <unistd.h> +.Ft int +.Fn chflags "const char *path" "u_long flags" +.Ft int +.Fn fchflags "int fd" "u_long flags" +.Sh DESCRIPTION +The file whose name +is given by +.Fa path +or referenced by the descriptor +.Fa fd +has its flags changed to +.Fa flags . +.Pp +The flags specified are formed by +.Em or Ns 'ing +the following values +.Pp +.Bl -tag -width "SF_IMMUTABLE" -compact -offset indent +.It UF_NODUMP +Do not dump the file. +.It UF_IMMUTABLE +The file may not be changed. +.It UF_APPEND +The file may only be appended to. +.It UF_NOUNLINK +The file may not be renamed or deleted. +.It UF_OPAQUE +The directory is opaque when viewed through a union stack. +.\".It ARCHIVED +.\"File is archived. +.It SF_IMMUTABLE +The file may not be changed. +.It SF_APPEND +The file may only be appended to. +.It SF_NOUNLINK +The file may not be renamed or deleted. +.El +.Pp +The +.Dq UF_IMMUTABLE , +.Dq UF_APPEND +and +.Dq UF_NOUNLINK +flags may be set or unset by either the owner of a file or the super-user. +.Pp +The +.Dq SF_IMMUTABLE , +.Dq SF_APPEND +and +.Dq SF_NOUNLINK +flags may only be set or unset by the super-user. +Attempts by the non-super-user to set the super-user only flags +are silently ignored. +These flags may be set at any time, but normally may only be unset when +the system is in single-user mode. +(See +.Xr init 8 +for details.) +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Chflags +will fail if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The effective user ID does not match the owner of the file and +the effective user ID is not the super-user. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.It Bq Er EOPNOTSUPP +The underlying file system does not support file flags. +.El +.Pp +.Fn Fchflags +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The descriptor is not valid. +.It Bq Er EINVAL +.Fa Fd +refers to a socket, not to a file. +.It Bq Er EPERM +The effective user ID does not match the owner of the file and +the effective user ID is not the super-user. +.It Bq Er EROFS +The file resides on a read-only file system. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.It Bq Er EOPNOTSUPP +The underlying file system does not support file flags. +.El +.Sh SEE ALSO +.Xr chflags 1 , +.Xr init 8 , +.Xr mount_union 8 +.Sh HISTORY +The +.Nm chflags +and +.Nm fchflags +functions first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/chmod.2 b/lib/libc/sys/chmod.2 new file mode 100644 index 0000000..87e171f --- /dev/null +++ b/lib/libc/sys/chmod.2 @@ -0,0 +1,223 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)chmod.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt CHMOD 2 +.Os BSD 4 +.Sh NAME +.Nm chmod , +.Nm fchmod , +.Nm lchmod +.Nd change mode of file +.Sh SYNOPSIS +.Fd #include <sys/stat.h> +.Ft int +.Fn chmod "const char *path" "mode_t mode" +.Ft int +.Fn fchmod "int fd" "mode_t mode" +.Ft int +.Fn lchmod "const char *path" "mode_t mode" +.Sh DESCRIPTION +The file permission bits of the file named specified by +.Fa path +or referenced by the file descriptor +.Fa fd +are changed to +.Fa mode . +The +.Fn chmod +function verifies that the process owner (user) either owns +the file specified by +.Fa path +(or +.Fa fd ) , +or +is the super-user. +The +.Fn chmod +function follows symbolic links to operate on the target of the link +rather than the link itself. +.Pp +The +.Fa lchmod +function is similar to +.Fn chmod +but does not follow symbolic links. +.Pp +A mode is created from +.Em or'd +permission bit masks +defined in +.Aq Pa sys/stat.h : +.Pp +.Bd -literal -offset indent -compact +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#define S_ISVTX 0001000 /* sticky bit */ +#ifndef _POSIX_SOURCE +#define S_ISTXT 0001000 +#endif +.Ed +.Pp +The +.Tn FreeBSD +VM system totally ignores the sticky bit +.Pf ( Dv ISVTX +) for executables. On UFS-based filesystems (FFS, MFS, LFS) the sticky +bit may only be set upon directories. +.Pp +If mode +.Dv ISVTX +(the `sticky bit') is set on a directory, +an unprivileged user may not delete or rename +files of other users in that directory. The sticky bit may be +set by any user on a directory which the user owns or has appropriate +permissions. +For more details of the properties of the sticky bit, see +.Xr sticky 8 . +.Pp +If mode ISUID (set UID) is set on a directory, +and the MNT_SUIDDIR option was used in the mount of the filesystem, +then the owner of any new files and sub-directories +created within this directory are set +to be the same as the owner of that directory. +If this function is enabled, new directories will inherit +the bit from their parents. Execute bits are removed from +the file, and it will not be given to root. This behavior does not change the +requirements for the user to be allowed to write the file, but only the eventual +owner after it has been created. Group inheritance is not effected. +.Pp +This feature is designed for use on fileservers serving PC users via +ftp, SAMBA, or netatalk. It provides security holes for shell users and as +such should not be used on shell machines, especially on home directories. +This option requires the SUIDDIR +option in the kernel to work. Only UFS filesystems support this option. +For more details of the suiddir mount option, see +.Xr mount 8 . +.Pp +Writing or changing the owner of a file +turns off the set-user-id and set-group-id bits +unless the user is the super-user. +This makes the system somewhat more secure +by protecting set-user-id (set-group-id) files +from remaining set-user-id (set-group-id) if they are modified, +at the expense of a degree of compatibility. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Chmod +will fail and the file mode will be unchanged if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The effective user ID does not match the owner of the file and +the effective user ID is not the super-user. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er EFTYPE +An attempt was made to set the sticky bit upon an executable. +.El +.Pp +.Fn Fchmod +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The descriptor is not valid. +.It Bq Er EINVAL +.Fa Fd +refers to a socket, not to a file. +.It Bq Er EROFS +The file resides on a read-only file system. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr chmod 1 , +.Xr chown 2 , +.Xr open 2 , +.Xr stat 2 , +.Xr sticky 8 +.Sh STANDARDS +The +.Fn chmod +function call is expected to conform to +.St -p1003.1-90 , +except for the return of EFTYPE and the use of S_ISTXT. +.Sh HISTORY +A +.Fn chmod +function call appeared in +.At v7 . +The +.Fn fchmod +function call +appeared in +.Bx 4.2 . +The +.Fn lchmod +function call appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/chown.2 b/lib/libc/sys/chown.2 new file mode 100644 index 0000000..6411045 --- /dev/null +++ b/lib/libc/sys/chown.2 @@ -0,0 +1,169 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)chown.2 8.4 (Berkeley) 4/19/94 +.\" $FreeBSD$ +.\" +.Dd April 19, 1994 +.Dt CHOWN 2 +.Os BSD 4 +.Sh NAME +.Nm chown , +.Nm fchown , +.Nm lchown +.Nd change owner and group of a file +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn chown "const char *path" "uid_t owner" "gid_t group" +.Ft int +.Fn fchown "int fd" "uid_t owner" "gid_t group" +.Ft int +.Fn lchown "const char *path" "uid_t owner" "gid_t group" +.Sh DESCRIPTION +The owner ID and group ID of the file +named by +.Fa path +or referenced by +.Fa fd +is changed as specified by the arguments +.Fa owner +and +.Fa group . +The owner of a file may change the +.Fa group +to a group of which +he or she is a member, +but the change +.Fa owner +capability is restricted to the super-user. +.Pp +.Fn Chown +clears the set-user-id and set-group-id bits +on the file +to prevent accidental or mischievous creation of +set-user-id and set-group-id programs if not executed +by the super-user. +.Fn chown +follows symbolic links to operate on the target of the link +rather than the link itself. +.Pp +.Fn Fchown +is particularly useful when used in conjunction +with the file locking primitives (see +.Xr flock 2 ) . +.Pp +.Fn Lchown +is similar to +.Fn chown +but does not follow symbolic links. +.Pp +One of the owner or group id's +may be left unchanged by specifying it as -1. +.Sh RETURN VALUES +Zero is returned if the operation was successful; +-1 is returned if an error occurs, with a more specific +error code being placed in the global variable +.Va errno . +.Sh ERRORS +.Fn Chown +and +.Fn lchown +will fail and the file will be unchanged if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The effective user ID is not the super-user. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Pp +.Fn Fchown +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa Fd +does not refer to a valid descriptor. +.It Bq Er EINVAL +.Fa Fd +refers to a socket, not a file. +.It Bq Er EPERM +The effective user ID is not the super-user. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr chgrp 1 , +.Xr chmod 2 , +.Xr flock 2 , +.Xr chown 8 +.Sh STANDARDS +The +.Fn chown +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn chown +function call appeared in +.At v7 . +The +.Fn fchown +function call +appeared in +.Bx 4.2 . +.Pp +The +.Fn chown +function was changed to follow symbolic links in +.Bx 4.4 . +The +.Fn lchown +function was added in +.Fx 3.0 +to compensate for the loss of functionality. diff --git a/lib/libc/sys/chroot.2 b/lib/libc/sys/chroot.2 new file mode 100644 index 0000000..7f1a866 --- /dev/null +++ b/lib/libc/sys/chroot.2 @@ -0,0 +1,125 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)chroot.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt CHROOT 2 +.Os BSD 4.2 +.Sh NAME +.Nm chroot +.Nd change root directory +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn chroot "const char *dirname" +.Sh DESCRIPTION +.Fa Dirname +is the address of the pathname of a directory, terminated by an ASCII NUL. +.Fn Chroot +causes +.Fa dirname +to become the root directory, +that is, the starting point for path searches of pathnames +beginning with +.Ql / . +.Pp +In order for a directory to become the root directory +a process must have execute (search) access for that directory. +.Pp +It should be noted that +.Fn chroot +has no effect on the process's current directory. +.Pp +This call is restricted to the super-user. +.Pp +Depending on the setting of the +.Ql kern.chroot_allow_open_directories +sysctl variable, open filedescriptors which reference directories +will make the +.Fn chroot +fail as follows: +.Pp +If +.Ql kern.chroot_allow_open_directories +is set to zero, +.Fn chroot +will always fail with EPERM if there are any directories open. +.Pp +If +.Ql kern.chroot_allow_open_directories +is set to one (the default), +.Fn chroot +will fail with EPERM if there are any directories open and the +process is already subject to a +.Fn chroot +call. +.Pp +Any other value for +.Ql kern.chroot_allow_open_directories +will bypass the check for open directories +.Pp +Upon successful completion, a value of 0 is returned. Otherwise, +a value of -1 is returned and +.Va errno +is set to indicate an error. +.Sh ERRORS +.Fn Chroot +will fail and the root directory will be unchanged if: +.Bl -tag -width [ENOTDIR] +.It Bq Er ENOTDIR +A component of the path name is not a directory. +.It Bq Er EPERM +The effective user ID is not the super-user, or one or more +filedescriptors are open directories. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named directory does not exist. +.It Bq Er EACCES +Search permission is denied for any component of the path name. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr chdir 2 +.Sh HISTORY +The +.Fn chroot +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2 new file mode 100644 index 0000000..4e0dd55 --- /dev/null +++ b/lib/libc/sys/clock_gettime.2 @@ -0,0 +1,124 @@ +.\" $OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey Exp $ +.\" $FreeBSD$ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 8, 1997 +.Dt CLOCK_GETTIME 2 +.Os BSD 4 +.Sh NAME +.Nm clock_gettime , +.Nm clock_settime , +.Nm clock_getres +.Nd get/set/calibrate date and time +.Sh SYNOPSIS +.Fd #include <sys/time.h> +.Ft int +.Fn clock_gettime "clockid_t clock_id" "struct timespec *tp" +.Ft int +.Fn clock_settime "clockid_t clock_id" "const struct timespec *tp" +.Ft int +.Fn clock_getres "clockid_t clock_id" "struct timespec *tp" +.Sh DESCRIPTION +The +.Fn clock_gettime +and +.Fn clock_settime +allow the calling process to retrieve or set the value used by a clock +which is specifed by +.Fa clock_id . +.Pp +.Fa clock_id +can be one of three values: CLOCK_REALTIME for time that increments as +a wall clock should, CLOCK_VIRTUAL for time that increments only when +the CPU is running in user mode on behalf of the calling process, or +CLOCK_PROF for time that increments when the CPU is running in user or +kernel mode. +.Pp +The structure pointed to by +.Fa tp +is defined in +.Ao Pa sys/time.h Ac +as: +.Pp +.Bd -literal +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +.Ed +.Pp +Only the super-user may set the time of day. +If the system securelevel is greater than 1 (see +.Xr init 8 ), +the time may only be advanced. +This limitation is imposed to prevent a malicious super-user +from setting arbitrary time stamps on files. +The system time can still be adjusted backwards using the +.Xr adjtime 2 +system call even when the system is secure. +.Pp +The resolution (granularity) of a clock is returned by the +.Fn clock_getres +call. This value is placed in a (non-NULL) +.Fa *tp . +.Sh RETURN +A 0 return value indicates that the call succeeded. +A -1 return value indicates an error occurred, and in this +case an error code is stored into the global variable +.Va errno . +.Sh ERRORS +The following error codes may be set in +.Va errno : +.Bl -tag -width [EFAULT] +.It Bq Er EINVAL +The +.Fa clock_id +was not a valid value. +.It Bq Er EFAULT +The +.Fa *tp +argument address referenced invalid memory. +.It Bq Er EPERM +A user other than the super-user attempted to set the time. +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr adjtime 2 , +.Xr ctime 3 , +.Xr timed 8 +.Sh STANDARDS +The +.Fn clock_gettime , +etc. +functions conform to +.St -p1003.1b-93 . diff --git a/lib/libc/sys/close.2 b/lib/libc/sys/close.2 new file mode 100644 index 0000000..4a478e4 --- /dev/null +++ b/lib/libc/sys/close.2 @@ -0,0 +1,157 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)close.2 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD$ +.\" +.Dd April 19, 1994 +.Dt CLOSE 2 +.Os BSD 4 +.Sh NAME +.Nm close +.Nd delete a descriptor +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn close "int d" +.Sh DESCRIPTION +The +.Fn close +call deletes a descriptor from the per-process object +reference table. +If this is the last reference to the underlying object, the +object will be deactivated. +For example, on the last close of a file +the current +.Em seek +pointer associated with the file is lost; +on the last close of a +.Xr socket 2 +associated naming information and queued data are discarded; +on the last close of a file holding an advisory lock +the lock is released (see further +.Xr flock 2 ) . +However, the semantics of System V and +.St -p1003.1-88 +dictate that all +.Xr fcntl 2 +advisory record locks associated with a file for a given process +are removed when +.Em any +file descriptor for that file is closed by that process. +.Pp +When a process exits, +all associated file descriptors are freed, but since there is +a limit on active descriptors per processes, the +.Fn close +function call +is useful when a large quantity of file descriptors are being handled. +.Pp +When a process forks (see +.Xr fork 2 ) , +all descriptors for the new child process reference the same +objects as they did in the parent before the fork. +If a new process is then to be run using +.Xr execve 2 , +the process would normally inherit these descriptors. Most +of the descriptors can be rearranged with +.Xr dup2 2 +or deleted with +.Fn close +before the +.Xr execve 2 +is attempted, but if some of these descriptors will still +be needed if the execve fails, it is necessary to arrange for them +to be closed if the execve succeeds. +For this reason, the call +.Dq Li fcntl(d, F_SETFD, 1) +is provided, +which arranges that a descriptor will be closed after a successful +execve; the call +.Dq Li fcntl(d, F_SETFD, 0) +restores the default, +which is to not close the descriptor. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn close +is implemented as the +.Va close +syscall. +.Pp +In the threaded library, the +.Va close +syscall is assembled to +.Fn _thread_sys_close +and +.Fn close +is implemented as a function which locks +.Va d +for read and write, then calls +.Fn _thread_sys_close . +Before returning, +.Fn close +unlocks +.Va d . +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and the global integer variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Close +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa D +is not an active descriptor. +.It Bq Er EINTR +An interrupt was received. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr execve 2 , +.Xr fcntl 2 , +.Xr flock 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr socket 2 , +.Xr socketpair 2 +.Sh STANDARDS +The +.Fn close +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn close +function call appeared in +.At v7 . diff --git a/lib/libc/sys/connect.2 b/lib/libc/sys/connect.2 new file mode 100644 index 0000000..aef52f1 --- /dev/null +++ b/lib/libc/sys/connect.2 @@ -0,0 +1,171 @@ +.\" Copyright (c) 1983, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)connect.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt CONNECT 2 +.Os BSD 4.2 +.Sh NAME +.Nm connect +.Nd initiate a connection on a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen" +.Sh DESCRIPTION +The parameter +.Fa s +is a socket. +If it is of type +.Dv SOCK_DGRAM , +this call specifies the peer with which the socket is to be associated; +this address is that to which datagrams are to be sent, +and the only address from which datagrams are to be received. +If the socket is of type +.Dv SOCK_STREAM , +this call attempts to make a connection to +another socket. +The other socket is specified by +.Fa name , +which is an address in the communications space of the socket. +Each communications space interprets the +.Fa name +parameter in its own way. +Generally, stream sockets may successfully +.Fn connect +only once; datagram sockets may use +.Fn connect +multiple times to change their association. +Datagram sockets may dissolve the association +by connecting to an invalid address, such as a null address. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn connect +is implemented as the +.Va connect +syscall. +.Pp +In the threaded library, the +.Va connect +syscall is assembled to +.Fn _thread_sys_connect +and +.Fn connect +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_connect . +If the call to +.Fn _thread_sys_connect +would block, a context switch is performed. Before returning, +.Fn connect +unlocks +.Va s . +.Sh RETURN VALUES +If the connection or binding succeeds, 0 is returned. +Otherwise a -1 is returned, and a more specific error +code is stored in +.Va errno . +.Sh ERRORS +The +.Fn connect +call fails if: +.Bl -tag -width EADDRNOTAVAILABB +.It Bq Er EBADF +.Fa s +is not a valid descriptor. +.It Bq Er ENOTSOCK +.Fa s +is a descriptor for a file, not a socket. +.It Bq Er EADDRNOTAVAIL +The specified address is not available on this machine. +.It Bq Er EAFNOSUPPORT +Addresses in the specified address family cannot be used with this socket. +.It Bq Er EISCONN +The socket is already connected. +.It Bq Er ETIMEDOUT +Connection establishment timed out without establishing a connection. +.It Bq Er ECONNREFUSED +The attempt to connect was forcefully rejected. +.It Bq Er ENETUNREACH +The network isn't reachable from this host. +.It Bq Er EADDRINUSE +The address is already in use. +.It Bq Er EFAULT +The +.Fa name +parameter specifies an area outside +the process address space. +.It Bq Er EINPROGRESS +The socket is non-blocking +and the connection cannot +be completed immediately. +It is possible to +.Xr select 2 +for completion by selecting the socket for writing. +.It Bq Er EALREADY +The socket is non-blocking +and a previous connection attempt +has not yet been completed. +.El +.Pp +The following errors are specific to connecting names in the UNIX domain. +These errors may not apply in future versions of the UNIX IPC domain. +.Bl -tag -width EADDRNOTAVAILABB +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named socket does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +Write access to the named socket is denied. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr getpeername 2 , +.Xr getsockname 2 , +.Xr select 2 , +.Xr socket 2 +.Sh HISTORY +The +.Fn connect +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2 new file mode 100644 index 0000000..6f86325 --- /dev/null +++ b/lib/libc/sys/dup.2 @@ -0,0 +1,204 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)dup.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt DUP 2 +.Os BSD 4 +.Sh NAME +.Nm dup , +.Nm dup2 +.Nd duplicate an existing file descriptor +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn dup "int oldd" +.Ft int +.Fn dup2 "int oldd" "int newd" +.Sh DESCRIPTION +.Fn Dup +duplicates an existing object descriptor and returns its value to +the calling process +.Fa ( newd += +.Fn dup oldd ) . +The argument +.Fa oldd +is a small non-negative integer index in +the per-process descriptor table. The value must be less +than the size of the table, which is returned by +.Xr getdtablesize 2 . +The new descriptor returned by the call +is the lowest numbered descriptor +currently not in use by the process. +.Pp +The object referenced by the descriptor does not distinguish +between +.Fa oldd +and +.Fa newd +in any way. +Thus if +.Fa newd +and +.Fa oldd +are duplicate references to an open +file, +.Xr read 2 , +.Xr write 2 +and +.Xr lseek 2 +calls all move a single pointer into the file, +and append mode, non-blocking I/O and asynchronous I/O options +are shared between the references. +If a separate pointer into the file is desired, a different +object reference to the file must be obtained by issuing an +additional +.Xr open 2 +call. +The close-on-exec flag on the new file descriptor is unset. +.Pp +In +.Fn dup2 , +the value of the new descriptor +.Fa newd +is specified. If this descriptor is already in use and +.Fa oldd +!= +.Fa newd , +the descriptor is first deallocated as if a +.Xr close 2 +call had been used. +If +.Fa oldd +is not a valid descriptor, then +.Fa newd +is not closed. +If +.Fa oldd +== +.Fa newd +and +.Fa oldd +is a valid descriptor, then +.Fn dup2 +is successful, and does nothing. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn dup +is implemented as the +.Va dup +syscall. +.Pp +In the threaded library, the +.Va dup +syscall is assembled to +.Fn _thread_sys_dup +and +.Fn dup +is implemented as a function which locks +.Va oldd +for read and write, then calls +.Fn _thread_sys_dup . +Before returning, +.Fn dup +unlocks +.Va oldd . +.Pp +In the non-threaded library +.Fn dup2 +is implemented as the +.Va dup2 +syscall. +.Pp +In the threaded library, the +.Va dup2 +syscall is assembled to +.Fn _thread_sys_dup2 +and +.Fn dup2 +is implemented as a function which locks both +.Va oldd +and +.Va newd +for read and write, then calls +.Fn _thread_sys_dup2 . +Before returning, +.Fn dup2 +unlocks +.Va oldd . +and +.Va newd . +.Sh RETURN VALUES +The value -1 is returned if an error occurs in either call. +The external variable +.Va errno +indicates the cause of the error. +.Sh ERRORS +.Fn Dup +and +.Fn dup2 +fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa Oldd +or +.Fa newd +is not a valid active descriptor +.It Bq Er EMFILE +Too many descriptors are active. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr close 2 , +.Xr fcntl 2 , +.Xr getdtablesize 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr socket 2 , +.Xr socketpair 2 +.Sh STANDARDS +The +.Fn dup +and +.Fn dup2 +function calls are expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn dup +and a +.Fn dup2 +function call appeared in +.At v7 . diff --git a/lib/libc/sys/execve.2 b/lib/libc/sys/execve.2 new file mode 100644 index 0000000..2adc7c9 --- /dev/null +++ b/lib/libc/sys/execve.2 @@ -0,0 +1,288 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)execve.2 8.5 (Berkeley) 6/1/94 +.\" $FreeBSD$ +.\" +.Dd June 1, 1994 +.Dt EXECVE 2 +.Os BSD 4 +.Sh NAME +.Nm execve +.Nd execute a file +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn execve "const char *path" "char *const argv[]" "char *const envp[]" +.Sh DESCRIPTION +.Fn Execve +transforms the calling process into a new process. +The new process is constructed from an ordinary file, +whose name is pointed to by +.Fa path , +called the +.Em new process file . +This file is either an executable object file, +or a file of data for an interpreter. +An executable object file consists of an identifying header, +followed by pages of data representing the initial program (text) +and initialized data pages. Additional pages may be specified +by the header to be initialized with zero data; see +.Xr a.out 5 . +.Pp +An interpreter file begins with a line of the form: +.Pp +.Bd -filled -offset indent -compact +.Sy \&#! +.Em interpreter +.Bq Em arg +.Ed +.Pp +When an interpreter file is +.Sy execve Ap d , +the system actually +.Sy execve Ap s +the specified +.Em interpreter . +If the optional +.Em arg +is specified, it becomes the first argument to the +.Em interpreter , +and the name of the originally +.Sy execve Ap d +file becomes the second argument; +otherwise, the name of the originally +.Sy execve Ap d +file becomes the first argument. The original arguments are shifted over to +become the subsequent arguments. The zeroth argument, normally the name of the +.Sy execve Ap d +file, is left unchanged. +.Pp +The argument +.Fa argv +is a pointer to a null-terminated array of +character pointers to null-terminated character strings. +These strings construct the argument list to be made available to the new +process. At least one argument must be present in +the array; by custom, the first element should be +the name of the executed program (for example, the last component of +.Fa path ) . +.Pp +The argument +.Fa envp +is also a pointer to a null-terminated array of +character pointers to null-terminated strings. +A pointer to this array is normally stored in the global variable +.Va environ. +These strings pass information to the +new process that is not directly an argument to the command (see +.Xr environ 7 ) . +.Pp +File descriptors open in the calling process image remain open in +the new process image, except for those for which the close-on-exec +flag is set (see +.Xr close 2 +and +.Xr fcntl 2 ) . +Descriptors that remain open are unaffected by +.Fn execve . +.Pp +Signals set to be ignored in the calling process are set to be ignored in +the +new process. Signals which are set to be caught in the calling process image +are set to default action in the new process image. +Blocked signals remain blocked regardless of changes to the signal action. +The signal stack is reset to be undefined (see +.Xr sigaction 2 +for more information). +.Pp +If the set-user-ID mode bit of the new process image file is set +(see +.Xr chmod 2 ) , +the effective user ID of the new process image is set to the owner ID +of the new process image file. +If the set-group-ID mode bit of the new process image file is set, +the effective group ID of the new process image is set to the group ID +of the new process image file. +(The effective group ID is the first element of the group list.) +The real user ID, real group ID and +other group IDs of the new process image remain the same as the calling +process image. +After any set-user-ID and set-group-ID processing, +the effective user ID is recorded as the saved set-user-ID, +and the effective group ID is recorded as the saved set-group-ID. +These values may be used in changing the effective IDs later (see +.Xr setuid 2 ) . +.ne 1i +.Pp +The set-ID bits are not honored if the respective file system has the +.Ar nosuid +option enabled or if the new process file is an interpreter file. Syscall +tracing is disabled if effective IDs are changed. +.Pp +The new process also inherits the following attributes from +the calling process: +.Pp +.Bl -column parent_process_ID -offset indent -compact +.It process ID Ta see Xr getpid 2 +.It parent process ID Ta see Xr getppid 2 +.It process group ID Ta see Xr getpgrp 2 +.It access groups Ta see Xr getgroups 2 +.It working directory Ta see Xr chdir 2 +.It root directory Ta see Xr chroot 2 +.It control terminal Ta see Xr termios 4 +.It resource usages Ta see Xr getrusage 2 +.It interval timers Ta see Xr getitimer 2 +.It resource limits Ta see Xr getrlimit 2 +.It file mode mask Ta see Xr umask 2 +.It signal mask Ta see Xr sigvec 2 , +.Xr sigsetmask 2 +.El +.Pp +When a program is executed as a result of an +.Fn execve +call, it is entered as follows: +.Bd -literal -offset indent +main(argc, argv, envp) +int argc; +char **argv, **envp; +.Ed +.Pp +where +.Fa argc +is the number of elements in +.Fa argv +(the ``arg count'') +and +.Fa argv +points to the array of character pointers +to the arguments themselves. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn execve +is implemented as the +.Va execve +syscall. +.Pp +In the threaded library, the +.Va execve +syscall is assembled to +.Fn _thread_sys_execve +and +.Fn execve +is implemented as a function which performs user-thread +library re-initialization and then calls +.Fn _thread_sys_execve . +.Sh RETURN VALUES +As the +.Fn execve +function overlays the current process image +with a new process image the successful call +has no process to return to. +If +.Fn execve +does return to the calling process an error has occurred; the +return value will be -1 and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Execve +will fail and return to the calling process if: +.Bl -tag -width [ENAMETOOLONG] +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The new process file does not exist. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +The new process file is not an ordinary file. +.It Bq Er EACCES +The new process file mode denies execute permission. +.It Bq Er ENOEXEC +The new process file has the appropriate access +permission, but has an invalid magic number in its header. +.It Bq Er ETXTBSY +The new process file is a pure procedure (shared text) +file that is currently open for writing or reading by some process. +.ne 1i +.It Bq Er ENOMEM +The new process requires more virtual memory than +is allowed by the imposed maximum +.Pq Xr getrlimit 2 . +.It Bq Er E2BIG +The number of bytes in the new process' argument list +is larger than the system-imposed limit. +This limit is specified by the +.Xr sysctl 3 +MIB variable +.Dv KERN_ARGMAX . +.It Bq Er EFAULT +The new process file is not as long as indicated by +the size values in its header. +.It Bq Er EFAULT +.Fa Path , +.Fa argv , +or +.Fa envp +point +to an illegal address. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.El +.Sh CAVEAT +If a program is +.Em setuid +to a non-super-user, but is executed when +the real +.Em uid +is ``root'', then the program has some of the powers +of a super-user as well. +.Sh SEE ALSO +.Xr ktrace 1 , +.Xr _exit 2 , +.Xr fork 2 , +.Xr execl 3 , +.Xr exit 3 , +.Xr sysctl 3 , +.Xr environ 7 , +.Xr mount 8 +.Sh HISTORY +The +.Fn execve +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2 new file mode 100644 index 0000000..97236fe --- /dev/null +++ b/lib/libc/sys/fcntl.2 @@ -0,0 +1,530 @@ +.\" Copyright (c) 1983, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 +.\" $FreeBSD$ +.\" +.Dd January 12, 1994 +.Dt FCNTL 2 +.Os BSD 4.2 +.Sh NAME +.Nm fcntl +.Nd file control +.Sh SYNOPSIS +.Fd #include <fcntl.h> +.Ft int +.Fn fcntl "int fd" "int cmd" "..." +.Sh DESCRIPTION +.Fn Fcntl +provides for control over descriptors. +The argument +.Fa fd +is a descriptor to be operated on by +.Fa cmd +as described below. Depending on the value of +.Fa cmd , +.Nm +can take an additional third argument +.Fa "int arg" . +.Bl -tag -width F_GETOWNX +.It Dv F_DUPFD +Return a new descriptor as follows: +.Pp +.Bl -bullet -compact -offset 4n +.It +Lowest numbered available descriptor greater than or equal to +.Fa arg . +.It +Same object references as the original descriptor. +.It +New descriptor shares the same file offset if the object +was a file. +.It +Same access mode (read, write or read/write). +.It +Same file status flags (i.e., both file descriptors +share the same file status flags). +.It +The close-on-exec flag associated with the new file descriptor +is set to remain open across +.Xr execve 2 +system calls. +.El +.It Dv F_GETFD +Get the close-on-exec flag associated with the file descriptor +.Fa fd . +If the low-order bit of the returned value is 0, +the file will remain open across +.Fn exec , +otherwise the file will be closed upon execution of +.Fn exec +.Fa ( arg +is ignored). +.It Dv F_SETFD +Set the close-on-exec flag associated with +.Fa fd +to the low order bit of +.Fa arg +(0 or 1 as above). +.It Dv F_GETFL +Get descriptor status flags, as described below +.Fa ( arg +is ignored). +.It Dv F_SETFL +Set descriptor status flags to +.Fa arg . +.It Dv F_GETOWN +Get the process ID or process group +currently receiving +.Dv SIGIO +and +.Dv SIGURG +signals; process groups are returned +as negative values +.Fa ( arg +is ignored). +.It Dv F_SETOWN +Set the process or process group +to receive +.Dv SIGIO +and +.Dv SIGURG +signals; +process groups are specified by supplying +.Fa arg +as negative, otherwise +.Fa arg +is interpreted as a process ID. +.El +.Pp +The flags for the +.Dv F_GETFL +and +.Dv F_SETFL +flags are as follows: +.Bl -tag -width O_NONBLOCKX +.It Dv O_NONBLOCK +Non-blocking I/O; if no data is available to a +.Xr read 2 +call, or if a +.Xr write 2 +operation would block, +the read or write call returns -1 with the error +.Er EAGAIN . +.It Dv O_APPEND +Force each write to append at the end of file; +corresponds to the +.Dv O_APPEND +flag of +.Xr open 2 . +.It Dv O_ASYNC +Enable the +.Dv SIGIO +signal to be sent to the process group +when I/O is possible, e.g., +upon availability of data to be read. +.El +.Pp +Several commands are available for doing advisory file locking; +they all operate on the following structure: +.ne 7v +.Bd -literal +struct flock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ +}; +.Ed +The commands available for advisory record locking are as follows: +.Bl -tag -width F_SETLKWX +.It Dv F_GETLK +Get the first lock that blocks the lock description pointed to by the +third argument, +.Fa arg , +taken as a pointer to a +.Fa "struct flock" +(see above). +The information retrieved overwrites the information passed to +.Fn fcntl +in the +.Fa flock +structure. +If no lock is found that would prevent this lock from being created, +the structure is left unchanged by this function call except for the +lock type which is set to +.Dv F_UNLCK . +.It Dv F_SETLK +Set or clear a file segment lock according to the lock description +pointed to by the third argument, +.Fa arg , +taken as a pointer to a +.Fa "struct flock" +(see above). +.Dv F_SETLK +is used to establish shared (or read) locks +.Dv (F_RDLCK) +or exclusive (or write) locks, +.Dv (F_WRLCK) , +as well as remove either type of lock +.Dv (F_UNLCK) . +If a shared or exclusive lock cannot be set, +.Fn fcntl +returns immediately with +.Er EAGAIN . +.It Dv F_SETLKW +This command is the same as +.Dv F_SETLK +except that if a shared or exclusive lock is blocked by other locks, +the process waits until the request can be satisfied. +If a signal that is to be caught is received while +.Fn fcntl +is waiting for a region, the +.Fn fcntl +will be interrupted if the signal handler has not specified the +.Dv SA_RESTART +(see +.Xr sigaction 2 ) . +.El +.Pp +When a shared lock has been set on a segment of a file, +other processes can set shared locks on that segment +or a portion of it. +A shared lock prevents any other process from setting an exclusive +lock on any portion of the protected area. +A request for a shared lock fails if the file descriptor was not +opened with read access. +.Pp +An exclusive lock prevents any other process from setting a shared lock or +an exclusive lock on any portion of the protected area. +A request for an exclusive lock fails if the file was not +opened with write access. +.Pp +The value of +.Fa l_whence +is +.Dv SEEK_SET , +.Dv SEEK_CUR , +or +.Dv SEEK_END +to indicate that the relative offset, +.Fa l_start +bytes, will be measured from the start of the file, +current position, or end of the file, respectively. +The value of +.Fa l_len +is the number of consecutive bytes to be locked. +If +.Fa l_len +is negative, the result is undefined. +The +.Fa l_pid +field is only used with +.Dv F_GETLK +to return the process ID of the process holding a blocking lock. +After a successful +.Dv F_GETLK +request, the value of +.Fa l_whence +is +.Dv SEEK_SET . +.Pp +Locks may start and extend beyond the current end of a file, +but may not start or extend before the beginning of the file. +A lock is set to extend to the largest possible value of the +file offset for that file if +.Fa l_len +is set to zero. If +.Fa l_whence +and +.Fa l_start +point to the beginning of the file, and +.Fa l_len +is zero, the entire file is locked. +If an application wishes only to do entire file locking, the +.Xr flock 2 +system call is much more efficient. +.Pp +There is at most one type of lock set for each byte in the file. +Before a successful return from an +.Dv F_SETLK +or an +.Dv F_SETLKW +request when the calling process has previously existing locks +on bytes in the region specified by the request, +the previous lock type for each byte in the specified +region is replaced by the new lock type. +As specified above under the descriptions +of shared locks and exclusive locks, an +.Dv F_SETLK +or an +.Dv F_SETLKW +request fails or blocks respectively when another process has existing +locks on bytes in the specified region and the type of any of those +locks conflicts with the type specified in the request. +.Pp +This interface follows the completely stupid semantics of System V and +.St -p1003.1-88 +that require that all locks associated with a file for a given process are +removed when +.Em any +file descriptor for that file is closed by that process. +This semantic means that applications must be aware of any files that +a subroutine library may access. +For example if an application for updating the password file locks the +password file database while making the update, and then calls +.Xr getpwnam 3 +to retrieve a record, +the lock will be lost because +.Xr getpwnam 3 +opens, reads, and closes the password database. +The database close will release all locks that the process has +associated with the database, even if the library routine never +requested a lock on the database. +Another minor semantic problem with this interface is that +locks are not inherited by a child process created using the +.Xr fork 2 +function. +The +.Xr flock 2 +interface has much more rational last close semantics and +allows locks to be inherited by child processes. +.Xr Flock 2 +is recommended for applications that want to ensure the integrity +of their locks when using library routines or wish to pass locks +to their children. +Note that +.Xr flock 2 +and +.Xr fcntl 2 +locks may be safely used concurrently. +.Pp +All locks associated with a file for a given process are +removed when the process terminates. +.Pp +A potential for deadlock occurs if a process controlling a locked region +is put to sleep by attempting to lock the locked region of another process. +This implementation detects that sleeping until a locked region is unlocked +would cause a deadlock and fails with an +.Er EDEADLK +error. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn fcntl +is implemented as the +.Va fcntl +syscall. +.Pp +In the threaded library, the +.Va fcntl +syscall is assembled to +.Fn _thread_sys_fcntl +and +.Fn fcntl +is implemented as a function which disables thread rescheduling, locks +.Va fd +for read and write, then calls +.Fn _thread_sys_fcntl . +Before returning, +.Fn fcntl +unlocks +.Va fd +and enables thread rescheduling. +.Sh RETURN VALUES +Upon successful completion, the value returned depends on +.Fa cmd +as follows: +.Bl -tag -width F_GETOWNX -offset indent +.It Dv F_DUPFD +A new file descriptor. +.It Dv F_GETFD +Value of flag (only the low-order bit is defined). +.It Dv F_GETFL +Value of flags. +.It Dv F_GETOWN +Value of file descriptor owner. +.It other +Value other than -1. +.El +.Pp +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Fcntl +will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The argument +.Fa cmd +is +.Dv F_SETLK , +the type of lock +.Fa (l_type) +is a shared lock +.Dv (F_RDLCK) +or exclusive lock +.Dv (F_WRLCK) , +and the segment of a file to be locked is already +exclusive-locked by another process; +or the type is an exclusive lock and some portion of the +segment of a file to be locked is already shared-locked or +exclusive-locked by another process. +.It Bq Er EBADF +.Fa Fildes +is not a valid open file descriptor. +.Pp +The argument +.Fa cmd +is +.Dv F_SETLK +or +.Dv F_SETLKW , +the type of lock +.Fa (l_type) +is a shared lock +.Dv (F_RDLCK) , +and +.Fa fildes +is not a valid file descriptor open for reading. +.Pp +The argument +.Fa cmd +is +.Dv F_SETLK +or +.Dv F_SETLKW , +the type of lock +.Fa (l_type) +is an exclusive lock +.Dv (F_WRLCK) , +and +.Fa fildes +is not a valid file descriptor open for writing. +.It Bq Er EDEADLK +The argument +.Fa cmd +is +.Dv F_SETLKW , +and a deadlock condition was detected. +.It Bq Er EINTR +The argument +.Fa cmd +is +.Dv F_SETLKW , +and the function was interrupted by a signal. +.It Bq Er EINVAL +.Fa Cmd +is +.Dv F_DUPFD +and +.Fa arg +is negative or greater than the maximum allowable number +(see +.Xr getdtablesize 2 ) . +.Pp +The argument +.Fa cmd +is +.Dv F_GETLK , +.Dv F_SETLK , +or +.Dv F_SETLKW +and the data to which +.Fa arg +points is not valid, or +.Fa fildes +refers to a file that does not support locking. +.It Bq Er EMFILE +The argument +.Fa cmd +is +.Dv F_DUPFD +and the maximum number of file descriptors permitted for the +process are already in use, +or no file descriptors greater than or equal to +.Fa arg +are available. +.It Bq Er ENOLCK +The argument +.Fa cmd +is +.Dv F_SETLK +or +.Dv F_SETLKW , +and satisfying the lock or unlock request would result in the +number of locked regions in the system exceeding a system-imposed limit. +.It Bq Er EPERM +.Fa Cmd +is +.Dv F_SETOWN +and +the process ID or process group given as an argument is in a +different session than the caller. +.It Bq Er ESRCH +.Fa Cmd +is +.Dv F_SETOWN +and +the process ID given as argument is not in use. +.El +.Pp +In addition, if +.Fa fd +refers to a descriptor open on a terminal device (as opposed to a +descriptor open on a socket), a +.Fa cmd +of +.Dv F_SETOWN +can fail for the same reasons as in +.Xr tcsetpgrp 3 , +and a +.Fa cmd +of +.Dv F_GETOWN +for the reasons as stated in +.Xr tcgetpgrp 3 . +.Sh SEE ALSO +.Xr close 2 , +.Xr execve 2 , +.Xr flock 2 , +.Xr getdtablesize 2 , +.Xr open 2 , +.Xr sigvec 2 , +.Xr tcgetpgrp 3 , +.Xr tcsetpgrp 3 +.Sh HISTORY +The +.Fn fcntl +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/fhopen.2 b/lib/libc/sys/fhopen.2 new file mode 100644 index 0000000..18838a2 --- /dev/null +++ b/lib/libc/sys/fhopen.2 @@ -0,0 +1,137 @@ +.\" $NetBSD: fhopen.2,v 1.1 1999/06/30 01:32:15 wrstuden Exp $ +.\" $FreeBSD$ +.\" +.\" Copyright (c) 1999 National Aeronautics & Space Administration +.\" All rights reserved. +.\" +.\" This software was written by William Studenmund of the +.\" Numerical Aerospace Similation Facility, NASA Ames Research Center. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the the name of the National Aeronautics & Space Administration +.\" nor the names of its contributors may be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB- +.\" UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +.\" OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\"/ +.Dd June 29, 1999 +.Dt FHOPEN 2 +.Os +.Sh NAME +.Nm fhopen , +.Nm fhstat , +.Nm fhstatfs +.Nd access file via file handle +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/stat.h> +.Fd #include <sys/mount.h> +.Ft int +.Fn fhopen "const fhandle_t *fhp" "int flags" +.Ft int +.Fn fhstat "const fhandle_t *fhp" "struct stat *sb" +.Ft int +.Fn fhstatfs "const fhandle_t *fhp" "struct statfs *buf" +.Sh DESCRIPTION +These functions provide a means to access a file given the file handle +.Fa fhp. +As this method bypasses directory access restrictions, these calls are +restricted to the superuser. +.Pp +.Fn fhopen +opens the file referenced by +.Fa fhp +for reading and/or writing as specified by the argument +.Fa flags +and returns the file descriptor to the calling process. The +.Fa flags +are specified by +.Em or Ns 'ing +together the flags used for the +.Xr open 2 +call. All said flags are valid except for +.Dv O_CREAT . +.Pp +.Fn fhstat +and +.Fn fhstatfs +provide the functionality of the +.Xr fstat 2 +and +.Xr fstatfs 2 +calls except that they return information for the file refered to by +.Fa fhp +rather than an open file. +.Sh RETURN VALUES +Upon successful completion, +.Fn fhopen +returns the file descriptor for the opened file, while +.Fn fhstat +and +.Fn fhstatfs +return 0. +Otherwise, -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +In addition to the errors returned by +.Xr open 2 , +.Xr fstat 2 , +and +.Xr fstatfs 2 +respectivly, +.Fn fhopen , +.Fn fhstat , +and +.Fn fhstatfs +will return +.Bl -tag -width Er +.It Bq Er EINVAL +Calling +.Fn fhopen +with +.Dv O_CREAT +set. +.It Bq Er ESTALE +The file handle +.Fa fhp +is no longer valid. +.El +.Sh SEE ALSO +.Xr getfh 2 , +.Xr open 2 , +.Xr fstat 2 , +.Xr fstatfs 2 +.Sh HISTORY +The +.Fn fhopen , +.Fn fhstat , +and +.Fn fhstatfs +functions first appeared in +.Nx 1.5 +and was adapted to +.Fx 4.0 +by Alfred Perlstein. +.Sh AUTHORS +This man page was written by +.An William Studenmund +for NetBSD. diff --git a/lib/libc/sys/flock.2 b/lib/libc/sys/flock.2 new file mode 100644 index 0000000..4d3fb06 --- /dev/null +++ b/lib/libc/sys/flock.2 @@ -0,0 +1,172 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)flock.2 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD$ +.\" +.Dd December 11, 1993 +.Dt FLOCK 2 +.Os BSD 4.2 +.Sh NAME +.Nm flock +.Nd "apply or remove an advisory lock on an open file" +.Sh SYNOPSIS +.Fd #include <sys/file.h> +.Fd #define LOCK_SH 0x01 /* shared file lock */ +.Fd #define LOCK_EX 0x02 /* exclusive file lock */ +.Fd #define LOCK_NB 0x04 /* don't block when locking */ +.Fd #define LOCK_UN 0x08 /* unlock file */ +.Ft int +.Fn flock "int fd" "int operation" +.Sh DESCRIPTION +.Fn Flock +applies or removes an +.Em advisory +lock on the file associated with the file descriptor +.Fa fd . +A lock is applied by specifying an +.Fa operation +parameter that is one of +.Dv LOCK_SH +or +.Dv LOCK_EX +with the optional addition of +.Dv LOCK_NB . +To unlock +an existing lock +.Dv operation +should be +.Dv LOCK_UN . +.Pp +Advisory locks allow cooperating processes to perform +consistent operations on files, but do not guarantee +consistency (i.e., processes may still access files +without using advisory locks possibly resulting in +inconsistencies). +.Pp +The locking mechanism allows two types of locks: +.Em shared +locks and +.Em exclusive +locks. +At any time multiple shared locks may be applied to a file, +but at no time are multiple exclusive, or both shared and exclusive, +locks allowed simultaneously on a file. +.Pp +A shared lock may be +.Em upgraded +to an exclusive lock, and vice versa, simply by specifying +the appropriate lock type; this results in the previous +lock being released and the new lock applied (possibly +after other processes have gained and released the lock). +.Pp +Requesting a lock on an object that is already locked +normally causes the caller to be blocked until the lock may be +acquired. If +.Dv LOCK_NB +is included in +.Fa operation , +then this will not happen; instead the call will fail and +the error +.Er EWOULDBLOCK +will be returned. +.Sh NOTES +Locks are on files, not file descriptors. That is, file descriptors +duplicated through +.Xr dup 2 +or +.Xr fork 2 +do not result in multiple instances of a lock, but rather multiple +references to a single lock. If a process holding a lock on a file +forks and the child explicitly unlocks the file, the parent will +lose its lock. +.Pp +Processes blocked awaiting a lock may be awakened by signals. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn flock +is implemented as the +.Va flock +syscall. +.Pp +In the threaded library, the +.Va flock +syscall is assembled to +.Fn _thread_sys_flock +and +.Fn flock +is implemented as a function which locks +.Va fd +for read and write, then calls +.Fn _thread_sys_flock . +Before returning, +.Fn flock +unlocks +.Va fd . +.Sh RETURN VALUES +Zero is returned if the operation was successful; +on an error a -1 is returned and an error code is left in +the global location +.Va errno . +.Sh ERRORS +The +.Fn flock +call fails if: +.Bl -tag -width EWOULDBLOCKAA +.It Bq Er EWOULDBLOCK +The file is locked and the +.Dv LOCK_NB +option was specified. +.It Bq Er EBADF +The argument +.Fa fd +is an invalid descriptor. +.It Bq Er EINVAL +The argument +.Fa fd +refers to an object other than a file. +.It Bq Er EOPNOTSUPP +The argument +.Fa fd +refers to an object that does not support file locking. +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr dup 2 , +.Xr execve 2 , +.Xr fork 2 , +.Xr open 2 +.Sh HISTORY +The +.Fn flock +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 new file mode 100644 index 0000000..d01e600 --- /dev/null +++ b/lib/libc/sys/fork.2 @@ -0,0 +1,127 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)fork.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt FORK 2 +.Os BSD 4 +.Sh NAME +.Nm fork +.Nd create a new process +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <unistd.h> +.Ft pid_t +.Fn fork void +.Sh DESCRIPTION +.Fn Fork +causes creation of a new process. +The new process (child process) is an exact copy of the +calling process (parent process) except for the following: +.Bl -bullet -offset indent +.It +The child process has a unique process ID. +.It +The child process has a different parent +process ID (i.e., the process ID of the parent process). +.It +The child process has its own copy of the parent's descriptors. +These descriptors reference the same underlying objects, so that, +for instance, file pointers in file objects are shared between +the child and the parent, so that an +.Xr lseek 2 +on a descriptor in the child process can affect a subsequent +.Xr read 2 +or +.Xr write 2 +by the parent. +This descriptor copying is also used by the shell to +establish standard input and output for newly created processes +as well as to set up pipes. +.It +The child process' resource utilizations +are set to 0; see +.Xr setrlimit 2 . +.El +.Sh RETURN VALUES +Upon successful completion, +.Fn fork +returns a value +of 0 to the child process and returns the process ID of the child +process to the parent process. Otherwise, a value of -1 is returned +to the parent process, no child process is created, and the global +variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Fork +will fail and no child process will be created if: +.Bl -tag -width [EAGAIN] +.It Bq Er EAGAIN +The system-imposed limit on the total +number of processes under execution would be exceeded. +The limit is given by the +.Xr sysctl 3 +MIB variable +.Dv KERN_MAXPROC . +(The limit is actually one less than this +except for the super user). +.It Bq Er EAGAIN +The user is not the super user, and +the system-imposed limit +on the total number of +processes under execution by a single user would be exceeded. +The limit is given by the +.Xr sysctl 3 +MIB variable +.Dv KERN_MAXPROCPERUID . +.It Bq Er EAGAIN +The user is not the super user, and +the soft resource limit corresponding to the resource parameter +.Dv RLIMIT_NPROC +would be exceeded (see +.Xr getrlimit 2 ) . +.It Bq Er ENOMEM +There is insufficient swap space for the new process. +.El +.Sh SEE ALSO +.Xr execve 2 , +.Xr rfork 2 , +.Xr setrlimit 2 , +.Xr vfork 2 , +.Xr wait 2 +.Sh HISTORY +A +.Fn fork +function call appeared in +.At v6 . diff --git a/lib/libc/sys/fsync.2 b/lib/libc/sys/fsync.2 new file mode 100644 index 0000000..a83ebcb --- /dev/null +++ b/lib/libc/sys/fsync.2 @@ -0,0 +1,104 @@ +.\" Copyright (c) 1983, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)fsync.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt FSYNC 2 +.Os BSD 4.2 +.Sh NAME +.Nm fsync +.Nd "synchronize a file's in-core state with that on disk" +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn fsync "int fd" +.Sh DESCRIPTION +.Fn Fsync +causes all modified data and attributes of +.Fa fd +to be moved to a permanent storage device. +This normally results in all in-core modified copies +of buffers for the associated file to be written to a disk. +.Pp +.Fn Fsync +should be used by programs that require a file to be +in a known state, for example, in building a simple transaction +facility. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn fsync +is implemented as the +.Va fsync +syscall. +.Pp +In the threaded library, the +.Va fsync +syscall is assembled to +.Fn _thread_sys_fsync +and +.Fn fsync +is implemented as a function which locks +.Va fd +for read and write, then calls +.Fn _thread_sys_fsync . +Before returning, +.Fn fsync +unlocks +.Va fd . +.Sh RETURN VALUES +A 0 value is returned on success. A -1 value indicates +an error. +.Sh ERRORS +The +.Fn fsync +fails if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa Fd +is not a valid descriptor. +.It Bq Er EINVAL +.Fa Fd +refers to a socket, not to a file. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr sync 2 , +.Xr update 4 , +.Xr sync 8 +.Sh HISTORY +The +.Fn fsync +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c new file mode 100644 index 0000000..9d7d5fb --- /dev/null +++ b/lib/libc/sys/ftruncate.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +int +ftruncate(fd, length) + int fd; + off_t length; +{ + +#ifdef _THREAD_SAFE + int retval; + if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { + retval = -1; + } else { + retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length); + _FD_UNLOCK(fd, FD_RDWR); + } + return(retval); +#else + return(__syscall((quad_t)SYS_ftruncate, fd, 0, length)); +#endif +} diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2 new file mode 100644 index 0000000..a3ca671 --- /dev/null +++ b/lib/libc/sys/getdirentries.2 @@ -0,0 +1,204 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getdirentries.2 8.2 (Berkeley) 5/3/95 +.\" $FreeBSD$ +.\" +.Dd May 3, 1995 +.Dt GETDIRENTRIES 2 +.Os +.Sh NAME +.Nm getdirentries , +.Nm getdents +.Nd "get directory entries in a filesystem independent format" +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <dirent.h> +.Ft int +.Fn getdirentries "int fd" "char *buf" "int nbytes" "long *basep" +.Ft int +.Fn getdents "int fd" "char *buf" "int nbytes" +.Sh DESCRIPTION +The +.Fn getdirentries +and +.Fn getdents +functions read directory entries from the directory +referenced by the file descriptor +.Fa fd +into the buffer pointed to by +.Fa buf , +in a filesystem independent format. +Up to +.Fa nbytes +of data will be transferred. +The +.Fa nbytes +argument must be greater than or equal to the +block size associated with the file, +see +.Xr stat 2 . +Some filesystems may not support these functions +with buffers smaller than this size. +.Pp +The data in the buffer is a series of +.Em dirent +structures each containing the following entries: +.Bd -literal -offset indent +u_int32_t d_fileno; +u_int16_t d_reclen; +u_int8_t d_type; +u_int8_t d_namlen; +char d_name[MAXNAMELEN + 1]; /* see below */ +.Ed +.Pp +The +.Fa d_fileno +entry is a number which is unique for each +distinct file in the filesystem. +Files that are linked by hard links (see +.Xr link 2 ) +have the same +.Fa d_fileno . +The +.Fa d_reclen +entry is the length, in bytes, of the directory record. +The +.Fa d_type +entry is the type of the file pointed to by the directory record. +The file type values are defined in +.Fa <sys/dirent.h> . +The +.Fa d_name +entry contains a null terminated file name. +The +.Fa d_namlen +entry specifies the length of the file name excluding the null byte. +Thus the actual size of +.Fa d_name +may vary from 1 to +.Dv MAXNAMELEN +\&+ 1. +.Pp +Entries may be separated by extra space. +The +.Fa d_reclen +entry may be used as an offset from the start of a +.Fa dirent +structure to the next structure, if any. +.Pp +The actual number of bytes transferred is returned. +The current position pointer associated with +.Fa fd +is set to point to the next block of entries. +The pointer may not advance by the number of bytes returned by +.Fn getdirentries +or +.Fn getdents . +A value of zero is returned when +the end of the directory has been reached. +.Pp +The +.Fn getdirentries +function writes the position of the block read into the location pointed to by +.Fa basep . +Alternatively, the current position pointer may be set and retrieved by +.Xr lseek 2 . +The current position pointer should only be set to a value returned by +.Xr lseek 2 , +a value returned in the location pointed to by +.Fa basep ( Ns Fn getdirentries +only) +or zero. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn getdirentries +is implemented as the +.Va getdirentries +syscall. +.Pp +In the threaded library, the +.Va getdirentries +syscall is assembled to +.Fn _thread_sys_getdirentries +and +.Fn getdirentries +is implemented as a function which locks +.Va fd +for read and write, then calls +.Fn _thread_sys_getdirentries . +Before returning, +.Fn getdirentries +unlocks +.Va fd . +.Sh RETURN VALUES +If successful, the number of bytes actually transferred is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Getdirentries +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is not a valid file descriptor open for reading. +.It Bq Er EFAULT +Either +.Fa buf +or +.Fa basep +point outside the allocated address space. +.It Bq Er EINVAL +The file referenced by +.Fa fd +is not a directory, or +.Fa nbytes +is too small for returning a directory entry or block of entries, +or the current position pointer is invalid. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr lseek 2 , +.Xr open 2 +.Sh HISTORY +The +.Fn getdirentries +function first appeared in +.Bx 4.4 . +The +.Fn getdents +function first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/getdtablesize.2 b/lib/libc/sys/getdtablesize.2 new file mode 100644 index 0000000..a41980c --- /dev/null +++ b/lib/libc/sys/getdtablesize.2 @@ -0,0 +1,61 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getdtablesize.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETDTABLESIZE 2 +.Os BSD 4.2 +.Sh NAME +.Nm getdtablesize +.Nd get descriptor table size +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn getdtablesize void +.Sh DESCRIPTION +Each process has a fixed size descriptor table, +which is guaranteed to have at least 20 slots. The entries in +the descriptor table are numbered with small integers starting at 0. +The call +.Fn getdtablesize +returns the size of this table. +.Sh SEE ALSO +.Xr close 2 , +.Xr dup 2 , +.Xr open 2 , +.Xr select 2 +.Sh HISTORY +The +.Fn getdtablesize +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getfh.2 b/lib/libc/sys/getfh.2 new file mode 100644 index 0000000..e64babf --- /dev/null +++ b/lib/libc/sys/getfh.2 @@ -0,0 +1,95 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getfh.2 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD$ +.\" +.Dd June 9, 1993 +.Dt GETFH 2 +.Os +.Sh NAME +.Nm getfh +.Nd get file handle +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/mount.h> +.Ft int +.Fn getfh "const char *path" "fhandle_t *fhp" +.Sh DESCRIPTION +.Fn Getfh +returns a file handle for the specified file or directory +in the file handle pointed to by +.Fa fhp . +This system call is restricted to the superuser. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Getfh +fails if one or more of the following are true: +.Bl -tag -width Er +.It Bq ENOTDIR +A component of the path prefix of +.Fa path +is not a directory. +.It Bq ENAMETOOLONG +The length of a component of +.Fa path +exceeds 255 characters, +or the length of +.Fa path +exceeds 1023 characters. +.It Bq ENOENT +The file referred to by +.Fa path +does not exist. +.It Bq EACCES +Search permission is denied for a component of the path prefix of +.Fa path . +.It Bq ELOOP +Too many symbolic links were encountered in translating +.Fa path . +.It Bq EFAULT +.Fa Fhp +points to an invalid address. +.It Bq EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.El +.Sh HISTORY +The +.Fn getfh +function +first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/getfsstat.2 b/lib/libc/sys/getfsstat.2 new file mode 100644 index 0000000..3dc87bc --- /dev/null +++ b/lib/libc/sys/getfsstat.2 @@ -0,0 +1,172 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getfsstat.2 8.3 (Berkeley) 5/25/95 +.\" $FreeBSD$ +.\" +.Dd May 25, 1995 +.Dt GETFSSTAT 2 +.Os +.Sh NAME +.Nm getfsstat +.Nd get list of all mounted filesystems +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/ucred.h> +.Fd #include <sys/mount.h> +.Ft int +.Fn getfsstat "struct statfs *buf" "long bufsize" "int flags" +.Sh DESCRIPTION +.Fn Getfsstat +returns information about all mounted filesystems. +.Fa Buf +is a pointer to +.Xr statfs +structures defined as follows: +.Bd -literal +typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ + +/* + * file system statistics + */ + +#define MFSNAMELEN 16 /* length of fs type name, including null */ +#define MNAMELEN 90 /* length of buffer for returned name */ + +struct statfs { + long f_spare2; /* placeholder */ + long f_bsize; /* fundamental file system block size */ + long f_iosize; /* optimal transfer block size */ + long f_blocks; /* total data blocks in file system */ + long f_bfree; /* free blocks in fs */ + long f_bavail; /* free blocks avail to non-superuser */ + long f_files; /* total file nodes in file system */ + long f_ffree; /* free file nodes in fs */ + fsid_t f_fsid; /* file system id */ + uid_t f_owner; /* user that mounted the filesystem */ + int f_type; /* type of filesystem (see below) */ + int f_flags; /* copy of mount flags */ + long f_spare[2]; /* spare for later */ + char f_fstypename[MFSNAMELEN];/* fs type name */ + char f_mntonname[MNAMELEN];/* directory on which mounted */ + char f_mntfromname[MNAMELEN];/* mounted filesystem */ +}; +.Ed +.Pp +The flags that may be returned include: +.Bl -tag -width MNT_ASYNCHRONOUS +.It Dv MNT_RDONLY +The filesystem is mounted read-only; +Even the super-user may not write on it. +.It Dv MNT_NOEXEC +Files may not be executed from the filesystem. +.It Dv MNT_NOSUID +Setuid and setgid bits on files are not honored when they are executed. +.It Dv MNT_NODEV +Special files in the filesystem may not be opened. +.It Dv MNT_SYNCHRONOUS +All I/O to the filesystem is done synchronously. +.It Dv MNT_ASYNCHRONOUS +No filesystem I/O is done synchronously. +.It Dv MNT_LOCAL +The filesystem resides locally. +.It Dv MNT_QUOTA +The filesystem has quotas enabled on it. +.It Dv MNT_ROOTFS +Identifies the root filesystem. +.It Dv MNT_EXRDONLY +The filesystem is exported read-only. +.It Dv MNT_EXPORTED +The filesystem is exported for both reading and writing. +.It Dv MNT_DEFEXPORTED +The filesystem is exported for both reading and writing to any Internet host. +.It Dv MNT_EXPORTANON +The filesystem maps all remote accesses to the anonymous user. +.It Dv MNT_EXKERB +The filesystem is exported with Kerberos uid mapping. +.El +.Pp +Fields that are undefined for a particular filesystem are set to -1. +The buffer is filled with an array of +.Fa fsstat +structures, one for each mounted filesystem +up to the size specified by +.Fa bufsize . +.Pp +If +.Fa buf +is given as NULL, +.Fn getfsstat +returns just the number of mounted filesystems. +.Pp +Normally +.Fa flags +should be specified as +.Dv MNT_WAIT . +If +.Fa flags +is set to +.Dv MNT_NOWAIT , +.Fn getfsstat +will return the information it has available without requesting +an update from each filesystem. +Thus, some of the information will be out of date, but +.Fn getfsstat +will not block waiting for information from a filesystem that is +unable to respond. +.Sh RETURN VALUES +Upon successful completion, the number of +.Fa fsstat +structures is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Getfsstat +fails if one or more of the following are true: +.Bl -tag -width Er +.It EFAULT +.Fa Buf +points to an invalid address. +.It EIO +An +.Tn I/O +error occurred while reading from or writing to the filesystem. +.El +.Sh SEE ALSO +.Xr statfs 2 , +.Xr fstab 5 , +.Xr mount 8 +.Sh HISTORY +The +.Fn getfsstat +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/getgid.2 b/lib/libc/sys/getgid.2 new file mode 100644 index 0000000..d9c4db4 --- /dev/null +++ b/lib/libc/sys/getgid.2 @@ -0,0 +1,83 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getgid.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETGID 2 +.Os BSD 4.2 +.Sh NAME +.Nm getgid , +.Nm getegid +.Nd get group process identification +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <unistd.h> +.Ft gid_t +.Fn getgid void +.Ft gid_t +.Fn getegid void +.Sh DESCRIPTION +The +.Fn getgid +function returns the real group ID of the calling process, +.Fn getegid +returns the effective group ID of the calling process. +.Pp +The real group ID is specified at login time. +.Pp +The real group ID is the group of the user who invoked the program. +As the effective group ID gives the process additional permissions +during the execution of +.Dq Em set-group-ID +mode processes, +.Fn getgid +is used to determine the real-user-id of the calling process. +.Sh ERRORS +The +.Fn getgid +and +.Fn getegid +functions are always successful, and no return value is reserved to +indicate an error. +.Sh SEE ALSO +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr setgid 2 , +.Xr setregid 2 +.Sh STANDARDS +The +.Fn getgid +and +.Fn getegid +function calls are expected to conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/getgroups.2 b/lib/libc/sys/getgroups.2 new file mode 100644 index 0000000..ab1d029 --- /dev/null +++ b/lib/libc/sys/getgroups.2 @@ -0,0 +1,96 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getgroups.2 8.2 (Berkeley) 4/16/94 +.\" $FreeBSD$ +.\" +.Dd March 5, 1999 +.Dt GETGROUPS 2 +.Os BSD 4.2 +.Sh NAME +.Nm getgroups +.Nd get group access list +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <unistd.h> +.Ft int +.Fn getgroups "int gidsetlen" "gid_t *gidset" +.Sh DESCRIPTION +.Fn Getgroups +gets the current group access list of the user process +and stores it in the array +.Fa gidset . +The parameter +.Fa gidsetlen +indicates the number of entries that may be placed in +.Fa gidset . +.Fn Getgroups +returns the actual number of groups returned in +.Fa gidset . +No more than +.Dv NGROUPS_MAX +will ever +be returned. +If +.Fa gidsetlen +is zero, +.Fn getgroups +returns the number of supplementary group IDs associated with +the calling process without modifying the array pointed to by +.Fa gidset . +.Sh RETURN VALUES +A successful call returns the number of groups in the group set. +A value of -1 indicates that an error occurred, and the error +code is stored in the global variable +.Va errno . +.Sh ERRORS +The possible errors for +.Fn getgroups +are: +.Bl -tag -width Er +.It Bq Er EINVAL +The argument +.Fa gidsetlen +is smaller than the number of groups in the group set. +.It Bq Er EFAULT +The argument +.Fa gidset +specifies +an invalid address. +.El +.Sh SEE ALSO +.Xr setgroups 2 , +.Xr initgroups 3 +.Sh HISTORY +The +.Fn getgroups +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getitimer.2 b/lib/libc/sys/getitimer.2 new file mode 100644 index 0000000..b60349a --- /dev/null +++ b/lib/libc/sys/getitimer.2 @@ -0,0 +1,177 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getitimer.2 8.3 (Berkeley) 5/16/95 +.\" $FreeBSD$ +.\" +.Dd May 16, 1995 +.Dt GETITIMER 2 +.Os BSD 4.2 +.Sh NAME +.Nm getitimer , +.Nm setitimer +.Nd get/set value of interval timer +.Sh SYNOPSIS +.Fd #include <sys/time.h> +.Fd #define ITIMER_REAL 0 +.Fd #define ITIMER_VIRTUAL 1 +.Fd #define ITIMER_PROF 2 +.Ft int +.Fn getitimer "int which" "struct itimerval *value" +.Ft int +.Fn setitimer "int which" "const struct itimerval *value" "struct itimerval *ovalue" +.Sh DESCRIPTION +The system provides each process with three interval timers, +defined in +.Ao Pa sys/time.h Ac . +The +.Fn getitimer +call returns the current value for the timer specified in +.Fa which +in the structure at +.Fa value . +The +.Fn setitimer +call sets a timer to the specified +.Fa value +(returning the previous value of the timer if +.Fa ovalue +is non-nil). +.Pp +A timer value is defined by the +.Fa itimerval +structure: +.Bd -literal -offset indent +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; +.Ed +.Pp +If +.Fa it_value +is non-zero, it indicates the time to the next timer expiration. +If +.Fa it_interval +is non-zero, it specifies a value to be used in reloading +.Fa it_value +when the timer expires. +Setting +.Fa it_value +to 0 disables a timer, regardless of the value of +.Fa it_interval . +Setting +.Fa it_interval +to 0 causes a timer to be disabled after its next expiration (assuming +.Fa it_value +is non-zero). +.Pp +Time values smaller than the resolution of the +system clock are rounded up to this resolution +(typically 10 milliseconds). +.Pp +The +.Dv ITIMER_REAL +timer decrements in real time. A +.Dv SIGALRM +signal is +delivered when this timer expires. +.Pp +The +.Dv ITIMER_VIRTUAL +timer decrements in process virtual time. +It runs only when the process is executing. A +.Dv SIGVTALRM +signal +is delivered when it expires. +.Pp +The +.Dv ITIMER_PROF +timer decrements both in process virtual time and +when the system is running on behalf of the process. It is designed +to be used by interpreters in statistically profiling the execution +of interpreted programs. +Each time the +.Dv ITIMER_PROF +timer expires, the +.Dv SIGPROF +signal is +delivered. Because this signal may interrupt in-progress +system calls, programs using this timer must be prepared to +restart interrupted system calls. +.Pp +The maximum number of seconds allowed for +.Fa it_interval +and +.Fa it_value +in +.Fn setitimer +is 100000000. +.Sh NOTES +Three macros for manipulating time values are defined in +.Ao Pa sys/time.h Ac . +.Fa Timerclear +sets a time value to zero, +.Fa timerisset +tests if a time value is non-zero, and +.Fa timercmp +compares two time values. +.Sh RETURN VALUES +If the calls succeed, a value of 0 is returned. If an error occurs, +the value -1 is returned, and a more precise error code is placed +in the global variable +.Va errno . +.Sh ERRORS +.Fn Getitimer +and +.Fn setitimer +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa value +parameter specified a bad address. +.It Bq Er EINVAL +A +.Fa value +parameter specified a time that was too large +to be handled. +.El +.Sh SEE ALSO +.Xr gettimeofday 2 , +.Xr select 2 , +.Xr sigvec 2 , +.Xr clocks 7 +.Sh HISTORY +The +.Fn getitimer +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getlogin.2 b/lib/libc/sys/getlogin.2 new file mode 100644 index 0000000..122431d5 --- /dev/null +++ b/lib/libc/sys/getlogin.2 @@ -0,0 +1,186 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getlogin.2 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD$ +.\" +.Dd June 9, 1993 +.Dt GETLOGIN 2 +.Os BSD 4.4 +.Sh NAME +.Nm getlogin , +.Nm getlogin_r , +.Nm setlogin +.Nd get/set login name +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft char * +.Fn getlogin void +.Fd #include <sys/param.h> +.Ft char * +.Fn getlogin_r "char *name" "int len" +.Ft int +.Fn setlogin "const char *name" +.Sh DESCRIPTION +The +.Fn getlogin +routine +returns the login name of the user associated with the current session, +as previously set by +.Fn setlogin . +The name is normally associated with a login shell +at the time a session is created, +and is inherited by all processes descended from the login shell. +(This is true even if some of those processes assume another user ID, +for example when +.Xr su 1 +is used). +.Pp +.Fn getlogin_r +provides the same service as +.Fn getlogin +except the caller must provide the buffer +.Fa name +with length +.Fa len +bytes +to hold the result. The buffer should be at least +.Dv MAXLOGNAME +bytes in length. +.Pp +.Fn Setlogin +sets the login name of the user associated with the current session to +.Fa name . +This call is restricted to the super-user, and +is normally used only when a new session is being created on behalf +of the named user +(for example, at login time, or when a remote shell is invoked). +.Pp +.Em NOTE: +There is only one `login name' per `session . +.Pp +It is +.Em CRITICALLY +important to ensure that +.Fn setlogin +is only ever called after the process has taken adequate steps to ensure +that it is detached from its parent's session. +Making a +.Fn setsid +system call is the +.Em ONLY +way to do this. The +.Fn daemon +library call calls +.Fn setsid +which is an ideal way of detaching from a controlling terminal and +forking into the background. +.Pp +In particular, doing a +.Fn ioctl ttyfd TIOCNOTTY ... +or +.Fn setpgrp ... +is +.Em NOT +sufficient. +.Pp +Once a parent process does a +.Fn setsid +call, it is acceptable for some child of that process to then do a +.Fn setlogin +even though it is not the session leader, but beware that ALL processes +in the session will change their login name at the same time, even the +parent. +.Pp +This is not the same as the traditional UNIX behavior of inheriting privilege. +.Pp +Since the +.Fn setlogin +system call is restricted to the super-user, it is assumed that (like +all other privileged programs) the programmer has taken adequate +precautions to prevent security violations. +.Sh RETURN VALUES +If a call to +.Fn getlogin +succeeds, it returns a pointer to a null-terminated string in a static buffer. +.Fn getlogin_r +returns a pointer to the buffer passed in by the caller on success. +Both return +.Dv NULL +if the name has not been set. +.Pp +If a call to +.Fn setlogin +succeeds, a value of 0 is returned. If +.Fn setlogin +fails, a value of -1 is returned and an error code is +placed in the global location +.Va errno . +.Sh ERRORS +The following errors may be returned by these calls: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa name +parameter gave an +invalid address. +.It Bq Er EINVAL +The +.Fa name +parameter +pointed to a string that was too long. +Login names are limited to +.Dv MAXLOGNAME +(from +.Ao Pa sys/param.h Ac ) +characters, currently 17 including null. +.It Bq Er EPERM +The caller tried to set the login name and was not the super-user. +.El +.Sh SEE ALSO +.Xr setsid 2 , +.Xr daemon 3 +.Sh BUGS +In earlier versions of the system, +.Fn getlogin +failed unless the process was associated with a login terminal. +The current implementation (using +.Fn setlogin ) +allows getlogin to succeed even when the process has no controlling terminal. +In earlier versions of the system, the value returned by +.Fn getlogin +could not be trusted without checking the user ID. +Portable programs should probably still make this check. +.Sh HISTORY +The +.Fn getlogin +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/getpeername.2 b/lib/libc/sys/getpeername.2 new file mode 100644 index 0000000..109d195 --- /dev/null +++ b/lib/libc/sys/getpeername.2 @@ -0,0 +1,114 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getpeername.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETPEERNAME 2 +.Os BSD 4.2 +.Sh NAME +.Nm getpeername +.Nd get name of connected peer +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn getpeername "int s" "struct sockaddr *name" "socklen_t *namelen" +.Sh DESCRIPTION +.Fn Getpeername +returns the name of the peer connected to +socket +.Fa s . +The +.Fa namelen +parameter should be initialized to indicate +the amount of space pointed to by +.Fa name . +On return it contains the actual size of the name +returned (in bytes). +The name is truncated if the buffer provided is too small. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn getpeername +is implemented as the +.Va getpeername +syscall. +.Pp +In the threaded library, the +.Va getpeername +syscall is assembled to +.Fn _thread_sys_getpeername +and +.Fn getpeername +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_getpeername . +Before returning, +.Fn getpeername +unlocks +.Va s . +.Sh RETURN VALUES +A 0 is returned if the call succeeds, -1 if it fails. +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width ENOTSOCKAA +.It Bq Er EBADF +The argument +.Fa s +is not a valid descriptor. +.It Bq Er ENOTSOCK +The argument +.Fa s +is a file, not a socket. +.It Bq Er ENOTCONN +The socket is not connected. +.It Bq Er ENOBUFS +Insufficient resources were available in the system +to perform the operation. +.It Bq Er EFAULT +The +.Fa name +parameter points to memory not in a valid part of the +process address space. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr bind 2 , +.Xr getsockname 2 , +.Xr socket 2 +.Sh HISTORY +The +.Fn getpeername +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getpgrp.2 b/lib/libc/sys/getpgrp.2 new file mode 100644 index 0000000..9f5ba3e --- /dev/null +++ b/lib/libc/sys/getpgrp.2 @@ -0,0 +1,123 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getpgrp.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETPGRP 2 +.Os BSD 4.2 +.Sh NAME +.Nm getpgrp +.Nd get process group +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft pid_t +.Fn getpgrp void +.Ft pid_t +.Fn getpgid "pid_t pid" +.Sh DESCRIPTION +The process group of the current process is returned by +.Fn getpgrp . +The process group of the process identified by +.Fa pid +is returned by +.Fn getpgid . +If +.Fa pid +is zero, +.Fn getpgid +returns the process group of the current process. +.Pp +Process groups are used for distribution of signals, and +by terminals to arbitrate requests for their input: processes +that have the same process group as the terminal are foreground +and may read, while others will block with a signal if they attempt +to read. +.Pp +This call is thus used by programs such as +.Xr csh 1 +to create +process groups +in implementing job control. +The +.Fn tcgetpgrp +and +.Fn tcsetpgrp +calls +are used to get/set the process group of the control terminal. +.Sh SEE ALSO +.Xr getsid 2 , +.Xr setpgid 2 , +.Xr termios 4 +.Sh HISTORY +The +.Fn getpgrp +function call appeared in +.Bx 4.0 . +The +.Fn getpgid +function call is derived from it's usage in System V Release 4. +.Sh STANDARDS +The +.Fn getpgrp +function call is expected to conform to +.St -p1003.1-90 . +.Sh COMPATIBILITY +This version of +.Fn getpgrp +differs from past Berkeley versions by not taking a +.Fa "pid_t pid" +argument. +This incompatibility is required by +.St -p1003.1-90 . +.Pp +From the +.St -p1003.1-90 +Rationale: +.Pp +.Bx 4.3 +provides a +.Fn getpgrp +function that returns the process group ID for a specified process. +Although this function is used to support job control, all known +job-control shells always specify the calling process with this +function. +Thus, the simpler +.At V +.Fn getpgrp +suffices, and the added complexity of the +.Bx 4.3 +.Fn getpgrp +has been omitted from POSIX.1. +The old functionality is available from the +.Fn getpgid +function. diff --git a/lib/libc/sys/getpid.2 b/lib/libc/sys/getpid.2 new file mode 100644 index 0000000..5a282b1 --- /dev/null +++ b/lib/libc/sys/getpid.2 @@ -0,0 +1,80 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getpid.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETPID 2 +.Os BSD 4 +.Sh NAME +.Nm getpid , +.Nm getppid +.Nd get parent or calling process identification +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <unistd.h> +.Ft pid_t +.Fn getpid void +.Ft pid_t +.Fn getppid void +.Sh DESCRIPTION +.Fn Getpid +returns +the process ID of +the calling process. +The ID is guaranteed to be unique and is +useful for constructing temporary file names. +.Pp +.Fn Getppid +returns the process ID of the parent +of the calling process. +.Sh ERRORS +The +.Fn getpid +and +.Fn getppid +functions are always successful, and no return value is reserved to +indicate an error. +.Sh SEE ALSO +.Xr gethostid 3 +.Sh STANDARDS +The +.Fn getpid +and +.Fn getppid +function calls are expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn getpid +function call appeared in +.At v7 . diff --git a/lib/libc/sys/getpriority.2 b/lib/libc/sys/getpriority.2 new file mode 100644 index 0000000..3a6eee4 --- /dev/null +++ b/lib/libc/sys/getpriority.2 @@ -0,0 +1,143 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getpriority.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETPRIORITY 2 +.Os BSD 4 +.Sh NAME +.Nm getpriority , +.Nm setpriority +.Nd get/set program scheduling priority +.Sh SYNOPSIS +.Fd #include <sys/time.h> +.Fd #include <sys/resource.h> +.Ft int +.Fn getpriority "int which" "int who" +.Ft int +.Fn setpriority "int which" "int who" "int prio" +.Sh DESCRIPTION +The scheduling +priority of the process, process group, or user, as indicated by +.Fa which +and +.Fa who +is obtained with the +.Fn getpriority +call and set with the +.Fn setpriority +call. +.Fa Which +is one of +.Dv PRIO_PROCESS , +.Dv PRIO_PGRP , +or +.Dv PRIO_USER , +and +.Fa who +is interpreted relative to +.Fa which +(a process identifier for +.Dv PRIO_PROCESS , +process group +identifier for +.Dv PRIO_PGRP , +and a user ID for +.Dv PRIO_USER ) . +A zero value of +.Fa who +denotes the current process, process group, or user. +.Fa Prio +is a value in the range -20 to 20. The default priority is 0; +lower priorities cause more favorable scheduling. +.Pp +The +.Fn getpriority +call returns the highest priority (lowest numerical value) +enjoyed by any of the specified processes. The +.Fn setpriority +call sets the priorities of all of the specified processes +to the specified value. Only the super-user may lower priorities. +.Sh RETURN VALUES +Since +.Fn getpriority +can legitimately return the value -1, it is necessary +to clear the external variable +.Va errno +prior to the +call, then check it afterward to determine +if a -1 is an error or a legitimate value. +The +.Fn setpriority +call returns 0 if there is no error, or +-1 if there is. +.Sh ERRORS +.Fn Getpriority +and +.Fn setpriority +will fail if: +.Bl -tag -width Er +.It Bq Er ESRCH +No process was located using the +.Fa which +and +.Fa who +values specified. +.It Bq Er EINVAL +.Fa Which +was not one of +.Dv PRIO_PROCESS , +.Dv PRIO_PGRP , +or +.Dv PRIO_USER . +.El +.Pp +.Bl -tag -width Er +In addition to the errors indicated above, +.Fn setpriority +will fail if: +.It Bq Er EPERM +A process was located, but neither its effective nor real user +ID matched the effective user ID of the caller. +.It Bq Er EACCES +A non super-user attempted to lower a process priority. +.El +.Sh SEE ALSO +.Xr nice 1 , +.Xr fork 2 , +.Xr renice 8 +.Sh HISTORY +The +.Fn getpriority +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2 new file mode 100644 index 0000000..eebb874 --- /dev/null +++ b/lib/libc/sys/getrlimit.2 @@ -0,0 +1,188 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETRLIMIT 2 +.Os BSD 4 +.Sh NAME +.Nm getrlimit , +.Nm setrlimit +.Nd control maximum system resource consumption +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/time.h> +.Fd #include <sys/resource.h> +.Ft int +.Fn getrlimit "int resource" "struct rlimit *rlp" +.Ft int +.Fn setrlimit "int resource" "const struct rlimit *rlp" +.Sh DESCRIPTION +Limits on the consumption of system resources by the current process +and each process it creates may be obtained with the +.Fn getrlimit +call, and set with the +.Fn setrlimit +call. +.Pp +The +.Fa resource +parameter is one of the following: +.Bl -tag -width RLIMIT_FSIZEAA +.It Li RLIMIT_CORE +The largest size (in bytes) +.Xr core 5 +file that may be created. +.It Li RLIMIT_CPU +The maximum amount of cpu time (in seconds) to be used by +each process. +.It Li RLIMIT_DATA +The maximum size (in bytes) of the data segment for a process; +this defines how far a program may extend its break with the +.Xr sbrk 2 +system call. +.It Li RLIMIT_FSIZE +The largest size (in bytes) file that may be created. +.It Li RLIMIT_MEMLOCK +The maximum size (in bytes) which a process may lock into memory +using the +.Xr mlock 2 +function. +.It Li RLIMIT_NOFILE +The maximum number of open files for this process. +.It Li RLIMIT_NPROC +The maximum number of simultaneous processes for this user id. +.It Li RLIMIT_RSS +The maximum size (in bytes) to which a process's resident set size may +grow. +This imposes a limit on the amount of physical memory to be given to +a process; if memory is tight, the system will prefer to take memory +from processes that are exceeding their declared resident set size. +.It Li RLIMIT_STACK +The maximum size (in bytes) of the stack segment for a process; +this defines how far a program's stack segment may be extended. +Stack extension is performed automatically by the system. +.It Li RLIMIT_SBSIZE +The maximum size (in bytes) of socket buffer usage for this user. +This limits the amount of network memory, and hence the amount of +mbufs, that this user may hold at any time. +.El +.Pp +A resource limit is specified as a soft limit and a hard limit. When a +soft limit is exceeded a process may receive a signal (for example, if +the cpu time or file size is exceeded), but it will be allowed to +continue execution until it reaches the hard limit (or modifies +its resource limit). The +.Em rlimit +structure is used to specify the hard and soft limits on a resource, +.Bd -literal -offset indent +struct rlimit { + rlim_t rlim_cur; /* current (soft) limit */ + rlim_t rlim_max; /* maximum value for rlim_cur */ +}; +.Ed +.Pp +Only the super-user may raise the maximum limits. Other users +may only alter +.Fa rlim_cur +within the range from 0 to +.Fa rlim_max +or (irreversibly) lower +.Fa rlim_max . +.Pp +An +.Dq infinite +value for a limit is defined as +.Dv RLIM_INFINITY . +.Pp +Because this information is stored in the per-process information, +this system call must be executed directly by the shell if it +is to affect all future processes created by the shell; +.Ic limit +is thus a built-in command to +.Xr csh 1 . +.Pp +The system refuses to extend the data or stack space when the limits +would be exceeded in the normal way: a +.Xr brk 2 +call fails if the data space limit is reached. +When the stack limit is reached, the process receives +a segmentation fault +.Pq Dv SIGSEGV ; +if this signal is not +caught by a handler using the signal stack, this signal +will kill the process. +.Pp +A file I/O operation that would create a file larger that the process' +soft limit will cause the write to fail and a signal +.Dv SIGXFSZ +to be +generated; this normally terminates the process, but may be caught. When +the soft cpu time limit is exceeded, a signal +.Dv SIGXCPU +is sent to the +offending process. +.Sh RETURN VALUES +A 0 return value indicates that the call succeeded, changing +or returning the resource limit. A return value of -1 indicates +that an error occurred, and an error code is stored in the global +location +.Va errno . +.Sh ERRORS +.Fn Getrlimit +and +.Fn setrlimit +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +The address specified for +.Fa rlp +is invalid. +.It Bq Er EPERM +The limit specified to +.Fn setrlimit +would have +raised the maximum limit value, and the caller is not the super-user. +.El +.Sh SEE ALSO +.Xr csh 1 , +.Xr quota 1 , +.Xr quotactl 2 , +.Xr sigaltstack 2 , +.Xr sigvec 2 , +.Xr sysctl 3 +.Sh HISTORY +The +.Fn getrlimit +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getrusage.2 b/lib/libc/sys/getrusage.2 new file mode 100644 index 0000000..dcbda2d --- /dev/null +++ b/lib/libc/sys/getrusage.2 @@ -0,0 +1,177 @@ +.\" Copyright (c) 1985, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getrusage.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETRUSAGE 2 +.Os BSD 4 +.Sh NAME +.Nm getrusage +.Nd get information about resource utilization +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/time.h> +.Fd #include <sys/resource.h> +.Fd #define RUSAGE_SELF 0 +.Fd #define RUSAGE_CHILDREN -1 +.Ft int +.Fn getrusage "int who" "struct rusage *rusage" +.Sh DESCRIPTION +.Fn Getrusage +returns information describing the resources utilized by the current +process, or all its terminated child processes. +The +.Fa who +parameter is either +.Dv RUSAGE_SELF +or +.Dv RUSAGE_CHILDREN . +The buffer to which +.Fa rusage +points will be filled in with +the following structure: +.Bd -literal +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ + long ru_maxrss; /* max resident set size */ + long ru_ixrss; /* integral shared text memory size */ + long ru_idrss; /* integral unshared data size */ + long ru_isrss; /* integral unshared stack size */ + long ru_minflt; /* page reclaims */ + long ru_majflt; /* page faults */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary context switches */ +}; +.Ed +.Pp +The fields are interpreted as follows: +.Bl -tag -width ru_minfltaa +.It Fa ru_utime +the total amount of time spent executing in user mode. +.It Fa ru_stime +the total amount of time spent in the system executing on behalf +of the process(es). +.It Fa ru_maxrss +the maximum resident set size utilized (in kilobytes). +.It Fa ru_ixrss +an \*(lqintegral\*(rq value indicating the amount of memory used +by the text segment +that was also shared among other processes. This value is expressed +in units of kilobytes * ticks-of-execution. +Ticks are statistics clock ticks. +The statistics clock has a frequency of +.Fn sysconf _SC_CLOCK_TCK +ticks per second. +.It Fa ru_idrss +an integral value of the amount of unshared memory residing in the +data segment of a process (expressed in units of +kilobytes * ticks-of-execution). +.It Fa ru_isrss +an integral value of the amount of unshared memory residing in the +stack segment of a process (expressed in units of +kilobytes * ticks-of-execution). +.It Fa ru_minflt +the number of page faults serviced without any I/O activity; here +I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from +the list of pages awaiting reallocation. +.It Fa ru_majflt +the number of page faults serviced that required I/O activity. +.It Fa ru_nswap +the number of times a process was \*(lqswapped\*(rq out of main +memory. +.It Fa ru_inblock +the number of times the file system had to perform input. +.It Fa ru_oublock +the number of times the file system had to perform output. +.It Fa ru_msgsnd +the number of IPC messages sent. +.It Fa ru_msgrcv +the number of IPC messages received. +.It Fa ru_nsignals +the number of signals delivered. +.It Fa ru_nvcsw +the number of times a context switch resulted due to a process +voluntarily giving up the processor before its time slice was +completed (usually to await availability of a resource). +.It Fa ru_nivcsw +the number of times a context switch resulted due to a higher +priority process becoming runnable or because the current process +exceeded its time slice. +.El +.Sh NOTES +The numbers +.Fa ru_inblock +and +.Fa ru_oublock +account only for real +I/O; data supplied by the caching mechanism is charged only +to the first process to read or write the data. +.Sh RETURN VALUES +Upon successful completion, +.Fn getrusage +returns 0. Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn getrusage +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa who +parameter is not a valid value. +.It Bq Er EFAULT +The address specified by the +.Fa rusage +parameter is not in a valid part of the process address space. +.El +.Sh SEE ALSO +.Xr gettimeofday 2 , +.Xr wait 2 , +.Xr clocks 7 +.Sh BUGS +There is no way to obtain information about a child process +that has not yet terminated. +.Sh HISTORY +The +.Fn getrusage +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getsid.2 b/lib/libc/sys/getsid.2 new file mode 100644 index 0000000..4a7f13e --- /dev/null +++ b/lib/libc/sys/getsid.2 @@ -0,0 +1,77 @@ +.\" Copyright (c) 1997 Peter Wemm <peter@freebsd.org> +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd August 19, 1997 +.Dt GETSID 2 +.Os BSD 4.2 +.Sh NAME +.Nm getsid +.Nd get process session +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft pid_t +.Fn getsid "pid_t pid" +.Sh DESCRIPTION +The session ID of the process identified by +.Fa pid +is returned by +.Fn getsid . +If +.Fa pid +is zero, +.Fn getsid +returns the session ID of the current process. +.Sh RETURN VALUES +Upon successful completion, the function +.Fn getsid +returns the session ID of +the specified process; otherwise, it returns a value of -1 and +sets errno to indicate an error. +.Sh ERRORS +.Fn getsid +will succeed unless: +.Bl -tag -width Er +.It Bq Er ESRCH +if there is no process with a process ID equal to +.Fa pid . +.El +.Pp +Note that an implementation may restrict this function call to +processes within the same session ID as the calling process. +.Sh SEE ALSO +.Xr getpgid 2 , +.Xr getpgrp 2 , +.Xr setpgid 2 , +.Xr setsid 2 , +.Xr termios 4 +.Sh HISTORY +The +.Fn setsid +function call appeared in +.Fx 3.0 . +The +.Fn getsid +function call is derived from it's usage in +.At V . diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2 new file mode 100644 index 0000000..9355596 --- /dev/null +++ b/lib/libc/sys/getsockname.2 @@ -0,0 +1,113 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getsockname.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETSOCKNAME 2 +.Os BSD 4.2 +.Sh NAME +.Nm getsockname +.Nd get socket name +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn getsockname "int s" "struct sockaddr *name" "socklen_t *namelen" +.Sh DESCRIPTION +.Fn Getsockname +returns the current +.Fa name +for the specified socket. The +.Fa namelen +parameter should be initialized to indicate +the amount of space pointed to by +.Fa name . +On return it contains the actual size of the name +returned (in bytes). +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn getsockname +is implemented as the +.Va getsockname +syscall. +.Pp +In the threaded library, the +.Va getsockname +syscall is assembled to +.Fn _thread_sys_getsockname +and +.Fn getsockname +is implemented as a function which locks +.Va fd +for read and write, then calls +.Fn _thread_sys_getsockname . +Before returning, +.Fn getsockname +unlocks +.Va fd . +.Sh RETURN VALUES +A 0 is returned if the call succeeds, -1 if it fails. +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width ENOTSOCKAA +.It Bq Er EBADF +The argument +.Fa s +is not a valid descriptor. +.It Bq Er ENOTSOCK +The argument +.Fa s +is a file, not a socket. +.It Bq Er ENOBUFS +Insufficient resources were available in the system +to perform the operation. +.It Bq Er EFAULT +The +.Fa name +parameter points to memory not in a valid part of the +process address space. +.El +.Sh SEE ALSO +.Xr bind 2 , +.Xr getpeername 2 , +.Xr socket 2 +.Sh BUGS +Names bound to sockets in the UNIX domain are inaccessible; +.Xr getsockname +returns a zero length name. +.Sh HISTORY +The +.Fn getsockname +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 new file mode 100644 index 0000000..db1f834 --- /dev/null +++ b/lib/libc/sys/getsockopt.2 @@ -0,0 +1,397 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 +.\" $FreeBSD$ +.\" +.Dd May 2, 1995 +.Dt GETSOCKOPT 2 +.Os BSD 4.3r +.Sh NAME +.Nm getsockopt , +.Nm setsockopt +.Nd get and set options on sockets +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn getsockopt "int s" "int level" "int optname" "void *optval" "socklen_t *optlen" +.Ft int +.Fn setsockopt "int s" "int level" "int optname" "const void *optval" "socklen_t optlen" +.Sh DESCRIPTION +.Fn Getsockopt +and +.Fn setsockopt +manipulate the +.Em options +associated with a socket. Options may exist at multiple +protocol levels; they are always present at the uppermost +.Dq socket +level. +.Pp +When manipulating socket options the level at which the +option resides and the name of the option must be specified. +To manipulate options at the socket level, +.Fa level +is specified as +.Dv SOL_SOCKET . +To manipulate options at any +other level the protocol number of the appropriate protocol +controlling the option is supplied. For example, +to indicate that an option is to be interpreted by the +.Tn TCP +protocol, +.Fa level +should be set to the protocol number of +.Tn TCP ; +see +.Xr getprotoent 3 . +.Pp +The parameters +.Fa optval +and +.Fa optlen +are used to access option values for +.Fn setsockopt . +For +.Fn getsockopt +they identify a buffer in which the value for the +requested option(s) are to be returned. For +.Fn getsockopt , +.Fa optlen +is a value-result parameter, initially containing the +size of the buffer pointed to by +.Fa optval , +and modified on return to indicate the actual size of +the value returned. If no option value is +to be supplied or returned, +.Fa optval +may be NULL. +.Pp +.Fa Optname +and any specified options are passed uninterpreted to the appropriate +protocol module for interpretation. +The include file +.Ao Pa sys/socket.h Ac +contains definitions for +socket level options, described below. +Options at other protocol levels vary in format and +name; consult the appropriate entries in +section +4 of the manual. +.Pp +Most socket-level options utilize an +.Fa int +parameter for +.Fa optval . +For +.Fn setsockopt , +the parameter should be non-zero to enable a boolean option, +or zero if the option is to be disabled. +.Dv SO_LINGER +uses a +.Fa struct linger +parameter, defined in +.Ao Pa sys/socket.h Ac , +which specifies the desired state of the option and the +linger interval (see below). +.Dv SO_SNDTIMEO +and +.Dv SO_RCVTIMEO +use a +.Fa struct timeval +parameter, defined in +.Ao Pa sys/time.h Ac . +.Pp +The following options are recognized at the socket level. +Except as noted, each may be examined with +.Fn getsockopt +and set with +.Fn setsockopt . +.Bl -column SO_OOBINLINE -offset indent +.It Dv SO_DEBUG Ta "enables recording of debugging information" +.It Dv SO_REUSEADDR Ta "enables local address reuse" +.It Dv SO_REUSEPORT Ta "enables duplicate address and port bindings" +.It Dv SO_KEEPALIVE Ta "enables keep connections alive" +.It Dv SO_DONTROUTE Ta "enables routing bypass for outgoing messages" +.It Dv SO_LINGER Ta "linger on close if data present" +.It Dv SO_BROADCAST Ta "enables permission to transmit broadcast messages" +.It Dv SO_OOBINLINE Ta "enables reception of out-of-band data in band" +.It Dv SO_SNDBUF Ta "set buffer size for output" +.It Dv SO_RCVBUF Ta "set buffer size for input" +.It Dv SO_SNDLOWAT Ta "set minimum count for output" +.It Dv SO_RCVLOWAT Ta "set minimum count for input" +.It Dv SO_SNDTIMEO Ta "set timeout value for output" +.It Dv SO_RCVTIMEO Ta "set timeout value for input" +.It Dv SO_TYPE Ta "get the type of the socket (get only)" +.It Dv SO_ERROR Ta "get and clear error on the socket (get only)" +.El +.Pp +.Dv SO_DEBUG +enables debugging in the underlying protocol modules. +.Dv SO_REUSEADDR +indicates that the rules used in validating addresses supplied +in a +.Xr bind 2 +call should allow reuse of local addresses. +.Dv SO_REUSEPORT +allows completely duplicate bindings by multiple processes +if they all set +.Dv SO_REUSEPORT +before binding the port. +This option permits multiple instances of a program to each +receive UDP/IP multicast or broadcast datagrams destined for the bound port. +.Dv SO_KEEPALIVE +enables the +periodic transmission of messages on a connected socket. Should the +connected party fail to respond to these messages, the connection is +considered broken and processes using the socket are notified via a +.Dv SIGPIPE +signal when attempting to send data. +.Dv SO_DONTROUTE +indicates that outgoing messages should +bypass the standard routing facilities. Instead, messages are directed +to the appropriate network interface according to the network portion +of the destination address. +.Pp +.Dv SO_LINGER +controls the action taken when unsent messages +are queued on socket and a +.Xr close 2 +is performed. +If the socket promises reliable delivery of data and +.Dv SO_LINGER is set, +the system will block the process on the +.Xr close 2 +attempt until it is able to transmit the data or until it decides it +is unable to deliver the information (a timeout period, termed the +linger interval, is specified in seconds in the +.Fn setsockopt +call when +.Dv SO_LINGER +is requested). +If +.Dv SO_LINGER +is disabled and a +.Xr close 2 +is issued, the system will process the close in a manner that allows +the process to continue as quickly as possible. +.Pp +The option +.Dv SO_BROADCAST +requests permission to send broadcast datagrams +on the socket. +Broadcast was a privileged operation in earlier versions of the system. +With protocols that support out-of-band data, the +.Dv SO_OOBINLINE +option +requests that out-of-band data be placed in the normal data input queue +as received; it will then be accessible with +.Xr recv 2 +or +.Xr read 2 +calls without the +.Dv MSG_OOB +flag. +Some protocols always behave as if this option is set. +.Dv SO_SNDBUF +and +.Dv SO_RCVBUF +are options to adjust the normal +buffer sizes allocated for output and input buffers, respectively. +The buffer size may be increased for high-volume connections, +or may be decreased to limit the possible backlog of incoming data. +The system places an absolute maximum on these values, which is accessible +through the +.Xr sysctl 3 +MIB variable +.Dq Li kern.ipc.maxsockbuf . +.Pp +.Dv SO_SNDLOWAT +is an option to set the minimum count for output operations. +Most output operations process all of the data supplied +by the call, delivering data to the protocol for transmission +and blocking as necessary for flow control. +Nonblocking output operations will process as much data as permitted +subject to flow control without blocking, but will process no data +if flow control does not allow the smaller of the low water mark value +or the entire request to be processed. +A +.Xr select 2 +operation testing the ability to write to a socket will return true +only if the low water mark amount could be processed. +The default value for +.Dv SO_SNDLOWAT +is set to a convenient size for network efficiency, often 1024. +.Dv SO_RCVLOWAT +is an option to set the minimum count for input operations. +In general, receive calls will block until any (non-zero) amount of data +is received, then return with the smaller of the amount available or the amount +requested. +The default value for +.Dv SO_RCVLOWAT +is 1. +If +.Dv SO_RCVLOWAT +is set to a larger value, blocking receive calls normally +wait until they have received the smaller of the low water mark value +or the requested amount. +Receive calls may still return less than the low water mark if an error +occurs, a signal is caught, or the type of data next in the receive queue +is different from that which was returned. +.Pp +.Dv SO_SNDTIMEO +is an option to set a timeout value for output operations. +It accepts a +.Fa struct timeval +parameter with the number of seconds and microseconds +used to limit waits for output operations to complete. +If a send operation has blocked for this much time, +it returns with a partial count +or with the error +.Er EWOULDBLOCK +if no data were sent. +In the current implementation, this timer is restarted each time additional +data are delivered to the protocol, +implying that the limit applies to output portions ranging in size +from the low water mark to the high water mark for output. +.Dv SO_RCVTIMEO +is an option to set a timeout value for input operations. +It accepts a +.Fa struct timeval +parameter with the number of seconds and microseconds +used to limit waits for input operations to complete. +In the current implementation, this timer is restarted each time additional +data are received by the protocol, +and thus the limit is in effect an inactivity timer. +If a receive operation has been blocked for this much time without +receiving additional data, it returns with a short count +or with the error +.Er EWOULDBLOCK +if no data were received. +.Pp +Finally, +.Dv SO_TYPE +and +.Dv SO_ERROR +are options used only with +.Fn getsockopt . +.Dv SO_TYPE +returns the type of the socket, such as +.Dv SOCK_STREAM ; +it is useful for servers that inherit sockets on startup. +.Dv SO_ERROR +returns any pending error on the socket and clears +the error status. +It may be used to check for asynchronous errors on connected +datagram sockets or for other asynchronous errors. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn getsockopt +is implemented as the +.Va getsockopt +syscall. +.Pp +In the threaded library, the +.Va getsockopt +syscall is assembled to +.Fn _thread_sys_getsockopt +and +.Fn getsockopt +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_getsockopt . +Before returning, +.Fn getsockopt +unlocks +.Va s . +.Pp +In the non-threaded library +.Fn setsockopt +is implemented as the +.Va setsockopt +syscall. +.Pp +In the threaded library, the +.Va setsockopt +syscall is assembled to +.Fn _thread_sys_setsockopt +and +.Fn setsockopt +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_setsockopt . +Before returning, +.Fn setsockopt +unlocks +.Va s . +.Sh RETURN VALUES +A 0 is returned if the call succeeds, -1 if it fails. +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width ENOPROTOOPTAA +.It Bq Er EBADF +The argument +.Fa s +is not a valid descriptor. +.It Bq Er ENOTSOCK +The argument +.Fa s +is a file, not a socket. +.It Bq Er ENOPROTOOPT +The option is unknown at the level indicated. +.It Bq Er EFAULT +The address pointed to by +.Fa optval +is not in a valid part of the process address space. +For +.Fn getsockopt , +this error may also be returned if +.Fa optlen +is not in a valid part of the process address space. +.El +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr socket 2 , +.Xr getprotoent 3 , +.Xr sysctl 3 , +.Xr protocols 5 , +.Xr sysctl 8 +.Sh BUGS +Several of the socket options should be handled at lower levels of the system. +.Sh HISTORY +The +.Fn getsockopt +system call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/gettimeofday.2 b/lib/libc/sys/gettimeofday.2 new file mode 100644 index 0000000..cb385a4 --- /dev/null +++ b/lib/libc/sys/gettimeofday.2 @@ -0,0 +1,132 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)gettimeofday.2 8.2 (Berkeley) 5/26/95 +.\" $FreeBSD$ +.\" +.Dd May 26, 1995 +.Dt GETTIMEOFDAY 2 +.Os BSD 4 +.Sh NAME +.Nm gettimeofday , +.Nm settimeofday +.Nd get/set date and time +.Sh SYNOPSIS +.Fd #include <sys/time.h> +.Ft int +.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp" +.Ft int +.Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp" +.Sh DESCRIPTION +.Bf -symbolic +Note: timezone is no longer used; this information is kept outside +the kernel. +.Ef +.Pp +The system's notion of the current Greenwich time and the current time +zone is obtained with the +.Fn gettimeofday +call, and set with the +.Fn settimeofday +call. The time is expressed in seconds and microseconds +since midnight (0 hour), January 1, 1970. The resolution of the system +clock is hardware dependent, and the time may be updated continuously or +in +.Dq ticks . +If +.Fa tp +or +.Fa tzp +is NULL, the associated time +information will not be returned or set. +.Pp +The structures pointed to by +.Fa tp +and +.Fa tzp +are defined in +.Ao Pa sys/time.h Ac +as: +.Pp +.Bd -literal +struct timeval { + long tv_sec; /* seconds since Jan. 1, 1970 */ + long tv_usec; /* and microseconds */ +}; + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +.Ed +.Pp +The +.Fa timezone +structure indicates the local time zone +(measured in minutes of time westward from Greenwich), +and a flag that, if nonzero, indicates that +Daylight Saving time applies locally during +the appropriate part of the year. +.Pp +Only the super-user may set the time of day or time zone. +If the system is running in secure mode (see +.Xr init 8 ), +the time may only be advanced. +This limitation is imposed to prevent a malicious super-user +from setting arbitrary time stamps on files. +The system time can still be adjusted backwards using the +.Xr adjtime 2 +system call even when the system is secure. +.Sh RETURN +A 0 return value indicates that the call succeeded. +A -1 return value indicates an error occurred, and in this +case an error code is stored into the global variable +.Va errno . +.Sh ERRORS +The following error codes may be set in +.Va errno : +.Bl -tag -width [EFAULT] +.It Bq Er EFAULT +An argument address referenced invalid memory. +.It Bq Er EPERM +A user other than the super-user attempted to set the time. +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr adjtime 2 , +.Xr ctime 3 , +.Xr clocks 7 , +.Xr timed 8 +.Sh HISTORY +The +.Fn gettimeofday +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/getuid.2 b/lib/libc/sys/getuid.2 new file mode 100644 index 0000000..ae6c946 --- /dev/null +++ b/lib/libc/sys/getuid.2 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getuid.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt GETUID 2 +.Os BSD 4 +.Sh NAME +.Nm getuid , +.Nm geteuid +.Nd get user identification +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Fd #include <sys/types.h> +.Ft uid_t +.Fn getuid void +.Ft uid_t +.Fn geteuid void +.Sh DESCRIPTION +The +.Fn getuid +function returns the real user ID of the calling process. +The +.Fn geteuid +function +returns the effective user ID of the calling process. +.Pp +The real user ID is that of the user who has invoked the program. +As the effective user ID +gives the process additional permissions during +execution of +.Dq Em set-user-ID +mode processes, +.Fn getuid +is used to determine the real-user-id of the calling process. +.Sh ERRORS +The +.Fn getuid +and +.Fn geteuid +functions are always successful, and no return value is reserved to +indicate an error. +.Sh SEE ALSO +.Xr getgid 2 , +.Xr issetugid 2 , +.Xr setgid 2 , +.Xr setreuid 2 , +.Xr setuid 2 +.Sh STANDARDS +The +.Fn geteuid +and +.Fn getuid +function calls are expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn getuid +and a +.Fn geteuid +function call appeared in +.At v7 . diff --git a/lib/libc/sys/intro.2 b/lib/libc/sys/intro.2 new file mode 100644 index 0000000..fd978ca --- /dev/null +++ b/lib/libc/sys/intro.2 @@ -0,0 +1,712 @@ +.\" Copyright (c) 1980, 1983, 1986, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.2 8.5 (Berkeley) 2/27/95 +.\" $FreeBSD$ +.\" +.Dd February 27, 1995 +.Dt INTRO 2 +.Os BSD 4 +.Sh NAME +.Nm intro +.Nd introduction to system calls and error numbers +.Sh SYNOPSIS +.Fd #include <errno.h> +.Sh DESCRIPTION +This section provides an overview of the system calls, +their error returns, and other common definitions and concepts. +.\".Pp +.\".Sy System call restart +.\".Pp +.\"<more later...> +.Sh RETURN VALUES +Nearly all of the system calls provide an error number referenced via +the external identifier errno. This identifier is defined in +.Aq Pa sys/errno.h +as +.Pp +.Dl extern int * __error(); +.Dl #define errno (* __error()) +.Pp +The +.Va __error() +function returns a pointer to a field in the thread specific structure for +threads other than the initial thread. For the initial thread and +non-threaded processes, +.Va __error() +returns a pointer to a global +.Va errno +variable that is compatible with the previous definition. +.Pp +When a system call detects an error, +it returns an integer value +indicating failure (usually -1) +and sets the variable +.Va errno +accordingly. +<This allows interpretation of the failure on receiving +a -1 and to take action accordingly.> +Successful calls never set +.Va errno ; +once set, it remains until another error occurs. +It should only be examined after an error. +Note that a number of system calls overload the meanings of these +error numbers, and that the meanings must be interpreted according +to the type and circumstances of the call. +.Pp +The following is a complete list of the errors and their +names as given in +.Aq Pa sys/errno.h . +.Bl -hang -width Ds +.It Er 0 Em "Error 0" . +Not used. +.It Er 1 EPERM Em "Operation not permitted" . +An attempt was made to perform an operation limited to processes +with appropriate privileges or to the owner of a file or other +resources. +.It Er 2 ENOENT Em "No such file or directory" . +A component of a specified pathname did not exist, or the +pathname was an empty string. +.It Er 3 ESRCH Em "No such process" . +No process could be found corresponding to that specified by the given +process ID. +.It Er 4 EINTR Em "Interrupted function call" . +An asynchronous signal (such as +.Dv SIGINT +or +.Dv SIGQUIT ) +was caught by the process during the execution of an interruptible +function. If the signal handler performs a normal return, the +interrupted function call will seem to have returned the error condition. +.It Er 5 EIO Em "Input/output error" . +Some physical input or output error occurred. +This error will not be reported until a subsequent operation on the same file +descriptor and may be lost (over written) by any subsequent errors. +.It Er 6 ENXIO Em "\&No such device or address" . +Input or output on a special file referred to a device that did not +exist, or +made a request beyond the limits of the device. +This error may also occur when, for example, +a tape drive is not online or no disk pack is +loaded on a drive. +.It Er 7 E2BIG Em "Arg list too long" . +The number of bytes used for the argument and environment +list of the new process exceeded the current limit +of 65536 bytes +.Pf ( Dv NCARGS +in +.Aq Pa sys/param.h ) . +.It Er 8 ENOEXEC Em "Exec format error" . +A request was made to execute a file +that, although it has the appropriate permissions, +was not in the format required for an +executable file. +.It Er 9 EBADF Em "Bad file descriptor" . +A file descriptor argument was out of range, referred to no open file, +or a read (write) request was made to a file that was only open for +writing (reading). +.Pp +.It Er 10 ECHILD Em "\&No child processes" . +A +.Xr wait 2 +or +.Xr waitpid 2 +function was executed by a process that had no existing or unwaited-for +child processes. +.It Er 11 EDEADLK Em "Resource deadlock avoided" . +An attempt was made to lock a system resource that +would have resulted in a deadlock situation. +.It Er 12 ENOMEM Em "Cannot allocate memory" . +The new process image required more memory than was allowed by the hardware +or by system-imposed memory management constraints. +A lack of swap space is normally temporary; however, +a lack of core is not. +Soft limits may be increased to their corresponding hard limits. +.It Er 13 EACCES Em "Permission denied" . +An attempt was made to access a file in a way forbidden +by its file access permissions. +.It Er 14 EFAULT Em "Bad address" . +The system detected an invalid address in attempting to +use an argument of a call. +.It Er 15 ENOTBLK Em "Not a block device" . +A block device operation was attempted on a non-block device or file. +.It Er 16 EBUSY Em "Resource busy" . +An attempt to use a system resource which was in use at the time +in a manner which would have conflicted with the request. +.It Er 17 EEXIST Em "File exists" . +An existing file was mentioned in an inappropriate context, +for instance, as the new link name in a +.Xr link 2 +function. +.It Er 18 EXDEV Em "Improper link" . +A hard link to a file on another file system +was attempted. +.It Er 19 ENODEV Em "Operation not supported by device" . +An attempt was made to apply an inappropriate +function to a device, +for example, +trying to read a write-only device such as a printer. +.It Er 20 ENOTDIR Em "Not a directory" . +A component of the specified pathname existed, but it was +not a directory, when a directory was expected. +.It Er 21 EISDIR Em "Is a directory" . +An attempt was made to open a directory with write mode specified. +.It Er 22 EINVAL Em "Invalid argument" . +Some invalid argument was supplied. (For example, +specifying an undefined signal to a +.Xr signal 3 +or +.Xr kill 2 +function). +.It Er 23 ENFILE Em "Too many open files in system" . +Maximum number of file descriptors allowable on the system +has been reached and a requests for an open cannot be satisfied +until at least one has been closed. +.It Er 24 EMFILE Em "Too many open files" . +<As released, the limit on the number of +open files per process is 64.> +.Xr Getdtablesize 2 +will obtain the current limit. +.It Er 25 ENOTTY Em "Inappropriate ioctl for device" . +A control function (see +.Xr ioctl 2 ) +was attempted for a file or +special device for which the operation was inappropriate. +.It Er 26 ETXTBSY Em "Text file busy" . +The new process was a pure procedure (shared text) file +which was open for writing by another process, or +while the pure procedure file was being executed an +.Xr open 2 +call requested write access. +.It Er 27 EFBIG Em "File too large" . +The size of a file exceeded the maximum (about +.if t 2\u\s-231\s+2\d +.if n 2.1E9 +bytes). +.It Er 28 ENOSPC Em "Device out of space" . +A +.Xr write 2 +to an ordinary file, the creation of a +directory or symbolic link, or the creation of a directory +entry failed because no more disk blocks were available +on the file system, or the allocation of an inode for a newly +created file failed because no more inodes were available +on the file system. +.It Er 29 ESPIPE Em "Illegal seek" . +An +.Xr lseek 2 +function was issued on a socket, pipe or +.Tn FIFO . +.It Er 30 EROFS Em "Read-only file system" . +An attempt was made to modify a file or directory +was made +on a file system that was read-only at the time. +.It Er 31 EMLINK Em "Too many links" . +Maximum allowable hard links to a single file has been exceeded (limit +of 32767 hard links per file). +.It Er 32 EPIPE Em "Broken pipe" . +A write on a pipe, socket or +.Tn FIFO +for which there is no process +to read the data. +.It Er 33 EDOM Em "Numerical argument out of domain" . +A numerical input argument was outside the defined domain of the mathematical +function. +.It Er 34 ERANGE Em "Numerical result out of range" . +A numerical result of the function was too large to fit in the +available space (perhaps exceeded precision). +.It Er 35 EAGAIN Em "Resource temporarily unavailable" . +This is a temporary condition and later calls to the +same routine may complete normally. +.It Er 36 EINPROGRESS Em "Operation now in progress" . +An operation that takes a long time to complete (such as +a +.Xr connect 2 ) +was attempted on a non-blocking object (see +.Xr fcntl 2 ) . +.It Er 37 EALREADY Em "Operation already in progress" . +An operation was attempted on a non-blocking object that already +had an operation in progress. +.It Er 38 ENOTSOCK Em "Socket operation on non-socket" . +Self-explanatory. +.It Er 39 EDESTADDRREQ Em "Destination address required" . +A required address was omitted from an operation on a socket. +.It Er 40 EMSGSIZE Em "Message too long" . +A message sent on a socket was larger than the internal message buffer +or some other network limit. +.It Er 41 EPROTOTYPE Em "Protocol wrong type for socket" . +A protocol was specified that does not support the semantics of the +socket type requested. For example, you cannot use the +.Tn ARPA +Internet +.Tn UDP +protocol with type +.Dv SOCK_STREAM . +.It Er 42 ENOPROTOOPT Em "Protocol not available" . +A bad option or level was specified in a +.Xr getsockopt 2 +or +.Xr setsockopt 2 +call. +.It Er 43 EPROTONOSUPPORT Em "Protocol not supported" . +The protocol has not been configured into the +system or no implementation for it exists. +.It Er 44 ESOCKTNOSUPPORT Em "Socket type not supported" . +The support for the socket type has not been configured into the +system or no implementation for it exists. +.It Er 45 EOPNOTSUPP Em "Operation not supported" . +The attempted operation is not supported for the type of object referenced. +Usually this occurs when a file descriptor refers to a file or socket +that cannot support this operation, +for example, trying to +.Em accept +a connection on a datagram socket. +.It Er 46 EPFNOSUPPORT Em "Protocol family not supported" . +The protocol family has not been configured into the +system or no implementation for it exists. +.It Er 47 EAFNOSUPPORT Em "Address family not supported by protocol family" . +An address incompatible with the requested protocol was used. +For example, you shouldn't necessarily expect to be able to use +.Tn NS +addresses with +.Tn ARPA +Internet protocols. +.It Er 48 EADDRINUSE Em "Address already in use" . +Only one usage of each address is normally permitted. +.Pp +.It Er 49 EADDRNOTAVAIL Em "Cannot assign requested address" . +Normally results from an attempt to create a socket with an +address not on this machine. +.It Er 50 ENETDOWN Em "Network is down" . +A socket operation encountered a dead network. +.It Er 51 ENETUNREACH Em "Network is unreachable" . +A socket operation was attempted to an unreachable network. +.It Er 52 ENETRESET Em "Network dropped connection on reset" . +The host you were connected to crashed and rebooted. +.It Er 53 ECONNABORTED Em "Software caused connection abort" . +A connection abort was caused internal to your host machine. +.It Er 54 ECONNRESET Em "Connection reset by peer" . +A connection was forcibly closed by a peer. This normally +results from a loss of the connection on the remote socket +due to a timeout or a reboot. +.It Er 55 ENOBUFS Em "\&No buffer space available" . +An operation on a socket or pipe was not performed because +the system lacked sufficient buffer space or because a queue was full. +.It Er 56 EISCONN Em "Socket is already connected" . +A +.Xr connect 2 +request was made on an already connected socket; or, +a +.Xr sendto 2 +or +.Xr sendmsg 2 +request on a connected socket specified a destination +when already connected. +.It Er 57 ENOTCONN Em "Socket is not connected" . +An request to send or receive data was disallowed because +the socket was not connected and (when sending on a datagram socket) +no address was supplied. +.It Er 58 ESHUTDOWN Em "Cannot send after socket shutdown" . +A request to send data was disallowed because the socket +had already been shut down with a previous +.Xr shutdown 2 +call. +.It Er 60 ETIMEDOUT Em "Operation timed out" . +A +.Xr connect 2 +or +.Xr send 2 +request failed because the connected party did not +properly respond after a period of time. (The timeout +period is dependent on the communication protocol.) +.It Er 61 ECONNREFUSED Em "Connection refused" . +No connection could be made because the target machine actively +refused it. This usually results from trying to connect +to a service that is inactive on the foreign host. +.It Er 62 ELOOP Em "Too many levels of symbolic links" . +A path name lookup involved more than 32 +.Pq Dv MAXSYMLINKS +symbolic links. +.It Er 63 ENAMETOOLONG Em "File name too long" . +A component of a path name exceeded 255 +.Pq Dv MAXNAMELEN +characters, or an entire +path name exceeded 1023 +.Pq Dv MAXPATHLEN Ns -1 +characters. +.It Er 64 EHOSTDOWN Em "Host is down" . +A socket operation failed because the destination host was down. +.It Er 65 EHOSTUNREACH Em "No route to host" . +A socket operation was attempted to an unreachable host. +.It Er 66 ENOTEMPTY Em "Directory not empty" . +A directory with entries other than +.Ql \&. +and +.Ql \&.. +was supplied to a remove directory or rename call. +.It Er 67 EPROCLIM Em "Too many processes" . +.It Er 68 EUSERS Em "Too many users" . +The quota system ran out of table entries. +.It Er 69 EDQUOT Em "Disc quota exceeded" . +A +.Xr write 2 +to an ordinary file, the creation of a +directory or symbolic link, or the creation of a directory +entry failed because the user's quota of disk blocks was +exhausted, or the allocation of an inode for a newly +created file failed because the user's quota of inodes +was exhausted. +.ne 1i +.It Er 70 ESTALE Em "Stale NFS file handle" . +An attempt was made to access an open file (on an +.Tn NFS +filesystem) +which is now unavailable as referenced by the file descriptor. +This may indicate the file was deleted on the +.Tn NFS +server or some +other catastrophic event occurred. +.It Er 72 EBADRPC Em "RPC struct is bad" . +Exchange of +.Tn RPC +information was unsuccessful. +.It Er 73 ERPCMISMATCH Em "RPC version wrong" . +The version of +.Tn RPC +on the remote peer is not compatible with +the local version. +.It Er 74 EPROGUNAVAIL Em "RPC prog. not avail" . +The requested program is not registered on the remote host. +.It Er 75 EPROGMISMATCH Em "Program version wrong" . +The requested version of the program is not available +on the remote host +.Pq Tn RPC . +.It Er 76 EPROCUNAVAIL Em "Bad procedure for program" . +An +.Tn RPC +call was attempted for a procedure which doesn't exist +in the remote program. +.It Er 77 ENOLCK Em "No locks available" . +A system-imposed limit on the number of simultaneous file +locks was reached. +.It Er 78 ENOSYS Em "Function not implemented" . +Attempted a system call that is not available on this +system. +.It Er 79 EFTYPE Em "Inappropriate file type or format" . +The file was the wrong type for the operation, or a data file had +the wrong format. +.It Er 80 EAUTH Em "Authentication error" . +Attempted to use an invalid authentication ticket to mount a +.Tn NFS +filesystem. +.It Er 81 ENEEDAUTH Em "Need authenticator" . +An authentication ticket must be obtained before the given +.Tn NFS +filesystem may be mounted. +.It Er 82 EIDRM Em "Identifier removed" . +An IPC identifier was removed while the current process was waiting on it. +.It Er 83 ENOMSG Em "No message of desired type" . +An IPC message queue does not contain a message of the desired type, or a +message catalog does not contain the requested message. +.It Er 84 EOVERFLOW Em "Value too large to be stored in data type" . +A numerical result of the function was too large to be stored in the caller +provided space. +.It Er 85 ECANCELED Em "Operation canceled" . +The scheduled operation was canceled. +.It Er 86 EILSEQ Em "Illegal byte sequence" . +While decoding a multibyte character the function came along an +invalid or an incomplete sequence of bytes or the given wide +character is invalid. +.Sh DEFINITIONS +.Bl -tag -width Ds +.It Process ID . +Each active process in the system is uniquely identified by a non-negative +integer called a process ID. The range of this ID is from 0 to 99999. +.It Parent process ID +A new process is created by a currently active process; (see +.Xr fork 2 ) . +The parent process ID of a process is initially the process ID of its creator. +If the creating process exits, +the parent process ID of each child is set to the ID of a system process, +.Xr init 8 . +.It Process Group +Each active process is a member of a process group that is identified by +a non-negative integer called the process group ID. This is the process +ID of the group leader. This grouping permits the signaling of related +processes (see +.Xr termios 4 ) +and the job control mechanisms of +.Xr csh 1 . +.It Session +A session is a set of one or more process groups. +A session is created by a successful call to +.Xr setsid 2 , +which causes the caller to become the only member of the only process +group in the new session. +.It Session leader +A process that has created a new session by a successful call to +.Xr setsid 2 , +is known as a session leader. +Only a session leader may acquire a terminal as its controlling terminal (see +.Xr termios 4 ) . +.It Controlling process +A session leader with a controlling terminal is a controlling process. +.It Controlling terminal +A terminal that is associated with a session is known as the controlling +terminal for that session and its members. +.ne 1i +.It "Terminal Process Group ID" +A terminal may be acquired by a session leader as its controlling terminal. +Once a terminal is associated with a session, any of the process groups +within the session may be placed into the foreground by setting +the terminal process group ID to the ID of the process group. +This facility is used +to arbitrate between multiple jobs contending for the same terminal; +(see +.Xr csh 1 +and +.Xr tty 4 ) . +.It "Orphaned Process Group" +A process group is considered to be +.Em orphaned +if it is not under the control of a job control shell. +More precisely, a process group is orphaned +when none of its members has a parent process that is in the same session +as the group, +but is in a different process group. +Note that when a process exits, the parent process for its children +is changed to be +.Xr init 8 , +which is in a separate session. +Not all members of an orphaned process group are necessarily orphaned +processes (those whose creating process has exited). +The process group of a session leader is orphaned by definition. +.It "Real User ID and Real Group ID" +Each user on the system is identified by a positive integer +termed the real user ID. +.Pp +Each user is also a member of one or more groups. +One of these groups is distinguished from others and +used in implementing accounting facilities. The positive +integer corresponding to this distinguished group is termed +the real group ID. +.Pp +All processes have a real user ID and real group ID. +These are initialized from the equivalent attributes +of the process that created it. +.It "Effective User Id, Effective Group Id, and Group Access List" +Access to system resources is governed by two values: +the effective user ID, and the group access list. +The first member of the group access list is also known as the +effective group ID. +(In POSIX.1, the group access list is known as the set of supplementary +group IDs, and it is unspecified whether the effective group ID is +a member of the list.) +.Pp +The effective user ID and effective group ID are initially the +process's real user ID and real group ID respectively. Either +may be modified through execution of a set-user-ID or set-group-ID +file (possibly by one its ancestors) (see +.Xr execve 2 ) . +By convention, the effective group ID (the first member of the group access +list) is duplicated, so that the execution of a set-group-ID program +does not result in the loss of the original (real) group ID. +.Pp +The group access list is a set of group IDs +used only in determining resource accessibility. Access checks +are performed as described below in ``File Access Permissions''. +.It "Saved Set User ID and Saved Set Group ID" +When a process executes a new file, the effective user ID is set +to the owner of the file if the file is set-user-ID, and the effective +group ID (first element of the group access list) is set to the group +of the file if the file is set-group-ID. +The effective user ID of the process is then recorded as the saved set-user-ID, +and the effective group ID of the process is recorded as the saved set-group-ID. +These values may be used to regain those values as the effective user +or group ID after reverting to the real ID (see +.Xr setuid 2 ) . +(In POSIX.1, the saved set-user-ID and saved set-group-ID are optional, +and are used in setuid and setgid, but this does not work as desired +for the super-user.) +.It Super-user +A process is recognized as a +.Em super-user +process and is granted special privileges if its effective user ID is 0. +.ne 1i +.It Special Processes +The processes with process IDs of 0, 1, and 2 are special. +Process 0 is the scheduler. Process 1 is the initialization process +.Xr init 8 , +and is the ancestor of every other process in the system. +It is used to control the process structure. +Process 2 is the paging daemon. +.It Descriptor +An integer assigned by the system when a file is referenced +by +.Xr open 2 +or +.Xr dup 2 , +or when a socket is created by +.Xr pipe 2 , +.Xr socket 2 +or +.Xr socketpair 2 , +which uniquely identifies an access path to that file or socket from +a given process or any of its children. +.It File Name +Names consisting of up to 255 +.Pq Dv MAXNAMELEN +characters may be used to name +an ordinary file, special file, or directory. +.Pp +These characters may be selected from the set of all +.Tn ASCII +character +excluding 0 (NUL) and the +.Tn ASCII +code for +.Ql \&/ +(slash). +.Pp +Note that it is generally unwise to use +.Ql \&* , +.Ql \&? , +.Ql \&[ +or +.Ql \&] +as part of +file names because of the special meaning attached to these characters +by the shell. +.It Path Name +A path name is a +.Tn NUL Ns -terminated +character string starting with an +optional slash +.Ql \&/ , +followed by zero or more directory names separated +by slashes, optionally followed by a file name. +The total length of a path name must be less than 1024 +.Pq Dv MAXPATHLEN +characters. +.Pp +If a path name begins with a slash, the path search begins at the +.Em root +directory. +Otherwise, the search begins from the current working directory. +A slash by itself names the root directory. An empty +pathname refers to the current directory. +.It Directory +A directory is a special type of file that contains entries +that are references to other files. +Directory entries are called links. By convention, a directory +contains at least two links, +.Ql \&. +and +.Ql \&.. , +referred to as +.Em dot +and +.Em dot-dot +respectively. Dot refers to the directory itself and +dot-dot refers to its parent directory. +.It "Root Directory and Current Working Directory" +Each process has associated with it a concept of a root directory +and a current working directory for the purpose of resolving path +name searches. A process's root directory need not be the root +directory of the root file system. +.It File Access Permissions +Every file in the file system has a set of access permissions. +These permissions are used in determining whether a process +may perform a requested operation on the file (such as opening +a file for writing). Access permissions are established at the +time a file is created. They may be changed at some later time +through the +.Xr chmod 2 +call. +.Pp +File access is broken down according to whether a file may be: read, +written, or executed. Directory files use the execute +permission to control if the directory may be searched. +.Pp +File access permissions are interpreted by the system as +they apply to three different classes of users: the owner +of the file, those users in the file's group, anyone else. +Every file has an independent set of access permissions for +each of these classes. When an access check is made, the system +decides if permission should be granted by checking the access +information applicable to the caller. +.Pp +Read, write, and execute/search permissions on +a file are granted to a process if: +.Pp +The process's effective user ID is that of the super-user. (Note: +even the super-user cannot execute a non-executable file.) +.Pp +The process's effective user ID matches the user ID of the owner +of the file and the owner permissions allow the access. +.Pp +The process's effective user ID does not match the user ID of the +owner of the file, and either the process's effective +group ID matches the group ID +of the file, or the group ID of the file is in +the process's group access list, +and the group permissions allow the access. +.Pp +Neither the effective user ID nor effective group ID +and group access list of the process +match the corresponding user ID and group ID of the file, +but the permissions for ``other users'' allow access. +.Pp +Otherwise, permission is denied. +.It Sockets and Address Families +.Pp +A socket is an endpoint for communication between processes. +Each socket has queues for sending and receiving data. +.Pp +Sockets are typed according to their communications properties. +These properties include whether messages sent and received +at a socket require the name of the partner, whether communication +is reliable, the format used in naming message recipients, etc. +.Pp +Each instance of the system supports some +collection of socket types; consult +.Xr socket 2 +for more information about the types available and +their properties. +.Pp +Each instance of the system supports some number of sets of +communications protocols. Each protocol set supports addresses +of a certain format. An Address Family is the set of addresses +for a specific group of protocols. Each socket has an address +chosen from the address family in which the socket was created. +.Sh SEE ALSO +.Xr intro 3 , +.Xr perror 3 diff --git a/lib/libc/sys/ioctl.2 b/lib/libc/sys/ioctl.2 new file mode 100644 index 0000000..703e1ee --- /dev/null +++ b/lib/libc/sys/ioctl.2 @@ -0,0 +1,144 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)ioctl.2 8.2 (Berkeley) 12/11/93 +.\" +.\" $FreeBSD$ +.\" +.Dd December 11, 1993 +.Dt IOCTL 2 +.Os BSD 4 +.Sh NAME +.Nm ioctl +.Nd control device +.Sh SYNOPSIS +.Fd #include <sys/ioctl.h> +.Ft int +.Fn ioctl "int d" "unsigned long request" ... +.Sh DESCRIPTION +The +.Fn ioctl +function manipulates the underlying device parameters of special files. +In particular, many operating +characteristics of character special files (e.g. terminals) +may be controlled with +.Fn ioctl +requests. +The argument +.Fa d +must be an open file descriptor. +.Pp +The third argument to +.Nm +is traditionally named +.Ar "char *argp" . +Most uses of +.Nm +in +.Fx 3.0 +however, require the third argument to be a +.Ar caddr_t +or an +.Ar int . +.Pp +An ioctl +.Fa request +has encoded in it whether the argument is an +.Dq in +parameter +or +.Dq out +parameter, and the size of the argument +.Fa argp +in bytes. +Macros and defines used in specifying an ioctl +.Fa request +are located in the file +.Ao Pa sys/ioctl.h Ac . +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn ioctl +is implemented as the +.Va ioctl +syscall. +.Pp +In the threaded library, the +.Va ioctl +syscall is assembled to +.Fn _thread_sys_ioctl +and +.Fn ioctl +is implemented as a function which locks +.Va d +for read and write, then calls +.Fn _thread_sys_ioctl . +Before returning, +.Fn ioctl +unlocks +.Va d . +.Sh RETURN VALUES +If an error has occurred, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Ioctl +will fail if: +.Bl -tag -width [ENOTTY] +.It Bq Er EBADF +.Fa d +is not a valid descriptor. +.It Bq Er ENOTTY +.Fa d +is not associated with a character +special device. +.It Bq Er ENOTTY +The specified request does not apply to the kind +of object that the descriptor +.Fa d +references. +.It Bq Er EINVAL +.Fa Request +or +.Fa argp +is not valid. +.El +.Sh SEE ALSO +.Xr mt 1 , +.Xr execve 2 , +.Xr fcntl 2 , +.Xr intro 4 , +.Xr tty 4 +.Sh HISTORY +An +.Fn ioctl +function call appeared in +.At v7 . diff --git a/lib/libc/sys/issetugid.2 b/lib/libc/sys/issetugid.2 new file mode 100644 index 0000000..91adf6c --- /dev/null +++ b/lib/libc/sys/issetugid.2 @@ -0,0 +1,99 @@ +.\" $OpenBSD: issetugid.2,v 1.7 1997/02/18 00:16:09 deraadt Exp $ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd August, 25 1996 +.Dt ISSETUGID 2 +.Os +.Sh NAME +.Nm issetugid +.Nd is current process tainted by uid or gid changes +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn issetugid void +.Sh DESCRIPTION +The +.Fn issetugid +function returns 1 if the process environment or memory address space +is considered +.Dq tainted , +and returns 0 otherwise. +.Pp +A process is tainted if it was created as a result of an +.Xr execve 2 +system call which had either of the setuid or setgid bits set (and extra +privileges were given as a result) or if it has changed any of it's real, +effective or saved user or group ID's since it began execution. +.Pp +This system call exists so that library routines (eg: libc, libtermcap) +can reliably determine if it is safe to use information +that was obtained from the user, in particular the results from +.Xr getenv 3 +should be viewed with suspicion if it is used to control operation. +.Pp +A +.Dq tainted +status is inherited by child processes as a result of the +.Xr fork 2 +system call (or other library code that calls fork, such as +.Xr popen 3 ) . +.Pp +It is assumed that a program that clears all privileges as it prepares +to execute another will also reset the environment, hence the +.Dq tainted +status will not be passed on. This is important for programs such as +.Xr su 1 +which begin setuid but need to be able to create an untainted process. +.Sh ERRORS +The +.Fn issetugid +function is always successful, and no return value is reserved to +indicate an error. +.Sh SEE ALSO +.Xr execve 2 , +.Xr fork 2 , +.Xr setegid 2 , +.Xr seteuid 2 , +.Xr setgid 2 , +.Xr setregid 2 , +.Xr setreuid 2 , +.Xr setuid 2 +.Sh HISTORY +A +.Fn issetugid +function call first appeared in +.Ox 2.0 +and was also implemented in +.Fx 3.0 . diff --git a/lib/libc/sys/jail.2 b/lib/libc/sys/jail.2 new file mode 100644 index 0000000..00aae7e --- /dev/null +++ b/lib/libc/sys/jail.2 @@ -0,0 +1,105 @@ +.\" +.\"---------------------------------------------------------------------------- +.\""THE BEER-WARE LICENSE" (Revision 42): +.\"<phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you +.\"can do whatever you want with this stuff. If we meet some day, and you think +.\"this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp +.\"---------------------------------------------------------------------------- +.\" +.\"$FreeBSD$ +.\" +.\" +.Dd April 28, 1999 +.Dt JAIL 2 +.Os FreeBSD 4.0 +.Sh NAME +.Nm jail +.Nd Imprison current process and future decendants. +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/jail.h> +.Ft int +.Fn jail "struct jail *jail" +.Sh DESCRIPTION +The +.Nm +system call sets up a jail and locks the current process in it. +.Pp +The argument is a pointer to a structure describing the prison: +.Bd -literal -offset indent +struct jail { + u_int32_t version; + char *path; + char *hostname; + u_int32_t ip_number; +}; +.Ed +.Pp +.Dq Li version +defines the version of the API in use. It should be set to zero at this time. +.Pp +The +.Dq Li path +pointer should be set to the directory which is to be the root of the +prison. +.Pp +The +.Dq Li hostname +pointer can be set the hostname of the prison. This can be changed +from the inside of the prison. +.Pp +The +.Dq Li ip_number +can be set to the IP number assigned to the prison. +.Sh PRISON ? +Once a process has been put in a prison, it and its decendants cannot escape +the prison. It is not possible to add a process to a preexisting prison. +.Pp +Inside the prison, the concept of "superuser" is very diluted. In general, +it can be assumed that nothing can be mangled from inside a prison which +doesn't exist entirely inside that prison. For instance the directory +tree below +.Dq Li path +can be manipulated all the ways a root can normally do it, including +.Dq Li "rm -rf /*" +but new device special notes cannot be created because the reference +shared resources (the device drivers in the kernel). +.Pp +All IP activity will be forced to happen to/from the IP number specified, +which should be an alias on one of the network interfaces. +.Pp +It is possible to identify a process as jailed by examining +.Dq Li /proc/<pid>/status : +it will show a field near the end of the line, either as +a single hyphen for a process at large, or the hostname currently +set for the prison for jailed processes. +.Sh ERRORS +.Fn jail +will fail if: +.Bl -tag -width EWOULDBLOCK +.It Bq Er EINVAL +The version number of the argument is not correct. +.El +Further +.Fn Jail +calls +.Xr chroot 2 +internally, so the it can fail for all the same reasons. +Please consult the +.Xr chroot 2 +manual page for details. +.Sh SEE ALSO +.Xr chdir 2 , +.Xr chroot 2 +.Sh HISTORY +The +.Fn jail +function call appeared in +.Fx 4.0 . +.Pp +The jail feature was written by +.An Poul-Henning Kamp +for R&D Associates +.Dq Li http://www.rndassociates.com/ +who contributed it to +.Fx . diff --git a/lib/libc/sys/kill.2 b/lib/libc/sys/kill.2 new file mode 100644 index 0000000..c8667d8 --- /dev/null +++ b/lib/libc/sys/kill.2 @@ -0,0 +1,142 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)kill.2 8.3 (Berkeley) 4/19/94 +.\" $FreeBSD$ +.\" +.Dd April 19, 1994 +.Dt KILL 2 +.Os BSD 4 +.Sh NAME +.Nm kill +.Nd send signal to a process +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <signal.h> +.Ft int +.Fn kill "pid_t pid" "int sig" +.Sh DESCRIPTION +The +.Fn kill +function sends the signal given by +.Fa sig +to +.Fa pid , +a +process or a group of processes. +.Fa Sig +may be one of the signals specified in +.Xr sigaction 2 +or it may be 0, in which case +error checking is performed but no +signal is actually sent. +This can be used to check the validity of +.Fa pid . +.Pp +For a process to have permission to send a signal to a process designated +by +.Fa pid , +the real or effective user ID of the receiving process must match +that of the sending process or the user must have appropriate privileges +(such as given by a set-user-ID program or the user is the super-user). +A single exception is the signal SIGCONT, which may always be sent +to any descendant of the current process. +.Bl -tag -width Ds +.It \&If Fa pid No \&is greater than zero : +.Fa Sig +is sent to the process whose ID is equal to +.Fa pid. +.It \&If Fa pid No \&is zero : +.Fa Sig +is sent to all processes whose group ID is equal +to the process group ID of the sender, and for which the +process has permission; +this is a variant of +.Xr killpg 2 . +.It \&If Fa pid No \&is -1 : +If the user has super-user privileges, +the signal is sent to all processes excluding +system processes +.Pq with Dv P_SYSTEM flag set , +process with ID 1 +.Pq usually Xr init 8 , +and the process sending the signal. +If the user is not the super user, the signal is sent to all processes +with the same uid as the user excluding the process sending the signal. +No error is returned if any process could be signaled. +.El +.Pp +For compatibility with System V, +if the process number is negative but not -1, +the signal is sent to all processes whose process group ID +is equal to the absolute value of the process number. +This is a variant of +.Xr killpg 2 . +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Kill +will fail and no signal will be sent if: +.Bl -tag -width [EINVAL] +.It Bq Er EINVAL +.Fa Sig +is not a valid signal number. +.It Bq Er ESRCH +No process can be found corresponding to that specified by +.Fa pid . +.It Bq Er ESRCH +The process id was given as 0 +but the sending process does not have a process group. +.It Bq Er EPERM +The sending process is not the super-user and its effective +user id does not match the effective user-id of the receiving process. +When signaling a process group, this error is returned if any members +of the group could not be signaled. +.El +.Sh SEE ALSO +.Xr getpgrp 2 , +.Xr getpid 2 , +.Xr killpg 2 , +.Xr sigaction 2 , +.Xr init 8 +.Sh STANDARDS +The +.Fn kill +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn kill +function call appeared in +.At v7 . diff --git a/lib/libc/sys/kldfind.2 b/lib/libc/sys/kldfind.2 new file mode 100644 index 0000000..96be122 --- /dev/null +++ b/lib/libc/sys/kldfind.2 @@ -0,0 +1,74 @@ +.\" +.\" Copyright (c) 1999 Chris Costello +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 3, 1999 +.Dt KLDFIND 2 +.Os FreeBSD +.Sh NAME +.Nm kldfind +.Nd returns the fileid of a kld file +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/linker.h> +.Ft int +.Fn kldfind "const char *file" +.Sh DESCRIPTION +The function +.Fn kldfind +returns the fileid of the kld file referenced by +.Va file . +.Sh RETURN VALUES +.Fn kldfind +returns the fileid of the kld file referenced by +.Va file . +Upon error, +.Fn kldfind +returns -1 and sets +.Va errno +to indicate the error. +.Sh ERRORS +.Va errno +is set to the following if +.Fn kldfind +fails: +.Bl -tag -width Er +.It Bq Er EFAULT +The data required for this operation could not be read from the kernel space. +.It Bq Er ENOENT +The file specified is not loaded in the kernel. +.Sh SEE ALSO +.Xr kldfirstmod 2 , +.Xr kldload 2 , +.Xr kldnext 2 , +.Xr kldstat 2 , +.Xr kldunload 2 , +.Xr kld 4 +.Sh HISTORY +The +.Nm kld +interface first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/kldfirstmod.2 b/lib/libc/sys/kldfirstmod.2 new file mode 100644 index 0000000..29e43d6 --- /dev/null +++ b/lib/libc/sys/kldfirstmod.2 @@ -0,0 +1,67 @@ +.\" +.\" Copyright (c) 1999 Chris Costello +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 3, 1999 +.Dt KLDFIRSTMOD 2 +.Os FreeBSD +.Sh NAME +.Nm kldfirstmod +.Nd "return first module id from the kld file specified" +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/linker.h> +.Ft int +.Fn kldfirstmod "int fileid" +.Sh DESCRIPTION +The +.Fn kldfirstmod +function returns the module id pertaining to the first module referenced by +.Va fileid . +.Sh RETURN VALUES +The +.Fn kldfirstmod +will return the id of the first module referenced by +.Va fileid +or 0 if there are no references. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ENOENT +The kld file referenced by +.Va fileid +was not found. +.Sh SEE ALSO +.Xr kldfind 2 , +.Xr kldload 2 , +.Xr kldnext 2 , +.Xr kldstat 2 , +.Xr kldunload 2 , +.Xr kld 4 +.Sh HISTORY +The +.Nm kld +interface first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/kldload.2 b/lib/libc/sys/kldload.2 new file mode 100644 index 0000000..7a2f9a1 --- /dev/null +++ b/lib/libc/sys/kldload.2 @@ -0,0 +1,83 @@ +.\" +.\" Copyright (c) 1999 Chris Costello +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" + +.Dd March 3, 1999 +.Dt KLDLOAD 2 +.Os FreeBSD +.Sh NAME +.Nm kldload +.Nd load KLD files into the kernel +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/linker.h> +.Ft int +.Fn kldload "const char *file" +.Sh DESCRIPTION +The function +.Fn kldload +loads a kld file into the kernel using the kernel linker. +.Sh RETURN VALUES +The function +.Fn kldload +returns the fileid of the kld file which was loaded into the kernel. If +an error occurs, +.Fn kldload +will return -1 and set +.Va errno +to indicate the error. +.Sh ERRORS +The named file is loaded unless: +.Bl -tag -width Er +.It Bq Er EPERM +You do not have access to read the file or link it with the kernel. You should +be the root user to be able to use the +.Nm kld +functions. +.It Bq Er EFAULT +Bad address encountered when adding kld info into the kernel space. +.It Bq Er ENOMEM +There is no memory to load the file into the kernel. +.It Bq Er ENOENT +The file was not found. +.It Bq Er ENOEXEC +The file format of +.Va file +was unrecognized. +.Sh SEE ALSO +.Xr kldfind 2 , +.Xr kldfirstmod 2 , +.Xr kldnext 2 , +.Xr kldstat 2 , +.Xr kldunload 2 , +.Xr kld 4 , +.Xr kldload 8 +.Sh HISTORY +The +.Nm kld +interface first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/kldnext.2 b/lib/libc/sys/kldnext.2 new file mode 100644 index 0000000..9e73564 --- /dev/null +++ b/lib/libc/sys/kldnext.2 @@ -0,0 +1,70 @@ +.\" +.\" Copyright (c) 1999 Chris Costello +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 3, 1999 +.Dt KLDNEXT 2 +.Os FreeBSD +.Sh NAME +.Nm kldnext +.Nd return the fileid of the next kld file +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/linker.h> +.Ft int +.Fn kldnext "int fileid" +.Sh DESCRIPTION +The function +.Fn kldnext +returns the fileid of the next kld file (that is, the one after +.Va fileid ) +or 0 if +.Va fileid +is the last file loaded. +.Sh RETURN VALUES +.Fn kldnext +returns the fileid of the next kld file (see DESCRIPTION) or 0. If an error +occurs, +.Va errno +is set to indicate the error. +.Sh ERRORS +The only error set by +.Fn kldnext +is ENOENT, which is set when +.Va fileid +refers to a kld file that does not exist (isn't loaded). +.Sh SEE ALSO +.Xr kldfind 2 , +.Xr kldfirstmod 2 , +.Xr kldload 2 , +.Xr kldstat 2 , +.Xr kldunload 2 , +.Xr kld 4 +.Sh HISTORY +The +.Nm kld +interface first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/kldstat.2 b/lib/libc/sys/kldstat.2 new file mode 100644 index 0000000..bc9adb3 --- /dev/null +++ b/lib/libc/sys/kldstat.2 @@ -0,0 +1,116 @@ +.\" +.\" Copyright (c) 1999 Chris Costello +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 3, 1999 +.Dt KLDSTAT 2 +.Os FreeBSD +.Sh NAME +.Nm kldstat +.Nd get status of kld file +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/linker.h> +.Ft int +.Fn kldstat "int fileid" "struct kld_file_stat *stat" +.Sh DESCRIPTION +The +.Fn kldstat +function writes the info for the file referred to by +.Va fileid +into +.Va stat . +.Bd -literal +struct kld_file_stat { + int version; /* set to sizeof(linker_file_stat) */ + char name[MAXPATHLEN]; + int refs; + int id; + caddr_t address; /* load address */ + size_t size; /* size in bytes */ +}; +.Ed +.Pp +.Bl -tag -width XXXaddress +.It version +This field is set to the size of the structure mentioned above by the code +calling +.Fn kldstat , +and not +.Fn kldstat +itself. +.It name +The name of the file referred to by +.Va fileid . +.It refs +The number of modules referenced by +.Va fileid . +.It id +The id of the file specified in +.Va fileid . +.It address +The load address of the kld file. +.It size +The size of the file. +.Sh RETURN VALUES +.Fn kldstat +seems to always return 0. +.Sh ERRORS +The information for the file referred to by +.Va fileid +is filled into the structure pointed to by +.Va stat +unless: +.Bl -tag -width Er +.It Bq Er ENOENT +The file was not found (probably not loaded). +.It Bq Er EINVAL +The version specified in the +.Va version +field of stat is not the proper version. You would need to rebuild world, the +kernel, or your application, if this error occurs, given that you did properly +fill in the +.Va version +field. +.It Bq Er EFAULT +There was a problem copying one, some, or all of the fields into +.Va stat +in the +.Fn copyout +function. +.Sh SEE ALSO +.Xr kldfind 2 , +.Xr kldfirstmod 2 , +.Xr kldload 2 , +.Xr kldnext 2 , +.Xr kldunload 2 , +.Xr kld 4 , +.Xr kldstat 8 +.Sh HISTORY +The +.Nm kld +interface first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/kldunload.2 b/lib/libc/sys/kldunload.2 new file mode 100644 index 0000000..fd803e7 --- /dev/null +++ b/lib/libc/sys/kldunload.2 @@ -0,0 +1,78 @@ +.\" +.\" Copyright (c) 1999 Chris Costello +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" + +.Dd March 3, 1999 +.Dt KLDUNLOAD 2 +.Os FreeBSD +.Sh NAME +.Nm kldunload +.Nd unload kld files +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/linker.h> +.Ft int +.Fn kldunload "int fileid" +.Sh DESCRIPTION +The function +.Fn kldunload +unloads a kld file from the kernel that was previously linked via +.Xr kldload 2 . +.Sh RETURN VALUES +The function +.Fn kldunload +returns the fileid of the kld file which was previously loaded into memory via +.Fn kldload . +If an error occurs, +.Fn kldunload +will return -1 and set +.Va errno +to indicate the error. +.Sh ERRORS +The file referred to by +.Va fileid +is unloaded unless: +.Bl -tag -width Er +.It Bq Er EPERM +You don't have access to unlink the file from the kernel. +.It Bq Er ENOENT +The file was not found. +.It Bq Er EBUSY +You attempted to unload a file linked by the kernel. +.Sh SEE ALSO +.Xr kldfind 2 , +.Xr kldfirstmod 2 , +.Xr kldload 2 , +.Xr kldnext 2 , +.Xr kldstat 2 , +.Xr kld 4 , +.Xr kldunload 8 +.Sh HISTORY +The +.Nm kld +interface first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/ktrace.2 b/lib/libc/sys/ktrace.2 new file mode 100644 index 0000000..9b25bdb --- /dev/null +++ b/lib/libc/sys/ktrace.2 @@ -0,0 +1,167 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)ktrace.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt KTRACE 2 +.Os BSD 4 +.Sh NAME +.Nm ktrace +.Nd process tracing +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/time.h> +.Fd #include <sys/uio.h> +.Fd #include <sys/ktrace.h> +.Ft int +.Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid" +.Sh DESCRIPTION +The +.Fn ktrace +function enables or disables tracing of one or more processes. +Users may only trace their own processes. +Only the super-user can trace setuid or setgid programs. +.Pp +The +.Ar tracefile +gives the pathname of the file to be used for tracing. +The file must exist and be a regular file writable by the calling process. +All trace records are always appended to the file, +so the file must be truncated to zero length to discard +previous trace data. +If tracing points are being disabled (see KTROP_CLEAR below), +.Ar tracefile +may be NULL. +.Pp +The +.Nm ops +parameter specifies the requested ktrace operation. +The defined operations are: +.Bl -column KTRFLAG_DESCENDXXX -offset indent +.It KTROP_SET Enable trace points specified in Ar trpoints . +.It KTROP_CLEAR Disable trace points specified in Ar trpoints . +.It KTROP_CLEARFILE Stop all tracing. +.It KTRFLAG_DESCEND The tracing change should apply to the +specified process and all its current children. +.El +.Pp +The +.Nm trpoints +parameter specifies the trace points of interest. +The defined trace points are: +.Bl -column KTRFAC_SYSCALLXXX -offset indent +.It KTRFAC_SYSCALL Trace system calls. +.It KTRFAC_SYSRET Trace return values from system calls. +.It KTRFAC_NAMEI Trace name lookup operations. +.It KTRFAC_GENIO Trace all I/O (note that this option can +generate much output). +.It KTRFAC_PSIG Trace posted signals. +.It KTRFAC_CSW Trace context switch points. +.It KTRFAC_INHERIT Inherit tracing to future children. +.El +.Pp +Each tracing event outputs a record composed of a generic header +followed by a trace point specific structure. +The generic header is: +.Bd -literal +struct ktr_header { + int ktr_len; /* length of buf */ + short ktr_type; /* trace record type */ + pid_t ktr_pid; /* process id */ + char ktr_comm[MAXCOMLEN+1]; /* command name */ + struct timeval ktr_time; /* timestamp */ + caddr_t ktr_buf; +}; +.Ed +.Pp +The +.Nm ktr_len +field specifies the length of the +.Nm ktr_type +data that follows this header. +The +.Nm ktr_pid +and +.Nm ktr_comm +fields specify the process and command generating the record. +The +.Nm ktr_time +field gives the time (with microsecond resolution) +that the record was generated. +The +.Nm ktr_buf +is an internal kernel pointer and is not useful. +.Pp +The generic header is followed by +.Nm ktr_len +bytes of a +.Nm ktr_type +record. +The type specific records are defined in the +.Pa <sys/ktrace.h> +include file. +.Sh RETURN VALUES +On successful completion a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to show the error. +.Sh ERRORS +.Fn Ktrace +will fail if: +.Bl -tag -width ENAMETOOLONGAA +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named tracefile does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er ENOSYS +The kernel was not compiled with +.Nm +support. +.El +.Sh SEE ALSO +.Xr kdump 1 , +.Xr ktrace 1 +.Sh HISTORY +A +.Fn ktrace +function call first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/link.2 b/lib/libc/sys/link.2 new file mode 100644 index 0000000..a1b6d4b --- /dev/null +++ b/lib/libc/sys/link.2 @@ -0,0 +1,168 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)link.2 8.3 (Berkeley) 1/12/94 +.\" $FreeBSD$ +.\" +.Dd Mar 5, 1999 +.Dt LINK 2 +.Os BSD 4 +.Sh NAME +.Nm link +.Nd make a hard file link +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn link "const char *name1" "const char *name2" +.Sh DESCRIPTION +The +.Fn link +function call +atomically creates the specified directory entry (hard link) +.Fa name2 +with the attributes of the underlying object pointed at by +.Fa name1 . +If the link is successful: the link count of the underlying object +is incremented; +.Fa name1 +and +.Fa name2 +share equal access and rights +to the +underlying object. +.Pp +If +.Fa name1 +is removed, the file +.Fa name2 +is not deleted and the link count of the +underlying object is +decremented. +.Pp +.Fa Name1 +must exist for the hard link to +succeed and +both +.Fa name1 +and +.Fa name2 +must be in the same file system. +.Fa name1 +may not be a directory. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. Otherwise, +a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Link +will fail and no link will be created if: +.Bl -tag -width Ar +.It Bq Er ENOTDIR +A component of either path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of either pathname exceeded 255 characters, +or entire length of either path name exceeded 1023 characters. +.It Bq Er ENOENT +A component of either path prefix does not exist. +.It Bq Er EOPNOTSUPP +The file system containing the file named by +.Fa name1 +does not support links. +.It Bq Er EMLINK +The link count of the file named by +.Fa name1 +would exceed 32767. +.It Bq Er EACCES +A component of either path prefix denies search permission. +.It Bq Er EACCES +The requested link requires writing in a directory with a mode +that denies write permission. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating one of the pathnames. +.It Bq Er ENOENT +The file named by +.Fa name1 +does not exist. +.It Bq Er EEXIST +The link named by +.Fa name2 +does exist. +.It Bq Er EPERM +The file named by +.Fa name1 +is a directory. +.It Bq Er EXDEV +The link named by +.Fa name2 +and the file named by +.Fa name1 +are on different file systems. +.It Bq Er ENOSPC +The directory in which the entry for the new link is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.ne 3v +.It Bq Er EDQUOT +The directory in which the entry for the new link +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EIO +An I/O error occurred while reading from or writing to +the file system to make the directory entry. +.It Bq Er EROFS +The requested link requires writing in a directory on a read-only file +system. +.It Bq Er EFAULT +One of the pathnames specified +is outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr readlink 2 , +.Xr symlink 2 , +.Xr unlink 2 +.Sh STANDARDS +The +.Fn link +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn link +function call appeared in +.At v7 . +.Pp +The +.Fn link +system call traditionally allows the super-user to link directories which +corrupts the filesystem coherency. This implementation no longer permits +it. diff --git a/lib/libc/sys/listen.2 b/lib/libc/sys/listen.2 new file mode 100644 index 0000000..4f87434 --- /dev/null +++ b/lib/libc/sys/listen.2 @@ -0,0 +1,142 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)listen.2 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD$ +.\" +.Dd November 3, 1995 +.Dt LISTEN 2 +.Os BSD 4.2 +.Sh NAME +.Nm listen +.Nd listen for connections on a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn listen "int s" "int backlog" +.Sh DESCRIPTION +To accept connections, a socket +is first created with +.Xr socket 2 , +a willingness to accept incoming connections and +a queue limit for incoming connections are specified with +.Fn listen , +and then the connections are +accepted with +.Xr accept 2 . +The +.Fn listen +call applies only to sockets of type +.Dv SOCK_STREAM +or +.Dv SOCK_SEQPACKET. +.Pp +The +.Fa backlog +parameter defines the maximum length the queue of +pending connections may grow to. +If a connection +request arrives with the queue full the client may +receive an error with an indication of +.Er ECONNREFUSED , +or, if the underlying protocol supports retransmission, +the request may be ignored so that retries may succeed. +.Pp +The +.Xr sysctl 3 +MIB variable +.Dq Li kern.ipc.somaxconn +specifies a hard limit on +.Fa backlog ; +if a value greater than +.Li kern.ipc.somaxconn +or less than zero is specified, +.Fa backlog +is silently forced to +.Li kern.ipc.somaxconn . +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn listen +is implemented as the +.Va listen +syscall. +.Pp +In the threaded library, the +.Va listen +syscall is assembled to +.Fn _thread_sys_listen +and +.Fn listen +is implemented as a function which locks +.Va s +for read and write, then calls +.Fn _thread_sys_listen . +Before returning, +.Fn listen +unlocks +.Va s . +.Sh RETURN VALUES +A 0 return value indicates success; -1 indicates an error. +.Sh ERRORS +.Fn Listen +will fail if: +.Bl -tag -width [EOPNOTSUPP] +.It Bq Er EBADF +The argument +.Fa s +is not a valid descriptor. +.It Bq Er ENOTSOCK +The argument +.Fa s +is not a socket. +.It Bq Er EOPNOTSUPP +The socket is not of a type that supports the operation +.Fn listen . +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr connect 2 , +.Xr socket 2 , +.Xr sysctl 3 , +.Xr sysctl 8 +.Sh HISTORY +The +.Fn listen +function call appeared in +.Bx 4.2 . +The ability to configure the maximum +.Fa backlog +at run-time, and to use a negative +.Fa backlog +to request the maximum allowable value, was introduced in +.Fx 2.2 . diff --git a/lib/libc/sys/lseek.2 b/lib/libc/sys/lseek.2 new file mode 100644 index 0000000..aaccac7 --- /dev/null +++ b/lib/libc/sys/lseek.2 @@ -0,0 +1,141 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)lseek.2 8.3 (Berkeley) 4/19/94 +.\" $FreeBSD$ +.\" +.Dd April 19, 1994 +.Dt LSEEK 2 +.Os BSD 4 +.Sh NAME +.Nm lseek +.Nd reposition read/write file offset +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft off_t +.Fn lseek "int fildes" "off_t offset" "int whence" +.Sh DESCRIPTION +The +.Fn lseek +function repositions the offset of the file descriptor +.Fa fildes +to the +argument +.Fa offset +according to the directive +.Fa whence. +The argument +.Fa fildes +must be an open +file descriptor. +.Fn Lseek +repositions the file position pointer associated with the file +descriptor +.Fa fildes +as follows: +.Bl -item -offset indent +.It +If +.Fa whence +is +.Dv SEEK_SET , +the offset is set to +.Fa offset +bytes. +.It +If +.Fa whence +is +.Dv SEEK_CUR , +the offset is set to its current location plus +.Fa offset +bytes. +.It +If +.Fa whence +is +.Dv SEEK_END , +the offset is set to the size of the +file plus +.Fa offset +bytes. +.El +.Pp +The +.Fn lseek +function allows the file offset to be set beyond the end +of the existing end-of-file of the file. If data is later written +at this point, subsequent reads of the data in the gap return +bytes of zeros (until data is actually written into the gap). +.Pp +Some devices are incapable of seeking. The value of the pointer +associated with such a device is undefined. +.Sh RETURN VALUES +Upon successful completion, +.Fn lseek +returns the resulting offset location as measured in bytes from the +beginning of the file. +Otherwise, +a value of -1 is returned and +.Va errno +is set to indicate +the error. +.Sh ERRORS +.Fn Lseek +will fail and the file position pointer will remain unchanged if: +.Bl -tag -width [EINVAL] +.It Bq Er EBADF +.Em Fildes +is not an open file descriptor. +.It Bq Er ESPIPE +.Em Fildes +is associated with a pipe, socket, or FIFO. +.It Bq Er EINVAL +.Fa Whence +is not a proper value. +.El +.Sh SEE ALSO +.Xr dup 2 , +.Xr open 2 +.Sh BUGS +This document's use of +.Fa whence +is incorrect English, but is maintained for historical reasons. +.Sh STANDARDS +The +.Fn lseek +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn lseek +function call appeared in +.At v7 . diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c new file mode 100644 index 0000000..284885f --- /dev/null +++ b/lib/libc/sys/lseek.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +off_t +lseek(fd, offset, whence) + int fd; + off_t offset; + int whence; +{ +#ifdef _THREAD_SAFE + off_t offs; + if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { + offs = -1; + } else { + offs = __syscall((quad_t) SYS_lseek,fd, 0, offset, whence); + _FD_UNLOCK(fd, FD_RDWR); + } + return(offs); + +#else + return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence)); +#endif +} diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2 new file mode 100644 index 0000000..9a82782 --- /dev/null +++ b/lib/libc/sys/madvise.2 @@ -0,0 +1,154 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)madvise.2 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD$ +.\" +.Dd Jul 19, 1996 +.Dt MADVISE 2 +.Os +.Sh NAME +.Nm madvise +.Nd give advice about use of memory +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn madvise "void *addr" "size_t len" "int behav" +.Sh DESCRIPTION +The +.Fn madvise +system call +allows a process that has knowledge of its memory behavior +to describe it to the system. +The known behaviors are given in +.Aq Pa sys/mman.h : +.Bd -literal +#define MADV_NORMAL 0 /* no further special treatment */ +#define MADV_RANDOM 1 /* expect random page references */ +#define MADV_SEQUENTIAL 2 /* expect sequential references */ +#define MADV_WILLNEED 3 /* will need these pages */ +#define MADV_DONTNEED 4 /* don't need these pages */ +#define MADV_FREE 5 /* data is now unimportant */ +#define MADV_NOSYNC 6 /* no explicit commit to physical backing store */ +#define MADV_AUTOSYNC 7 /* default commit method to physical backing store */ +.Ed +.Pp +.Bl -tag -width MADV_SEQUENTIAL +.It Dv MADV_NORMAL +Tells the system to revert to the default paging +behavior. +.It Dv MADV_RANDOM +Is a hint that pages will be accessed randomly, and prefetching +is likely not advantageous. +.It Dv MADV_SEQUENTIAL +Causes the VM system to depress the priority of +pages immediately preceding a given page when it is faulted in. +.It Dv MADV_WILLNEED +Causes pages that are in a given virtual address range +to temporarily have higher priority, and if they are in +memory, decrease the likelihood of them being freed. Additionally, +the pages that are already in memory will be immediately mapped into +the process, thereby eliminating unnecessary overhead of going through +the entire process of faulting the pages in. This WILL NOT fault +pages in from backing store, but quickly map the pages already in memory +into the calling process. +.It Dv MADV_DONTNEED +Allows the VM system to decrease the in-memory priority +of pages in the specified range. Additionally future references to +this address range will incur a page fault. +.It Dv MADV_FREE +Gives the VM system the freedom to free pages, +and tells the system that information in the specified page range +is no longer important. This is an efficient way of allowing +.Xr malloc 3 +to free pages anywhere in the address space, while keeping the address space +valid. The next time that the page is referenced, the page might be demand +zeroed, or might contain the data that was there before the +.Dv MADV_FREE +call. +References made to that address space range will not make the VM system +page the information back in from backing store until the page is +modified again. +.It Dv MADV_NOSYNC +Request that the system not flush the data associated with this map to +physical backing store unless it needs to. Typically this prevents the +filesystem update daemon from gratuitously writing pages dirtied +by the VM system to physical disk. Note that VM/filesystem coherency is +always maintained, this feature simply ensures that the mapped data is +only flush when it needs to be, usually by the system pager. +.Pp +This feature is typically used when you want to use a file-backed shared +memory area to communicate between processes (IPC) and do not particularly +need the data being stored in that area to be physically written to disk. +With this feature you get the equivalent performance with mmap that you +would expect to get with SysV shared memory calls, but in a more controllable +and less restrictive manner. However, note that this feature is not portable +across UNIX platforms (though some may do the right thing by default). +For more information see the MAP_NOSYNC section of +.Xr mmap 2 +.It Dv MADV_AUTOSYNC +Undoes the effects of MADV_NOSYNC for any future pages dirtied within the +address range. The effect on pages already dirtied is indeterminate - they +may or may not be reverted. You can guarentee reversion by using the +.Xr msync 2 +or +.Xr fsync 2 +system calls. +.El +.Sh RETURN VALUES +Upon successful completion, +.Fn madvise +returns 0. Otherwise a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn madvise +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The virtual address range specified by the +.Fa addr +and +.Fa len +arguments is not valid. +.El +.Sh SEE ALSO +.Xr mincore 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munmap 2 . +.Sh HISTORY +The +.Fn madvise +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/mincore.2 b/lib/libc/sys/mincore.2 new file mode 100644 index 0000000..533c153 --- /dev/null +++ b/lib/libc/sys/mincore.2 @@ -0,0 +1,88 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mincore.2 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD$ +.\" +.Dd June 9, 1993 +.Dt MINCORE 2 +.Os +.Sh NAME +.Nm mincore +.Nd get advice about use of memory +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn mincore "const void *addr" "size_t len" "char *vec" +.Sh DESCRIPTION +The +.Fn mincore +system call +allows a process to obtain information about whether pages are +core resident. +Here the current core residency of the pages is returned +in the character array +.Fa vec , +with a value of 1 meaning +that the page is in-core. +.Sh RETURN VALUES +Upon successful completion, +.Fn mincore +returns 0 and +.Fa vec +is updated to reflect the page status. Otherwise a value of -1 +is returned and +.Va error +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The virtial address range specified by the +.Fa addr +and +.Fa len +arguments is not valid. +.It Bq Er EFAULT +The +.Fa vec +argument points to an illegal address. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn mincore +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/minherit.2 b/lib/libc/sys/minherit.2 new file mode 100644 index 0000000..66dbb0b --- /dev/null +++ b/lib/libc/sys/minherit.2 @@ -0,0 +1,94 @@ +.\" $FreeBSD$ +.\" +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)minherit.2 8.1 (Berkeley) 6/9/93 +.\" +.Dd Feb 17, 1996 +.Dt MINHERIT 2 +.Os +.Sh NAME +.Nm minherit +.Nd control the inheritance of pages +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn minherit "void *addr" "size_t len" "int inherit" +.Sh DESCRIPTION +The +.Fn minherit +system call +changes the specified pages to have the inheritance characteristic +.Fa inherit . +Not all implementations will guarantee that the inheritance characteristic +can be set on a page basis; +the granularity of changes may be as large as an entire region. +.Sh RETURN VALUES +Upon successful completion, +.Fn minherit +returns 0. Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn minherit +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The virtual address range specified by the +.Fa addr +and +.Fa len +arguments is not valid. +.It Bq Er EACCES +The flags specified by the +.Fa inherit +argument were not valid for the pages specified +by the +.Fa addr +and +.Fa len +arguments. +.El +.Sh SEE ALSO +.Xr fork 2 , +.Xr madvise 2 , +.Xr mincore 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munmap 2 , +.Xr rfork 2 +.Sh HISTORY +The +.Fn minherit +function first appeared in OpenBSD. diff --git a/lib/libc/sys/mkdir.2 b/lib/libc/sys/mkdir.2 new file mode 100644 index 0000000..c2d8835 --- /dev/null +++ b/lib/libc/sys/mkdir.2 @@ -0,0 +1,110 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mkdir.2 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD$ +.\" +.Dd December 11, 1993 +.Dt MKDIR 2 +.Os BSD 4.2 +.Sh NAME +.Nm mkdir +.Nd make a directory file +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/stat.h> +.Ft int +.Fn mkdir "const char *path" "mode_t mode" +.Sh DESCRIPTION +The directory +.Fa path +is created with the access permissions specified by +.Fa mode +and restricted by the +.Xr umask 2 +of the calling process. +.Pp +The directory's owner ID is set to the process's effective user ID. +The directory's group ID is set to that of the parent directory in +which it is created. +.Sh RETURN VALUES +A 0 return value indicates success. A -1 return value +indicates an error, and an error code is stored in +.Va errno . +.Sh ERRORS +.Fn Mkdir +will fail and no directory will be created if: +.Bl -tag -width ENAMETOOLO +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +A component of the path prefix does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EEXIST +The named file exists. +.It Bq Er ENOSPC +The new directory cannot be created because there is no space left +on the file system that will contain the directory. +.It Bq Er ENOSPC +There are no free inodes on the file system on which the +directory is being created. +.It Bq Er EDQUOT +The new directory cannot be created because the user's +quota of disk blocks on the file system that will +contain the directory has been exhausted. +.It Bq Er EDQUOT +The user's quota of inodes on the file system on +which the directory is being created has been exhausted. +.It Bq Er EIO +An I/O error occurred while making the directory entry or allocating the inode. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr stat 2 , +.Xr umask 2 +.Sh STANDARDS +The +.Fn mkdir +function call is expected to conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/mkfifo.2 b/lib/libc/sys/mkfifo.2 new file mode 100644 index 0000000..36ab734 --- /dev/null +++ b/lib/libc/sys/mkfifo.2 @@ -0,0 +1,121 @@ +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mkfifo.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt MKFIFO 2 +.Os +.Sh NAME +.Nm mkfifo +.Nd make a fifo file +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/stat.h> +.Ft int +.Fn mkfifo "const char *path" "mode_t mode" +.Sh DESCRIPTION +.Fn Mkfifo +creates a new fifo file with name +.Fa path . +The access permissions are +specified by +.Fa mode +and restricted by the +.Xr umask 2 +of the calling process. +.Pp +The fifo's owner ID is set to the process's effective user ID. +The fifo's group ID is set to that of the parent directory in +which it is created. +.Sh RETURN VALUES +A 0 return value indicates success. A -1 return value +indicates an error, and an error code is stored in +.Va errno . +.Sh ERRORS +.Fn Mkfifo +will fail and no fifo will be created if: +.Bl -tag -width ENAMETOOLO +.It Bq Er ENOTSUPP +The kernel has not been configured to support fifo's. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +A component of the path prefix does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EEXIST +The named file exists. +.It Bq Er ENOSPC +The directory in which the entry for the new fifo is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.It Bq Er ENOSPC +There are no free inodes on the file system on which the +fifo is being created. +.It Bq Er EDQUOT +The directory in which the entry for the new fifo +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EDQUOT +The user's quota of inodes on the file system on +which the fifo is being created has been exhausted. +.It Bq Er EIO +An +.Tn I/O +error occurred while making the directory entry or allocating the inode. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr mknod 2 , +.Xr stat 2 , +.Xr umask 2 +.Sh STANDARDS +The +.Fn mkfifo +function call is expected to conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/mknod.2 b/lib/libc/sys/mknod.2 new file mode 100644 index 0000000..90287b2 --- /dev/null +++ b/lib/libc/sys/mknod.2 @@ -0,0 +1,125 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mknod.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt MKNOD 2 +.Os BSD 4 +.Sh NAME +.Nm mknod +.Nd make a special file node +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn mknod "const char *path" "mode_t mode" "dev_t dev" +.Sh DESCRIPTION +The filesystem node +.Fa path +is created with the file type and access permissions specified in +.Fa mode . +The access permissions are modified by the process's umask value. +.Pp +If +.Fa mode +indicates a block or character special file, +.Fa dev +is a configuration dependent specification denoting a particular device +on the system. +Otherwise, +.Fa dev +is ignored. +.Pp +.Fn Mknod +requires super-user privileges. +.Sh RETURN VALUES +Upon successful completion a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Mknod +will fail and the file will be not created if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +A component of the path prefix does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The process's effective user ID is not super-user. +.It Bq Er EIO +An I/O error occurred while making the directory entry or allocating the inode. +.It Bq Er ENOSPC +The directory in which the entry for the new node is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.It Bq Er ENOSPC +There are no free inodes on the file system on which the +node is being created. +.It Bq Er EDQUOT +The directory in which the entry for the new node +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EDQUOT +The user's quota of inodes on the file system on +which the node is being created has been exhausted. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EEXIST +The named file exists. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EINVAL +Creating anything else than a block or character special +file (or a +.Em whiteout ) +is not supported. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr mkfifo 2 , +.Xr stat 2 , +.Xr umask 2 +.Sh HISTORY +A +.Fn mknod +function call appeared in +.At v6 . diff --git a/lib/libc/sys/mlock.2 b/lib/libc/sys/mlock.2 new file mode 100644 index 0000000..b5706b0 --- /dev/null +++ b/lib/libc/sys/mlock.2 @@ -0,0 +1,173 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mlock.2 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD$ +.\" +.Dd June 2, 1993 +.Dt MLOCK 2 +.Os +.Sh NAME +.Nm mlock , +.Nm munlock +.Nd lock (unlock) physical pages in memory +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn mlock "const void *addr" "size_t len" +.Ft int +.Fn munlock "const void *addr" "size_t len" +.Sh DESCRIPTION +The +.Fn mlock +system call +locks into memory the physical pages associated with the virtual address +range starting at +.Fa addr +for +.Fa len +bytes. +The +.Fn munlock +call unlocks pages previously locked by one or more +.Fn mlock +calls. +For both, the +.Fa addr +parameter should be aligned to a multiple of the page size. +If the +.Fa len +parameter is not a multiple of the page size, it will be rounded up +to be so. +The entire range must be allocated. +.Pp +After an +.Fn mlock +call, the indicated pages will cause neither a non-resident page +nor address-translation fault until they are unlocked. +They may still cause protection-violation faults or TLB-miss faults on +architectures with software-managed TLBs. +The physical pages remain in memory until all locked mappings for the pages +are removed. +Multiple processes may have the same physical pages locked via their own +virtual address mappings. +A single process may likewise have pages multiply-locked via different virtual +mappings of the same pages or via nested +.Fn mlock +calls on the same address range. +Unlocking is performed explicitly by +.Fn munlock +or implicitly by a call to +.Fn munmap +which deallocates the unmapped address range. +Locked mappings are not inherited by the child process after a +.Xr fork 2 . +.Pp +Since physical memory is a potentially scarce resource, processes are +limited in how much they can lock down. +A single process can +.Fn mlock +the minimum of +a system-wide ``wired pages'' limit and +the per-process +.Li RLIMIT_MEMLOCK +resource limit. +.Pp +These calls are only available to the super-user. +.Sh RETURN VALUES +A return value of 0 indicates that the call +succeeded and all pages in the range have either been locked or unlocked. +A return value of -1 indicates an error occurred and the locked +status of all pages in the range remains unchanged. +In this case, the global location +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Mlock +will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er EINVAL +The address given is not page aligned or the length is negative. +.It Bq Er EAGAIN +Locking the indicated range would exceed either the system or per-process +limit for locked memory. +.It Bq Er ENOMEM +Some portion of the indicated address range is not allocated. +There was an error faulting/mapping a page. +.El +.Fn Munlock +will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er EINVAL +The address given is not page aligned or the length is negative. +.It Bq Er ENOMEM +Some portion of the indicated address range is not allocated. +Some portion of the indicated address range is not locked. +.El +.Sh "SEE ALSO" +.Xr fork 2 , +.Xr mincore 2 , +.Xr minherit 2 , +.Xr mmap 2 , +.Xr munmap 2 , +.Xr setrlimit 2 , +.Xr getpagesize 3 +.Sh BUGS +Unlike The Sun implementation, multiple +.Fn mlock +calls on the same address range require the corresponding number of +.Fn munlock +calls to actually unlock the pages, i.e. +.Fn mlock +nests. +This should be considered a consequence of the implementation +and not a feature. +.Pp +The per-process resource limit is a limit on the amount of virtual +memory locked, while the system-wide limit is for the number of locked +physical pages. +Hence a process with two distinct locked mappings of the same physical page +counts as 2 pages against the per-process limit and as only a single page +in the system limit. + +The per-process resource limit is not currently supported. +.Sh HISTORY +The +.Fn mlock +and +.Fn munlock +functions first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2 new file mode 100644 index 0000000..e165d32 --- /dev/null +++ b/lib/libc/sys/mmap.2 @@ -0,0 +1,290 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mmap.2 8.4 (Berkeley) 5/11/95 +.\" $FreeBSD$ +.\" +.Dd May 11, 1995 +.Dt MMAP 2 +.Os BSD 4 +.Sh NAME +.Nm mmap +.Nd map files or devices into memory +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft void * +.Fn mmap "void * addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset" +.Sh DESCRIPTION +The +.Fn mmap +function causes the pages starting at +.Fa addr +and continuing for at most +.Fa len +bytes to be mapped from the object described by +.Fa fd , +starting at byte offset +.Fa offset . +If +.Fa len +is not a multiple of the pagesize, the mapped region may extend past the +specified range. +Any such extension beyond the end of the mapped object will be zero-filled. +.Pp +If +.Fa addr +is non-zero, it is used as a hint to the system. +(As a convenience to the system, the actual address of the region may differ +from the address supplied.) +If +.Fa addr +is zero, an address will be selected by the system. +The actual starting address of the region is returned. +A successful +.Fa mmap +deletes any previous mapping in the allocated address range. +.Pp +The protections (region accessibility) are specified in the +.Fa prot +argument by +.Em or Ns 'ing +the following values: +.Pp +.Bl -tag -width MAP_FIXEDX +.It Dv PROT_EXEC +Pages may be executed. +.It Dv PROT_READ +Pages may be read. +.It Dv PROT_WRITE +Pages may be written. +.El +.Pp +The +.Fa flags +parameter specifies the type of the mapped object, mapping options and +whether modifications made to the mapped copy of the page are private +to the process or are to be shared with other references. +Sharing, mapping type and options are specified in the +.Fa flags +argument by +.Em or Ns 'ing +the following values: +.Pp +.Bl -tag -width MAP_FIXEDX +.It Dv MAP_ANON +Map anonymous memory not associated with any specific file. +The file descriptor used for creating +.Dv MAP_ANON +must be \-1. +The +.Fa offset +parameter is ignored. +.\".It Dv MAP_FILE +.\"Mapped from a regular file or character-special device memory. +.It Dv MAP_FIXED +Do not permit the system to select a different address than the one +specified. +If the specified address cannot be used, +.Fn mmap +will fail. +If MAP_FIXED is specified, +.Fa addr +must be a multiple of the pagesize. +Use of this option is discouraged. +.It Dv MAP_HASSEMAPHORE +Notify the kernel that the region may contain semaphores and that special +handling may be necessary. +.It Dv MAP_INHERIT +Permit regions to be inherited across +.Xr execve 2 +system calls. +.It Dv MAP_PRIVATE +Modifications are private. +.It Dv MAP_SHARED +Modifications are shared. +.It Dv MAP_STACK +This option is only available if your system has been compiled with +VM_STACK defined when compiling the kernel. This is the default for +i386 only. Consider adding -DVM_STACK to COPTFLAGS in your /etc/make.conf +to enable this option for other architechures. MAP_STACK implies +MAP_ANON, and +.Fa offset +of 0. +.Fa fd +must be -1 and +.Fa prot +must include at least PROT_READ and PROT_WRITE. This option creates +a memory region that grows to at most +.Fa len +bytes in size, starting from the stack top and growing down. The +stack top is the starting address returned by the call, plus +.Fa len +bytes. The bottom of the stack at maximum growth is the starting +address returned by the call. +.It Dv MAP_NOSYNC +Causes data dirtied via this VM map to be flushed to physical media +only when necessary (usually by the pager) rather then gratuitously. +Typically this prevents the update daemons from flushing pages dirtied +through such maps and thus allows efficient sharing of memory across +unassociated processes using a file-backed shared memory map. Without +this option any VM pages you dirty may be flushed to disk every so often +(every 30-60 seconds usually) which can create performance problems if you +do not need that to occur (such as when you are using shared file-backed +mmap regions for IPC purposes). Note that VM/filesystem coherency is +maintained whether you use MAP_NOSYNC or not. This option is not portable +across UNIX platforms (yet), though some may implement the same behavior +by default. +.Pp +The +.Xr fsync 2 +function will flush all dirty data and metadata associated with a file, +including dirty NOSYNC VM data, to physical media. The +.Xr sync 1 +command and +.Xr sync 2 +system call generally do not flush dirty NOSYNC VM data. +The +.Xr msync 2 +system call is obsolete since +.Os BSD +implements a coherent filesystem buffer cache. However, it may be +used to associate dirty VM pages with filesystem buffers and thus cause +them to be flushed to physical media sooner rather then later. +.El +.Pp +The +.Xr close 2 +function does not unmap pages, see +.Xr munmap 2 +for further information. +.Pp +The current design does not allow a process to specify the location of +swap space. +In the future we may define an additional mapping type, +.Dv MAP_SWAP , +in which +the file descriptor argument specifies a file or device to which swapping +should be done. +.Sh RETURN VALUES +Upon successful completion, +.Fn mmap +returns a pointer to the mapped region. +Otherwise, a value of MAP_FAILED is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Mmap +will fail if: +.Bl -tag -width Er +.It Bq Er EACCES +The flag +.Dv PROT_READ +was specified as part of the +.Fa prot +parameter and +.Fa fd +was not open for reading. +The flags +.Dv MAP_SHARED +and +.Dv PROT_WRITE +were specified as part of the +.Fa flags +and +.Fa prot +parameters and +.Fa fd +was not open for writing. +.It Bq Er EBADF +.Fa Fd +is not a valid open file descriptor. +.It Bq Er EINVAL +.Dv MAP_FIXED +was specified and the +.Fa addr +parameter was not page aligned, or part of the desired address space +resides out of the valid address space for a user process. +.It Bq Er EINVAL +.Fa Len +was negative. +.It Bq Er EINVAL +.Dv MAP_ANON +was specified and the +.Fa fd +parameter was not -1. +.It Bq Er EINVAL +.Dv MAP_ANON +has not been specified and +.Fa fd +did not reference a regular or character special file. +.It Bq Er EINVAL +.Fa Offset +was not page-aligned. (See BUGS below.) +.It Bq Er ENOMEM +.Dv MAP_FIXED +was specified and the +.Fa addr +parameter wasn't available. +.Dv MAP_ANON +was specified and insufficient memory was available. +.Sh "SEE ALSO" +.Xr madvise 2 , +.Xr mincore 2 , +.Xr mlock 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munlock 2 , +.Xr munmap 2 , +.Xr getpagesize 3 +.Sh BUGS +.Ar len +is limited to 2GB. Mmapping slightly more than 2GB doesn't work, but +it is possible to map a window of size (filesize % 2GB) for file sizes +of slightly less than 2G, 4GB, 6GB and 8GB. +.Pp +The limit is imposed for a variety of reasons. Most of them have to do +with +.Tn FreeBSD +not wanting to use 64 bit offsets in the VM system due to +the extreme performance penalty. So +.Tn FreeBSD +uses 32bit page indexes and +this gives +.Tn FreeBSD +a maximum of 8TB filesizes. It's actually bugs in +the filesystem code that causes the limit to be further restricted to +1TB (loss of precision when doing blockno calculations). +.Pp +Another reason for the 2GB limit is that filesystem metadata can +reside at negative offsets. +.Pp +We currently can only deal with page aligned file offsets. diff --git a/lib/libc/sys/mmap.c b/lib/libc/sys/mmap.c new file mode 100644 index 0000000..32aeffb --- /dev/null +++ b/lib/libc/sys/mmap.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/syscall.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +void * +mmap(addr, len, prot, flags, fd, offset) + void * addr; + size_t len; + int prot; + int flags; + int fd; + off_t offset; +{ + + return((void *)(long)__syscall((quad_t)SYS_mmap, addr, len, prot, flags, + fd, 0, offset)); +} diff --git a/lib/libc/sys/mount.2 b/lib/libc/sys/mount.2 new file mode 100644 index 0000000..d4959ed --- /dev/null +++ b/lib/libc/sys/mount.2 @@ -0,0 +1,324 @@ +.\" Copyright (c) 1980, 1989, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mount.2 8.3 (Berkeley) 5/24/95 +.\" $FreeBSD$ +.\" +.Dd May 24, 1995 +.Dt MOUNT 2 +.Os BSD 4 +.Sh NAME +.Nm mount , +.Nm unmount +.Nd mount or dismount a filesystem +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/mount.h> +.Ft int +.Fn mount "const char *type" "const char *dir" "int flags" "void *data" +.Ft int +.Fn unmount "const char *dir" "int flags" +.Sh DESCRIPTION +The +.Fn mount +function grafts +a filesystem object onto the system file tree +at the point +.Ar dir . +The argument +.Ar data +describes the filesystem object to be mounted. +The argument +.Ar type +tells the kernel how to interpret +.Ar data +(See +.Ar type +below). +The contents of the filesystem +become available through the new mount point +.Ar dir . +Any files in +.Ar dir +at the time +of a successful mount are swept under the carpet so to speak, and +are unavailable until the filesystem is unmounted. +.Pp +The following +.Ar flags +may be specified to +suppress default semantics which affect filesystem access. +.Bl -tag -width MNT_SYNCHRONOUS +.It Dv MNT_RDONLY +The filesystem should be treated as read-only; +Even the super-user may not write on it. +Specifying MNT_UPDATE without this option will upgrade +a read-only filesystem to read/write. +.It Dv MNT_NOEXEC +Do not allow files to be executed from the filesystem. +.It Dv MNT_NOSUID +Do not honor setuid or setgid bits on files when executing them. +.It Dv MNT_NOATIME +Disable update of file access times. +.It Dv MNT_NODEV +Do not interpret special files on the filesystem. +.It Dv MNT_SUIDDIR +Directories with the SUID bit set chown new files to their own owner. +.It Dv MNT_SYNCHRONOUS +All I/O to the filesystem should be done synchronously. +.It Dv MNT_ASYNC +All I/O to the filesystem should be done asynchronously. +.It Dv MNT_FORCE +Force a read-write mount even if the filesystem appears to be unclean. +Dangerous. +.It Dv MNT_NOCLUSTERR +Disable read clustering. +.It Dv MNT_NOCLUSTERW +Disable write clustering. +.El +.Pp +The flag +.Dv MNT_UPDATE +indicates that the mount command is being applied +to an already mounted filesystem. +This allows the mount flags to be changed without requiring +that the filesystem be unmounted and remounted. +Some filesystems may not allow all flags to be changed. +For example, +many filesystems will not allow a change from read-write to read-only. +.Pp +The flag +.Dv MNT_RELOAD +causes the vfs subsystem to update its data structures pertaining to +the specified already mounted filesystem. +.Pp +The +.Fa type +argument names the filesystem. +The types of filesystems known to the system can be obtained with +.Xr lsvfs 1 . +.Pp +.Fa Data +is a pointer to a structure that contains the type +specific arguments to mount. +The format for these argument structures is described in the +manual page for each filesystem. +By convention filesystem manual pages are named +by prefixing ``mount_'' to the name of the filesystem as returned by +.Xr lsvfs 1 . +Thus the +.Nm NFS +filesystem is described by the +.Xr mount_nfs 8 +manual page. +.Pp +The +.Fn unmount +function call disassociates the filesystem from the specified +mount point +.Fa dir . +.Pp +The +.Fa flags +argument may specify +.Dv MNT_FORCE +to specify that the filesystem should be forcibly unmounted or made read-only +(if MNT_UPDATE and MNT_RDONLY are also specified) +even if files are still active. +Active special devices continue to work, +but any further accesses to any other active files result in errors +even if the filesystem is later remounted. +.Pp +The +.Dv MNT_SUIDDIR +option requires the SUIDDIR option to have been compiled into the kernel +to have any effect. +See the +.Xr mount 8 +and +.Xr chmod 2 +pages for more information. +.Sh RETURN VALUES +The +.Fn mount +returns the value 0 if the mount was successful, otherwise -1 is returned +and the variable +.Va errno +is set to indicate the error. +.Pp +The +.Fn unmount +function returns the value 0 if the umount succeeded; otherwise -1 is returned +and the variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn mount +function will fail when one of the following occurs: +.Bl -tag -width [ENOTBLK] +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or the entire length of a path name exceeded 1023 characters. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating a pathname. +.It Bq Er ENOENT +A component of +.Fa dir +does not exist. +.It Bq Er ENOTDIR +A component of +.Ar name +is not a directory, +or a path prefix of +.Ar special +is not a directory. +.It Bq Er EBUSY +Another process currently holds a reference to +.Fa dir . +.It Bq Er EFAULT +.Fa Dir +points outside the process's allocated address space. +.El +.Pp +The following errors can occur for a +.Em ufs +filesystem mount: +.Bl -tag -width [ENOTBLK] +.It Bq Er ENODEV +A component of ufs_args +.Ar fspec +does not exist. +.It Bq Er ENOTBLK +.Ar Fspec +is not a block device. +.It Bq Er ENXIO +The major device number of +.Ar fspec +is out of range (this indicates no device driver exists +for the associated hardware). +.It Bq Er EBUSY +.Ar Fspec +is already mounted. +.It Bq Er EMFILE +No space remains in the mount table. +.It Bq Er EINVAL +The super block for the filesystem had a bad magic +number or an out of range block size. +.It Bq Er ENOMEM +Not enough memory was available to read the cylinder +group information for the filesystem. +.It Bq Er EIO +An I/O error occurred while reading the super block or +cylinder group information. +.It Bq Er EFAULT +.Ar Fspec +points outside the process's allocated address space. +.El +.Pp +The following errors can occur for a +.Em nfs +filesystem mount: +.Bl -tag -width [ENOTBLK] +.It Bq Er ETIMEDOUT +.Em Nfs +timed out trying to contact the server. +.It Bq Er EFAULT +Some part of the information described by nfs_args +points outside the process's allocated address space. +.El +.Pp +The following errors can occur for a +.Em mfs +filesystem mount: +.Bl -tag -width [ENOTBLK] +.It Bq Er EMFILE +No space remains in the mount table. +.It Bq Er EINVAL +The super block for the filesystem had a bad magic +number or an out of range block size. +.It Bq Er ENOMEM +Not enough memory was available to read the cylinder +group information for the filesystem. +.It Bq Er EIO +A paging error occurred while reading the super block or +cylinder group information. +.It Bq Er EFAULT +.Em Name +points outside the process's allocated address space. +.El +.Pp +The +.Fn unmount +function may fail with one of the following errors: +.Bl -tag -width [ENOTBLK] +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er ENOTDIR +A component of the path is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EINVAL +The requested directory is not in the mount table. +.It Bq Er EBUSY +A process is holding a reference to a file located +on the filesystem. +.It Bq Er EIO +An I/O error occurred while writing cached filesystem information. +.It Bq Er EFAULT +.Fa Dir +points outside the process's allocated address space. +.El +.Pp +A +.Em ufs +or +.Em mfs +mount can also fail if the maximum number of filesystems are currently +mounted. +.Sh SEE ALSO +.Xr lsvfs 1 , +.Xr mfs 8 , +.Xr mount 8 , +.Xr umount 8 +.Sh BUGS +Some of the error codes need translation to more obvious messages. +.Sh HISTORY +.Fn Mount +and +.Fn unmount +function calls appeared in +.At v6 . diff --git a/lib/libc/sys/mprotect.2 b/lib/libc/sys/mprotect.2 new file mode 100644 index 0000000..533b1fe --- /dev/null +++ b/lib/libc/sys/mprotect.2 @@ -0,0 +1,88 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)mprotect.2 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD$ +.\" +.Dd June 9, 1993 +.Dt MPROTECT 2 +.Os +.Sh NAME +.Nm mprotect +.Nd control the protection of pages +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn mprotect "const void *addr" "size_t len" "int prot" +.Sh DESCRIPTION +The +.Fn mprotect +system call +changes the specified pages to have protection +.Fa prot . +Not all implementations will guarantee protection on a page basis; +the granularity of protection changes may be as large as an entire region. +.Sh RETURN VALUES +Upon successful completion, +.Fn mprotect +returns 0. Otherwise a value of -1 is returned +and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn mprotect +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The virtual address range specified by the +.Fa addr +and +.Fa len +arguments is not valid. +.It Bq Er EACCES +The calling process was not allowed to change +the protection to the value specified by +the +.Fa prot +argument. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mincore 2 , +.Xr msync 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn mprotect +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/msync.2 b/lib/libc/sys/msync.2 new file mode 100644 index 0000000..7a86cd4 --- /dev/null +++ b/lib/libc/sys/msync.2 @@ -0,0 +1,99 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)msync.2 8.2 (Berkeley) 6/21/94 +.\" $FreeBSD$ +.\" +.Dd June 21, 1994 +.Dt MSYNC 2 +.Os +.Sh NAME +.Nm msync +.Nd synchronize a mapped region +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn msync "void *addr" "size_t len" "int flags" +.Sh DESCRIPTION +The +.Fn msync +system call +writes any modified pages back to the filesystem and updates +the file modification time. +If +.Fa len +is 0, all modified pages within the region containing +.Fa addr +will be flushed; +if +.Fa len +is non-zero, only those pages containing +.Fa addr +and +.Fa len-1 +succeeding locations will be examined. +The +.Fa flags +argument may be specified as follows: +.Bd -literal +MS_ASYNC Return immediately (not currently implemented) +MS_SYNC Perform synchronous writes +MS_INVALIDATE Invalidate all cached data +.Ed +.Sh RETURN VALUES +If any errors occur, -1 is returned and errno is set to indicate the +error. Otherwise, a 0 value is returned. +.Sh ERRORS +.Fn msync +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa addr +is not a multiple of the hardware page size. +.It Bq Er EINVAL +.Fa len +is too large or negative. +.It Bq Er EINVAL +.Fa flags +was both MS_ASYNC and MS_INVALIDATE. Only one of these flags is allowed. +.It Bq Er EIO +An I/O error occurred while writing to the file system. +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mincore 2 , +.Xr mprotect 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn msync +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/munmap.2 b/lib/libc/sys/munmap.2 new file mode 100644 index 0000000..e2c89bf --- /dev/null +++ b/lib/libc/sys/munmap.2 @@ -0,0 +1,83 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)munmap.2 8.3 (Berkeley) 5/27/94 +.\" $FreeBSD$ +.\" +.Dd May 27, 1994 +.Dt MUNMAP 2 +.Os +.Sh NAME +.Nm munmap +.Nd remove a mapping +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn munmap "void *addr" "size_t len" +.Sh DESCRIPTION +The +.Fn munmap +system call +deletes the mappings for the specified address range, +and causes further references to addresses within the range +to generate invalid memory references. +.Sh RETURN VALUES +Upon successful completion, +.Fn munmap +returns zero. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Munmap +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa addr +parameter was not page aligned, the +.Fa len +parameter was negative, or +some part of the region being unmapped is outside the +valid address range for a process. +.Sh "SEE ALSO" +.Xr madvise 2 , +.Xr mincore 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munmap 2 , +.Xr getpagesize 3 +.Sh HISTORY +The +.Fn munmap +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/nanosleep.2 b/lib/libc/sys/nanosleep.2 new file mode 100644 index 0000000..fe39fd7 --- /dev/null +++ b/lib/libc/sys/nanosleep.2 @@ -0,0 +1,104 @@ +.\" $FreeBSD$ +.\" $OpenBSD: nanosleep.2,v 1.1 1997/04/20 20:56:20 tholo Exp $ +.\" $NetBSD: nanosleep.2,v 1.1 1997/04/17 18:12:02 jtc Exp $ +.\" +.\" Copyright (c) 1986, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93 +.\" +.Dd April 17, 1997 +.Dt NANOSLEEP 2 +.Os +.Sh NAME +.Nm nanosleep +.Nd suspend process execution for an interval measured in nanoseconds +.Sh SYNOPSIS +.Fd #include <time.h> +.Ft int +.Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp" +.Sh DESCRIPTION +.Fn Nanosleep +causes the process to sleep for the specified time. An unmasked signal will +cause it to terminate the sleep early, regardless of the +.Dv SA_RESTART +value on the interrupting signal. +.Sh RETURN VALUES +If the +.Fn nanosleep +function returns because the requested time has elapsed, the value +returned will be zero. +.Pp +If the +.Fn nanosleep +function returns due to the delivery of a signal, the value returned +will be the -1, and the global variable +.Va errno +will be set to indicate the interruption. +If +.Fa rmtp +is +.Pf non- Dv NULL , +the timespec structure it references is updated to contain the +unslept amount (the request time minus the time actually slept). +.Pp +If any of the following conditions occur, the +.Fn nanosleep +function shall return -1 and set +.Va errno +to the corresponding value: +.Bl -tag -width Er +.It Bq Er EFAULT +Either +.Fa rqtp +or +.Fa rmtp +points to memory that is not a valid part of the process +address space. +.It Bq Er EINTR +.Fn nanosleep +was interrupted by the delivery of a signal. +.It Bq Er EINVAL +.Fa rqtp +specified a nanosecond value less than zero +or greater than or equal to 1000 million. +.It Bq Er ENOSYS +.Fn nanosleep +is not supported by this implementation. +.El +.Sh SEE ALSO +.Xr sigsuspend 2 , +.Xr sleep 3 +.Sh STANDARDS +The +.Fn nanosleep +function conforms to +.St -p1003.1b-93 . diff --git a/lib/libc/sys/nfssvc.2 b/lib/libc/sys/nfssvc.2 new file mode 100644 index 0000000..5d0eb3b --- /dev/null +++ b/lib/libc/sys/nfssvc.2 @@ -0,0 +1,252 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)nfssvc.2 8.1 (Berkeley) 6/9/93 +.\" $FreeBSD$ +.\" +.Dd June 9, 1993 +.Dt NFSSVC 2 +.Os +.Sh NAME +.Nm nfssvc +.Nd NFS services +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/mount.h> +.Fd #include <sys/time.h> +.Fd #include <nfs/rpcv2.h> +.Fd #include <nfs/nfs.h> +.Fd #include <unistd.h> +.Ft int +.Fn nfssvc "int flags" "void *argstructp" +.Sh DESCRIPTION +The +.Fn nfssvc +function is used by the NFS daemons to pass information into and out +of the kernel and also to enter the kernel as a server daemon. +The +.Fa flags +argument consists of several bits that show what action is to be taken +once in the kernel and the +.Fa argstructp +points to one of three structures depending on which bits are set in +flags. +.Pp +On the client side, +.Xr nfsiod 8 +calls +.Fn nfssvc +with the +.Fa flags +argument set to +.Dv NFSSVC_BIOD +and +.Fa argstructp +set to +.Dv NULL +to enter the kernel as a block I/O server daemon. +For +.Nm NQNFS , +.Xr mount_nfs 8 +calls +.Fn nfssvc +with the +.Dv NFSSVC_MNTD +flag, optionally or'd with the flags +.Dv NFSSVC_GOTAUTH +and +.Dv NFSSVC_AUTHINFAIL +along with a pointer to a +.Bd -literal +struct nfsd_cargs { + char *ncd_dirp; /* Mount dir path */ + uid_t ncd_authuid; /* Effective uid */ + int ncd_authtype; /* Type of authenticator */ + int ncd_authlen; /* Length of authenticator string */ + u_char *ncd_authstr; /* Authenticator string */ + int ncd_verflen; /* and the verifier */ + u_char *ncd_verfstr; + NFSKERBKEY_T ncd_key; /* Session key */ +}; +.Ed +.Pp +structure. +The initial call has only the +.Dv NFSSVC_MNTD +flag set to specify service for the mount point. +If the mount point is using Kerberos, then the +.Xr mount_nfs 8 +daemon will return from +.Fn nfssvc +with errno == ENEEDAUTH whenever the client side requires an ``rcmd'' +authentication ticket for the user. +.Xr Mount_nfs 8 +will attempt to get the Kerberos ticket, and if successful will call +.Fn nfssvc +with the flags +.Dv NFSSVC_MNTD +and +.Dv NFSSVC_GOTAUTH +after filling the ticket into the +ncd_authstr field +and +setting the ncd_authlen and ncd_authtype +fields of the nfsd_cargs structure. +If +.Xr mount_nfs 8 +failed to get the ticket, +.Fn nfssvc +will be called with the flags +.Dv NFSSVC_MNTD , +.Dv NFSSVC_GOTAUTH +and +.Dv NFSSVC_AUTHINFAIL +to denote a failed authentication attempt. +.Pp +On the server side, +.Fn nfssvc +is called with the flag +.Dv NFSSVC_NFSD +and a pointer to a +.Bd -literal +struct nfsd_srvargs { + struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ + uid_t nsd_uid; /* Effective uid mapped to cred */ + u_long nsd_haddr; /* Ip address of client */ + struct ucred nsd_cr; /* Cred. uid maps to */ + int nsd_authlen; /* Length of auth string (ret) */ + u_char *nsd_authstr; /* Auth string (ret) */ + int nsd_verflen; /* and the verfier */ + u_char *nsd_verfstr; + struct timeval nsd_timestamp; /* timestamp from verifier */ + u_long nsd_ttl; /* credential ttl (sec) */ + NFSKERBKEY_T nsd_key; /* Session key */ +}; +.Ed +.Pp +to enter the kernel as an +.Xr nfsd 8 +daemon. +Whenever an +.Xr nfsd 8 +daemon receives a Kerberos authentication ticket, it will return from +.Fn nfssvc +with errno == ENEEDAUTH. +The +.Xr nfsd 8 +will attempt to authenticate the ticket and generate a set of credentials +on the server for the ``user id'' specified in the field nsd_uid. +This is done by first authenticating the Kerberos ticket and then mapping +the Kerberos principal to a local name and getting a set of credentials for +that user via. +.Xr getpwnam 3 +and +.Xr getgrouplist 3 . +If successful, the +.Xr nfsd 8 +will call +.Fn nfssvc +with the +.Dv NFSSVC_NFSD +and +.Dv NFSSVC_AUTHIN +flags set to pass the credential mapping in nsd_cr into the +kernel to be cached on the server socket for that client. +If the authentication failed, +.Xr nfsd 8 +calls +.Fn nfssvc +with the flags +.Dv NFSSVC_NFSD +and +.Dv NFSSVC_AUTHINFAIL +to denote an authentication failure. +.Pp +The master +.Xr nfsd 8 +server daemon calls +.Fn nfssvc +with the flag +.Dv NFSSVC_ADDSOCK +and a pointer to a +.Bd -literal +struct nfsd_args { + int sock; /* Socket to serve */ + caddr_t name; /* Client address for connection based sockets */ + int namelen;/* Length of name */ +}; +.Ed +.Pp +to pass a server side +.Tn NFS +socket into the kernel for servicing by the +.Xr nfsd 8 +daemons. +.Sh RETURN VALUES +Normally +.Fn nfssvc +does not return unless the server +is terminated by a signal when a value of 0 is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to specify the error. +.Sh ERRORS +.Bl -tag -width [ENEEDAUTH] +.It Bq Er ENEEDAUTH +This special error value +is really used for authentication support, particularly Kerberos, +as explained above. +.It Bq Er EPERM +The caller is not the super-user. +.El +.Sh SEE ALSO +.Xr mount_nfs 8 , +.Xr nfsd 8 , +.Xr nfsiod 8 +.Sh HISTORY +The +.Fn nfssvc +function first appeared in +.Bx 4.4 . +.Sh BUGS +The +.Fn nfssvc +system call is designed specifically for the +.Tn NFS +support daemons and as such is specific to their requirements. +It should really return values to indicate the need for authentication +support, since +.Dv ENEEDAUTH +is not really an error. +Several fields of the argument structures are assumed to be valid and +sometimes to be unchanged from a previous call, such that +.Fn nfssvc +must be used with extreme care. diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2 new file mode 100644 index 0000000..2a91040 --- /dev/null +++ b/lib/libc/sys/open.2 @@ -0,0 +1,301 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)open.2 8.2 (Berkeley) 11/16/93 +.\" $FreeBSD$ +.\" +.Dd November 16, 1993 +.Dt OPEN 2 +.Os BSD 4 +.Sh NAME +.Nm open +.Nd open or create a file for reading or writing +.Sh SYNOPSIS +.Fd #include <fcntl.h> +.Ft int +.Fn open "const char *path" "int flags" "..." +.Sh DESCRIPTION +The file name specified by +.Fa path +is opened +for reading and/or writing as specified by the +argument +.Fa flags +and the file descriptor returned to the calling process. +The +.Fa flags +argument may indicate the file is to be +created if it does not exist (by specifying the +.Dv O_CREAT +flag). In this case +.Nm +requires a third argument +.Fa "mode_t mode" , +and the file is created with mode +.Fa mode +as described in +.Xr chmod 2 +and modified by the process' umask value (see +.Xr umask 2 ) . +.Pp +The flags specified are formed by +.Em or Ns 'ing +the following values +.Pp +.Bd -literal -offset indent -compact +O_RDONLY open for reading only +O_WRONLY open for writing only +O_RDWR open for reading and writing +O_NONBLOCK do not block on open +O_APPEND append on each write +O_CREAT create file if it does not exist +O_TRUNC truncate size to 0 +O_EXCL error if create and file exists +O_SHLOCK atomically obtain a shared lock +O_EXLOCK atomically obtain an exclusive lock +.Ed +.Pp +Opening a file with +.Dv O_APPEND +set causes each write on the file +to be appended to the end. If +.Dv O_TRUNC +is specified and the +file exists, the file is truncated to zero length. +If +.Dv O_EXCL +is set with +.Dv O_CREAT +and the file already +exists, +.Fn open +returns an error. This may be used to +implement a simple exclusive access locking mechanism. +If +.Dv O_EXCL +is set and the last component of the pathname is +a symbolic link, +.Fn open +will fail even if the symbolic +link points to a non-existent name. +If the +.Dv O_NONBLOCK +flag is specified and the +.Fn open +call would result +in the process being blocked for some reason (e.g., waiting for +carrier on a dialup line), +.Fn open +returns immediately. +The first time the process attempts to perform I/O on the open +file it will block (not currently implemented). +.Pp +When opening a file, a lock with +.Xr flock 2 +semantics can be obtained by setting +.Dv O_SHLOCK +for a shared lock, or +.Dv O_EXLOCK +for an exclusive lock. +If creating a file with +.Dv O_CREAT , +the request for the lock will never fail +(provided that the underlying filesystem supports locking). +.Pp +If successful, +.Fn open +returns a non-negative integer, termed a file descriptor. +It returns -1 on failure. +The file pointer used to mark the current position within the +file is set to the beginning of the file. +.Pp +When a new file is created it is given the group of the directory +which contains it. +.Pp +The new descriptor is set to remain open across +.Xr execve 2 +system calls; see +.Xr close 2 +and +.Xr fcntl 2 . +.Pp +The system imposes a limit on the number of file descriptors +open simultaneously by one process. +.Xr Getdtablesize 2 +returns the current system limit. +.Pp +.Sh IMPLEMENTATION NOTES +In the non-threaded library +.Fn open +is implemented as the +.Va open +syscall. +.Pp +In the threaded library, the +.Va open +syscall is assembled to +.Fn _thread_sys_open +and +.Fn open +is implemented as a function which disables thread rescheduling +and calls +.Fn _thread_sys_open . +Before returning, +.Fn open +enables thread rescheduling. +.Sh RETURN VALUES +If successful, +.Fn open +returns a non-negative integer, termed a file descriptor. +It returns -1 on failure, and sets +.Va errno +to indicate the error. +.Sh ERRORS +The named file is opened unless: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +.Dv O_CREAT +is not set and the named file does not exist. +.It Bq Er ENOENT +A component of the path name that must exist does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +The required permissions (for reading and/or writing) +are denied for the given flags. +.It Bq Er EACCES +.Dv O_CREAT +is specified, +the file does not exist, +and the directory in which it is to be created +does not permit writing. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EISDIR +The named file is a directory, and the arguments specify +it is to be opened for writing. +.It Bq Er EROFS +The named file resides on a read-only file system, +and the file is to be modified. +.It Bq Er EMFILE +The process has already reached its limit for open file descriptors. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENXIO +The named file is a character special or block +special file, and the device associated with this special file +does not exist. +.It Bq Er ENXIO +The named file is a fifo, no process has +it open for reading, and the arguments specify it is +to be opened for writing. +.It Bq Er EINTR +The +.Fn open +operation was interrupted by a signal. +.It Bq Er EOPNOTSUPP +.Dv O_SHLOCK +or +.Dv O_EXLOCK +is specified but the underlying filesystem does not support locking. +.It Bq Er ENOSPC +.Dv O_CREAT +is specified, +the file does not exist, +and the directory in which the entry for the new file is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.It Bq Er ENOSPC +.Dv O_CREAT +is specified, +the file does not exist, +and there are no free inodes on the file system on which the +file is being created. +.It Bq Er EDQUOT +.Dv O_CREAT +is specified, +the file does not exist, +and the directory in which the entry for the new file +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EDQUOT +.Dv O_CREAT +is specified, +the file does not exist, +and the user's quota of inodes on the file system on +which the file is being created has been exhausted. +.It Bq Er EIO +An I/O error occurred while making the directory entry or +allocating the inode for +.Dv O_CREAT . +.It Bq Er ETXTBSY +The file is a pure procedure (shared text) file that is being +executed and the +.Fn open +call requests write access. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EEXIST +.Dv O_CREAT +and +.Dv O_EXCL +were specified and the file exists. +.It Bq Er EOPNOTSUPP +An attempt was made to open a socket (not currently implemented). +.It Bq Er EINVAL +An attempt was made to open a descriptor with an illegal combination +of +.Dv O_RDONLY , +.Dv O_WRONLY , +and +.Dv O_RDWR . +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr close 2 , +.Xr dup 2 , +.Xr getdtablesize 2 , +.Xr lseek 2 , +.Xr read 2 , +.Xr umask 2 , +.Xr write 2 +.Sh HISTORY +An +.Fn open +function call appeared in +.At v6 . diff --git a/lib/libc/sys/pathconf.2 b/lib/libc/sys/pathconf.2 new file mode 100644 index 0000000..8631648 --- /dev/null +++ b/lib/libc/sys/pathconf.2 @@ -0,0 +1,165 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)pathconf.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt PATHCONF 2 +.Os BSD 4 +.Sh NAME +.Nm pathconf , +.Nm fpathconf +.Nd get configurable pathname variables +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft long +.Fn pathconf "const char *path" "int name" +.Ft long +.Fn fpathconf "int fd" "int name" +.Sh DESCRIPTION +.Pp +The +.Fn pathconf +and +.Fn fpathconf +functions provides a method for applications to determine the current +value of a configurable system limit or option variable associated +with a pathname or file descriptor. +.Pp +For +.Fn pathconf , +the +.Fa path +argument is the name of a file or directory. +For +.Fn fpathconf , +the +.Fa fd +argument is an open file descriptor. +The +.Fa name +argument specifies the system variable to be queried. +Symbolic constants for each name value are found in the include file +.Li <unistd.h> . +.Pp +The available values are as follows: +.Pp +.Bl -tag -width "123456" +.Pp +.It Li _PC_LINK_MAX +The maximum file link count. +.It Li _PC_MAX_CANON +The maximum number of bytes in terminal canonical input line. +.It Li _PC_MAX_INPUT +The minimum maximum number of bytes for which space is available in +a terminal input queue. +.It Li _PC_NAME_MAX +The maximum number of bytes in a file name. +.It Li _PC_PATH_MAX +The maximum number of bytes in a pathname. +.It Li _PC_PIPE_BUF +The maximum number of bytes which will be written atomically to a pipe. +.It Li _PC_CHOWN_RESTRICTED +Return 1 if appropriate privileges are required for the +.Xr chown 2 +system call, otherwise 0. +.It Li _PC_NO_TRUNC +Return 1 if file names longer than KERN_NAME_MAX are truncated. +.It Li _PC_VDISABLE +Returns the terminal character disabling value. +.El +.Sh RETURN VALUES +If the call to +.Fn pathconf +or +.Fn fpathconf +is not successful, \-1 is returned and +.Va errno +is set appropriately. +Otherwise, if the variable is associated with functionality that does +not have a limit in the system, \-1 is returned and +.Va errno +is not modified. +Otherwise, the current variable value is returned. +.Sh ERRORS +If any of the following conditions occur, the +.Fn pathconf +and +.Fn fpathconf +functions shall return -1 and set +.Va errno +to the corresponding value. +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa name +argument is invalid. +.It Bq Er EINVAL +The implementation does not support an association of the variable +name with the associated file. +.El +.Fn Pathconf +will fail if: +.Bl -tag -width ENAMETOOLONGAA +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Pp +.Bl -tag -width [EFAULT] +.Fn Fpathconf +will fail if: +.It Bq Er EBADF +.Fa fd +is not a valid open file descriptor. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr sysctl 3 +.Sh HISTORY +The +.Fn pathconf +and +.Fn fpathconf +functions first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/pipe.2 b/lib/libc/sys/pipe.2 new file mode 100644 index 0000000..1151505 --- /dev/null +++ b/lib/libc/sys/pipe.2 @@ -0,0 +1,122 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)pipe.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt PIPE 2 +.Os BSD 4 +.Sh NAME +.Nm pipe +.Nd create descriptor pair for interprocess communication +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn pipe "int *fildes" +.Sh DESCRIPTION +The +.Fn pipe +function +creates a +.Em pipe , +which is an object allowing +bidirectional data flow, +and allocates a pair of file descriptors. +.Pp +By convention, the first descriptor is normally used as the +.Em read end +of the pipe, +and the second is normally the +.Em write end , +so that data written to +.Fa fildes[1] +appears on (i.e., can be read from) +.Fa fildes[0] . +This allows the output of one program to be +sent +to another program: +the source's standard output is set up to be +the write end of the pipe, +and the sink's standard input is set up to be +the read end of the pipe. +The pipe itself persists until all its associated descriptors are +closed. +.Pp +A pipe that has had an end closed is considered +.Em widowed . +Writing on such a pipe causes the writing process to receive +a +.Dv SIGPIPE +signal. +Widowing a pipe is the only way to deliver end-of-file to a reader: +after the reader consumes any buffered data, reading a widowed pipe +returns a zero count. +.Pp +The bidirectional nature of this implementation of pipes is not +portable to older systems, so it is recommended to use the convention +for using the endpoints in the traditional manner when using a +pipe in one direction. +.Sh RETURN VALUES +On successful creation of the pipe, zero is returned. Otherwise, +a value of -1 is returned and the variable +.Va errno +set to indicate the +error. +.Sh ERRORS +The +.Fn pipe +call will fail if: +.Bl -tag -width [EMFILE] +.It Bq Er EMFILE +Too many descriptors are active. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er EFAULT +The +.Fa fildes +buffer is in an invalid area of the process's address +space. +.El +.Sh SEE ALSO +.Xr sh 1 , +.Xr fork 2 , +.Xr read 2 , +.Xr socketpair 2 , +.Xr write 2 +.Sh HISTORY +A +.Fn pipe +function call appeared in +.At v3 . +.Pp +Bidirectional pipes were first used on +.At V.4 . diff --git a/lib/libc/sys/poll.2 b/lib/libc/sys/poll.2 new file mode 100644 index 0000000..ea5b270 --- /dev/null +++ b/lib/libc/sys/poll.2 @@ -0,0 +1,190 @@ +.\" $NetBSD: poll.2,v 1.3 1996/09/07 21:53:08 mycroft Exp $ +.\" $FreeBSD$ +.\" +.\" Copyright (c) 1996 Charles M. Hannum. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Charles M. Hannum. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd September 7, 1996 +.Dt POLL 2 +.Os +.Sh NAME +.Nm poll +.Nd synchronous I/O multiplexing +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <poll.h> +.Ft int +.Fn poll "struct pollfd *fds" "unsigned int nfds" "int timeout" +.Sh DESCRIPTION +.Fn Poll +examines a set of file descriptors to see if some of them are ready for +I/O. +The +.Fa fds +argument is a pointer to an array of pollfd structures as defined in +.Aq Pa poll.h +(shown below). The +.Fa nfds +argument determines the size of the +.Fa fds +array. +.Bd -literal +struct pollfd { + int fd; /* file descriptor */ + short events; /* events to look for */ + short revents; /* events returned */ +}; +.Ed +.Pp +The fields of +.Fa struct pollfd +are as follows: +.Bl -tag -width XXXrevents +.It fd +File descriptor to poll. If fd is equal to -1 then +.Fa revents +is cleared (set to zero), and that pollfd is not checked. +.It events +Events to poll for. (See below.) +.It revents +Events which may occur. (See below.) +.El +.Pp +The event bitmasks in +.Fa events +and +.Fa revents +have the following bits: +.Bl -tag -width XXXPOLLWRNORM +.It POLLIN +Data other than high priority data may be read without blocking. +.It POLLRDNORM +Normal data may be read without blocking. +.It POLLRDBAND +Data with a non-zero priority may be read without blocking. +.It POLLPRI +High priority data may be read without blocking. +.It POLLOUT +.It POLLWRNORM +Normal data may be written without blocking. +.It POLLWRBAND +Data with a non-zero priority may be written without blocking. +.It POLLERR +An exceptional condition has occurred on the device or socket. This +flag is always checked, even if not present in the +.Fa events +bitmask. +.It POLLHUP +The device or socket has been disconnected. This flag is always +checked, even if not present in the +.Fa events +bitmask. Note that +POLLHUP +and +POLLOUT +should never be present in the +.Fa revents +bitmask at the same time. +.It POLLNVAL +The file descriptor is not open. This flag is always checked, even +if not present in the +.Fa events +bitmask. +.El +.Pp +If +.Fa timeout +is neither zero nor INFTIM (-1), it specifies a maximum interval to +wait for any file descriptor to become ready, in milliseconds. If +.Fa timeout +is INFTIM (-1), the poll blocks indefinitely. If +.Fa timeout +is zero, then +.Fn poll +will return without blocking. +.Sh RETURN VALUES +.Fn Poll +returns the number of descriptors that are ready for I/O, or -1 if an +error occured. If the time limit expires, +.Fn poll +returns 0. +If +.Fn poll +returns with an error, +including one due to an interrupted call, +the +.Fa fds +array will be unmodified. +.Sh COMPATIBILITY +This implementation differs from the historical one in that a given +file descriptor may not cause +.Fn poll +to return with an error. In cases where this would have happened in +the historical implementation (e.g. trying to poll a +.Xr revoke 2 ed +descriptor), this implementation instead copies the +.Fa events +bitmask to the +.Fa revents +bitmask. Attempting to perform I/O on this descriptor will then +return an error. This behaviour is believed to be more useful. +.Sh ERRORS +An error return from +.Fn poll +indicates: +.Bl -tag -width Er +.It Bq Er EFAULT +.Fa Fds +points outside the process's allocated address space. +.It Bq Er EINTR +A signal was delivered before the time limit expired and +before any of the selected events occurred. +.It Bq Er EINVAL +The specified time limit is negative. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr connect 2 , +.Xr read 2 , +.Xr recv 2 , +.Xr select 2 , +.Xr send 2 , +.Xr write 2 +.Sh BUGS +The distinction between some of the fields in the +.Fa events +and +.Fa revents +bitmasks is really not useful without STREAMS. The fields are +defined for compatibility with existing software. +.Sh HISTORY +The +.Fn poll +function call appeared in +.At V . +This manual page and the core of the implementation was taken from +.Nx . diff --git a/lib/libc/sys/pread.c b/lib/libc/sys/pread.c new file mode 100644 index 0000000..b639383 --- /dev/null +++ b/lib/libc/sys/pread.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +ssize_t +pread(fd, buf, nbyte, offset) + int fd; + void *buf; + size_t nbyte; + off_t offset; +{ + return ((ssize_t)__syscall((quad_t)SYS_pread, fd, buf, nbyte, 0, offset)); +} diff --git a/lib/libc/sys/profil.2 b/lib/libc/sys/profil.2 new file mode 100644 index 0000000..a629803 --- /dev/null +++ b/lib/libc/sys/profil.2 @@ -0,0 +1,136 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Donn Seeley of BSDI. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)profil.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt PROFIL 2 +.Os +.Sh NAME +.Nm profil +.Nd control process profiling +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn profil "char *samples" "size_t size" "vm_offset_t offset" "int scale" +.Sh DESCRIPTION +The +.Fn profil +function enables or disables +program counter profiling of the current process. +If profiling is enabled, +then at every profiling clock tick, +the kernel updates an appropriate count in the +.Fa samples +buffer. +The frequency of the profiling clock is recorded +in the header in the profiling output file. +.Pp +The buffer +.Fa samples +contains +.Fa size +bytes and is divided into +a series of 16-bit bins. +Each bin counts the number of times the program counter +was in a particular address range in the process +when a profiling clock tick occurred while profiling was enabled. +For a given program counter address, +the number of the corresponding bin is given +by the relation: +.Bd -literal -offset indent +[(pc - offset) / 2] * scale / 65536 +.Ed +.Pp +The +.Fa offset +parameter is the lowest address at which +the kernel takes program counter samples. +The +.Fa scale +parameter ranges from 1 to 65536 and +can be used to change the span of the bins. +A scale of 65536 maps each bin to 2 bytes of address range; +a scale of 32768 gives 4 bytes, 16384 gives 8 bytes and so on. +Intermediate values provide approximate intermediate ranges. +A +.Fa scale +value of 0 disables profiling. +.Sh RETURN VALUES +If the +.Fa scale +value is nonzero and the buffer +.Fa samples +contains an illegal address, +.Fn profil +returns \-1, +profiling is terminated and +.Va errno +is set appropriately. +Otherwise +.Fn profil +returns 0. +.Sh FILES +.Bl -tag -width /usr/lib/gcrt0.o -compact +.It Pa /usr/lib/gcrt0.o +profiling C run-time startup file +.It Pa gmon.out +conventional name for profiling output file +.El +.Sh ERRORS +The following error may be reported: +.Bl -tag -width Er +.It Bq Er EFAULT +The buffer +.Fa samples +contains an invalid address. +.El +.Sh SEE ALSO +.Xr gprof 1 +.Sh HISTORY +A +.Fn profil +function call appeared in +.At v7 . +.Sh BUGS +This routine should be named +.Fn profile . +.Pp +The +.Fa samples +argument should really be a vector of type +.Fa "unsigned short" . +.Pp +The format of the gmon.out file is undocumented. diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 69477e9..37eca05 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -1,9 +1,10 @@ +.\" $FreeBSD$ .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ .\" .\" This file is in the public domain. -.Dd November 7, 1994 +.Dd January 20, 1996 .Dt PTRACE 2 -.Os NetBSD 1.0BETA +.Os FreeBSD 2 .Sh NAME .Nm ptrace .Nd process tracing and debugging @@ -74,7 +75,9 @@ and data, which is why there are two requests: conceptually, .Dv PT_READ_I reads from the instruction space and .Dv PT_READ_D -reads from the data space. In the current NetBSD implementation, these +reads from the data space. In the current +.Tn FreeBSD +implementation, these two requests are completely identical. The .Fa addr argument specifies the address (in the traced process' virtual address @@ -163,7 +166,7 @@ succeeds, the traced process is no longer traced and continues execution normally. .El .Pp -Additionally, machine-specific requests can exist. On the SPARC, these +Additionally, machine-specific requests can exist. On the i386, these are: .Bl -tag -width 12n .It Dv PT_GETREGS @@ -199,114 +202,25 @@ it loads the traced process' floating-point registers from the .Aq Pa machine/reg.h ) pointed to by .Fa addr . -.It Dv PT_SYSCALL -This request is like -.Dv PT_CONTINUE -except that the process will stop next time it executes any system -call. Information about the system call can be examined with -.Dv PT_READ_U -and potentially modified with -.Dv PT_WRITE_U -through the -.Li u_kproc.kp_proc.p_md -element of the user structure (see below). If the process is continued -with another -.Dv PT_SYSCALL -request, it will stop again on exit from the syscall, at which point -the return values can be examined and potentially changed. The -.Li u_kproc.kp_proc.p_md -element is of type -.Dq Li "struct mdproc" , -which should be declared by including -.Aq Pa sys/param.h , -.Aq Pa sys/user.h , -and -.Aq Pa machine/proc.h , -and contains the following fields (among others): -.Bl -item -compact -offset indent -.It -.Li syscall_num -.It -.Li syscall_nargs -.It -.Li syscall_args[8] -.It -.Li syscall_err -.It -.Li syscall_rv[2] -.El -When a process stops on entry to a syscall, -.Li syscall_num -holds the number of the syscall, -.Li syscall_nargs -holds the number of arguments it expects, and -.Li syscall_args -holds the arguments themselves. (Only the first -.Li syscall_nargs -elements of -.Li syscall_args -are guaranteed to be useful.) When a process stops on exit from a -syscall, -.Li syscall_num -is -.Eo \& -.Li -1 -.Ec , -.Li syscall_err -holds the error number -.Po -see -.Xr errno 2 -.Pc , -or 0 if no error occurred, and -.Li syscall_rv -holds the return values. (If the syscall returns only one value, only -.Li syscall_rv[0] -is useful.) The tracing process can modify any of these with -.Dv PT_WRITE_U ; -only some modifications are useful. -.Pp -On entry to a syscall, -.Li syscall_num -can be changed, and the syscall actually performed will correspond to -the new number (it is the responsibility of the tracing process to fill -in -.Li syscall_args -appropriately for the new call, but there is no need to modify -.Eo \& -.Li syscall_nargs -.Ec ). -If the new syscall number is 0, no syscall is actually performed; -instead, -.Li syscall_err -and -.Li syscall_rv -are passed back to the traced process directly (and therefore should be -filled in). If the syscall number is otherwise out of range, a dummy -syscall which simply produces an -.Er ENOSYS -error is effectively performed. -.Pp -On exit from a syscall, only -.Li syscall_err -and -.Li syscall_rv -can usefully be changed; they are set to the values returned by the -syscall and will be passed back to the traced process by the normal -syscall return mechanism. .El -.Sh ERRORS +.Sh RETURN VALUES Some requests can cause .Fn ptrace to return .Li -1 as a non-error value; to disambiguate, .Va errno -can be set to 0 before the call and checked afterwards. The possible -errors are: +can be set to 0 before the call and checked afterwards. +.Sh ERRORS +The +.Fn ptrace +function may fail if: .Bl -tag -width 4n .It Bq Er ESRCH +.Bl -bullet -compact +.It No process having the specified process ID exists. +.El .It Bq Er EINVAL .Bl -bullet -compact .It @@ -331,8 +245,6 @@ The signal number (in .Fa data ) to .Dv PT_CONTINUE -or -.Dv PT_SYSCALL was neither 0 nor a legal signal number. .It .Dv PT_GETREGS , @@ -369,27 +281,13 @@ on a process in violation of the requirements listed under .Dv PT_ATTACH above. .El -.Sh BUGS -On the SPARC, the PC is set to the provided PC value for -.Dv PT_CONTINUE -and similar calls, but the NPC is set willy-nilly to 4 greater than the -PC value. Using -.Dv PT_GETREGS -and -.Dv PT_SETREGS -to modify the PC, passing -.Li (caddr_t)1 -to -.Eo \& +.Sh SEE ALSO +.Xr execve 2 , +.Xr sigaction 2 , +.Xr wait 2 , +.Xr execv 3 +.Sh HISTORY +A .Fn ptrace -.Ec , -should be able to sidestep this. -.Pp -Single-stepping is not available. -.Pp -When using -.Dv PT_SYSCALL , -there is no easy way to tell whether the traced process stopped because -it made a syscall or because a signal was sent at a moment that it just -happened to have valid-looking garbage in its -.Dq Li "struct mdproc" . +function call appeared in +.At v7 . diff --git a/lib/libc/sys/pwrite.c b/lib/libc/sys/pwrite.c new file mode 100644 index 0000000..6fb3c5a --- /dev/null +++ b/lib/libc/sys/pwrite.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +ssize_t +pwrite(fd, buf, nbyte, offset) + int fd; + const void *buf; + size_t nbyte; + off_t offset; +{ + return ((ssize_t)__syscall((quad_t)SYS_pwrite, fd, buf, nbyte, 0, offset)); +} diff --git a/lib/libc/sys/quotactl.2 b/lib/libc/sys/quotactl.2 new file mode 100644 index 0000000..a98cb1c --- /dev/null +++ b/lib/libc/sys/quotactl.2 @@ -0,0 +1,222 @@ +.\" Copyright (c) 1983, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Robert Elz at The University of Melbourne. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)quotactl.2 8.2 (Berkeley) 3/10/95 +.\" $FreeBSD$ +.\" +.Dd March 5, 1999 +.Dt QUOTACTL 2 +.Os +.Sh NAME +.Nm quotactl +.Nd manipulate filesystem quotas +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <ufs/ufs/quota.h> +.Ft int +.Fn quotactl "const char *path" "int cmd" "int id" "void *addr" +.Sh DESCRIPTION +The +.Fn quotactl +call enables, disables and +manipulates filesystem quotas. +A quota control command +given by +.Fa cmd +operates on the given filename +.Fa path +for the given user +.Fa id . +(NOTE: One should use the QCMD macro defined in +.Ao Pa ufs/ufs/quota.h Ac +to formulate the value for +.Fa cmd . ) +The address of an optional command specific data structure, +.Fa addr , +may be given; its interpretation +is discussed below with each command. +.Pp +Currently quotas are supported only for the +.Dq ufs +filesystem. +For +.Dq ufs , +a command is composed of a primary command (see below) +and a command type used to interpret the +.Fa id . +Types are supported for interpretation of user identifiers (USRQUOTA) +and group identifiers (GRPQUOTA). +The +.Dq ufs +specific commands are: +.Bl -tag -width Q_QUOTAOFFxx +.It Dv Q_QUOTAON +Enable disk quotas for the filesystem specified by +.Fa path . +The command type specifies the type of the quotas being enabled. +The +.Fa addr +argument specifies a file from which to take the quotas. +The quota file must exist; +it is normally created with the +.Xr quotacheck 8 +program. +The +.Fa id +argument is unused. +Only the super-user may turn quotas on. +.It Dv Q_QUOTAOFF +Disable disk quotas for the filesystem specified by +.Fa path . +The command type specifies the type of the quotas being disabled. +The +.Fa addr +and +.Fa id +arguments are unused. +Only the super-user may turn quotas off. +.It Dv Q_GETQUOTA +Get disk quota limits and current usage for the user or group +(as determined by the command type) with identifier +.Fa id . +.Fa Addr +is a pointer to a +.Fa struct dqblk +structure (defined in +.Ao Pa ufs/ufs/quota.h Ac ) . +.It Dv Q_SETQUOTA +Set disk quota limits for the user or group +(as determined by the command type) with identifier +.Fa id . +.Fa Addr +is a pointer to a +.Fa struct dqblk +structure (defined in +.Ao Pa ufs/ufs/quota.h Ac ) . +The usage fields of the +.Fa dqblk +structure are ignored. +This call is restricted to the super-user. +.It Dv Q_SETUSE +Set disk usage limits for the user or group +(as determined by the command type) with identifier +.Fa id . +.Fa Addr +is a pointer to a +.Fa struct dqblk +structure (defined in +.Ao Pa ufs/ufs/quota.h Ac ) . +Only the usage fields are used. +This call is restricted to the super-user. +.It Dv Q_SYNC +Update the on-disk copy of quota usages. +The command type specifies which type of quotas are to be updated. +The +.Fa id +and +.Fa addr +parameters are ignored. +.El +.Sh RETURN VALUES +A successful call returns 0, +otherwise the value -1 is returned and the global variable +.Va errno +indicates the reason for the failure. +.Sh ERRORS +A +.Fn quotactl +call will fail if: +.Bl -tag -width ENAMETOOLONGAA +.It Bq Er EOPNOTSUPP +The kernel has not been compiled with the +.Dv QUOTA +option. +.It Bq Er EUSERS +The quota table cannot be expanded. +.It Bq Er EINVAL +.Fa Cmd +or the command type is invalid. +.It Bq Er EACCES +In +.Dv Q_QUOTAON , +the quota file is not a plain file. +.It Bq Er EACCES +Search permission is denied for a component of a path prefix. +.It Bq Er ENOTDIR +A component of a path prefix was not a directory. +.It Bq Er ENAMETOOLONG +A component of either pathname exceeded 255 characters, +or the entire length of either path name exceeded 1023 characters. +.It Bq Er ENOENT +A filename does not exist. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating a pathname. +.It Bq Er EROFS +In +.Dv Q_QUOTAON , +the quota file resides on a read-only filesystem. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing +to a file containing quotas. +.It Bq Er EFAULT +An invalid +.Fa addr +was supplied; the associated structure could not be copied in or out +of the kernel. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EPERM +The call was privileged and the caller was not the super-user. +.El +.Sh SEE ALSO +.Xr quota 1 , +.Xr fstab 5 , +.Xr edquota 8 , +.Xr quotacheck 8 , +.Xr quotaon 8 , +.Xr repquota 8 +.Sh BUGS +There should be some way to integrate this call with the resource +limit interface provided by +.Xr setrlimit 2 +and +.Xr getrlimit 2 . +.Sh HISTORY +The +.Fn quotactl +function call appeared in +.Bx 4.3 Reno . diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2 new file mode 100644 index 0000000..b8c451d --- /dev/null +++ b/lib/libc/sys/read.2 @@ -0,0 +1,266 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)read.2 8.4 (Berkeley) 2/26/94 +.\" $FreeBSD$ +.\" +.Dd February 26, 1994 +.Dt READ 2 +.Os BSD 4 +.Sh NAME +.Nm read , +.Nm readv , +.Nm pread +.Nd read input +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/uio.h> +.Fd #include <unistd.h> +.Ft ssize_t +.Fn read "int d" "void *buf" "size_t nbytes" +.Ft ssize_t +.Fn readv "int d" "const struct iovec *iov" "int iovcnt" +.Ft ssize_t +.Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset" +.Sh DESCRIPTION +.Fn Read +attempts to read +.Fa nbytes +of data from the object referenced by the descriptor +.Fa d +into the buffer pointed to by +.Fa buf . +.Fn Readv +performs the same action, but scatters the input data +into the +.Fa iovcnt +buffers specified by the members of the +.Fa iov +array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1]. +.Fn Pread +performs the same function, but reads from the specified position in +the file without modifying the file pointer. +.Pp +For +.Fn readv , +the +.Fa iovec +structure is defined as: +.Pp +.Bd -literal -offset indent -compact +struct iovec { + char *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; +.Ed +.Pp +Each +.Fa iovec +entry specifies the base address and length of an area +in memory where data should be placed. +.Fn Readv +will always fill an area completely before proceeding +to the next. +.Pp +On objects capable of seeking, the +.Fn read +starts at a position +given by the pointer associated with +.Fa d +(see +.Xr lseek 2 ) . +Upon return from +.Fn read , +the pointer is incremented by the number of bytes actually read. +.Pp +Objects that are not capable of seeking always read from the current +position. The value of the pointer associated with such an +object is undefined. +.Pp +Upon successful completion, +.Fn read , +.Fn readv , +and +.Fn pread +return the number of bytes actually read and placed in the buffer. +The system guarantees to read the number of bytes requested if +the descriptor references a normal file that has that many bytes left +before the end-of-file, but in no other case. +.Pp +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn read +is implemented as the +.Va read +syscall. +.Pp +In the threaded library, the +.Va read +syscall is assembled to +.Fn _thread_sys_read +and +.Fn read +is implemented as a function which locks +.Va d +for read, then calls +.Fn _thread_sys_read . +If the call to +.Fn _thread_sys_read +would block, a context switch is performed. Before returning, +.Fn read +unlocks +.Va d . +.Pp +In the non-threaded library +.Fn readv +is implemented as the +.Va readv +syscall. +.Pp +In the threaded library, the +.Va readv +syscall is assembled to +.Fn _thread_sys_readv +and +.Fn readv +is implemented as a function which locks +.Va d +for read, then calls +.Fn _thread_sys_readv . +If the call to +.Fn _thread_sys_readv +would block, a context switch is performed. Before returning, +.Fn readv +unlocks +.Va d . +.Sh RETURN VALUES +If successful, the +number of bytes actually read is returned. Upon reading end-of-file, +zero is returned. +Otherwise, a -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Read , +.Fn readv , +and +.Fn pread +will succeed unless: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa D +is not a valid file or socket descriptor open for reading. +.It Bq Er EFAULT +.Fa Buf +points outside the allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.It Bq Er EINTR +A read from a slow device was interrupted before +any data arrived by the delivery of a signal. +.It Bq Er EINVAL +The pointer associated with +.Fa d +was negative. +.It Bq Er EAGAIN +The file was marked for non-blocking I/O, +and no data were ready to be read. +.El +.Pp +In addition, +.Fn readv +may return one of the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa Iovcnt +was less than or equal to 0, or greater than 16. +.It Bq Er EINVAL +One of the +.Fa iov_len +values in the +.Fa iov +array was negative. +.It Bq Er EINVAL +The sum of the +.Fa iov_len +values in the +.Fa iov +array overflowed a 32-bit integer. +.It Bq Er EFAULT +Part of the +.Fa iov +points outside the process's allocated address space. +.El +.Pp +The +.Fn pread +call may also return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified file offset is invalid. +.It Bq Er ESPIPE +The file descriptor is associated with a pipe, socket, or FIFO. +.El +.Sh SEE ALSO +.Xr dup 2 , +.Xr fcntl 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr select 2 , +.Xr socket 2 , +.Xr socketpair 2 +.Sh STANDARDS +The +.Fn read +function call is expected to conform to +.St -p1003.1-90 . +The +.Fn readv +and +.Fn pread +functions are expected to conform to +.St -xpg4.2 . +.Sh HISTORY +The +.Fn pread +function call +appeared in +.At V.4 . +The +.Fn readv +function call +appeared in +.Bx 4.2 . +A +.Fn read +function call appeared in +.At v6 . diff --git a/lib/libc/sys/readlink.2 b/lib/libc/sys/readlink.2 new file mode 100644 index 0000000..b395dc1 --- /dev/null +++ b/lib/libc/sys/readlink.2 @@ -0,0 +1,96 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)readlink.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt READLINK 2 +.Os BSD 4.2 +.Sh NAME +.Nm readlink +.Nd read value of a symbolic link +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn readlink "const char *path" "char *buf" "int bufsiz" +.Sh DESCRIPTION +.Fn Readlink +places the contents of the symbolic link +.Fa path +in the buffer +.Fa buf , +which has size +.Fa bufsiz . +The +.Fn readlink +function does not append a +.Dv NUL +character to +.Fa buf . +.Sh RETURN VALUES +The call returns the count of characters placed in the buffer +if it succeeds, or a -1 if an error occurs, placing the error +code in the global variable +.Va errno . +.Sh ERRORS +.Fn Readlink +will fail if: +.Bl -tag -width ENAMETOOLONG +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EINVAL +The named file is not a symbolic link. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.It Bq Er EFAULT +.Fa Buf +extends outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr lstat 2 , +.Xr stat 2 , +.Xr symlink 2 , +.Xr symlink 7 +.Sh HISTORY +The +.Fn readlink +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/reboot.2 b/lib/libc/sys/reboot.2 new file mode 100644 index 0000000..00d750c --- /dev/null +++ b/lib/libc/sys/reboot.2 @@ -0,0 +1,163 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)reboot.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt REBOOT 2 +.Os BSD 4 +.Sh NAME +.Nm reboot +.Nd reboot system or halt processor +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Fd #include <sys/reboot.h> +.Ft int +.Fn reboot "int howto" +.Sh DESCRIPTION +.Fn Reboot +reboots the system. +Only the super-user may reboot a machine on demand. +However, a reboot is invoked +automatically in the event of unrecoverable system failures. +.Pp +.Fa Howto +is a mask of options; the system call interface allows the following +options, defined in the include file +.Aq Pa sys/reboot.h , +to be passed +to the new kernel or the new bootstrap and init programs. +.Bl -tag -width RB_INITNAMEA +.It Dv RB_AUTOBOOT +The default, causing the system to reboot in its usual fashion. +.It Dv RB_ASKNAME +Interpreted by the bootstrap program itself, causing it to +prompt on the console as to what file should be booted. +Normally, the system is booted from the file +.Dq Em xx Ns No (0,0)kernel , +where +.Em xx +is the default disk name, +without prompting for the file name. +.It Dv RB_DFLTROOT +Use the compiled in root device. +Normally, the system uses the device from which it was booted +as the root device if possible. +(The default behavior is dependent on the ability of the bootstrap program +to determine the drive from which it was loaded, which is not possible +on all systems.) +.It Dv RB_DUMP +Dump kernel memory before rebooting; see +.Xr savecore 8 +for more information. +.It Dv RB_HALT +the processor is simply halted; no reboot takes place. +This option should be used with caution. +.It Dv RB_POWEROFF +After halting, the shutdown code will do what it can to turn +of the power. This requires hardware support. +.It Dv RB_INITNAME +An option allowing the specification of an init program (see +.Xr init 8 ) +other than +.Pa /sbin/init +to be run when the system reboots. +This switch is not currently available. +.It Dv RB_KDB +Load the symbol table and enable a built-in debugger in the system. +This option will have no useful function if the kernel is not configured +for debugging. +Several other options have different meaning if combined +with this option, although their use may not be possible +via the +.Fn reboot +call. +See +.Xr kadb 4 +for more information. +.It Dv RB_NOSYNC +Normally, the disks are sync'd (see +.Xr sync 8 ) +before the processor is halted or rebooted. +This option may be useful if file system changes have been made manually +or if the processor is on fire. +.It Dv RB_RDONLY +Initially mount the root file system read-only. +This is currently the default, and this option has been deprecated. +.It Dv RB_SINGLE +Normally, the reboot procedure involves an automatic disk consistency +check and then multi-user operations. +.Dv RB_SINGLE +prevents this, booting the system with a single-user shell +on the console. +.Dv RB_SINGLE +is actually interpreted by the +.Xr init 8 +program in the newly booted system. +.El +.Pp +When no options are given (i.e., +.Dv RB_AUTOBOOT +is used), the system is +rebooted from file +.Dq kernel +in the root file system of unit 0 +of a disk chosen in a processor specific way. +An automatic consistency check of the disks is normally performed +(see +.Xr fsck 8 ) . +.Sh RETURN VALUES +If successful, this call never returns. +Otherwise, a -1 is returned and an error is returned in the global +variable +.Va errno . +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EPERM +The caller is not the super-user. +.El +.Sh SEE ALSO +.Xr crash 8 , +.Xr halt 8 , +.Xr init 8 , +.Xr reboot 8 , +.Xr savecore 8 +.Sh BUGS +The HP300 implementation supports neither +.Dv RB_DFLTROOT +nor +.Dv RB_KDB . +.Sh HISTORY +The +.Fn reboot +function call appeared in +.Bx 4.0 . diff --git a/lib/libc/sys/recv.2 b/lib/libc/sys/recv.2 new file mode 100644 index 0000000..bf73dd5 --- /dev/null +++ b/lib/libc/sys/recv.2 @@ -0,0 +1,294 @@ +.\" Copyright (c) 1983, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)recv.2 8.3 (Berkeley) 2/21/94 +.\" $FreeBSD$ +.\" +.Dd February 21, 1994 +.Dt RECV 2 +.Os BSD 4.3r +.Sh NAME +.Nm recv , +.Nm recvfrom , +.Nm recvmsg +.Nd receive a message from a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft ssize_t +.Fn recv "int s" "void *buf" "size_t len" "int flags" +.Ft ssize_t +.Fn recvfrom "int s" "void *buf" "size_t len" "int flags" "struct sockaddr *from" "socklen_t *fromlen" +.Ft ssize_t +.Fn recvmsg "int s" "struct msghdr *msg" "int flags" +.Sh DESCRIPTION +.Fn Recvfrom +and +.Fn recvmsg +are used to receive messages from a socket, +and may be used to receive data on a socket whether or not +it is connection-oriented. +.Pp +If +.Fa from +is non-nil, and the socket is not connection-oriented, +the source address of the message is filled in. +.Fa Fromlen +is a value-result parameter, initialized to the size of +the buffer associated with +.Fa from , +and modified on return to indicate the actual size of the +address stored there. +.Pp +The +.Fn recv +call is normally used only on a +.Em connected +socket (see +.Xr connect 2 ) +and is identical to +.Fn recvfrom +with a nil +.Fa from +parameter. +As it is redundant, it may not be supported in future releases. +.Pp +All three routines return the length of the message on successful +completion. +If a message is too long to fit in the supplied buffer, +excess bytes may be discarded depending on the type of socket +the message is received from (see +.Xr socket 2 ) . +.Pp +If no messages are available at the socket, the +receive call waits for a message to arrive, unless +the socket is nonblocking (see +.Xr fcntl 2 ) +in which case the value +-1 is returned and the external variable +.Va errno +set to +.Er EAGAIN . +The receive calls normally return any data available, +up to the requested amount, +rather than waiting for receipt of the full amount requested; +this behavior is affected by the socket-level options +.Dv SO_RCVLOWAT +and +.Dv SO_RCVTIMEO +described in +.Xr getsockopt 2 . +.Pp +The +.Xr select 2 +call may be used to determine when more data arrive. +.Pp +The +.Fa flags +argument to a recv call is formed by +.Em or Ap ing +one or more of the values: +.Bl -column MSG_WAITALL -offset indent +.It Dv MSG_OOB Ta process out-of-band data +.It Dv MSG_PEEK Ta peek at incoming message +.It Dv MSG_WAITALL Ta wait for full request or error +.El +.Pp +The +.Dv MSG_OOB +flag requests receipt of out-of-band data +that would not be received in the normal data stream. +Some protocols place expedited data at the head of the normal +data queue, and thus this flag cannot be used with such protocols. +The MSG_PEEK flag causes the receive operation to return data +from the beginning of the receive queue without removing that +data from the queue. +Thus, a subsequent receive call will return the same data. +The MSG_WAITALL flag requests that the operation block until +the full request is satisfied. +However, the call may still return less data than requested +if a signal is caught, an error or disconnect occurs, +or the next data to be received is of a different type than that returned. +.Pp +The +.Fn recvmsg +call uses a +.Fa msghdr +structure to minimize the number of directly supplied parameters. +This structure has the following form, as defined in +.Ao Pa sys/socket.h Ac : +.Pp +.Bd -literal +struct msghdr { + caddr_t msg_name; /* optional address */ + u_int msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + u_int msg_iovlen; /* # elements in msg_iov */ + caddr_t msg_control; /* ancillary data, see below */ + u_int msg_controllen; /* ancillary data buffer len */ + int msg_flags; /* flags on received message */ +}; +.Ed +.Pp +Here +.Fa msg_name +and +.Fa msg_namelen +specify the destination address if the socket is unconnected; +.Fa msg_name +may be given as a null pointer if no names are desired or required. +.Fa Msg_iov +and +.Fa msg_iovlen +describe scatter gather locations, as discussed in +.Xr read 2 . +.Fa Msg_control , +which has length +.Fa msg_controllen , +points to a buffer for other protocol control related messages +or other miscellaneous ancillary data. +The messages are of the form: +.Bd -literal +struct cmsghdr { + u_int cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by + u_char cmsg_data[]; */ +}; +.Pp +.Ed +As an example, one could use this to learn of changes in the data-stream +in XNS/SPP, or in ISO, to obtain user-connection-request data by requesting +a recvmsg with no data buffer provided immediately after an +.Fn accept +call. +.Pp +Open file descriptors are now passed as ancillary data for +.Dv AF_UNIX +domain sockets, with +.Fa cmsg_level +set to +.Dv SOL_SOCKET +and +.Fa cmsg_type +set to +.Dv SCM_RIGHTS . +.Pp +Process credentials can also be passed as ancillary data for +.Dv AF_UNIX +domain sockets using a +.Fa cmsg_type +of +.Dv SCM_CREDS. +In this case, +.Fa cmsg_data +should be a structure of type +.Fa cmsgcred , +which is defined in +.Ao Pa sys/socket.h Ac +as follows: +.Pp +.Bd -literal +struct cmsgcred { + pid_t cmcred_pid; /* PID of sending process */ + uid_t cmcred_uid; /* real UID of sending process */ + uid_t cmcred_euid; /* effective UID of sending process */ + gid_t cmcred_gid; /* real GID of sending process */ + short cmcred_ngroups; /* number or groups */ + gid_t cmcred_groups[CMGROUP_MAX]; /* groups */ +}; +.Ed +.Pp +The kernel will fill in the credential information of the sending process +and deliver it to the receiver. +.Pp +The +.Fa msg_flags +field is set on return according to the message received. +.Dv MSG_EOR +indicates end-of-record; +the data returned completed a record (generally used with sockets of type +.Dv SOCK_SEQPACKET ) . +.Dv MSG_TRUNC +indicates that +the trailing portion of a datagram was discarded because the datagram +was larger than the buffer supplied. +.Dv MSG_CTRUNC +indicates that some +control data were discarded due to lack of space in the buffer +for ancillary data. +.Dv MSG_OOB +is returned to indicate that expedited or out-of-band data were received. +.Pp +.Sh RETURN VALUES +These calls return the number of bytes received, or -1 +if an error occurred. +.Sh ERRORS +The calls fail if: +.Bl -tag -width ENOTCONNAA +.It Bq Er EBADF +The argument +.Fa s +is an invalid descriptor. +.It Bq Er ENOTCONN +The socket is associated with a connection-oriented protocol +and has not been connected (see +.Xr connect 2 +and +.Xr accept 2 ). +.It Bq Er ENOTSOCK +The argument +.Fa s +does not refer to a socket. +.It Bq Er EAGAIN +The socket is marked non-blocking, and the receive operation +would block, or +a receive timeout had been set, +and the timeout expired before data were received. +.It Bq Er EINTR +The receive was interrupted by delivery of a signal before +any data were available. +.It Bq Er EFAULT +The receive buffer pointer(s) point outside the process's +address space. +.El +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr getsockopt 2 , +.Xr read 2 , +.Xr select 2 , +.Xr socket 2 +.Sh HISTORY +The +.Fn recv +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/rename.2 b/lib/libc/sys/rename.2 new file mode 100644 index 0000000..cce01d6 --- /dev/null +++ b/lib/libc/sys/rename.2 @@ -0,0 +1,199 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)rename.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt RENAME 2 +.Os BSD 4.2 +.Sh NAME +.Nm rename +.Nd change the name of a file +.Sh SYNOPSIS +.Fd #include <stdio.h> +.Ft int +.Fn rename "const char *from" "const char *to" +.Sh DESCRIPTION +.Fn Rename +causes the link named +.Fa from +to be renamed as +.Fa to . +If +.Fa to +exists, it is first removed. +Both +.Fa from +and +.Fa to +must be of the same type (that is, both directories or both +non-directories), and must reside on the same file system. +.Pp +.Fn Rename +guarantees that an instance of +.Fa to +will always exist, even if the system should crash in +the middle of the operation. +.Pp +If the final component of +.Fa from +is a symbolic link, +the symbolic link is renamed, +not the file or directory to which it points. +.\".Sh CAVEAT +.\"The system can deadlock if a loop in the file system graph is present. +.\"This loop takes the form of an entry in directory +.\".Ql Pa a , +.\"say +.\".Ql Pa a/foo , +.\"being a hard link to directory +.\".Ql Pa b , +.\"and an entry in +.\"directory +.\".Ql Pa b , +.\"say +.\".Ql Pa b/bar , +.\"being a hard link +.\"to directory +.\".Ql Pa a . +.\"When such a loop exists and two separate processes attempt to +.\"perform +.\".Ql rename a/foo b/bar +.\"and +.\".Ql rename b/bar a/foo , +.\"respectively, +.\"the system may deadlock attempting to lock +.\"both directories for modification. +.\"Hard links to directories should be +.\"replaced by symbolic links by the system administrator. +.Sh RETURN VALUES +A 0 value is returned if the operation succeeds, otherwise +.Fn rename +returns -1 and the global variable +.Va errno +indicates the reason for the failure. +.Sh ERRORS +.Fn Rename +will fail and neither of the argument files will be +affected if: +.Bl -tag -width ENAMETOOLONG +.It Bq Er ENAMETOOLONG +A component of either pathname exceeded 255 characters, +or the entire length of either path name exceeded 1023 characters. +.It Bq Er ENOENT +A component of the +.Fa from +path does not exist, +or a path prefix of +.Fa to +does not exist. +.It Bq Er EACCES +A component of either path prefix denies search permission. +.It Bq Er EACCES +The requested link requires writing in a directory with a mode +that denies write permission. +.It Bq Er EPERM +The directory containing +.Fa from +is marked sticky, +and neither the containing directory nor +.Fa from +are owned by the effective user ID. +.It Bq Er EPERM +The +.Fa to +file exists, +the directory containing +.Fa to +is marked sticky, +and neither the containing directory nor +.Fa to +are owned by the effective user ID. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating either pathname. +.It Bq Er ENOTDIR +A component of either path prefix is not a directory. +.It Bq Er ENOTDIR +.Fa from +is a directory, but +.Fa to +is not a directory. +.It Bq Er EISDIR +.Fa to +is a directory, but +.Fa from +is not a directory. +.It Bq Er EXDEV +The link named by +.Fa to +and the file named by +.Fa from +are on different logical devices (file systems). Note that this error +code will not be returned if the implementation permits cross-device +links. +.It Bq Er ENOSPC +The directory in which the entry for the new name is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.It Bq Er EDQUOT +The directory in which the entry for the new name +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EIO +An I/O error occurred while making or updating a directory entry. +.It Bq Er EROFS +The requested link requires writing in a directory on a read-only file +system. +.It Bq Er EFAULT +.Em Path +points outside the process's allocated address space. +.It Bq Er EINVAL +.Fa From +is a parent directory of +.Fa to , +or an attempt is made to rename +.Ql \&. +or +.Ql \&.. . +.It Bq Er ENOTEMPTY +.Fa To +is a directory and is not empty. +.El +.Sh SEE ALSO +.Xr open 2 , +.Xr symlink 7 +.Sh STANDARDS +The +.Fn rename +function call is expected to conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/revoke.2 b/lib/libc/sys/revoke.2 new file mode 100644 index 0000000..cafdf89 --- /dev/null +++ b/lib/libc/sys/revoke.2 @@ -0,0 +1,108 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Berkeley Software Design, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)revoke.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt REVOKE 2 +.Os +.Sh NAME +.Nm revoke +.Nd revoke file access +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn revoke "const char *path" +.Sh DESCRIPTION +The +.Fn revoke +function invalidates all current open file descriptors in the system +for the file named by +.Fa path . +Subsequent operations on any such descriptors +fail, with the exceptions that a +.Fn read +from a character device file which has been revoked +returns a count of zero (end of file), +and a +.Fn close +call will succeed. +If the file is a special file for a device which is open, +the device close function +is called as if all open references to the file had been closed. +.Pp +Access to a file may be revoked only by its owner or the super user. +The +.Fn revoke +function is currently supported only for block and character special +device files. +It is normally used to prepare a terminal device for a new login session, +preventing any access by a previous user of the terminal. +.Sh RETURN VALUES +A 0 value indicated that the call succeeded. A \-1 return value +indicates an error occurred and +.Va errno +is set to indicated the reason. +.Sh ERRORS +Access to the named file is revoked unless one of the following: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1024 characters. +.It Bq Er ENOENT +The named file or a component of the path name does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.It Bq Er EINVAL +The implementation does not support the +.Fn revoke +operation on the named file. +.It Bq Er EPERM +The caller is neither the owner of the file nor the super user. +.El +.Sh SEE ALSO +.Xr close 2 +.Sh HISTORY +The +.Fn revoke +function was introduced in +.Bx 4.3 Reno . diff --git a/lib/libc/sys/rfork.2 b/lib/libc/sys/rfork.2 new file mode 100644 index 0000000..c5825cb --- /dev/null +++ b/lib/libc/sys/rfork.2 @@ -0,0 +1,145 @@ +.\" +.\" This manual page is taken directly from Plan9, and modified to +.\" describe the actual BSD implementation. Permission for +.\" use of this page comes from Rob Pike <rob@plan9.att.com>. +.\" +.\" $FreeBSD$ +.\" +.Dd Jan 12, 1996 +.Dt RFORK 2 +.Os +.Sh NAME +.Nm rfork +.Nd manipulate process resources +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn rfork "int flags" +.Sh DESCRIPTION +Forking, vforking or rforking are the only ways new processes are created. +The +.Fa flags +argument to +.Fn rfork +selects which resources of the +invoking process (parent) are shared +by the new process (child) or initialized to +their default values. +The resources include +the open file descriptor table (which, when shared, permits processes +to open and close files for other processes), +and open files. +.Fa Flags +is the logical OR of some subset of: +.Bl -tag -width "RFCNAMEG" -compact -offset indent +.It RFPROC +If set a new process is created; otherwise changes affect the +current process. +The current implementation requires this flag to always be set. +.It RFNOWAIT +If set, the child process will be dissociated from the parent. Upon +exit the child will not leave a status for the parent to collect. +See +.Xr wait 2 . +.It RFFDG +If set, the invoker's file descriptor table (see +.Xr intro 2 +) is copied; otherwise the two processes share a +single table. +.It RFCFDG +If set, the new process starts with a clean file descriptor table. +Is mutually exclusive with +.Dv RFFDG . +.It RFMEM +If set, the kernel will force sharing of the entire address space. +The child +will then inherit all the shared segments the parent process owns. Other segment +types will be unaffected. Subsequent forks by the parent will then +propagate the shared data and bss between children. The stack segment +is always split. May be set only with +.Dv RFPROC . +.It RFSIGSHARE +If set, the kernel will force sharing the sigacts structure between the +child and the parent. +.It RFLINUXTHPN +If set, the kernel will return SIGUSR1 instead of SIGCHILD upon thread +exit for the child. This is intended to mimic certain Linux clone behaviour. +.El +.Pp +File descriptors in a shared file descriptor table are kept +open until either they are explicitly closed +or all processes sharing the table exit. +.Pp +If +.Dv RFPROC +is set, the +value returned in the parent process +is the process id +of the child process; the value returned in the child is zero. +Without +.Dv RFPROC , +the return value is zero. +Process id's range from 1 to the maximum integer +.Ft ( int ) +value. +.Fn Rfork +will sleep, if necessary, until required process resources are available. +.Pp +.Fn Fork +can be implemented as a call to +.Fn rfork "RFFDG | RFPROC" +but isn't for backwards compatibility. +.Sh RETURN VALUES +Upon successful completion, +.Fn rfork +returns a value +of 0 to the child process and returns the process ID of the child +process to the parent process. Otherwise, a value of -1 is returned +to the parent process, no child process is created, and the global +variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Rfork +will fail and no child process will be created if: +.Bl -tag -width [EAGAIN] +.It Bq Er EAGAIN +The system-imposed limit on the total +number of processes under execution would be exceeded. +The limit is given by the +.Xr sysctl 3 +MIB variable +.Dv KERN_MAXPROC . +(The limit is actually one less than this +except for the super user). +.It Bq Er EAGAIN +The user is not the super user, and +the system-imposed limit +on the total number of +processes under execution by a single user would be exceeded. +The limit is given by the +.Xr sysctl 3 +MIB variable +.Dv KERN_MAXPROCPERUID . +.It Bq Er EAGAIN +The user is not the super user, and +the soft resource limit corresponding to the resource parameter +.Dv RLIMIT_NOFILE +would be exceeded (see +.Xr getrlimit 2 ) . +.It Bq Er EINVAL +The RFPROC flag was not specified. +.It Bq Er EINVAL +Both the RFFDG and the RFCFDG flags were specified. +.It Bq Er ENOMEM +There is insufficient swap space for the new process. +.El +.Sh SEE ALSO +.Xr fork 2 , +.Xr intro 2 , +.Xr minherit 2 , +.Xr vfork 2 +.Sh HISTORY +The +.Fn rfork +function call first appeared in Plan9. diff --git a/lib/libc/sys/rmdir.2 b/lib/libc/sys/rmdir.2 new file mode 100644 index 0000000..d618287 --- /dev/null +++ b/lib/libc/sys/rmdir.2 @@ -0,0 +1,105 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)rmdir.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt RMDIR 2 +.Os BSD 4.2 +.Sh NAME +.Nm rmdir +.Nd remove a directory file +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn rmdir "const char *path" +.Sh DESCRIPTION +.Fn Rmdir +removes a directory file +whose name is given by +.Fa path . +The directory must not have any entries other +than +.Ql \&. +and +.Ql \&.. . +.Sh RETURN VALUES +A 0 is returned if the remove succeeds; otherwise a -1 is +returned and an error code is stored in the global location +.Va errno . +.Sh ERRORS +The named file is removed unless: +.Bl -tag -width [ENAMETOOLONG] +.It Bq Er ENOTDIR +A component of the path is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named directory does not exist. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er ENOTEMPTY +The named directory contains files other than +.Ql \&. +and +.Ql \&.. +in it. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +Write permission is denied on the directory containing the link +to be removed. +.It Bq Er EPERM +The directory containing the directory to be removed is marked sticky, +and neither the containing directory nor the directory to be removed +are owned by the effective user ID. +.It Bq Er EBUSY +The directory to be removed is the mount point +for a mounted file system. +.It Bq Er EIO +An I/O error occurred while deleting the directory entry +or deallocating the inode. +.It Bq Er EROFS +The directory entry to be removed resides on a read-only file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr mkdir 2 , +.Xr unlink 2 +.Sh HISTORY +The +.Fn rmdir +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/rtprio.2 b/lib/libc/sys/rtprio.2 new file mode 100644 index 0000000..579ed1b --- /dev/null +++ b/lib/libc/sys/rtprio.2 @@ -0,0 +1,110 @@ +.\" Copyright (c) 1994, Henrik Vestergaard Draboel +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Henrik Vestergaard Draboel. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd July 23, 1994 +.Dt RTPRIO 2 +.Sh NAME +.Nm rtprio +.Nd examine or modify a process realtime or idle priority +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/rtprio.h> +.Ft int +.Fn rtprio "int function" "pid_t pid" "struct rtprio *rtp" +.Sh DESCRIPTION +.Fn rtprio +is used to lookup or change the realtime or idle priority of a process. + +.Fa function +specifies the operation to be performed. RTP_LOOKUP to lookup the current priority, +and RTP_SET to set the priority. +.Fa pid +specifies the process to be used, 0 for the current process. + +.Fa *rtp +is a pointer to a struct rtprio which is used to specify the priority and priority type. +This structure has the following form: +.Bd -literal +struct rtprio { + u_short type; + u_short prio; +}; +.Ed +.Pp +The value of the +.Nm type +field may be RTP_PRIO_REALTIME for realtime priorities, +RTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities. +The priority specified by the +.Nm prio +field ranges between 0 and +.Dv RTP_PRIO_MAX (usually 31) . +0 is the highest possible priority. + +Realtime and idle priority is inherited through fork() and exec(). + +A realtime process can only be preempted by a process of equal or +higher priority, or by an interrupt; idle priority processes will run only +when no other real/normal priority process is runnable. Higher real/idle priority processes +preempt lower real/idle priority processes. Processes of equal real/idle priority are run round-robin. +.Sh RETURN VALUES +.Fn rtprio +will return 0 for success and -1 for all errors. The global variable +.Va errno +will be set to indicate the error. +.Sh ERRORS +.Fn rtprio +will fail if +.Bl -tag -width Er +.It Bq Er EINVAL +The specified +.Fa prio +was out of range. +.It Bq Er EPERM +The calling process is not allowed to set the realtime priority. Only +root is allowed to change the realtime priority of any process, and non-root +may only change the idle priority of the current process. +.It Bq Er ESRCH +The specified process was not found. +.Sh AUTHORS +The original author was +.An Henrik Vestergaard Draboel Aq hvd@terry.ping.dk . +This implementation in +.Fx +was substantially rewritten by +.An David Greenman . +.Sh SEE ALSO +.Xr nice 1 , +.Xr ps 1 , +.Xr rtprio 1 , +.Xr setpriority 2 , +.Xr nice 3 , +.Xr renice 8 diff --git a/lib/libc/sys/sched_get_priority_max.2 b/lib/libc/sys/sched_get_priority_max.2 new file mode 100644 index 0000000..185f561 --- /dev/null +++ b/lib/libc/sys/sched_get_priority_max.2 @@ -0,0 +1,121 @@ +.\" $FreeBSD$ +.\" Copyright (c) 1998 HD Associates, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd Mar 12, 1998 +.Dt SCHED_GET_PRIORITY_MAX 2 +.Os BSD 4 +.Sh NAME +.Nm sched_get_priority_max , +.Nm sched_get_priority_min , +.Nm sched_rr_get_interval +.Nd Get scheduling parameter limits +.Sh SYNOPSIS +.Fd #include <sched.h> +.Ft int +.Fn sched_get_priority_max "int policy" +.Ft int +.Fn sched_get_priority_min "int policy" +.Ft int +.Fn sched_rr_get_interval "pid_t pid" "struct timespec *interval" +.Sh DESCRIPTION +The +.Fn sched_get_priority_max +and +.Fn sched_get_priority_min +functions return the appropriate maximum or minimum, respectfully, +for the scheduling policy specified by policy. The +.Fn sched_rr_get_interval +function updates the +.Fa timespec +structure referenced by the +.Fa interval +argument to contain the current execution time limit (i.e., time +quantum) for the process specified by +.Fa pid . +If +.Fa pid +is zero, the current execution time limit for the calling process is +returned. +.Pp +The value of +.Fa policy +should be one of the scheduling policy values defined in +.Fa <sched.h> : +.Bl -tag -width [SCHED_OTHER] +.It Bq Er SCHED_FIFO +First-in-first-out fixed priority scheduling with no round robin scheduling; +.It Bq Er SCHED_OTHER +The standard time sharing scheduler; +.It Bq Er SCHED_RR +Round-robin scheduling across same priority processes. +.El +.Sh RETURN +If successful, the +.Fn sched_get_priority_max +and +.Fn sched_get_priority_min +functions shall return the appropriate maximum or minimum values, +respectively. If unsuccessful, the shall return a value of -1 and set +.Fa errno +to indicate the error. +.Pp +If successful, the +.Fn sched_rr_get_interval +function will return 0. Otherwise, it will +return a value of -1 and set +.Fa errno +to indicate the error. +.Sh ERRORS +On failure +.Va errno +will be set to the corresponding value: +.Bl -tag -width [EFAULT] +.It Bq Er EINVAL +The value of the +.Fa policy +parameter does not represent a defined scheduling policy. +.It Bq Er ENOSYS +The +.Fn sched_get_priority_max , +.Fn sched_get_priority_min , +and +.Fn sched_rr_get_interval +functions are not supported by the implementation. +.It Bq Er ESRCH +No process can be found corresponding to that specified by +.Fa pid . +.El +.Sh SEE ALSO +.Xr sched_get_scheduler 2 , +.Xr sched_getparam 2 , +.Xr sched_set_scheduler 2 , +.Xr sched_setparam 2 +.Sh STANDARDS +The +.Fn sched_setscheduler +and +.Fn sched_getscheduler +functions conform to +.St -p1003.1b-93 . diff --git a/lib/libc/sys/sched_setparam.2 b/lib/libc/sys/sched_setparam.2 new file mode 100644 index 0000000..b627e69 --- /dev/null +++ b/lib/libc/sys/sched_setparam.2 @@ -0,0 +1,172 @@ +.\" $FreeBSD$ +.\" Copyright (c) 1998 HD Associates, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd Mar 12, 1998 +.Dt SCHED_SETPARAM 2 +.Os BSD 4 +.Sh NAME +.Nm sched_setparam , +.Nm sched_getparam +.Nd set/get scheduling parameters +.Sh SYNOPSIS +.Fd #include <sched.h> +.Ft int +.Fn sched_setparam "pid_t pid" "const struct sched_param *param" +.Ft int +.Fn sched_getparam "pid_t pid" "struct sched_param *param" +.Sh DESCRIPTION +The +.Fn sched_setparam +function sets the scheduling parameters of the process specified by +.Fa pid +to the values specified by the +.Fa sched_param +structure pointed to by +.Fa param . +The value of the +.Fa sched_priority +member in the +.Fa param +structure must be any integer within the inclusive priority range for +the current scheduling policy of the process specified by +.Fa pid . +Higher numerical values for the priority represent higher priorities. +.Pp +In this implementation, if the value of +.Fa pid +is negative the function will fail. +.Pp +If a process specified by +.Fa pid +exists and if the calling process has permission, the scheduling +parameters are set for the process whose process ID is equal to +.Fa pid . +.Pp +If +.Fa pid +is zero, the scheduling parameters are set for the calling process. +.Pp +In this implementation, the policy of when a process can affect +the scheduling parameters of another process is specified in +.Xr p1003_1b +as a write-style operation. +.Pp +The target process, whether it is running or not running, will resume +execution after all other runnable processes of equal or greater +priority have been scheduled to run. +.Pp +If the priority of the process specified by the +.Fa pid +argument is set higher than that of the lowest priority running process +and if the specified process is ready to run, the process specified by +the +.Fa pid +argument will preempt a lowest priority running process. Similarly, if +the process calling +.Fn sched_setparam +sets its own priority lower than that of one or more other nonempty +process lists, then the process that is the head of the highest priority +list will also preempt the calling process. Thus, in either case, the +originating process might not receive notification of the completion of +the requested priority change until the higher priority process has +executed. +.Pp +In this implementation, when the current scheduling policy for the +process specified by +.Fa pid +is normal timesharing (SCHED_OTHER, aka SCHED_NORMAL when not POSIX-source) +or the idle policy (SCHED_IDLE when not POSIX-source) then the behavior +is as if the process had been running under SCHED_RR with a priority +lower than any actual realtime priority. +.Pp +The +.Fn sched_getparam +function will return the scheduling parameters of a process specified +by +.Fa pid +in the +.Fa sched_param +structure pointed to by +.Fa param . +.Pp +If a process specified by +.Fa pid +exists and if the calling process has permission, +the scheduling parameters for the process whose process ID is equal to +.Fa pid +are returned. +.Pp +In this implementation, the policy of when a process can obtain the +scheduling parameters of another process are detailed in +.Xr p1003_1b +as a read-style operation. +.Pp +If +.Fa pid +is zero, the scheduling parameters for the calling process will be +returned. In this implementation, the +.Fa sched_getparam +function will fail if +.Fa pid +is negative. +.Sh RETURN +The function will return zero if it completes successfully, or it +will return a value of -1 and set +.Va errno +to indicate the error. +.Sh ERRORS +On failure +.Va errno +will be set to the corresponding value: +.Bl -tag -width [EFAULT] +.It Bq Er ENOSYS +The system is not configured to support this functionality. +.It Bq Er EPERM +The requesting process doesn not have permission as detailed in +.Xr p1003_1b . +.It Bq Er ESRCH +No process can be found corresponding to that specified by +.Fa pid . +.It Bq Er EINVAL +For +.Fn sched_setparam : +one or more of the requested scheduling parameters +is outside the range defined for the scheduling policy of the specified +.Fa pid . +.El +.Sh SEE ALSO +.Xr sched_get_priority_max 2 , +.Xr sched_get_priority_min 2 , +.Xr sched_getscheduler 2 , +.Xr sched_rr_get_interval 2 , +.Xr sched_setscheduler 2 , +.Xr sched_yield 2 +.Sh STANDARDS +The +.Fn sched_setparam +and +.Fn sched_getparam +functions conform to +.St -p1003.1b-93 . diff --git a/lib/libc/sys/sched_setscheduler.2 b/lib/libc/sys/sched_setscheduler.2 new file mode 100644 index 0000000..94d9f57 --- /dev/null +++ b/lib/libc/sys/sched_setscheduler.2 @@ -0,0 +1,167 @@ +.\" $FreeBSD$ +.\" Copyright (c) 1998 HD Associates, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd Mar 12, 1998 +.Dt SCHED_SETSCHEDULER 2 +.Os BSD 4 +.Sh NAME +.Nm sched_setscheduler , +.Nm sched_getscheduler +.Nd set/get scheduling policy and scheduler parameters +.Sh SYNOPSIS +.Fd #include <sched.h> +.Ft int +.Fn sched_setscheduler "pid_t pid" "int policy" "const struct sched_param *param" +.Ft int +.Fn sched_getscheduler "pid_t pid" +.Sh DESCRIPTION +The +.Fn sched_setscheduler +function sets the scheduling policy and scheduling parameters +of the process specified by +.Fa pid +to +.Fa policy +and the parameters specified in the +.Fa sched_param +structure pointed to by +.Fa param , +respectively. +The value of the +.Fa sched_priority +member in the +.Fa param +structure must be any integer within the inclusive priority range for +the scheduling policy specified by +.Fa policy . +.Pp +In this implementation, if the value of +.Fa pid +is negative the function will fail. +.Pp +If a process specified by +.Fa pid +exists and if the calling process has permission, the scheduling +policy and scheduling parameters will be set for the process +whose process ID is equal to +.Fa pid . +.Pp +If +.Fa pid +is zero, the scheduling policy and scheduling +parameters are set for the calling process. +.Pp +In this implementation, the policy of when a process can affect +the scheduling parameters of another process is specified in +.Xr p1003_1b +as a write-style operation. +.Pp +The scheduling policies are in +.Fa <sched.h> : +.Bl -tag -width [SCHED_OTHER] +.It Bq Er SCHED_FIFO +First-in-first-out fixed priority scheduling with no round robin scheduling; +.It Bq Er SCHED_OTHER +The standard time sharing scheduler; +.It Bq Er SCHED_RR +Round-robin scheduling across same priority processes. +.El +.Pp +The +.Fa sched_param +structure is defined in +.Fa <sched.h> : + +.Bd -literal -offset indent +struct sched_param { + int sched_priority; /* scheduling priority */ +}; +.Ed +.Pp +The +.Fn sched_getscheduler +function returns the scheduling policy of the process specified +by +.Fa pid . +.Pp +If a process specified by +.Fa pid +exists and if the calling process has permission, +the scheduling parameters for the process whose process ID is equal to +.Fa pid +are returned. +.Pp +In this implementation, the policy of when a process can obtain the +scheduling parameters of another process are detailed in +.Xr p1003_1b +as a read-style operation. +.Pp +If +.Fa pid +is zero, the scheduling parameters for the calling process will be +returned. In this implementation, the +.Fa sched_getscheduler +function will fail if +.Fa pid +is negative. +.Sh RETURN +The function will return zero if it completes successfully, or it +will return a value of -1 and set +.Va errno +to indicate the error. +.Sh ERRORS +On failure +.Va errno +will be set to the corresponding value: +.Bl -tag -width [EFAULT] +.It Bq Er ENOSYS +The system is not configured to support this functionality. +.It Bq Er EPERM +The requesting process doesn not have permission as detailed in +.Xr p1003_1b . +.It Bq Er ESRCH +No process can be found corresponding to that specified by +.Fa pid . +.It Bq Er EINVAL +The value of the +.Fa policy +parameter is invalid, or one or more of the parameters contained in +.Fa param +is outside the valid range for the specified scheduling policy. +.El +.Sh SEE ALSO +.Xr sched_get_priority_max 2 , +.Xr sched_get_priority_min 2 , +.Xr sched_getparam 2 , +.Xr sched_rr_get_interval 2 , +.Xr sched_setparam 2 , +.Xr sched_yield 2 +.Sh STANDARDS +The +.Fn sched_setscheduler +and +.Fn sched_getscheduler +functions conform to +.St -p1003.1b-93 . diff --git a/lib/libc/sys/sched_yield.2 b/lib/libc/sys/sched_yield.2 new file mode 100644 index 0000000..28ac9cc --- /dev/null +++ b/lib/libc/sys/sched_yield.2 @@ -0,0 +1,59 @@ +.\" $FreeBSD$ +.\" Copyright (c) 1998 HD Associates, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd Mar 12, 1998 +.Dt SCHED_YIELD 2 +.Os BSD 4 +.Sh NAME +.Nm sched_yield +.Nd yield processor +.Sh SYNOPSIS +.Fd #include <sched.h> +.Ft int +.Fn sched_yield void +.Sh DESCRIPTION +The +.Fn sched_yield +function forces the running process to relinquish the processor until it +again becomes the head of its process list. It takes no arguments. +.Sh RETURN +The +.Fn sched_yield +function will return zero if it completes successfully, or it +will return a value of -1 and set +.Va errno +to indicate the error. +.Sh ERRORS +On failure +.Va errno +will be set to the corresponding value: +.Bl -tag -width [EFAULT] +.It Bq Er ENOSYS +The system is not configured to support this functionality. +.Sh STANDARDS +The +.Fn sched_yield +function conforms to +.St -p1003.1b-93 . diff --git a/lib/libc/sys/select.2 b/lib/libc/sys/select.2 new file mode 100644 index 0000000..938f0ec --- /dev/null +++ b/lib/libc/sys/select.2 @@ -0,0 +1,194 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)select.2 8.2 (Berkeley) 3/25/94 +.\" $FreeBSD$ +.\" +.Dd March 25, 1994 +.Dt SELECT 2 +.Os BSD 4.2 +.Sh NAME +.Nm select +.Nd synchronous I/O multiplexing +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/time.h> +.Fd #include <unistd.h> +.Ft int +.Fn select "int nfds" "fd_set *readfds" "fd_set *writefds" "fd_set *exceptfds" "struct timeval *timeout" +.Fn FD_SET fd &fdset +.Fn FD_CLR fd &fdset +.Fn FD_ISSET fd &fdset +.Fn FD_ZERO &fdset +.Sh DESCRIPTION +.Fn Select +examines the I/O descriptor sets whose addresses are passed in +.Fa readfds , +.Fa writefds , +and +.Fa exceptfds +to see if some of their descriptors +are ready for reading, are ready for writing, or have an exceptional +condition pending, respectively. +The only exceptional condition detectable is out-of-band +data received on a socket. +The first +.Fa nfds +descriptors are checked in each set; +i.e., the descriptors from 0 through +.Fa nfds Ns No -1 +in the descriptor sets are examined. +On return, +.Fn select +replaces the given descriptor sets +with subsets consisting of those descriptors that are ready +for the requested operation. +.Fn Select +returns the total number of ready descriptors in all the sets. +.Pp +The descriptor sets are stored as bit fields in arrays of integers. +The following macros are provided for manipulating such descriptor sets: +.Fn FD_ZERO &fdset +initializes a descriptor set +.Fa fdset +to the null set. +.Fn FD_SET fd &fdset +includes a particular descriptor +.Fa fd +in +.Fa fdset . +.Fn FD_CLR fd &fdset +removes +.Fa fd +from +.Fa fdset . +.Fn FD_ISSET fd &fdset +is non-zero if +.Fa fd +is a member of +.Fa fdset , +zero otherwise. +The behavior of these macros is undefined if +a descriptor value is less than zero or greater than or equal to +.Dv FD_SETSIZE , +which is normally at least equal +to the maximum number of descriptors supported by the system. +.Pp +If +.Fa timeout +is a non-nil pointer, it specifies a maximum interval to wait for the +selection to complete. If +.Fa timeout +is a nil pointer, the select blocks indefinitely. To effect a poll, the +.Fa timeout +argument should be non-nil, pointing to a zero-valued timeval structure. +.Pp +Any of +.Fa readfds , +.Fa writefds , +and +.Fa exceptfds +may be given as nil pointers if no descriptors are of interest. +.Sh RETURN VALUES +.Fn Select +returns the number of ready descriptors that are contained in +the descriptor sets, +or -1 if an error occurred. +If the time limit expires, +.Fn select +returns 0. +If +.Fn select +returns with an error, +including one due to an interrupted call, +the descriptor sets will be unmodified. +.Sh ERRORS +An error return from +.Fn select +indicates: +.Bl -tag -width Er +.It Bq Er EBADF +One of the descriptor sets specified an invalid descriptor. +.It Bq Er EINTR +A signal was delivered before the time limit expired and +before any of the selected events occurred. +.It Bq Er EINVAL +The specified time limit is invalid. One of its components is +negative or too large. +.It Bq Er EINVAL +.Fa nfds +was invalid. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr connect 2 , +.Xr getdtablesize 2 , +.Xr gettimeofday 2 , +.Xr read 2 , +.Xr recv 2 , +.Xr send 2 , +.Xr write 2 , +.Xr clocks 7 +.Sh NOTES +The default size of +.Dv FD_SETSIZE +is currently 1024. +In order to accommodate programs which might potentially +use a larger number of open files with +.Fn select +, it is possible +to increase this size by having the program define +.Dv FD_SETSIZE +before the inclusion of any header which includes +.Aq Pa sys/types.h . +.Pp +If +.Fa nfds +is greater than the number of open files, +.Fn select +is not guaranteed to examine the unused file descriptors. For historical +reasons, +.Fn select +will always examine the first 256 descriptors. +.Sh BUGS +.Fn select +should probably return the time remaining from the original timeout, +if any, by modifying the time value in place. +This may be implemented in future versions of the system. +Thus, it is unwise to assume that the timeout value will be unmodified +by the +.Fn select +call. +.Sh HISTORY +The +.Fn select +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/semctl.2 b/lib/libc/sys/semctl.2 new file mode 100644 index 0000000..1983f86 --- /dev/null +++ b/lib/libc/sys/semctl.2 @@ -0,0 +1,177 @@ +.\" +.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 12, 1995 +.Dt SEMCTL 2 +.Os FreeBSD +.Sh NAME +.Nm semctl +.Nd control operations on a semaphore set +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/ipc.h> +.Fd #include <sys/sem.h> +.Ft int +.Fn semctl "int semid" "int semnum" "int cmd" ... +.Sh DESCRIPTION +.Fn Semctl +performs the operation indicated by +.Fa cmd +on the semaphore set indicated by +.Fa semid . +A fourth argument, a +.Fa "union semun arg" , +is required for certain values of +.Fa cmd . +For the commands that use the +.Fa arg +parameter, +.Fa "union semun" +is defined as follows: +.Bd -literal +.\" +.\" From <sys/sem.h>: +.\" +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + u_short *array; /* array for GETALL & SETALL */ +}; +.Ed +.Pp +Commands are performed as follows: +.\" +.\" This section based on Stevens, _Advanced Programming in the UNIX +.\" Environment_. +.\" +.Bl -tag -width IPC_RMIDXXX +.It Dv IPC_STAT +Fetch the semaphore set's +.Fa "struct semid_ds" , +storing it in the memory pointed to by +.Fa arg.buf . +.It Dv IPC_SET +Changes the +.Fa sem_perm.uid , +.Fa sem_perm.gid , +and +.Fa sem_perm.mode +members of the semaphore set's +.Fa "struct semid_ds" +to match those of the struct pointed to by +.Fa arg.buf . +The calling process's effective uid must +match either +.Fa sem_perm.uid +or +.Fa sem_perm.cuid , +or it must have superuser privileges. +.It IPC_RMID +Immediately removes the semaphore set from the system. The calling +process's effective uid must equal the semaphore set's +.Fa sem_perm.uid +or +.Fa sem_perm.cuid , +or the process must have superuser privileges. +.It Dv GETVAL +Return the value of semaphore number +.Fa semnum . +.It Dv SETVAL +Set the value of semaphore number +.Fa semnum +to +.Fa arg.val . +.It Dv GETPID +Return the pid of the last process to perform an operation on +semaphore number +.Fa semnum . +.It Dv GETNCNT +Return the number of processes waiting for semaphore number +.Fa semnum Ns 's +value to become greater than its current value. +.It Dv GETZCNT +Return the number of processes waiting for semaphore number +.Fa semnum Ns 's +value to become 0. +.It Dv GETALL +Fetch the value of all of the semaphores in the set into the +array pointed to by +.Fa arg.array . +.It Dv SETALL +Set the values of all of the semaphores in the set to the values +in the array pointed to by +.Fa arg.array . +.El +.Pp +The +.Fa "struct semid_ds" +is defined as follows: +.Bd -literal +.\" +.\" Taken straight from <sys/sem.h>. +.\" +struct semid_ds { + struct ipc_perm sem_perm; /* operation permission struct */ + struct sem *sem_base; /* pointer to first semaphore in set */ + u_short sem_nsems; /* number of sems in set */ + time_t sem_otime; /* last operation time */ + long sem_pad1; /* SVABI/386 says I need this here */ + time_t sem_ctime; /* last change time */ + /* Times measured in secs since */ + /* 00:00:00 GMT, Jan. 1, 1970 */ + long sem_pad2; /* SVABI/386 says I need this here */ + long sem_pad3[4]; /* SVABI/386 says I need this here */ +}; +.Ed +.Sh RETURN VALUES +On success, when +.Fa cmd +is one of GETVAL, GETNCNT, or GETZCNT, +.Fn semctl +returns the corresponding value; otherwise, 0 is returned. +On failure, -1 is returned, and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Semctl +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +No semaphore set corresponds to +.Fa semid . +.It Bq Er EINVAL +.Fa semnum +is not in the range of valid semaphores for given semaphore set. +.It Bq Er EPERM +The calling process's effective uid does not match the uid of +the semaphore set's owner or creator. +.It Bq Er EACCES +Permission denied due to mismatch between operation and mode of +semaphore set. +.Sh SEE ALSO +.Xr semget 2 , +.Xr semop 2 diff --git a/lib/libc/sys/semget.2 b/lib/libc/sys/semget.2 new file mode 100644 index 0000000..edb0c87 --- /dev/null +++ b/lib/libc/sys/semget.2 @@ -0,0 +1,138 @@ +.\" +.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 12, 1995 +.Dt SEMGET 2 +.Os FreeBSD +.Sh NAME +.Nm semget +.Nd obtain a semaphore id +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/ipc.h> +.Fd #include <sys/sem.h> +.Ft int +.Fn semget "key_t key" "int nsems" "int flag" +.Sh DESCRIPTION +Based on the values of +.Fa key +and +.Fa flag , +.Fn semget +returns the identifier of a newly created or previously existing +set of semaphores. +.\" +.\" This is copied verbatim from the shmget manpage. Perhaps +.\" it should go in a common manpage, such as .Xr ipc 2 +.\" +The key +is analogous to a filename: it provides a handle that names an +IPC object. There are three ways to specify a key: +.Bl -bullet +.It +IPC_PRIVATE may be specified, in which case a new IPC object +will be created. +.It +An integer constant may be specified. If no IPC object corresponding +to +.Fa key +is specified and the IPC_CREAT bit is set in +.Fa flag , +a new one will be created. +.It +.Fn ftok +may be used to generate a key from a pathname. See +.Xr ftok 3 . +.El +.\" +.\" Likewise for this section, except SHM_* becomes SEM_*. +.\" +.Pp +The mode of a newly created IPC object is determined by +.Em OR Ns 'ing +the following constants into the +.Fa flag +parameter: +.Bl -tag -width XSEM_WXX6XXX +.It Dv SEM_R +Read access for user. +.It Dv SEM_A +Alter access for user. +.It Dv (SEM_R>>3) +Read access for group. +.It Dv (SEM_A>>3) +Alter access for group. +.It Dv (SEM_R>>6) +Read access for other. +.It Dv (SEM_A>>6) +Alter access for other. +.El +.Pp +If a new set of semaphores is being created, +.Fa nsems +is used to indicate the number of semaphores the set should contain. +Otherwise, +.Fa nsems +may be specified as 0. +.Sh RETURN VALUES +.Fn Semget +returns the id of a semaphore set if successful; otherwise, -1 +is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Semget +will fail if: +.Bl -tag -width Er +.\" ipcperm could fail (we're opening to read and write, as it were) +.It Bq Er EACCES +Access permission failure. +.\" +.\" sysv_sem.c is quite explicit about these, so I'm pretty sure +.\" this is accurate +.\" +.It Bq Er EEXIST +IPC_CREAT and IPC_EXCL were specified, and a semaphore set +corresponding to +.Fa key +already exists. +.It Bq Er EINVAL +The number of semaphores requested exceeds the system imposed maximum +per set. +.It Bq Er ENOSPC +Insufficiently many semaphores are available. +.It Bq Er ENOSPC +The kernel could not allocate a +.Fa "struct semid_ds" . +.It Bq Er ENOENT +No semaphore set was found corresponding to +.Fa key , +and IPC_CREAT was not specified. +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semop 2 , +.Xr ftok 3 diff --git a/lib/libc/sys/semop.2 b/lib/libc/sys/semop.2 new file mode 100644 index 0000000..abae921 --- /dev/null +++ b/lib/libc/sys/semop.2 @@ -0,0 +1,192 @@ +.\" +.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 22, 1995 +.Dt SEMOP 2 +.Os FreeBSD +.Sh NAME +.Nm semop +.Nd atomic array of operations on a semaphore set +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/ipc.h> +.Fd #include <sys/sem.h> +.Ft int +.Fn semop "int semid" "struct sembuf array[]" "unsigned nops" +.Sh DESCRIPTION +.Fn Semop +atomically performs the array of operations indicated by +.Fa array +on the semaphore set indicated by +.Fa semid . +The length of +.Fa array +is indicated by +.Fa nops . +Each operation is encoded in a +.Fa "struct sembuf" , +which is defined as follows: +.Bd -literal +.\" +.\" From <sys/sem.h> +.\" +struct sembuf { + u_short sem_num; /* semaphore # */ + short sem_op; /* semaphore operation */ + short sem_flg; /* operation flags */ +}; +.Ed +.Pp +For each element in +.Fa array , +.Fa sem_op +and +.Fa sem_flg +determine an operation to be performed on semaphore number +.Fa sem_num +in the set. The values SEM_UNDO and IPC_NOWAIT may be +.Em OR Ns 'ed +into the +.Fa sem_flg +member in order to modify the behavior of the given operation. +.Pp +The operation performed depends as follows on the value of +.Fa sem_op : +.\" +.\" This section is based on the description of semop() in +.\" Stevens, _Advanced Programming in the UNIX Environment_. +.\" +.Bl -bullet +.It +When +.Fa sem_op +is positive, the semaphore's value is incremented by +.Fa sem_op Ns 's +value. If SEM_UNDO is specified, the semaphore's adjust on exit +value is decremented by +.Fa sem_op Ns 's +value. A positive value for +.Fa sem_op +generally corresponds to a process releasing a resource +associated with the semaphore. +.It +The behavior when +.Fa sem_op +is negative depends on the current value of the semaphore: +.Bl -bullet +.It +If the current value of the semaphore is greater than or equal to +the absolute value of +.Fa sem_op , +then the value is decremented by the absolute value of +.Fa sem_op . +If SEM_UNDO is specified, the semaphore's adjust on exit +value is incremented by the absolute value of +.Fa sem_op . +.It +If the current value of the semaphore is less than +.Fa sem_op Ns 's +value, one of the following happens: +.\" XXX a *second* sublist? +.Bl -bullet +.It +If IPC_NOWAIT was specified, then +.Fn semop +returns immediately with a return value of EAGAIN. +.It +If some other process has removed the semaphore with the IPC_RMID +option of +.Fn semctl , +then +.Fn semop +returns immediately with a return value of EINVAL. +.It +Otherwise, the calling process is put to sleep until the semaphore's +value is greater than or equal to the absolute value of +.Fa sem_op . +When this condition becomes true, the semaphore's value is decremented +by the absolute value of +.Fa sem_op , +and the semaphore's adjust on exit value is incremented by the +absolute value of +.Fa sem_op . +.El +.Pp +A negative value for +.Fa sem_op +generally means that a process is waiting for a resource to become +available. +.El +.Pp +.It +When +.Fa sem_op +is zero, the process waits for the semaphore's value to become zero. +If it is already zero, the call to +.Fn semop +can return immediately. Otherwise, the calling process is put to +sleep until the semaphore's value becomes zero. +.El +.Pp +For each semaphore a process has in use, the kernel maintains an +`adjust on exit' value, as alluded to earlier. When a process +exits, either voluntarily or involuntarily, the adjust on exit value +for each semaphore is added to the semaphore's value. This can +be used to insure that a resource is released if a process terminates +unexpectedly. +.Sh RETURN VALUES +On success, +.Fn semop +returns 0; otherwise, -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Semop +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +No semaphore set corresponds to +.Fa semid . +.It Bq Er EACCES +Permission denied due to mismatch between operation and mode of +semaphore set. +.It Bq Er EAGAIN +The semaphore's value was less than +.Fa sem_op , +and IPC_NOWAIT was specified. +.It Bq Er E2BIG +Too many operations were specified. +.It Bq Er EFBIG +.\" +.\" I'd have thought this would be EINVAL, but the source says +.\" EFBIG. +.\" +.Fa sem_num +was not in the range of valid semaphores for the set. +.Sh SEE ALSO +.Xr semctl 2 , +.Xr semget 2 diff --git a/lib/libc/sys/send.2 b/lib/libc/sys/send.2 new file mode 100644 index 0000000..327307c --- /dev/null +++ b/lib/libc/sys/send.2 @@ -0,0 +1,198 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)send.2 8.2 (Berkeley) 2/21/94 +.\" $FreeBSD$ +.\" +.Dd February 15, 1995 +.Dt SEND 2 +.Os BSD 4.2 +.Sh NAME +.Nm send , +.Nm sendto , +.Nm sendmsg +.Nd send a message from a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft ssize_t +.Fn send "int s" "const void *msg" "size_t len" "int flags" +.Ft ssize_t +.Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen" +.Ft ssize_t +.Fn sendmsg "int s" "const struct msghdr *msg" "int flags" +.Sh DESCRIPTION +.Fn Send , +.Fn sendto , +and +.Fn sendmsg +are used to transmit a message to another socket. +.Fn Send +may be used only when the socket is in a +.Em connected +state, while +.Fn sendto +and +.Fn sendmsg +may be used at any time. +.Pp +The address of the target is given by +.Fa to +with +.Fa tolen +specifying its size. +The length of the message is given by +.Fa len . +If the message is too long to pass atomically through the +underlying protocol, the error +.Er EMSGSIZE +is returned, and +the message is not transmitted. +.Pp +No indication of failure to deliver is implicit in a +.Fn send . +Locally detected errors are indicated by a return value of -1. +.Pp +If no messages space is available at the socket to hold +the message to be transmitted, then +.Fn send +normally blocks, unless the socket has been placed in +non-blocking I/O mode. +The +.Xr select 2 +call may be used to determine when it is possible to +send more data. +.Pp +The +.Fa flags +parameter may include one or more of the following: +.Bd -literal +#define MSG_OOB 0x1 /* process out-of-band data */ +#define MSG_PEEK 0x2 /* peek at incoming message */ +#define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */ +#define MSG_EOR 0x8 /* data completes record */ +#define MSG_EOF 0x100 /* data completes transaction */ +.Ed +.Pp +The flag +.Dv MSG_OOB +is used to send +.Dq out-of-band +data on sockets that support this notion (e.g. +.Dv SOCK_STREAM ) ; +the underlying protocol must also support +.Dq out-of-band +data. +.Dv MSG_EOR +is used to indicate a record mark for protocols which support the +concept. +.Dv MSG_EOF +requests that the sender side of a socket be shut down, and that an +appropriate indication be sent at the end of the specified data; +this flag is only implemented for +.Dv SOCK_STREAM +sockets in the +.Dv PF_INET +protocol family, and is used to implement Transaction +.Tn TCP +(see +.Xr ttcp 4 ) . +.Dv MSG_DONTROUTE +is usually used only by diagnostic or routing programs. +.Pp +See +.Xr recv 2 +for a description of the +.Fa msghdr +structure. +.Sh RETURN VALUES +The call returns the number of characters sent, or -1 +if an error occurred. +.Sh ERRORS +.Fn Send , +.Fn sendto , +and +.Fn sendmsg +fail if: +.Bl -tag -width Er +.It Bq Er EBADF +An invalid descriptor was specified. +.It Bq Er EACCES +The destination address is a broadcast address, and +.Dv SO_BROADCAST +has not been set on the socket. +.It Bq Er ENOTSOCK +The argument +.Fa s +is not a socket. +.It Bq Er EFAULT +An invalid user space address was specified for a parameter. +.It Bq Er EMSGSIZE +The socket requires that message be sent atomically, +and the size of the message to be sent made this impossible. +.It Bq Er EAGAIN +The socket is marked non-blocking and the requested operation +would block. +.It Bq Er ENOBUFS +The system was unable to allocate an internal buffer. +The operation may succeed when buffers become available. +.It Bq Er ENOBUFS +The output queue for a network interface was full. +This generally indicates that the interface has stopped sending, +but may be caused by transient congestion. +.It Bq Er EHOSTUNREACH +The remote host was unreachable. +.El +.Sh BUGS +Because +.Fn sendmsg +doesn't necessarily block until the data has been transferred, it +is possible to transfer an open file descriptor across an +.Dv AF_UNIX +domain socket +.Pq see Xr recv 2 , +then +.Fn close +it before it has actually been sent, the result being that the receiver +gets a closed file descriptor. It is left to the application to +implement an acknowlegment mechanism to prevent this from happening. +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr getsockopt 2 , +.Xr recv 2 , +.Xr select 2 , +.Xr socket 2 , +.Xr write 2 +.Sh HISTORY +The +.Fn send +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/sendfile.2 b/lib/libc/sys/sendfile.2 new file mode 100644 index 0000000..87b9bac --- /dev/null +++ b/lib/libc/sys/sendfile.2 @@ -0,0 +1,155 @@ +.\" Copyright (c) 1998, David Greenman +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice unmodified, this list of conditions, and the following +.\" disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd November 5, 1998 +.Dt SENDFILE 2 +.Os +.Sh NAME +.Nm sendfile +.Nd send a file to a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Fd #include <sys/uio.h> +.Ft int +.Fn sendfile "int fd" "int s" "off_t offset" "size_t nbytes" "struct sf_hdtr *hdtr" "off_t *sbytes" "int flags" +.Sh DESCRIPTION +.Fn Sendfile +sends a regular file specified by descriptor +.Fa fd +out a stream socket specified by descriptor +.Fa s . +.Pp +The +.Fa offset +argument specifies where to begin in the file. The +.Fa nbytes +argument specifies how many bytes of the file should be sent, with 0 having the special +meaning of send until the end of file has been reached. +.Pp +An optional header and/or trailer can be sent before and after the file data by specifying +a pointer to a struct sf_hdtr, which has the following structure: +.Pp +.Bd -literal -offset indent -compact +struct sf_hdtr { + struct iovec *headers; /* pointer to header iovecs */ + int hdr_cnt; /* number of header iovecs */ + struct iovec *trailers; /* pointer to trailer iovecs */ + int trl_cnt; /* number of trailer iovecs */ +}; +.Ed +.Pp +The +.Fa headers +and +.Fa tailers +pointers, if non-NULL, point to arrays of struct iovec structures. See the +.Fn writev +system call for information on the iovec structure. The number of iovecs in these +arrays is specified by +.Fa hdr_cnt +and +.Fa trl_cnt . +.Pp +If non-NULL, the system will write the total number of bytes sent on the socket to the +variable pointed to by +.Fa sbytes . +.Pp +The +.Fa flags +argument is currently undefined and should be specified as 0. +.Pp +When using a socket marked for non-blocking I/O, +.Fn sendfile +may send fewer bytes than requested. In this case, the number of bytes successfully +written is returned in +.Fa *sbytes +(if specified), +and the error +.Er EAGAIN +is returned. +.Sh IMPLEMENTATION NOTES +.Pp +The FreeBSD implementation of +.Fn sendfile +is "zero-copy", meaning that it has been optimized so that copying of the file data is avoided. +.Sh RETURN VALUES +Upon successful completion, +.Fn sendfile +returns 0. Otherwise a -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is not a valid file descriptor. +.It Bq Er EBADF +.Fa s +is not a valid socket descriptor. +.It Bq Er ENOTSOCK +.Fa s +is not a socket. +.It Bq Er EINVAL +.Fa fd +is not a regular file. +.It Bq Er EINVAL +.Fa s +is not a SOCK_STREAM type socket. +.It Bq Er EINVAL +.Fa offset +is negative or out of range. +.It Bq Er ENOTCONN +.Fa s +points to an unconnected socket. +.It Bq Er EPIPE +The socket peer has closed the connection. +.It Bq Er EIO +An error occurred while reading from +.Fa fd . +.It Bq Er EFAULT +An invalid address was specified for a parameter. +.It Bq Er EAGAIN +The socket is marked for non-blocking I/O and not all data was sent due to the socket buffer being filled. +If specified, the number of bytes successfully sent will be returned in +.Fa *sbytes . +.El +.Sh SEE ALSO +.Xr open 2 , +.Xr send 2 , +.Xr socket 2 , +.Xr writev 2 +.Sh HISTORY +.Fn sendfile +first appeared in +.Fx 3.0 . +This manual page first appeared in +.Fx 3.1 . +.Sh AUTHORS +.Fn sendfile +and this manual page were written by +.An David Greenman Aq dg@root.com . diff --git a/lib/libc/sys/setgroups.2 b/lib/libc/sys/setgroups.2 new file mode 100644 index 0000000..f11cbd56 --- /dev/null +++ b/lib/libc/sys/setgroups.2 @@ -0,0 +1,84 @@ +.\" Copyright (c) 1983, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)setgroups.2 8.2 (Berkeley) 4/16/94 +.\" $FreeBSD$ +.\" +.Dd April 16, 1994 +.Dt SETGROUPS 2 +.Os BSD 4.2 +.Sh NAME +.Nm setgroups +.Nd set group access list +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <unistd.h> +.Ft int +.Fn setgroups "int ngroups" "const gid_t *gidset" +.Sh DESCRIPTION +.Fn Setgroups +sets the group access list of the current user process +according to the array +.Fa gidset . +The parameter +.Fa ngroups +indicates the number of entries in the array and must be no +more than +.Dv NGROUPS , +as defined in +.Ao Pa sys/param.h Ac . +.Pp +Only the super-user may set new groups. +.Sh RETURN VALUES +A 0 value is returned on success, -1 on error, with +an error code stored in +.Va errno . +.Sh ERRORS +The +.Fn setgroups +call will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er EFAULT +The address specified for +.Fa gidset +is outside the process +address space. +.El +.Sh SEE ALSO +.Xr getgroups 2 , +.Xr initgroups 3 +.Sh HISTORY +The +.Fn setgroups +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/setpgid.2 b/lib/libc/sys/setpgid.2 new file mode 100644 index 0000000..19af6f7 --- /dev/null +++ b/lib/libc/sys/setpgid.2 @@ -0,0 +1,91 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)setpgid.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SETPGID 2 +.Os BSD 4 +.Sh NAME +.Nm setpgid , +.Nm setpgrp +.Nd set process group +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn setpgid "pid_t pid" "pid_t pgrp" +.Ft int +.Fn setpgrp "pid_t pid" "pid_t pgrp" +.Sh DESCRIPTION +.Fn Setpgid +sets the process group of the specified process +.Ar pid +to the specified +.Ar pgrp . +If +.Ar pid +is zero, then the call applies to the current process. +.Pp +If the invoker is not the super-user, then the affected process +must have the same effective user-id as the invoker or be a descendant +of the invoking process. +.Sh RETURN VALUES +.Fn Setpgid +returns 0 when the operation was successful. +If the request failed, -1 is returned and the global variable +.Va errno +indicates the reason. +.Sh ERRORS +.Fn Setpgid +will fail and the process group will not be altered if: +.Bl -tag -width indent +.It Bq Er ESRCH +The requested process does not exist. +.It Bq Er EPERM +The effective user ID of the requested process is different +from that of the caller and the process is not a descendent +of the calling process. +.El +.Sh SEE ALSO +.Xr getpgrp 2 +.Sh STANDARDS +The +.Fn setpgid +function call is expected to conform to +.St -p1003.1-90 . +.Sh COMPATIBILITY +.Fn Setpgrp +is identical to +.Fn setpgid , +and is retained for calling convention compatibility with historical +versions of +.Bx . diff --git a/lib/libc/sys/setregid.2 b/lib/libc/sys/setregid.2 new file mode 100644 index 0000000..1802e6e --- /dev/null +++ b/lib/libc/sys/setregid.2 @@ -0,0 +1,93 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)setregid.2 8.2 (Berkeley) 4/16/94 +.\" $FreeBSD$ +.\" +.Dd April 16, 1994 +.Dt SETREGID 2 +.Os BSD 4.2 +.Sh NAME +.Nm setregid +.Nd set real and effective group ID +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn setregid "gid_t rgid" "gid_t egid" +.Sh DESCRIPTION +The real and effective group ID's of the current process +are set to the arguments. +Unprivileged users may change the real group +ID to the effective group ID and vice-versa; only the super-user may +make other changes. +.Pp +Supplying a value of -1 for either the real or effective +group ID forces the system to substitute the current +ID in place of the -1 parameter. +.Pp +The +.Fn setregid +function was intended to allow swapping +the real and effective group IDs +in set-group-ID programs to temporarily relinquish the set-group-ID value. +This function did not work correctly, +and its purpose is now better served by the use of the +.Fn setegid +function (see +.Xr setuid 2 ) . +.Pp +When setting the real and effective group IDs to the same value, +the standard +.Fn setgid +function is preferred. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. Otherwise, +a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width [EPERM] +.It Bq Er EPERM +The current process is not the super-user and a change +other than changing the effective group-id to the real group-id +was specified. +.El +.Sh SEE ALSO +.Xr getgid 2 , +.Xr issetugid 2 , +.Xr setegid 2 , +.Xr setgid 2 , +.Xr setuid 2 +.Sh HISTORY +The +.Fn setregid +system call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/setreuid.2 b/lib/libc/sys/setreuid.2 new file mode 100644 index 0000000..32d35ee --- /dev/null +++ b/lib/libc/sys/setreuid.2 @@ -0,0 +1,91 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)setreuid.2 8.2 (Berkeley) 4/16/94 +.\" $FreeBSD$ +.\" +.Dd April 16, 1994 +.Dt SETREUID 2 +.Os BSD 4 +.Sh NAME +.Nm setreuid +.Nd set real and effective user ID's +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn setreuid "uid_t ruid" "uid_t euid" +.Sh DESCRIPTION +The real and effective user IDs of the +current process are set according to the arguments. +If +.Fa ruid +or +.Fa euid +is -1, the current uid is filled in by the system. +Unprivileged users may change the real user +ID to the effective user ID and vice-versa; only the super-user may +make other changes. +.Pp +The +.Fn setreuid +function has been used to swap the real and effective user IDs +in set-user-ID programs to temporarily relinquish the set-user-ID value. +This purpose is now better served by the use of the +.Fn seteuid +function (see +.Xr setuid 2 ) . +.Pp +When setting the real and effective user IDs to the same value, +the standard +.Fn setuid +function is preferred. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. Otherwise, +a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width [EPERM] +.It Bq Er EPERM +The current process is not the super-user and a change +other than changing the effective user-id to the real user-id +was specified. +.El +.Sh SEE ALSO +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr seteuid 2 , +.Xr setuid 2 +.Sh HISTORY +The +.Fn setreuid +system call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/setsid.2 b/lib/libc/sys/setsid.2 new file mode 100644 index 0000000..631cc13 --- /dev/null +++ b/lib/libc/sys/setsid.2 @@ -0,0 +1,83 @@ +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)setsid.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SETSID 2 +.Os +.Sh NAME +.Nm setsid +.Nd create session and set process group ID +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft pid_t +.Fn setsid void +.Sh DESCRIPTION +The +.Fn setsid +function creates a new session. +The calling process is the session leader of the new session, is the +process group leader of a new process group and has no controlling +terminal. +The calling process is the only process in either the session or the +process group. +.Sh RETURN VALUES +Upon successful completion, the +.Fn setsid +function returns the value of the process group ID of the new process +group, which is the same as the process ID of the calling process. +If an error occurs, +.Fn setsid +returns -1 and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn setsid +function will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The calling process is already a process group leader, or the process +group ID of a process other than the calling process matches the process +ID of the calling process. +.El +.Sh SEE ALSO +.Xr setpgid 2 , +.Xr tcgetpgrp 3 , +.Xr tcsetpgrp 3 +.Sh STANDARDS +The +.Fn setsid +function is expected to be compliant with the +.St -p1003.1-90 +specification. diff --git a/lib/libc/sys/setuid.2 b/lib/libc/sys/setuid.2 new file mode 100644 index 0000000..0fc6890 --- /dev/null +++ b/lib/libc/sys/setuid.2 @@ -0,0 +1,161 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SETUID 2 +.Os BSD 4.2 +.Sh NAME +.Nm setuid , +.Nm seteuid , +.Nm setgid , +.Nm setegid , +.Nd set user and group ID +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <unistd.h> +.Ft int +.Fn setuid "uid_t uid" +.Ft int +.Fn seteuid "uid_t euid" +.Ft int +.Fn setgid "gid_t gid" +.Ft int +.Fn setegid "gid_t egid" +.Sh DESCRIPTION +The +.Fn setuid +function +sets the real and effective +user IDs and the saved set-user-ID of the current process +to the specified value. +.\" Comment out next block for !_POSIX_SAVED_IDS +.\" The real user ID and the saved set-user-ID are changed only if the +.\" effective user ID is that of the super user. +.\" I.e. +.\" .Fn setuid +.\" function is equal to +.\" .Fn seteuid +.\" function if the effective user ID is not that of the super user. +.\" End of block +The +.Fn setuid +function is permitted if the specified ID is equal to the real user ID +.\" Comment out next line for !_POSIX_SAVED_IDS +.\" or the saved set-user-ID +.\" Next line is for Appendix B.4.2.2 case. +or the effective user ID +of the process, or if the effective user ID is that of the super user. +.Pp +The +.Fn setgid +function +sets the real and effective +group IDs and the saved set-group-ID of the current process +to the specified value. +.\" Comment out next block for !_POSIX_SAVED_IDS +.\" The real group ID and the saved set-group-ID are changed only if the +.\" effective user ID is that of the super user. +.\" I.e. +.\" .Fn setgid +.\" function is equal to +.\" .Fn setegid +.\" function if the effective user ID is not that of the super user. +.\" End of block +The +.Fn setgid +function is permitted if the specified ID is equal to the real group ID +.\" Comment out next line for !_POSIX_SAVED_IDS +.\" or the saved set-group-ID +.\" Next line is for Appendix B.4.2.2 case. +or the effective group ID +of the process, or if the effective user ID is that of the super user. +.Pp +The +.Fn seteuid +function +.Pq Fn setegid +sets the effective user ID (group ID) of the +current process. +The effective user ID may be set to the value +of the real user ID or the saved set-user-ID (see +.Xr intro 2 +and +.Xr execve 2 ) ; +in this way, the effective user ID of a set-user-ID executable +may be toggled by switching to the real user ID, then re-enabled +by reverting to the set-user-ID value. +Similarly, the effective group ID may be set to the value +of the real group ID or the saved set-user-ID. +.Pp +.Sh RETURN VALUES +Upon success, these functions return 0; +otherwise \-1 is returned. +.Pp +If the user is not the super user, or the uid +specified is not the real, effective ID, or saved ID, +these functions return \-1. +.Sh SEE ALSO +.Xr getgid 2 , +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr setregid 2 , +.Xr setreuid 2 +.Sh STANDARDS +The +.Fn setuid +and +.Fn setgid +functions are compliant with the +.St -p1003.1-90 +specification with +.Li _POSIX_SAVED_IDS +.\" Uncomment next line for !_POSIX_SAVED_IDS +not +defined with the permitted extensions from Appendix B.4.2.2. +The +.Fn seteuid +and +.Fn setegid +functions are extensions based on the +.Tn POSIX +concept of +.Li _POSIX_SAVED_IDS , +and have been proposed for a future revision of the standard. +.Sh HISTORY +A +.Fn setuid +and a +.Fn setgid +function calls appeared in +.At v7 . diff --git a/lib/libc/sys/shmat.2 b/lib/libc/sys/shmat.2 new file mode 100644 index 0000000..331a4c9 --- /dev/null +++ b/lib/libc/sys/shmat.2 @@ -0,0 +1,111 @@ +.\" +.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd August 2, 1995 +.Dt SHMAT 2 +.Os FreeBSD +.Sh NAME +.Nm shmat , +.Nm shmdt +.Nd attach or detach shared memory +.Sh SYNOPSIS +.Fd #include <machine/param.h> +.Fd #include <sys/types.h> +.Fd #include <sys/ipc.h> +.Fd #include <sys/shm.h> +.Ft void * +.Fn shmat "int shmid" "void *addr" "int flag" +.Ft int +.Fn shmdt "void *addr" +.Sh DESCRIPTION +.Fn Shmat +attaches the shared memory segment identified by +.Fa shmid +to the calling process's address space. The address where the segment +is attached is determined as follows: +.\" +.\" These are cribbed almost exactly from Stevens, _Advanced Programming in +.\" the UNIX Environment_. +.\" +.Bl -bullet +.It +If +.Fa addr +is 0, the segment is attached at an address selected by the +kernel. +.It +If +.Fa addr +is nonzero and SHM_RND is not specified in +.Fa flag , +the segment is attached the specified address. +.It +If +.Fa addr +is specified and SHM_RND is specified, +.Fa addr +is rounded down to the nearest multiple of SHMLBA. +.El +.Pp +.Fn Shmdt +detaches the shared memory segment at the address specified by +.Fa addr +from the calling process's address space. +.Sh RETURN VALUES +Upon success, +.Fn shmat +returns the address where the segment is attached; otherwise, -1 +is returned and +.Va errno +is set to indicate the error. +.Pp +Upon success, +.Fn shmdt +returns 0; otherwise, -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Shmat +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +No shared memory segment was found corresponding to +.Fa shmid . +.It Bq Er EINVAL +.Fa addr +was not an acceptable address. +.El +.Pp +.Fn Shmdt +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa addr +does not point to a shared memory segment. +.Sh "SEE ALSO" +.Xr shmctl 2 , +.Xr shmget 2 diff --git a/lib/libc/sys/shmctl.2 b/lib/libc/sys/shmctl.2 new file mode 100644 index 0000000..e24d226 --- /dev/null +++ b/lib/libc/sys/shmctl.2 @@ -0,0 +1,137 @@ +.\" +.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd July 17, 1995 +.Dt SHMCTL 2 +.Os FreeBSD +.Sh NAME +.Nm shmctl +.Nd shared memory control +.Sh SYNOPSIS +.Fd #include <machine/param.h> +.Fd #include <sys/types.h> +.Fd #include <sys/ipc.h> +.Fd #include <sys/shm.h> +.Ft int +.Fn shmctl "int shmid" "int cmd" "struct shmid_ds *buf" +.Sh DESCRIPTION +Performs the action specified by +.Fa cmd +on the shared memory segment identified by +.Fa shmid : +.Bl -tag -width SHM_UNLOCKX +.It Dv IPC_STAT +Fetch the segment's +.Fa "struct shmid_ds" , +storing it in the memory pointed to by +.Fa buf . +.\" +.\" XXX need to make sure that this is correct for FreeBSD +.\" +.It Dv IPC_SET +Changes the +.Fa shm_perm.uid , +.Fa shm_perm.gid , +and +.Fa shm_perm.mode +members of the segment's +.Fa "struct shmid_ds" +to match those of the struct pointed to by +.Fa buf . +The calling process's effective uid must +match either +.Fa shm_perm.uid +or +.Fa shm_perm.cuid , +or it must have superuser privileges. +.It Dv IPC_RMID +Removes the segment from the system. The removal will not take +effect until all processes having attached the segment have exited; +however, once the IPC_RMID operation has taken place, no further +processes will be allowed to attach the segment. For the operation +to succeed, the calling process's effective uid must match +.Fa shm_perm.uid +or +.Fa shm_perm.cuid , +or the process must have superuser privileges. +.\" .It Dv SHM_LOCK +.\" Locks the segment in memory. The calling process must have +.\" superuser privileges. Not implemented in FreeBSD. +.\" .It Dv SHM_UNLOCK +.\" Unlocks the segment from memory. The calling process must +.\" have superuser privileges. Not implemented in FreeBSD. +.El +.Pp +The +.Fa shmid_ds +struct is defined as follows: +.\" +.\" I fiddled with the spaces a bit to make it fit well when viewed +.\" with nroff, but otherwise it's straight from sys/shm.h +.\" +.Bd -literal +struct shmid_ds { + struct ipc_perm shm_perm; /* operation permission structure */ + int shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shared memory op */ + pid_t shm_cpid; /* process ID of creator */ + short shm_nattch; /* number of current attaches */ + time_t shm_atime; /* time of last shmat() */ + time_t shm_dtime; /* time of last shmdt() */ + time_t shm_ctime; /* time of last change by shmctl() */ + void *shm_internal; /* sysv stupidity */ +}; +.Ed +.Sh RETURN VALUES +Upon successful completion, +.Fn shmctl +returns 0. Otherwise, it returns -1 and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Shmctl +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid operation, or +no shared memory segment was found corresponding to +.Fa shmid . +.\" +.\" XXX I think the following is right: ipcperm() only returns EPERM +.\" when an attempt is made to modify (IPC_M) by a non-creator +.\" non-owner +.It Bq Er EPERM +The calling process's effective uid does not match the uid of +the shared memory segment's owner or creator. +.It Bq Er EACCES +Permission denied due to mismatch between operation and mode of +shared memory segment. +.Sh "SEE ALSO" +.Xr shmat 2 , +.Xr shmdt 2 , +.Xr shmget 2 , +.Xr ftok 3 diff --git a/lib/libc/sys/shmget.2 b/lib/libc/sys/shmget.2 new file mode 100644 index 0000000..db5917f --- /dev/null +++ b/lib/libc/sys/shmget.2 @@ -0,0 +1,139 @@ +.\" +.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd July 3, 1995 +.Dt SHMGET 2 +.Os FreeBSD +.Sh NAME +.Nm shmget +.Nd obtain a shared memory identifier +.Sh SYNOPSIS +.Fd #include <machine/param.h> +.Fd #include <sys/types.h> +.Fd #include <sys/ipc.h> +.Fd #include <sys/shm.h> +.Ft int +.Fn shmget "key_t key" "int size" "int flag" +.Sh DESCRIPTION +Based on the values of +.Fa key +and +.Fa flag , +.Fn shmget +returns the identifier of a newly created or previously existing shared +memory segment. +.\" +.\" The following bit about keys and modes also applies to semaphores +.\" and message queues. +.\" +The key +is analogous to a filename: it provides a handle that names an +IPC object. There are three ways to specify a key: +.Bl -bullet +.It +IPC_PRIVATE may be specified, in which case a new IPC object +will be created. +.It +An integer constant may be specified. If no IPC object corresponding +to +.Fa key +is specified and the IPC_CREAT bit is set in +.Fa flag , +a new one will be created. +.It +.Fn ftok +may be used to generate a key from a pathname. See +.Xr ftok 3 . +.El +.Pp +The mode of a newly created IPC object is determined by +.Em OR Ns 'ing +the following constants into the +.Fa flag +parameter: +.Bl -tag -width XSHM_WXX6XXX +.It Dv SHM_R +Read access for user. +.It Dv SHM_W +Write access for user. +.It Dv (SHM_R>>3) +Read access for group. +.It Dv (SHM_W>>3) +Write access for group. +.It Dv (SHM_R>>6) +Read access for other. +.It Dv (SHM_W>>6) +Write access for other. +.El +.\" +.\" XXX - we should also mention how uid, euid, and gid affect ownership +.\" and use +.\" +.\" end section about keys and modes +.\" +.Pp +When creating a new shared memory segment, +.Fa size +indicates the desired size of the new segment in bytes. The size +of the segment may be rounded up to a multiple convenient to the +kernel (i.e., the page size). +.Sh RETURN VALUES +Upon successful completion, +.Fn shmget +returns the positive integer identifier of a shared memory segment. +Otherwise, -1 is returned and +.Va errno +set to indicate the error. +.Sh ERRORS +.Fn Shmget +will fail if: +.Bl -tag -width Er +.\" +.\" XXX What about ipcperm failing? +.\" +.It Bq Er EINVAL +Size specified is greater than the size of the previously existing segment. +Size specified is less than the system imposed minimum, or greater than +the system imposed maximum. +.It Bq Er ENOENT +No shared memory segment was found matching +.Fa key , +and IPC_CREAT was not specified. +.It Bq Er ENOSPC +The kernel was unable to allocate enough memory to +satisfy the request. +.It Bq Er EEXIST +IPC_CREAT and IPC_EXCL were specified, and a shared memory segment +corresponding to +.Fa key +already exists. +.Pp +.Sh "SEE ALSO" +.Xr shmat 2 , +.Xr shmctl 2 , +.Xr shmdt 2 , +.Xr ftok 3 diff --git a/lib/libc/sys/shutdown.2 b/lib/libc/sys/shutdown.2 new file mode 100644 index 0000000..b35a55d --- /dev/null +++ b/lib/libc/sys/shutdown.2 @@ -0,0 +1,100 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)shutdown.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SHUTDOWN 2 +.Os BSD 4.2 +.Sh NAME +.Nm shutdown +.Nd shut down part of a full-duplex connection +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn shutdown "int s" "int how" +.Sh DESCRIPTION +The +.Fn shutdown +call causes all or part of a full-duplex connection on +the socket associated with +.Fa s +to be shut down. +If +.Fa how +is +.No Dv SHUT_RD Pq 0 , +further receives will be disallowed. +If +.Fa how +is +.No Dv SHUT_WR Pq 1 , +further sends will be disallowed. +If +.Fa how +is +.No Dv SHUT_RDWR Pq 2 , +further sends and receives will be disallowed. +.Sh RETURN VALUES +A 0 is returned if the call succeeds, -1 if it fails. +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width ENOTCONNAA +.It Bq Er EBADF +.Fa S +is not a valid descriptor. +.It Bq Er ENOTSOCK +.Fa S +is a file, not a socket. +.It Bq Er ENOTCONN +The specified socket is not connected. +.El +.Sh SEE ALSO +.Xr connect 2 , +.Xr socket 2 +.Sh STANDARDS +The +.Fn shutdown +function is expected to comply with +.St -p1003.1g , +when finalized. +.Sh HISTORY +The +.Fn shutdown +function call appeared in +.Bx 4.2 . +The +.Dv SHUT_ +constants appeared in +.St -p1003.1g . + diff --git a/lib/libc/sys/sigaction.2 b/lib/libc/sys/sigaction.2 new file mode 100644 index 0000000..c3c41f7 --- /dev/null +++ b/lib/libc/sys/sigaction.2 @@ -0,0 +1,577 @@ +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)sigaction.2 8.2 (Berkeley) 4/3/94 +.\" $FreeBSD$ +.\" +.Dd April 3, 1994 +.Dt SIGACTION 2 +.Os +.Sh NAME +.Nm sigaction +.Nd software signal facilities +.Sh SYNOPSIS +.Fd #include <signal.h> +.Bd -literal +struct sigaction { + /* + * Signal handler function if flag SA_SIGINFO is not used and for + * SIG_DFL and SIG_IGN. + */ + void (*sa_handler)(int); + + /* Signal handler function if flag SA_SIGINFO is used */ + void (*sa_sigaction)(int, siginfo_t *, void *); + + sigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ +}; +.Ed +.Ft int +.Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact" +.Sh DESCRIPTION +The system defines a set of signals that may be delivered to a process. +Signal delivery resembles the occurrence of a hardware interrupt: +the signal is normally blocked from further occurrence, the current process +context is saved, and a new one is built. A process may specify a +.Em handler +to which a signal is delivered, or specify that a signal is to be +.Em ignored . +A process may also specify that a default action is to be taken +by the system when a signal occurs. +A signal may also be +.Em blocked , +in which case its delivery is postponed until it is +.Em unblocked . +The action to be taken on delivery is determined at the time +of delivery. +Normally, signal handlers execute on the current stack +of the process. This may be changed, on a per-handler basis, +so that signals are taken on a special +.Em "signal stack" . +.Pp +Signal routines normally execute with the signal that caused their +invocation +.Em blocked , +but other signals may yet occur. +A global +.Em "signal mask" +defines the set of signals currently blocked from delivery +to a process. The signal mask for a process is initialized +from that of its parent (normally empty). It +may be changed with a +.Xr sigprocmask 2 +call, or when a signal is delivered to the process. +.Pp +When a signal +condition arises for a process, the signal is added to a set of +signals pending for the process. +If the signal is not currently +.Em blocked +by the process then it is delivered to the process. +Signals may be delivered any time a process enters the operating system +(e.g., during a system call, page fault or trap, or clock interrupt). +If multiple signals are ready to be delivered at the same time, +any signals that could be caused by traps are delivered first. +Additional signals may be processed at the same time, with each +appearing to interrupt the handlers for the previous signals +before their first instructions. +The set of pending signals is returned by the +.Xr sigpending 2 +function. +When a caught signal +is delivered, the current state of the process is saved, +a new signal mask is calculated (as described below), +and the signal handler is invoked. The call to the handler +is arranged so that if the signal handling routine returns +normally the process will resume execution in the context +from before the signal's delivery. +If the process wishes to resume in a different context, then it +must arrange to restore the previous context itself. +.Pp +When a signal is delivered to a process a new signal mask is +installed for the duration of the process' signal handler +(or until a +.Xr sigprocmask +call is made). +This mask is formed by taking the union of the current signal mask set, +the signal to be delivered, and +the signal mask associated with the handler to be invoked. +.Pp +.Fn Sigaction +assigns an action for a signal specified by +.Fa sig . +If +.Fa act +is non-zero, it +specifies an action +.Pf ( Dv SIG_DFL , +.Dv SIG_IGN , +or a handler routine) and mask +to be used when delivering the specified signal. +If +.Fa oact +is non-zero, the previous handling information for the signal +is returned to the user. +.Pp +Once a signal handler is installed, it normally remains installed +until another +.Fn sigaction +call is made, or an +.Xr execve 2 +is performed. +A signal-specific default action may be reset by +setting +.Fa sa_handler +to +.Dv SIG_DFL . +The defaults are process termination, possibly with core dump; +no action; stopping the process; or continuing the process. +See the signal list below for each signal's default action. +If +.Fa sa_handler +is +.Dv SIG_DFL , +the default action for the signal is to discard the signal, +and if a signal is pending, +the pending signal is discarded even if the signal is masked. +If +.Fa sa_handler +is set to +.Dv SIG_IGN +current and pending instances +of the signal are ignored and discarded. +.Pp +Options may be specified by setting +.Em sa_flags . +The meaning of the various bits is as follows: +.Bl -tag -offset indent -width SA_RESETHANDXX +.It Dv SA_NOCLDSTOP +If this bit is set when installing a catching function +for the +.Dv SIGCHLD +signal, +the +.Dv SIGCHLD +signal will be generated only when a child process exits, +not when a child process stops. +.It Dv SA_NOCLDWAIT +If this bit is set when calling +.Fn sigaction +for the +.Dv SIGCHLD +signal, the system will not create zombie processes when children of +the calling process exit. If the calling process subsequently issues +a +.Xr wait 2 +(or equivalent), it blocks until all of the calling process's child +processes terminate, and then returns a value of -1 with errno set to +.Dv ECHILD . +.It Dv SA_ONSTACK +If this bit is set, the system will deliver the signal to the process +on a +.Em "signal stack" , +specified with +.Xr sigaltstack 2 . +.It Dv SA_NODEFER +If this bit is set, further occurrences of the delivered signal are +not masked during the execution of the handler. +.It Dv SA_RESETHAND +If this bit is set, the handler is reset back to +.Dv SIG_DFL +at the moment the signal is delivered. +.It Dv SA_SIGINFO +If this bit is set, the handler function is assumed to be pointed to +by the sa_sigaction member of struct sigaction and should match the +prototype shown above or as below in +.Sx EXAMPLES . +This bit should not be set when assigning +.Dv SIG_DFL +or +.Dv SIG_IGN . +.El +.Pp +If a signal is caught during the system calls listed below, +the call may be forced to terminate +with the error +.Dv EINTR , +the call may return with a data transfer shorter than requested, +or the call may be restarted. +Restart of pending calls is requested +by setting the +.Dv SA_RESTART +bit in +.Ar sa_flags . +The affected system calls include +.Xr open 2 , +.Xr read 2 , +.Xr write 2 , +.Xr sendto 2 , +.Xr recvfrom 2 , +.Xr sendmsg 2 +and +.Xr recvmsg 2 +on a communications channel or a slow device (such as a terminal, +but not a regular file) +and during a +.Xr wait 2 +or +.Xr ioctl 2 . +However, calls that have already committed are not restarted, +but instead return a partial success (for example, a short read count). +.Pp +After a +.Xr fork 2 +or +.Xr vfork 2 +all signals, the signal mask, the signal stack, +and the restart/interrupt flags are inherited by the child. +.Pp +.Xr Execve 2 +reinstates the default +action for all signals which were caught and +resets all signals to be caught on the user stack. +Ignored signals remain ignored; +the signal mask remains the same; +signals that restart pending system calls continue to do so. +.Pp +The following is a list of all signals +with names as in the include file +.Aq Pa signal.h : +.Bl -column SIGVTALARMXX "create core imagexxx" +.It Sy " NAME " " Default Action " " Description" +.It Dv SIGHUP No " terminate process" " terminal line hangup" +.It Dv SIGINT No " terminate process" " interrupt program" +.It Dv SIGQUIT No " create core image" " quit program" +.It Dv SIGILL No " create core image" " illegal instruction" +.It Dv SIGTRAP No " create core image" " trace trap" +.It Dv SIGABRT No " create core image" Xr abort 3 +call (formerly +.Dv SIGIOT ) +.It Dv SIGEMT No " create core image" " emulate instruction executed" +.It Dv SIGFPE No " create core image" " floating-point exception" +.It Dv SIGKILL No " terminate process" " kill program" +.It Dv SIGBUS No " create core image" " bus error" +.It Dv SIGSEGV No " create core image" " segmentation violation" +.It Dv SIGSYS No " create core image" " non-existent system call invoked" +.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" +.It Dv SIGALRM No " terminate process" " real-time timer expired" +.It Dv SIGTERM No " terminate process" " software termination signal" +.It Dv SIGURG No " discard signal" " urgent condition present on socket" +.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" +.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" +.It Dv SIGCONT No " discard signal" " continue after stop" +.It Dv SIGCHLD No " discard signal" " child status has changed" +.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" +.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" +.It Dv SIGIO No " discard signal" Tn " I/O" +is possible on a descriptor (see +.Xr fcntl 2 ) +.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" +.Xr setrlimit 2 ) +.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" +.Xr setrlimit 2 ) +.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" +.Xr setitimer 2 ) +.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" +.Xr setitimer 2 ) +.It Dv SIGWINCH No " discard signal" " Window size change" +.It Dv SIGINFO No " discard signal" " status request from keyboard" +.It Dv SIGUSR1 No " terminate process" " User defined signal 1" +.It Dv SIGUSR2 No " terminate process" " User defined signal 2" +.El +.Sh NOTE +The +.Fa sa_mask +field specified in +.Fa act +is not allowed to block +.Dv SIGKILL +or +.Dv SIGSTOP . +Any attempt to do so will be silently ignored. +.Pp +The following functions are either reentrant or not interruptible +by signals and are async-signal safe. Therefore applications may +invoke them, without restriction, from signal-catching functions: +.Pp +Base Interfaces: +.Pp +.Fn _exit , +.Fn access , +.Fn alarm , +.Fn cfgetispeed , +.Fn cfgetospeed , +.Fn cfsetispeed , +.Fn cfsetospeed , +.Fn chdir , +.Fn chmod , +.Fn chown , +.Fn close , +.Fn creat , +.Fn dup , +.Fn dup2 , +.Fn execle , +.Fn execve , +.Fn fcntl , +.Fn fork , +.Fn fpathconf , +.Fn fstat , +.Fn fsync , +.Fn getegid , +.Fn geteuid , +.Fn getgid , +.Fn getgroups , +.Fn getpgrp , +.Fn getpid , +.Fn getppid , +.Fn getuid , +.Fn kill , +.Fn link , +.Fn lseek , +.Fn mkdir , +.Fn mkfifo , +.Fn open , +.Fn pathconf , +.Fn pause , +.Fn pipe , +.Fn raise , +.Fn read , +.Fn rename , +.Fn rmdir , +.Fn setgid , +.Fn setpgid , +.Fn setsid , +.Fn setuid , +.Fn sigaction , +.Fn sigaddset , +.Fn sigdelset , +.Fn sigemptyset , +.Fn sigfillset , +.Fn sigismember , +.Fn signal , +.Fn sigpending , +.Fn sigprocmask , +.Fn sigsuspend , +.Fn sleep , +.Fn stat , +.Fn sysconf , +.Fn tcdrain , +.Fn tcflow , +.Fn tcflush , +.Fn tcgetattr , +.Fn tcgetpgrp , +.Fn tcsendbreak , +.Fn tcsetattr , +.Fn tcsetpgrp , +.Fn time , +.Fn times , +.Fn umask , +.Fn uname , +.Fn unlink , +.Fn utime , +.Fn wait , +.Fn waitpid , +.Fn write . +.Pp +Realtime Interfaces: +.Pp +.Fn aio_error , +.Fn clock_gettime , +.Fn sigpause , +.Fn timer_getoverrun , +.Fn aio_return , +.Fn fdatasync , +.Fn sigqueue , +.Fn timer_gettime , +.Fn aio_suspend , +.Fn sem_post , +.Fn sigset , +.Fn timer_settime . +.Pp +All functions not in the above lists are considered to be unsafe +with respect to signals. That is to say, the behaviour of such +functions when called from a signal handler is undefined. +.Sh RETURN VALUES +A 0 value indicated that the call succeeded. A \-1 return value +indicates an error occurred and +.Va errno +is set to indicated the reason. +.Sh EXAMPLES +There are three possible prototypes the handler may match: +.Bl -tag -offset indent -width short +.It ANSI C: +.Fd +void handler(int); +.It Traditional BSD style: +.Fd +void handler(int, int code, struct sigcontext *scp); +.It POSIX SA_SIGINFO: +.Fd +void handler(int, siginfo_t *info, void *context); +.El +.Pp +The handler function should match the SA_SIGINFO prototype if the +SA_SIGINFO bit is set in flags. +It then should be pointed to by the +.Dv sa_siginfo +member of +.Dv struct sigaction . +Note that you should not assign SIG_DFL or SIG_IGN this way. +.Pp +If the SA_SIGINFO flag is not set, the handler function should match +either the ANSI C or traditional BSD prototype and be pointed to by +the +.Dv sa_handler +member of +.Dv struct sigaction . +In pratice, +.Fx +always sends the three arguments of the latter and since the ANSI C +prototype is a subset, both will work. +The +.Dv sa_handler +member declaration in +.Fx +include files is that of ANSI C (as required by POSIX), +so a function pointer of a BSD-style function needs to be casted to +compile without warning. +The traditional BSD style is not portable and since its capabilities +are a full subset of a SA_SIGINFO handler, +its use is deprecated. +.Pp +The +.Fa sig +argument is the signal number, one of the +.Dv SIG... +values from <signal.h>. +.Pp +The +.Fa code +argument of the BSD-style handler and the +.Dv si_code +member of the +.Dv info +argument to a SA_SIGINFO handler contain a numeric code explaning the +cause of the signal, usually one of the +.Dv SI_... +values from +<sys/signal.h> or codes specific to a signal, i.e. one of the +.Dv FPE_... +values for SIGFPE. +.Pp +The +.Fa scp +argument to a BSD-style handler points to an instance of struct +sigcontext. +.Pp +The +.Fa context +argument to a POSIX SA_SIGINFO handler points to an instance of +mcontext_t. +.Sh ERRORS +.Fn Sigaction +will fail and no new signal handler will be installed if one +of the following occurs: +.Bl -tag -width Er +.It Bq Er EFAULT +Either +.Fa act +or +.Fa oact +points to memory that is not a valid part of the process +address space. +.It Bq Er EINVAL +.Fa Sig +is not a valid signal number. +.It Bq Er EINVAL +An attempt is made to ignore or supply a handler for +.Dv SIGKILL +or +.Dv SIGSTOP . +.El +.Sh STANDARDS +The +.Fn sigaction +function call is expected to conform to +.St -p1003.1-90 . +The +.Dv SA_ONSTACK +and +.Dv SA_RESTART +flags are Berkeley extensions, +as are the signals, +.Dv SIGTRAP , +.Dv SIGEMT , +.Dv SIGBUS , +.Dv SIGSYS , +.Dv SIGURG , +.Dv SIGIO , +.Dv SIGXCPU , +.Dv SIGXFSZ , +.Dv SIGVTALRM , +.Dv SIGPROF , +.Dv SIGWINCH , +and +.Dv SIGINFO . +Those signals are available on most +.Tn BSD Ns \-derived +systems. +The +.Dv SA_NODEFER +and +.Dv SA_RESETHAND +flags are intended for backwards compatibility with other operating +systems. The +.Dv SA_NOCLDSTOP , +and +.Dv SA_NOCLDWAIT +.\" and +.\" SA_SIGINFO +flags are featuring options commonly found in other operating systems. +.Sh SEE ALSO +.Xr kill 1 , +.Xr kill 2 , +.Xr ptrace 2 , +.Xr sigaltstack 2 , +.Xr sigblock 2 , +.Xr sigpause 2 , +.Xr sigpending 2 , +.Xr sigprocmask 2 , +.Xr sigsetmask 2 , +.Xr sigsuspend 2 , +.Xr sigvec 2 , +.Xr wait 2 , +.Xr fpsetmask 3 , +.Xr setjmp 3 , +.Xr siginterrupt 3 , +.Xr sigsetops 3 , +.Xr tty 4 diff --git a/lib/libc/sys/sigaltstack.2 b/lib/libc/sys/sigaltstack.2 new file mode 100644 index 0000000..d16612c --- /dev/null +++ b/lib/libc/sys/sigaltstack.2 @@ -0,0 +1,165 @@ +.\" Copyright (c) 1983, 1991, 1992, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sigaltstack.2 8.2 (Berkeley) 5/1/95 +.\" $FreeBSD$ +.\" +.Dd May 1, 1995 +.Dt SIGALTSTACK 2 +.Os BSD 4.2 +.Sh NAME +.Nm sigaltstack +.Nd set and/or get signal stack context +.Sh SYNOPSIS +.Fd #include <signal.h> +.Bd -literal +struct sigaltstack { + char *ss_sp; + size_t ss_size; + int ss_flags; +}; +.Ed +.Ft int +.Fn sigaltstack "const struct sigaltstack *ss" "struct sigaltstack *oss" +.Sh DESCRIPTION +.Fn Sigaltstack +allows users to define an alternate stack on which signals +are to be processed. +If +.Fa ss +is non-zero, +it specifies a pointer to and the size of a +.Em "signal stack" +on which to deliver signals, +and tells the system if the process is currently executing +on that stack. +When a signal's action indicates its handler +should execute on the signal stack (specified with a +.Xr sigaction 2 +call), the system checks to see +if the process is currently executing on that stack. +If the process is not currently executing on the signal stack, +the system arranges a switch to the signal stack for the +duration of the signal handler's execution. +.Pp +If +.Dv SS_DISABLE +is set in +.Fa ss_flags , +.Fa ss_sp +and +.Fa ss_size +are ignored and the signal stack will be disabled. +Trying to disable an active stack will cause +.Fn sigaltstack +to return -1 with +.Va errno +set to +.Dv EINVAL . +A disabled stack will cause all signals to be +taken on the regular user stack. +If the stack is later re-enabled then all signals that were specified +to be processed on an alternate stack will resume doing so. +.Pp +If +.Fa oss +is non-zero, the current signal stack state is returned. +The +.Fa ss_flags +field will contain the value +.Dv SS_ONSTACK +if the process is currently on a signal stack and +.Dv SS_DISABLE +if the signal stack is currently disabled. +.Sh NOTES +The value +.Dv SIGSTKSZ +is defined to be the number of bytes/chars that would be used to cover +the usual case when allocating an alternate stack area. +The following code fragment is typically used to allocate an alternate stack. +.Bd -literal -offset indent +if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL) + /* error return */ +sigstk.ss_size = SIGSTKSZ; +sigstk.ss_flags = 0; +if (sigaltstack(&sigstk,0) < 0) + perror("sigaltstack"); +.Ed +An alternative approach is provided for programs with signal handlers +that require a specific amount of stack space other than the default size. +The value +.Dv MINSIGSTKSZ +is defined to be the number of bytes/chars that is required by +the operating system to implement the alternate stack feature. +In computing an alternate stack size, +programs should add +.Dv MINSIGSTKSZ +to their stack requirements to allow for the operating system overhead. +.Pp +Signal stacks are automatically adjusted for the direction of stack +growth and alignment requirements. +Signal stacks may or may not be protected by the hardware and +are not ``grown'' automatically as is done for the normal stack. +If the stack overflows and this space is not protected +unpredictable results may occur. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Sigaltstack +will fail and the signal stack context will remain unchanged +if one of the following occurs. +.Bl -tag -width [ENOMEM] +.It Bq Er EFAULT +Either +.Fa ss +or +.Fa oss +points to memory that is not a valid part of the process +address space. +.It Bq Er EINVAL +An attempt was made to disable an active stack. +.It Bq Er ENOMEM +Size of alternate stack area is less than or equal to +.Dv MINSIGSTKSZ . +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr setjmp 3 +.Sh HISTORY +The predecessor to +.Fn sigaltstack , +the +.Fn sigstack +system call, appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/sigpending.2 b/lib/libc/sys/sigpending.2 new file mode 100644 index 0000000..481bd19 --- /dev/null +++ b/lib/libc/sys/sigpending.2 @@ -0,0 +1,73 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Berkeley Software Design, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sigpending.2 8.3 (Berkeley) 1/12/94 +.\" $FreeBSD$ +.\" +.Dd January 12, 1994 +.Dt SIGPENDING 2 +.Os +.Sh NAME +.Nm sigpending +.Nd get pending signals +.Sh SYNOPSIS +.Fd #include <signal.h> +.Ft int +.Fn sigpending "sigset_t *set" +.Sh DESCRIPTION +The +.Fn sigpending +function returns a mask of the signals pending for delivery +to the calling process in the location indicated by +.Fa set . +Signals may be pending because they are currently masked, +or transiently before delivery (although the latter case is not +normally detectable). +.Sh RETURN VALUES +A 0 value indicated that the call succeeded. A \-1 return value +indicates an error occurred and +.Va errno +is set to indicated the reason. +.Sh ERRORS +The +.Fn sigpending +function does not currently detect any errors. +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigprocmask 2 +.Sh STANDARDS +The +.Fn sigpending +function call is expected to conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/sigprocmask.2 b/lib/libc/sys/sigprocmask.2 new file mode 100644 index 0000000..8f58f96 --- /dev/null +++ b/lib/libc/sys/sigprocmask.2 @@ -0,0 +1,121 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sigprocmask.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SIGPROCMASK 2 +.Os +.Sh NAME +.Nm sigprocmask +.Nd manipulate current signal mask +.Sh SYNOPSIS +.Fd #include <signal.h> +.Ft int +.Fn sigprocmask "int how" "const sigset_t *set" "sigset_t *oset" +.Sh DESCRIPTION +The +.Fn sigprocmask +function examines and/or changes the current signal mask (those signals +that are blocked from delivery). +Signals are blocked if they are members of the current signal mask set. +.Pp +If +.Fa set +is not null, the action of +.Fn sigprocmask +depends on the value of the parameter +.Fa how . +The signal mask is changed as a function of the specified +.Fa set +and the current mask. +The function is specified by +.Fa how +using one of the following values from +.Aq Pa signal.h : +.Bl -tag -width SIG_UNBLOCK +.It Dv SIG_BLOCK +The new mask is the union of the current mask and the specified +.Fa set . +.It Dv SIG_UNBLOCK +The new mask is the intersection of the current mask +and the complement of the specified +.Fa set . +.It Dv SIG_SETMASK +The current mask is replaced by the specified +.Fa set . +.El +.Pp +If +.Fa oset +is not null, it is set to +the previous value of the signal mask. +When +.Fa set +is null, +the value of +.Ar how +is insignificant and the mask remains unset +providing a way to examine the signal mask without modification. +.Pp +The system +quietly disallows +.Dv SIGKILL +or +.Dv SIGSTOP +to be blocked. +.Sh RETURN VALUES +A 0 value indicated that the call succeeded. A -1 return value +indicates an error occurred and +.Va errno +is set to indicated the reason. +.Sh ERRORS +The +.Fn sigprocmask +call will fail and the signal mask will be unchanged if one +of the following occurs: +.Bl -tag -width Bq Er EINVAL +.It Bq Er EINVAL +.Fa how +has a value other than those listed here. +.Sh SEE ALSO +.Xr kill 2 , +.Xr sigaction 2 , +.Xr sigsuspend 2 , +.Xr fpsetmask 3 , +.Xr sigsetops 3 +.Sh STANDARDS +The +.Fn sigprocmask +function call is expected to +conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/sigreturn.2 b/lib/libc/sys/sigreturn.2 new file mode 100644 index 0000000..f00e464 --- /dev/null +++ b/lib/libc/sys/sigreturn.2 @@ -0,0 +1,113 @@ +.\" Copyright (c) 1985, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sigreturn.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SIGRETURN 2 +.Os BSD 4.3 +.Sh NAME +.Nm sigreturn +.Nd return from signal +.Sh SYNOPSIS +.Fd #include <signal.h> +.Pp +.Bd -literal +struct sigcontext { + int sc_onstack; /* sigstack state to restore */ + int sc_mask; /* signal mask to restore */ + int sc_esp; /* machine state */ + int sc_ebp; + int sc_isp; + int sc_eip; + int sc_efl; + int sc_es; + int sc_ds; + int sc_cs; + int sc_ss; + int sc_edi; + int sc_esi; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; +# define sc_sp sc_esp +# define sc_fp sc_ebp +# define sc_pc sc_eip +# define sc_ps sc_efl +}; +.Ed +.Ft int +.Fn sigreturn "struct sigcontext *scp" +.Sh DESCRIPTION +.Fn Sigreturn +allows users to atomically unmask, switch stacks, +and return from a signal context. +The processes signal mask and stack status are +restored from the context. +The system call does not return; +the users stack pointer, frame pointer, argument pointer, +and processor status longword are restored from the context. +Execution resumes at the specified pc. +This system call is used by the trampoline code and +.Xr longjmp 3 +when returning from a signal to the previously executing program. +.Sh NOTES +This system call is not available in 4.2 +.Tn BSD +hence it should not be used if backward compatibility is needed. +.Sh RETURN VALUES +If successful, the system call does not return. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Sigreturn +will fail and the process context will remain unchanged +if one of the following occurs. +.Bl -tag -width [EINVAL] +.It Bq Er EFAULT +.Fa Scp +points to memory that is not a valid part of the process +address space. +.It Bq Er EINVAL +The process status longword is invalid or would improperly +raise the privilege level of the process. +.El +.Sh SEE ALSO +.Xr sigvec 2 , +.Xr setjmp 3 +.Sh HISTORY +The +.Fn sigreturn +function call appeared in +.Bx 4.3 . diff --git a/lib/libc/sys/sigstack.2 b/lib/libc/sys/sigstack.2 new file mode 100644 index 0000000..404fc3e --- /dev/null +++ b/lib/libc/sys/sigstack.2 @@ -0,0 +1,52 @@ +.\" Copyright (c) 1983, 1992, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sigstack.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SIGSTACK 2 +.Os BSD 4.2 +.Sh NAME +.Nm sigstack +.Nd set and/or get signal stack context +.Sh DESCRIPTION +The +.Fn sigstack +function has been deprecated in favor of the interface described in +.Xr sigaltstack 2 . +.Sh SEE ALSO +.Xr sigaltstack 2 +.Sh HISTORY +The +.Fn sigstack +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/sigsuspend.2 b/lib/libc/sys/sigsuspend.2 new file mode 100644 index 0000000..c3e36ad --- /dev/null +++ b/lib/libc/sys/sigsuspend.2 @@ -0,0 +1,80 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sigsuspend.2 8.2 (Berkeley) 5/16/95 +.\" $FreeBSD$ +.\" +.Dd May 16, 1995 +.Dt SIGSUSPEND 2 +.Os +.Sh NAME +.Nm sigsuspend +.Nd atomically release blocked signals and wait for interrupt +.Sh SYNOPSIS +.Fd #include <signal.h> +.Ft int +.Fn sigsuspend "const sigset_t *sigmask" +.Sh DESCRIPTION +.Fn Sigsuspend +temporarily changes the blocked signal mask to the set to which +.Fa sigmask +points, +and then waits for a signal to arrive; +on return the previous set of masked signals is restored. +The signal mask set +is usually empty to indicate that all +signals are to be unblocked for the duration of the call. +.Pp +In normal usage, a signal is blocked using +.Xr sigprocmask 2 +to begin a critical section, variables modified on the occurrence +of the signal are examined to determine that there is no work +to be done, and the process pauses awaiting work by using +.Fn sigsuspend +with the previous mask returned by +.Xr sigprocmask . +.Sh RETURN VALUES +The +.Fn sigsuspend +function +always terminates by being interrupted, returning -1 with +.Va errno +set to +.Dv EINTR . +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigprocmask 2 , +.Xr sigsetops 3 +.Sh STANDARDS +The +.Fn sigsupend +function call is expected to conform to +.St -p1003.1-90 . diff --git a/lib/libc/sys/socket.2 b/lib/libc/sys/socket.2 new file mode 100644 index 0000000..7fbe976 --- /dev/null +++ b/lib/libc/sys/socket.2 @@ -0,0 +1,300 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)socket.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd November 24, 1997 +.Dt SOCKET 2 +.Os BSD 4.2 +.Sh NAME +.Nm socket +.Nd create an endpoint for communication +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn socket "int domain" "int type" "int protocol" +.Sh DESCRIPTION +.Fn Socket +creates an endpoint for communication and returns a descriptor. +.Pp +The +.Fa domain +parameter specifies a communications domain within which +communication will take place; this selects the protocol family +which should be used. +These families are defined in the include file +.Ao Pa sys/socket.h Ac . +The currently understood formats are: +.Pp +.Bd -literal -offset indent -compact +PF_LOCAL Host-internal protocols, formerly called PF_UNIX, +PF_UNIX Host-internal protocols, depreciated, use PF_LOCAL, +PF_INET Internet version 4 protocols, +PF_IMPLINK ARPAnet IMP addresses, +PF_PUP PUP protocols, like BSP, +PF_CHAOS MIT CHAOS protocols, +PF_NS Xerox Network Systems protocols, +PF_ISO ISO protocols, +PF_OSI Open Systems Interconnection protocols, +PF_ECMA European Computer Manufacturers, +PF_DATAKIT Datakit protocols, +PF_CCITT ITU-T protocols, like X.25, +PF_SNA IBM SNA, +PF_DECnet DECnet, +PF_DLI DEC Direct Data Link Interface protocol, +PF_LAT LAT protocol, +PF_HYLINK NSC Hyperchannel, +PF_APPLETALK AppleTalk protocols, +PF_ROUTE Internal Routing protocol, +PF_LINK Link layer interface, +PF_XTP eXpress Transfer Protocol, +PF_COIP Connection-Oriented IP, aka ST II, +PF_CNT Computer Network Technology, +PF_SIP Simple Internet Protocol, +PF_IPX Novell Intenet Packet eXchange protocol, +PF_RTIP Help Identify RTIP packets, +PF_PIP Help Identify PIP packets, +PF_ISDN Integrated Services Digital Network, +PF_KEY Internal key-management function, +PF_INET6 Internet version 6 protocols, +PF_NATM Native ATM access, +PF_ATM ATM, +PF_NETGRAPH Netgraph sockets +.Ed +.Pp +The socket has the indicated +.Fa type , +which specifies the semantics of communication. Currently +defined types are: +.Pp +.Bd -literal -offset indent -compact +SOCK_STREAM Stream socket, +SOCK_DGRAM Datagram socket, +SOCK_RAW Raw-protocol interface, +SOCK_RDM Sequenced packet stream, +SOCK_SEQPACKET Reliably-delivered packet +.Ed +.Pp +A +.Dv SOCK_STREAM +type provides sequenced, reliable, +two-way connection based byte streams. +An out-of-band data transmission mechanism may be supported. +A +.Dv SOCK_DGRAM +socket supports +datagrams (connectionless, unreliable messages of +a fixed (typically small) maximum length). +A +.Dv SOCK_SEQPACKET +socket may provide a sequenced, reliable, +two-way connection-based data transmission path for datagrams +of fixed maximum length; a consumer may be required to read +an entire packet with each read system call. +This facility is protocol specific, and presently implemented +only for +.Dv PF_NS . +.Dv SOCK_RAW +sockets provide access to internal network protocols and interfaces. +The types +.Dv SOCK_RAW , +which is available only to the super-user, and +.Dv SOCK_RDM , +which is planned, +but not yet implemented, are not described here. +.Pp +The +.Fa protocol +specifies a particular protocol to be used with the socket. +Normally only a single protocol exists to support a particular +socket type within a given protocol family. However, it is possible +that many protocols may exist, in which case a particular protocol +must be specified in this manner. The protocol number to use is +particular to the \*(lqcommunication domain\*(rq in which communication +is to take place; see +.Xr protocols 5 . +.Pp +Sockets of type +.Dv SOCK_STREAM +are full-duplex byte streams, similar +to pipes. A stream socket must be in a +.Em connected +state before any data may be sent or received +on it. A connection to another socket is created with a +.Xr connect 2 +call. +Once connected, data may be transferred using +.Xr read 2 +and +.Xr write 2 +calls or some variant of the +.Xr send 2 +and +.Xr recv 2 +calls. +(Some protocol families, such as the Internet family, +support the notion of an +.Dq implied connect, +which permits data to be sent piggybacked onto a connect operation by +using the +.Xr sendto 2 +call.) +When a session has been completed a +.Xr close 2 +may be performed. +Out-of-band data may also be transmitted as described in +.Xr send 2 +and received as described in +.Xr recv 2 . +.Pp +The communications protocols used to implement a +.Dv SOCK_STREAM +insure that data +is not lost or duplicated. If a piece of data for which the +peer protocol has buffer space cannot be successfully transmitted +within a reasonable length of time, then +the connection is considered broken and calls +will indicate an error with +-1 returns and with +.Dv ETIMEDOUT +as the specific code +in the global variable +.Va errno . +The protocols optionally keep sockets +.Dq warm +by forcing transmissions +roughly every minute in the absence of other activity. +An error is then indicated if no response can be +elicited on an otherwise +idle connection for a extended period (e.g. 5 minutes). +A +.Dv SIGPIPE +signal is raised if a process sends +on a broken stream; this causes naive processes, +which do not handle the signal, to exit. +.Pp +.Dv SOCK_SEQPACKET +sockets employ the same system calls +as +.Dv SOCK_STREAM +sockets. The only difference +is that +.Xr read 2 +calls will return only the amount of data requested, +and any remaining in the arriving packet will be discarded. +.Pp +.Dv SOCK_DGRAM +and +.Dv SOCK_RAW +sockets allow sending of datagrams to correspondents +named in +.Xr send 2 +calls. Datagrams are generally received with +.Xr recvfrom 2 , +which returns the next datagram with its return address. +.Pp +An +.Xr fcntl 2 +call can be used to specify a process group to receive +a +.Dv SIGURG +signal when the out-of-band data arrives. +It may also enable non-blocking I/O +and asynchronous notification of I/O events +via +.Dv SIGIO . +.Pp +The operation of sockets is controlled by socket level +.Em options . +These options are defined in the file +.Ao Pa sys/socket.h Ac . +.Xr Setsockopt 2 +and +.Xr getsockopt 2 +are used to set and get options, respectively. +.Sh RETURN VALUES +A -1 is returned if an error occurs, otherwise the return +value is a descriptor referencing the socket. +.Sh ERRORS +The +.Fn socket +call fails if: +.Bl -tag -width EPROTONOPSUPPORTA +.It Bq Er EPROTONOSUPPORT +The protocol type or the specified protocol is not supported +within this domain. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er EACCES +Permission to create a socket of the specified type and/or protocol +is denied. +.It Bq Er ENOBUFS +Insufficient buffer space is available. +The socket cannot be created until sufficient resources are freed. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr bind 2 , +.Xr connect 2 , +.Xr getpeername 2 , +.Xr getsockname 2 , +.Xr getsockopt 2 , +.Xr ioctl 2 , +.Xr listen 2 , +.Xr read 2 , +.Xr recv 2 , +.Xr select 2 , +.Xr send 2 , +.Xr shutdown 2 , +.Xr socketpair 2 , +.Xr write 2 , +.Xr getprotoent 3 , +.Xr netgraph 4 , +.Xr protocols 5 +.Rs +.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" +.%B PS1 +.%N 7 +.Re +.Rs +.%T "BSD Interprocess Communication Tutorial" +.%B PS1 +.%N 8 +.Re +.Sh HISTORY +The +.Fn socket +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/socketpair.2 b/lib/libc/sys/socketpair.2 new file mode 100644 index 0000000..bf4e842 --- /dev/null +++ b/lib/libc/sys/socketpair.2 @@ -0,0 +1,92 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)socketpair.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SOCKETPAIR 2 +.Os BSD 4.2 +.Sh NAME +.Nm socketpair +.Nd create a pair of connected sockets +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Ft int +.Fn socketpair "int d" "int type" "int protocol" "int *sv" +.Sh DESCRIPTION +The +.Fn socketpair +call creates an unnamed pair of connected sockets in +the specified domain +.Fa d , +of the specified +.Fa type , +and using the optionally specified +.Fa protocol . +The descriptors used in referencing the new sockets +are returned in +.Fa sv Ns [0] +and +.Fa sv Ns [1] . +The two sockets are indistinguishable. +.Sh RETURN VALUES +A 0 is returned if the call succeeds, -1 if it fails. +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width EPROTONOSUPPORTA +.It Bq Er EMFILE +Too many descriptors are in use by this process. +.It Bq Er EAFNOSUPPORT +The specified address family is not supported on this machine. +.It Bq Er EPROTONOSUPPORT +The specified protocol is not supported on this machine. +.It Bq Er EOPNOSUPPORT +The specified protocol does not support creation of socket pairs. +.It Bq Er EFAULT +The address +.Fa sv +does not specify a valid part of the +process address space. +.Sh SEE ALSO +.Xr pipe 2 , +.Xr read 2 , +.Xr write 2 +.Sh BUGS +This call is currently implemented only for the +.Tn UNIX +domain. +.Sh HISTORY +The +.Fn socketpair +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2 new file mode 100644 index 0000000..5617c36 --- /dev/null +++ b/lib/libc/sys/stat.2 @@ -0,0 +1,284 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)stat.2 8.4 (Berkeley) 5/1/95 +.\" $FreeBSD$ +.\" +.Dd May 1, 1995 +.Dt STAT 2 +.Os BSD 4 +.Sh NAME +.Nm stat , +.Nm lstat , +.Nm fstat +.Nd get file status +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/stat.h> +.Ft int +.Fn stat "const char *path" "struct stat *sb" +.Ft int +.Fn lstat "const char *path" "struct stat *sb" +.Ft int +.Fn fstat "int fd" "struct stat *sb" +.Sh DESCRIPTION +The +.Fn stat +function obtains information about the file pointed to by +.Fa path . +Read, write or execute +permission of the named file is not required, but all directories +listed in the path name leading to the file must be searchable. +.Pp +.Fn Lstat +is like +.Fn stat +except in the case where the named file is a symbolic link, +in which case +.Fn lstat +returns information about the link, +while +.Fn stat +returns information about the file the link references. +.Pp +The +.Fn fstat +obtains the same information about an open file +known by the file descriptor +.Fa fd . +.Pp +The +.Fa sb +argument is a pointer to a +.Fn stat +structure +as defined by +.Aq Pa sys/stat.h +(shown below) +and into which information is placed concerning the file. +.Bd -literal +struct stat { + dev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + mode_t st_mode; /* inode protection mode */ + nlink_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + dev_t st_rdev; /* device type */ +#ifndef _POSIX_SOURCE + struct timespec st_atimespec; /* time of last access */ + struct timespec st_mtimespec; /* time of last data modification */ + struct timespec st_ctimespec; /* time of last file status change */ +#else + time_t st_atime; /* time of last access */ + long st_atimensec; /* nsec of last access */ + time_t st_mtime; /* time of last data modification */ + long st_mtimensec; /* nsec of last data modification */ + time_t st_ctime; /* time of last file status change */ + long st_ctimensec; /* nsec of last file status change */ +#endif + off_t st_size; /* file size, in bytes */ + int64_t st_blocks; /* blocks allocated for file */ + u_int32_t st_blksize; /* optimal blocksize for I/O */ + u_int32_t st_flags; /* user defined flags for file */ + u_int32_t st_gen; /* file generation number */ +}; +.Ed +.Pp +The time-related fields of +.Fa struct stat +are as follows: +.Bl -tag -width XXXst_mtime +.It st_atime +Time when file data last accessed. +Changed by the +.Xr mknod 2 , +.Xr utimes 2 +and +.Xr read 2 +system calls. +.It st_mtime +Time when file data last modified. +Changed by the +.Xr mknod 2 , +.Xr utimes 2 +and +.Xr write 2 +system calls. +.It st_ctime +Time when file status was last changed (inode data modification). +Changed by the +.Xr chmod 2 , +.Xr chown 2 , +.Xr link 2 , +.Xr mknod 2 , +.Xr rename 2 , +.Xr unlink 2 , +.Xr utimes 2 +and +.Xr write 2 +system calls. +.El +.Pp +If +.Dv _POSIX_SOURCE +is not defined, the time-related fields are defined as: +.Bd -literal +#ifndef _POSIX_SOURCE +#define st_atime st_atimespec.tv_sec +#define st_mtime st_mtimespec.tv_sec +#define st_ctime st_ctimespec.tv_sec +#endif +.Ed +.Pp +The size-related fields of the +.Fa struct stat +are as follows: +.Bl -tag -width XXXst_blksize +.It st_blksize +The optimal I/O block size for the file. +.It st_blocks +The actual number of blocks allocated for the file in 512-byte units. +As short symbolic links are stored in the inode, this number may +be zero. +.El +.Pp +The status information word +.Fa st_mode +has the following bits: +.Bd -literal +#define S_IFMT 0170000 /* type of file */ +#define S_IFIFO 0010000 /* named pipe (fifo) */ +#define S_IFCHR 0020000 /* character special */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ +#define S_IFWHT 0160000 /* whiteout */ +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#define S_IRUSR 0000400 /* read permission, owner */ +#define S_IWUSR 0000200 /* write permission, owner */ +#define S_IXUSR 0000100 /* execute/search permission, owner */ +.Ed +.Pp +For a list of access modes, see +.Aq Pa sys/stat.h , +.Xr access 2 +and +.Xr chmod 2 . +.Sh RETURN VALUES +Upon successful completion a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh COMPATIBILITY +Previous versions of the system used different types for the +.Li st_dev , +.Li st_uid , +.Li st_gid , +.Li st_rdev , +.Li st_size , +.Li st_blksize +and +.Li st_blocks +fields. +.Sh ERRORS +.Fn Stat +and +.Fn lstat +will fail if: +.Bl -tag -width ENAMETOOLONGAA +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EFAULT +.Fa Sb +or +.Em name +points to an invalid address. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Pp +.Bl -tag -width [EFAULT] +.Fn Fstat +will fail if: +.It Bq Er EBADF +.Fa fd +is not a valid open file descriptor. +.It Bq Er EFAULT +.Fa Sb +points to an invalid address. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr access 2 , +.Xr chmod 2 , +.Xr chown 2 , +.Xr utimes 2 , +.Xr symlink 7 +.Sh BUGS +Applying +.Fn fstat +to a socket (and thus to a pipe) +returns a zeroed buffer, +except for the blocksize field, +and a unique device and inode number. +.Sh STANDARDS +The +.Fn stat +and +.Fn fstat +function calls are expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +A +.Fn stat +and a +.Fn fstat +function call appeared in +.At v7 . +A +.Fn lstat +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/statfs.2 b/lib/libc/sys/statfs.2 new file mode 100644 index 0000000..e1ccb69 --- /dev/null +++ b/lib/libc/sys/statfs.2 @@ -0,0 +1,183 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)statfs.2 8.5 (Berkeley) 5/24/95 +.\" $FreeBSD$ +.\" +.Dd May 24, 1995 +.Dt STATFS 2 +.Os +.Sh NAME +.Nm statfs +.Nd get file system statistics +.Sh SYNOPSIS +.Fd #include <sys/param.h> +.Fd #include <sys/mount.h> +.Ft int +.Fn statfs "const char *path" "struct statfs *buf" +.Ft int +.Fn fstatfs "int fd" "struct statfs *buf" +.Sh DESCRIPTION +.Fn Statfs +returns information about a mounted file system. +.Fa Path +is the path name of any file within the mounted filesystem. +.Fa Buf +is a pointer to a +.Fn statfs +structure defined as follows: +.Bd -literal +typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ + +/* + * file system statistics + */ + +#define MFSNAMELEN 16 /* length of fs type name, including null */ +#define MNAMELEN 90 /* length of buffer for returned name */ + +struct statfs { +long f_spare2; /* placeholder */ +long f_bsize; /* fundamental file system block size */ +long f_iosize; /* optimal transfer block size */ +long f_blocks; /* total data blocks in file system */ +long f_bfree; /* free blocks in fs */ +long f_bavail; /* free blocks avail to non-superuser */ +long f_files; /* total file nodes in file system */ +long f_ffree; /* free file nodes in fs */ +fsid_t f_fsid; /* file system id */ +uid_t f_owner; /* user that mounted the filesystem */ +int f_type; /* type of filesystem (see below) */ +int f_flags; /* copy of mount flags */ +long f_syncwrites; /* count of sync writes since mount */ +long f_asyncwrites; /* count of async writes since mount */ +char f_fstypename[MFSNAMELEN];/* fs type name */ +char f_mntonname[MNAMELEN]; /* mount point */ +char f_mntfromname[MNAMELEN]; /* mounted filesystem */ +}; +.Ed +The flags that may be returned include: +.Bl -tag -width MNT_ASYNCHRONOUS +.It Dv MNT_RDONLY +The filesystem is mounted read-only; +Even the super-user may not write on it. +.It Dv MNT_NOEXEC +Files may not be executed from the filesystem. +.It Dv MNT_NOSUID +Setuid and setgid bits on files are not honored when they are executed. +.It Dv MNT_NODEV +Special files in the filesystem may not be opened. +.It Dv MNT_SYNCHRONOUS +All I/O to the filesystem is done synchronously. +.It Dv MNT_ASYNCHRONOUS +No filesystem I/O is done synchronously. +.It Dv MNT_LOCAL +The filesystem resides locally. +.It Dv MNT_QUOTA +The filesystem has quotas enabled on it. +.It Dv MNT_ROOTFS +Identifies the root filesystem. +.It Dv MNT_EXRDONLY +The filesystem is exported read-only. +.It Dv MNT_EXPORTED +The filesystem is exported for both reading and writing. +.It Dv MNT_DEFEXPORTED +The filesystem is exported for both reading and writing to any Internet host. +.It Dv MNT_EXPORTANON +The filesystem maps all remote accesses to the anonymous user. +.It Dv MNT_EXKERB +The filesystem is exported with Kerberos uid mapping. +.El +.Pp +Fields that are undefined for a particular file system are set to -1. +.Fn Fstatfs +returns the same information about an open file referenced by descriptor +.Fa fd . +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Statfs +fails if one or more of the following are true: +.Bl -tag -width ENAMETOOLONGA +.It Bq Er ENOTDIR +A component of the path prefix of +.Fa Path +is not a directory. +.It Bq Er ENAMETOOLONG +The length of a component of +.Fa path +exceeds 255 characters, +or the length of +.Fa path +exceeds 1023 characters. +.It Bq Er ENOENT +The file referred to by +.Fa path +does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix of +.Fa path . +.It Bq Er ELOOP +Too many symbolic links were encountered in translating +.Fa path . +.It Bq Er EFAULT +.Fa Buf +or +.Fa path +points to an invalid address. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.El +.Pp +.Fn Fstatfs +fails if one or more of the following are true: +.Bl -tag -width ENAMETOOLONGA +.It Bq Er EBADF +.Fa Fd +is not a valid open file descriptor. +.It Bq Er EFAULT +.Fa Buf +points to an invalid address. +.It Bq Er EIO +An +.Tn I/O +error occurred while reading from or writing to the file system. +.El +.Sh HISTORY +The +.Fn statfs +function first appeared in +.Bx 4.4 . diff --git a/lib/libc/sys/swapon.2 b/lib/libc/sys/swapon.2 new file mode 100644 index 0000000..0ab908c --- /dev/null +++ b/lib/libc/sys/swapon.2 @@ -0,0 +1,112 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)swapon.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SWAPON 2 +.Os BSD 4 +.Sh NAME +.Nm swapon +.Nd add a swap device for interleaved paging/swapping +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn swapon "const char *special" +.Sh DESCRIPTION +.Fn Swapon +makes the block device +.Fa special +available to the system for +allocation for paging and swapping. The names of potentially +available devices are known to the system and defined at system +configuration time. The size of the swap area on +.Fa special +is calculated at the time the device is first made available +for swapping. +.Sh RETURN VALUES +If an error has occurred, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Swapon +succeeds unless: +.Bl -tag -width ENAMETOOLONG +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named device does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The caller is not the super-user. +.It Bq Er ENOTBLK +.Fa Special +is not a block device. +.It Bq Er EBUSY +The device specified by +.Fa special +has already +been made available for swapping +.It Bq Er EINVAL +The device configured by +.Fa special +was not +configured into the system as a swap device. +.It Bq Er ENXIO +The major device number of +.Fa special +is out of range (this indicates no device driver exists +for the associated hardware). +.It Bq Er EIO +An I/O error occurred while opening the swap device. +.It Bq Er EFAULT +.Fa Special +points outside the process's allocated address space. +.Sh SEE ALSO +.Xr config 8 , +.Xr swapon 8 +.Sh BUGS +There is no way to stop swapping on a disk so that the pack may be +dismounted. +.Pp +This call will be upgraded in future versions of the system. +.Sh HISTORY +The +.Fn swapon +function call appeared in +.Bx 4.0 . diff --git a/lib/libc/sys/symlink.2 b/lib/libc/sys/symlink.2 new file mode 100644 index 0000000..f88a309 --- /dev/null +++ b/lib/libc/sys/symlink.2 @@ -0,0 +1,137 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)symlink.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SYMLINK 2 +.Os BSD 4.2 +.Sh NAME +.Nm symlink +.Nd make symbolic link to a file +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn symlink "const char *name1" "const char *name2" +.Sh DESCRIPTION +A symbolic link +.Fa name2 +is created to +.Fa name1 +.Pf ( Fa name2 +is the name of the +file created, +.Fa name1 +is the string +used in creating the symbolic link). +Either name may be an arbitrary path name; the files need not +be on the same file system. +.Sh RETURN VALUES +Upon successful completion, a zero value is returned. +If an error occurs, the error code is stored in +.Va errno +and a -1 value is returned. +.Sh ERRORS +The symbolic link succeeds unless: +.Bl -tag -width ENAMETOO +.It Bq Er ENOTDIR +A component of the +.Fa name2 +prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of either pathname exceeded 255 characters, +or the entire length of either path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +A component of the +.Fa name2 +path prefix denies search permission. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EEXIST +.Fa Name2 +already exists. +.It Bq Er EIO +An I/O error occurred while making the directory entry for +.Fa name2 , +or allocating the inode for +.Fa name2 , +or writing out the link contents of +.Fa name2 . +.It Bq Er EROFS +The file +.Fa name2 +would reside on a read-only file system. +.It Bq Er ENOSPC +The directory in which the entry for the new symbolic link is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.It Bq Er ENOSPC +The new symbolic link cannot be created because +there is no space left on the file +system that will contain the symbolic link. +.It Bq Er ENOSPC +There are no free inodes on the file system on which the +symbolic link is being created. +.It Bq Er EDQUOT +The directory in which the entry for the new symbolic link +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EDQUOT +The new symbolic link cannot be created because the user's +quota of disk blocks on the file system that will +contain the symbolic link has been exhausted. +.It Bq Er EDQUOT +The user's quota of inodes on the file system on +which the symbolic link is being created has been exhausted. +.It Bq Er EIO +An I/O error occurred while making the directory entry or allocating the inode. +.It Bq Er EFAULT +.Fa Name1 +or +.Fa name2 +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr ln 1 , +.Xr link 2 , +.Xr lstat 2 , +.Xr readlink 2 , +.Xr unlink 2 , +.Xr symlink 7 +.Sh HISTORY +The +.Fn symlink +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/sync.2 b/lib/libc/sys/sync.2 new file mode 100644 index 0000000..a989e8d5 --- /dev/null +++ b/lib/libc/sys/sync.2 @@ -0,0 +1,75 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sync.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt SYNC 2 +.Os BSD 4 +.Sh NAME +.Nm sync +.Nd "synchronize disk block in-core status with that on disk" +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft void +.Fn sync void +.Sh DESCRIPTION +The +.Fn sync +function forces a write of dirty (modified) buffers +in the block buffer cache out +to disk. The kernel keeps this information in core to reduce +the number of disk I/O transfers required by the system. +As information in the cache is lost after a system crash a +.Fn sync +call is issued +frequently +by the user process +.Xr update 4 +(about every 30 seconds). +.Pp +The function +.Xr fsync 2 +may be used to synchronize individual file descriptor +attributes. +.Sh SEE ALSO +.Xr fsync 2 , +.Xr update 4 , +.Xr sync 8 +.Sh BUGS +.Fn Sync +may return before the buffers are completely flushed. +.Sh HISTORY +A +.Fn sync +function call appeared in +.At v6 . diff --git a/lib/libc/sys/sysarch.2 b/lib/libc/sys/sysarch.2 new file mode 100644 index 0000000..c3840e9 --- /dev/null +++ b/lib/libc/sys/sysarch.2 @@ -0,0 +1,79 @@ +.\" $NetBSD: sysarch.2,v 1.6 1998/02/25 21:24:57 perry Exp $ +.\" $FreeBSD$ +.\" +.\" Copyright (c) 1980, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)syscall.2 6.3 (Berkeley) 3/10/91 +.\" +.Dd October 11, 1993 +.Dt SYSARCH 2 +.Os +.Sh NAME +.Nm sysarch +.Nd architecture-dependent system call +.Sh SYNOPSIS +.Fd #include <machine/sysarch.h> +.Ft int +.Fn sysarch "int number" "void *args" +.Sh DESCRIPTION +.Fn Sysarch +performs the architecture-dependent function +specified by +.Fa number +with the arguments specified by the +.Fa args +pointer. +.Fa Args +is a pointer to a structure defining the actual +arguments of the function. +Symbolic constants and argument structures +for the architecture-dependent +functions can be found in the header file +.Ao Pa machine/sysarch.h Ac . +.Pp +The +.Fn sysarch +system call should never be called directly by +user programs. Instead, they should access +its functions using the architecture-dependent +library. +.Pp +.Sh RETURN VALUES +See the manual pages for specific architecture-dependent function calls +for information about their return values. +.Sh SEE ALSO +.Xr i386_get_ioperm 2 , +.Xr i386_get_ldt 2 , +.Xr i386_vm86 2 +.Sh HISTORY +This manual page was taken from +.Nx . diff --git a/lib/libc/sys/syscall.2 b/lib/libc/sys/syscall.2 new file mode 100644 index 0000000..c5192fb --- /dev/null +++ b/lib/libc/sys/syscall.2 @@ -0,0 +1,77 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)syscall.2 8.1 (Berkeley) 6/16/93 +.\" $FreeBSD$ +.\" +.Dd June 16, 1993 +.Dt SYSCALL 2 +.Os BSD 4 +.Sh NAME +.Nm syscall , +.Nm __syscall +.Nd indirect system call +.Sh SYNOPSIS +.Fd #include <sys/syscall.h> +.Fd #include <unistd.h> +.Ft int +.Fn syscall "int number" ... +.Ft off_t +.Fn __syscall "quad_t number" ... +.Sh DESCRIPTION +.Fn Syscall +performs the system call whose assembly language +interface has the specified +.Fa number +with the specified arguments. +Symbolic constants for system calls can be found in the header file +.Ao Pa sys/syscall.h Ac . +The +.Fn __syscall +form should be used when one or more of the parameters is a +64-bit argument to ensure that argument alignment is correct. +This system call is useful for testing new system calls that +do not have entries in the C library. +.Sh RETURN VALUES +The return values are defined by the system call being invoked. +In general, a 0 return value indicates success. +A -1 return value indicates an error, +and an error code is stored in +.Va errno . +.Sh BUGS +There is no way to simulate system calls that have multiple return values +such as +.Xr pipe 2 . +.Sh HISTORY +The +.Fn syscall +function call appeared in +.Bx 4.0 . diff --git a/lib/libc/sys/truncate.2 b/lib/libc/sys/truncate.2 new file mode 100644 index 0000000..ce17ff2 --- /dev/null +++ b/lib/libc/sys/truncate.2 @@ -0,0 +1,129 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)truncate.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt TRUNCATE 2 +.Os BSD 4.2 +.Sh NAME +.Nm truncate , +.Nm ftruncate +.Nd truncate or extend a file to a specified length +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn truncate "const char *path" "off_t length" +.Ft int +.Fn ftruncate "int fd" "off_t length" +.Sh DESCRIPTION +.Fn Truncate +causes the file named by +.Fa path +or referenced by +.Fa fd +to be truncated or extended to +.Fa length +bytes in size. If the file +was larger than this size, the extra data +is lost. +If the file was smaller than this size, +it will be extended as if by writing bytes +with the value zero. +With +.Fn ftruncate , +the file must be open for writing. +.Sh RETURN VALUES +A value of 0 is returned if the call succeeds. If the call +fails a -1 is returned, and the global variable +.Va errno +specifies the error. +.Sh ERRORS +.Fn Truncate +succeeds unless: +.Bl -tag -width [ENOTDIR] +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +The named file is not writable by the user. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EISDIR +The named file is a directory. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er ETXTBSY +The file is a pure procedure (shared text) file that is being executed. +.It Bq Er EIO +An I/O error occurred updating the inode. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.El +.Pp +.Fn Ftruncate +succeeds unless: +.Bl -tag -width [ENOTDIR] +.It Bq Er EBADF +The +.Fa fd +is not a valid descriptor. +.It Bq Er EINVAL +The +.Fa fd +references a socket, not a file. +.It Bq Er EINVAL +The +.Fa fd +is not open for writing. +.El +.Sh SEE ALSO +.Xr open 2 +.Sh BUGS +These calls should be generalized to allow ranges +of bytes in a file to be discarded. +.Pp +Use of +.Fn truncate +to extend a file is not portable. +.Sh HISTORY +The +.Fn truncate +function call appeared in +.Bx 4.2 . diff --git a/lib/libc/sys/truncate.c b/lib/libc/sys/truncate.c new file mode 100644 index 0000000..5bfeeb6 --- /dev/null +++ b/lib/libc/sys/truncate.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)truncate.c 8.1 (Berkeley) 6/17/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> + +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +int +truncate(path, length) + const char *path; + off_t length; +{ + + return(__syscall((quad_t)SYS_truncate, path, 0, length)); +} diff --git a/lib/libc/sys/umask.2 b/lib/libc/sys/umask.2 new file mode 100644 index 0000000..aaeaaa5 --- /dev/null +++ b/lib/libc/sys/umask.2 @@ -0,0 +1,88 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)umask.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt UMASK 2 +.Os BSD 4 +.Sh NAME +.Nm umask +.Nd set file creation mode mask +.Sh SYNOPSIS +.Fd #include <sys/stat.h> +.Ft mode_t +.Fn umask "mode_t numask" +.Sh DESCRIPTION +The +.Fn umask +routine sets the process's file mode creation mask to +.Fa numask +and returns the previous value of the mask. The 9 low-order +access permission +bits of +.Fa numask +are used by system calls, including +.Xr open 2 , +.Xr mkdir 2 , +and +.Xr mkfifo 2 , +to turn off corresponding bits +requested in file mode. +(See +.Xr chmod 2 ) . +This clearing allows each user to restrict the default access +to his files. +.Pp +The default mask value is S_IWGRP|S_IWOTH (022, write access for the +owner only). +Child processes inherit the mask of the calling process. +.Sh RETURN VALUES +The previous value of the file mode mask is returned by the call. +.Sh ERRORS +The +.Fn umask +function is always successful. +.Sh SEE ALSO +.Xr chmod 2 , +.Xr mknod 2 , +.Xr open 2 +.Sh STANDARDS +The +.Fn umask +function call is expected to conform to +.St -p1003.1-90 . +.Sh HISTORY +An +.Fn umask +function call appeared in +.At v7 . diff --git a/lib/libc/sys/undelete.2 b/lib/libc/sys/undelete.2 new file mode 100644 index 0000000..b95a3a6 --- /dev/null +++ b/lib/libc/sys/undelete.2 @@ -0,0 +1,104 @@ +.\" Copyright (c) 1994 +.\" Jan-Simon Pendry +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)undelete.2 8.4 (Berkeley) 10/18/94 +.\" $FreeBSD$ +.\" +.Dd October 18, 1994 +.Dt UNDELETE 2 +.Os BSD 4 +.Sh NAME +.Nm undelete +.Nd attempt to recover a deleted file +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn undelete "const char *path" +.Sh DESCRIPTION +The +.Fn undelete +function attempts to recover the deleted file named by +.Fa path . +Currently, this works only when the named object +is a whiteout in a union filesystem. +The system call removes the whiteout causing +any objects in a lower layer of the +union stack to become visible once more. +.Pp +Eventually, the +.Nm undelete +functionality may be expanded to other filesystems able to recover +deleted files such as the log-structured filesystem. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn undelete +succeeds unless: +.Bl -tag -width ENAMETOOLONGAA +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er EEXIST +The path does not reference a whiteout. +.It Bq Er ENOENT +The named whiteout does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +Write permission is denied on the directory containing the name +to be undeleted. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The directory containing the name is marked sticky, +and the containing directory is not owned by the effective user ID. +.It Bq Er EIO +An I/O error occurred while updating the directory entry. +.It Bq Er EROFS +The name resides on a read-only file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr unlink 2 , +.Xr mount_union 8 +.Sh HISTORY +An +.Nm undelete +function call first appeared in 4.4BSD-Lite. diff --git a/lib/libc/sys/unlink.2 b/lib/libc/sys/unlink.2 new file mode 100644 index 0000000..874a001 --- /dev/null +++ b/lib/libc/sys/unlink.2 @@ -0,0 +1,119 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)unlink.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt UNLINK 2 +.Os BSD 4 +.Sh NAME +.Nm unlink +.Nd remove directory entry +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn unlink "const char *path" +.Sh DESCRIPTION +The +.Fn unlink +function +removes the link named by +.Fa path +from its directory and decrements the link count of the +file which was referenced by the link. +If that decrement reduces the link count of the file +to zero, +and no process has the file open, then +all resources associated with the file are reclaimed. +If one or more process have the file open when the last link is removed, +the link is removed, but the removal of the file is delayed until +all references to it have been closed. +.Fa path +may not be a directory. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn unlink +succeeds unless: +.Bl -tag -width ENAMETOOLONGAA +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1023 characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EACCES +Write permission is denied on the directory containing the link +to be removed. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EPERM +The named file is a directory. +.It Bq Er EPERM +The directory containing the file is marked sticky, +and neither the containing directory nor the file to be removed +are owned by the effective user ID. +.It Bq Er EBUSY +The entry to be unlinked is the mount point for a +mounted file system. +.It Bq Er EIO +An I/O error occurred while deleting the directory entry +or deallocating the inode. +.It Bq Er EROFS +The named file resides on a read-only file system. +.It Bq Er EFAULT +.Fa Path +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr link 2 , +.Xr rmdir 2 , +.Xr symlink 7 +.Sh HISTORY +An +.Fn unlink +function call appeared in +.At v6 . +.Pp +The +.Fn unlink +system call traditionally allows the super-user to unlink directories which +can damage the filesystem integrity. This implementation no longer permits +it. diff --git a/lib/libc/sys/utimes.2 b/lib/libc/sys/utimes.2 new file mode 100644 index 0000000..ea04d85 --- /dev/null +++ b/lib/libc/sys/utimes.2 @@ -0,0 +1,187 @@ +.\" $NetBSD: utimes.2,v 1.13 1999/03/22 19:45:11 garbled Exp $ +.\" +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)utimes.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt UTIMES 2 +.Os +.Sh NAME +.Nm utimes , +.Nm lutimes , +.Nm futimes +.Nd set file access and modification times +.Sh SYNOPSIS +.Fd #include <sys/time.h> +.Ft int +.Fn utimes "const char *path" "const struct timeval *times" +.Ft int +.Fn lutimes "const char *path" "const struct timeval *times" +.Ft int +.Fn futimes "int fd" "const struct timeval *times" +.Sh DESCRIPTION +The access and modification times of the file named by +.Fa path +or referenced by +.Fa fd +are changed as specified by the argument +.Fa times . +.Pp +If +.Fa times +is +.Dv NULL , +the access and modification times are set to the current time. +The caller must be the owner of the file, have permission to +write the file, or be the super-user. +.Pp +If +.Fa times +is +.Pf non- Dv NULL , +it is assumed to point to an array of two timeval structures. +The access time is set to the value of the first element, and the +modification time is set to the value of the second element. +The caller must be the owner of the file or be the super-user. +.Pp +In either case, the inode-change-time of the file is set to the current +time. +.Pp +.Fn lutimes +is like +.Fn utimes +except in the case where the named file is a symbolic link, +in which case +.Fn lutimes +changes the access and modification times of the link, +while +.Fn utimes +changes the times of the file the link references. +.Sh RETURN VALUES +Upon successful completion, a value of 0 is returned. +Otherwise, a value of -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn utimes +and +.Fn lutimes +will fail if: +.Bl -tag -width Er +.It Bq Er EACCES +Search permission is denied for a component of the path prefix; +or the +.Fa times +argument is +.Dv NULL +and the effective user ID of the process does not +match the owner of the file, and is not the super-user, and write +access is denied. +.It Bq Er EFAULT +.Fa path +or +.Fa times +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading or writing the affected inode. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire path name exceeded +.Dv PATH_MAX +characters. +.It Bq Er ENOENT +The named file does not exist. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er EPERM +The +.Fa times +argument is not +.Dv NULL +and the calling process's effective user ID +does not match the owner of the file and is not the super-user. +.It Bq Er EROFS +The file system containing the file is mounted read-only. +.El +.Pp +.Fn futimes +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +does not refer to a valid descriptor. +.El +.Pp +All of the functions will fail if: +.Bl -tag -width Er +.It Bq Er EACCES +The +.Fa times +argument is +.Dv NULL +and the effective user ID of the process does not +match the owner of the file, and is not the super-user, and write +access is denied. +.It Bq Er EFAULT +.Fa times +points outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading or writing the affected inode. +.It Bq Er EPERM +The +.Fa times +argument is not +.Dv NULL +and the calling process's effective user ID +does not match the owner of the file and is not the super-user. +.It Bq Er EROFS +The file system containing the file is mounted read-only. +.El +.Sh SEE ALSO +.Xr stat 2 , +.Xr utime 3 +.Sh HISTORY +The +.Fn utimes +function call appeared in +.Bx 4.2 . +The +.Fn futimes +and +.Fn lutimes +function calls first appeared in +.Fx 3.0 . diff --git a/lib/libc/sys/vfork.2 b/lib/libc/sys/vfork.2 new file mode 100644 index 0000000..7363c55 --- /dev/null +++ b/lib/libc/sys/vfork.2 @@ -0,0 +1,130 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)vfork.2 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd June 4, 1993 +.Dt VFORK 2 +.Os BSD 4 +.Sh NAME +.Nm vfork +.Nd spawn new process in a virtual memory efficient way +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn vfork void +.Sh DESCRIPTION +.Fn Vfork +can be used to create new processes without fully copying the address +space of the old process, which is horrendously inefficient in a paged +environment. It is useful when the purpose of +.Xr fork 2 +would have been to create a new system context for an +.Xr execve 2 . +.Fn Vfork +differs from +.Xr fork 2 +in that the child borrows the parent's memory and thread of +control until a call to +.Xr execve 2 +or an exit (either by a call to +.Xr _exit 2 +or abnormally). +The parent process is suspended while the child is using its resources. +.Pp +.Fn Vfork +returns 0 in the child's context and (later) the pid of the child in +the parent's context. +.Pp +.Fn Vfork +can normally be used just like +.Xr fork 2 . +It does not work, however, to return while running in the childs context +from the procedure that called +.Fn vfork +since the eventual return from +.Fn vfork +would then return to a no longer existent stack frame. +Be careful, also, to call +.Xr _exit 2 +rather than +.Xr exit 3 +if you can't +.Xr execve 2 , +since +.Xr exit 3 +will flush and close standard I/O channels, and thereby mess up the +parent processes standard I/O data structures. +(Even with +.Xr fork 2 +it is wrong to call +.Xr exit 3 +since buffered data would then be flushed twice.) +.Sh SEE ALSO +.Xr _exit 2 , +.Xr execve 2 , +.Xr fork 2 , +.Xr rfork 2 , +.Xr sigvec 2 , +.Xr wait 2 , +.Xr exit 3 +.Sh RETURN VALUES +Same as for +.Xr fork 2 . +.Sh BUGS +This system call will be eliminated when proper system sharing +mechanisms are implemented. +Users should not depend on the memory +sharing semantics of +.Xr vfork 2 +as it will, in that case, be made synonymous to +.Xr fork 2 . +.Pp +To avoid a possible deadlock situation, +processes that are children in the middle +of a +.Fn vfork +are never sent +.Dv SIGTTOU +or +.Dv SIGTTIN +signals; rather, +output or +.Xr ioctl 2 +calls +are allowed +and input attempts result in an end-of-file indication. +.Sh HISTORY +The +.Fn vfork +function call appeared in +.Bx 3.0 . diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2 new file mode 100644 index 0000000..5cbd812 --- /dev/null +++ b/lib/libc/sys/wait.2 @@ -0,0 +1,299 @@ +.\" Copyright (c) 1980, 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)wait.2 8.2 (Berkeley) 4/19/94 +.\" $FreeBSD$ +.\" +.Dd April 19, 1994 +.Dt WAIT 2 +.Os BSD 4 +.Sh NAME +.Nm wait , +.Nm waitpid , +.Nm wait4 , +.Nm wait3 +.Nd wait for process termination +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/wait.h> +.Ft pid_t +.Fn wait "int *status" +.Fd #include <sys/time.h> +.Fd #include <sys/resource.h> +.Ft pid_t +.Fn waitpid "pid_t wpid" "int *status" "int options" +.Ft pid_t +.Fn wait3 "int *status" "int options" "struct rusage *rusage" +.Ft pid_t +.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage" +.Sh DESCRIPTION +The +.Fn wait +function suspends execution of its calling process until +.Fa status +information is available for a terminated child process, +or a signal is received. +On return from a successful +.Fn wait +call, +the +.Fa status +area contains termination information about the process that exited +as defined below. +.Pp +The +.Fn wait4 +call provides a more general interface for programs +that need to wait for certain child processes, +that need resource utilization statistics accumulated by child processes, +or that require options. +The other wait functions are implemented using +.Fn wait4 . +.Pp +The +.Fa wpid +parameter specifies the set of child processes for which to wait. +If +.Fa wpid +is -1, the call waits for any child process. +If +.Fa wpid +is 0, +the call waits for any child process in the process group of the caller. +If +.Fa wpid +is greater than zero, the call waits for the process with process id +.Fa wpid . +If +.Fa wpid +is less than -1, the call waits for any process whose process group id +equals the absolute value of +.Fa wpid . +.Pp +The +.Fa status +parameter is defined below. The +.Fa options +parameter contains the bitwise OR of any of the following options. +The +.Dv WNOHANG +option +is used to indicate that the call should not block if +there are no processes that wish to report status. +If the +.Dv WUNTRACED +option is set, +children of the current process that are stopped +due to a +.Dv SIGTTIN , SIGTTOU , SIGTSTP , +or +.Dv SIGSTOP +signal also have +their status reported. +.Pp +If +.Fa rusage +is non-zero, a summary of the resources used by the terminated +process and all its +children is returned (this information is currently not available +for stopped processes). +.Pp +When the +.Dv WNOHANG +option is specified and no processes +wish to report status, +.Fn wait4 +returns a +process id +of 0. +.Pp +The +.Fn waitpid +call is identical to +.Fn wait4 +with an +.Fa rusage +value of zero. +The older +.Fn wait3 +call is the same as +.Fn wait4 +with a +.Fa wpid +value of -1. +.Pp +The following macros may be used to test the manner of exit of the process. +One of the first three macros will evaluate to a non-zero (true) value: +.Bl -tag -width Ds +.It Fn WIFEXITED status +True if the process terminated normally by a call to +.Xr _exit 2 +or +.Xr exit 3 . +.It Fn WIFSIGNALED status +True if the process terminated due to receipt of a signal. +.It Fn WIFSTOPPED status +True if the process has not terminated, but has stopped and can be restarted. +This macro can be true only if the wait call specified the +.Dv WUNTRACED +option +or if the child process is being traced (see +.Xr ptrace 2 ) . +.El +.Pp +Depending on the values of those macros, the following macros +produce the remaining status information about the child process: +.Bl -tag -width Ds +.It Fn WEXITSTATUS status +If +.Fn WIFEXITED status +is true, evaluates to the low-order 8 bits +of the argument passed to +.Xr _exit 2 +or +.Xr exit 3 +by the child. +.It Fn WTERMSIG status +If +.Fn WIFSIGNALED status +is true, evaluates to the number of the signal +that caused the termination of the process. +.It Fn WCOREDUMP status +If +.Fn WIFSIGNALED status +is true, evaluates as true if the termination +of the process was accompanied by the creation of a core file +containing an image of the process when the signal was received. +.It Fn WSTOPSIG status +If +.Fn WIFSTOPPED status +is true, evaluates to the number of the signal +that caused the process to stop. +.El +.Sh NOTES +See +.Xr sigaction 2 +for a list of termination signals. +A status of 0 indicates normal termination. +.Pp +If a parent process terminates without +waiting for all of its child processes to terminate, +the remaining child processes are assigned the parent +process 1 ID (the init process ID). +.Pp +If a signal is caught while any of the +.Fn wait +calls is pending, +the call may be interrupted or restarted when the signal-catching routine +returns, +depending on the options in effect for the signal; +see +.Xr intro 2 , +System call restart. +.Sh RETURN VALUES +If +.Fn wait +returns due to a stopped +or terminated child process, the process ID of the child +is returned to the calling process. Otherwise, a value of -1 +is returned and +.Va errno +is set to indicate the error. +.Pp +If +.Fn wait4 , +.Fn wait3 +or +.Fn waitpid +returns due to a stopped +or terminated child process, the process ID of the child +is returned to the calling process. +If there are no children not previously awaited, +-1 is returned with +.Va errno +set to +.Bq Er ECHILD . +Otherwise, if +.Dv WNOHANG +is specified and there are +no stopped or exited children, +0 is returned. +If an error is detected or a caught signal aborts the call, +a value of -1 +is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Wait +will fail and return immediately if: +.Bl -tag -width Er +.It Bq Er ECHILD +The calling process has no existing unwaited-for +child processes. +.It Bq Er EFAULT +The +.Fa status +or +.Fa rusage +arguments point to an illegal address. +(May not be detected before exit of a child process.) +.It Bq Er EINTR +The call was interrupted by a caught signal, +or the signal did not have the +.Dv SA_RESTART +flag set. +.El +.Sh STANDARDS +The +.Fn wait +and +.Fn waitpid +functions are defined by POSIX; +.Fn wait4 +and +.Fn wait3 +are not specified by POSIX. +The +.Fn WCOREDUMP +macro +and the ability to restart a pending +.Fn wait +call are extensions to the POSIX interface. +.Sh SEE ALSO +.Xr _exit 2 , +.Xr ptrace 2 , +.Xr sigaction 2 , +.Xr exit 3 +.Sh HISTORY +A +.Fn wait +function call appeared in +.At v6 . diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2 new file mode 100644 index 0000000..ab5d236 --- /dev/null +++ b/lib/libc/sys/write.2 @@ -0,0 +1,289 @@ +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)write.2 8.5 (Berkeley) 4/2/94 +.\" $FreeBSD$ +.\" +.Dd April 2, 1994 +.Dt WRITE 2 +.Os BSD 4 +.Sh NAME +.Nm write , +.Nm writev , +.Nm pwrite +.Nd write output +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/uio.h> +.Fd #include <unistd.h> +.Ft ssize_t +.Fn write "int d" "const void *buf" "size_t nbytes" +.Ft ssize_t +.Fn writev "int d" "const struct iovec *iov" "int iovcnt" +.Ft ssize_t +.Fn pwrite "int d" "const void *buf" "size_t nbytes" "off_t offset" +.Sh DESCRIPTION +.Fn Write +attempts to write +.Fa nbytes +of data to the object referenced by the descriptor +.Fa d +from the buffer pointed to by +.Fa buf . +.Fn Writev +performs the same action, but gathers the output data +from the +.Fa iovcnt +buffers specified by the members of the +.Fa iov +array: iov[0], iov[1], ..., iov[iovcnt\|-\|1]. +.Fn Pwrite +performs the same function, but writes to the specified position in +the file without modifying the file pointer. +.Pp +For +.Fn writev , +the +.Fa iovec +structure is defined as: +.Pp +.Bd -literal -offset indent -compact +struct iovec { + char *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; +.Ed +.Pp +Each +.Fa iovec +entry specifies the base address and length of an area +in memory from which data should be written. +.Fn Writev +will always write a complete area before proceeding +to the next. +.Pp +On objects capable of seeking, the +.Fn write +starts at a position +given by the pointer associated with +.Fa d , +see +.Xr lseek 2 . +Upon return from +.Fn write , +the pointer is incremented by the number of bytes which were written. +.Pp +Objects that are not capable of seeking always write from the current +position. The value of the pointer associated with such an object +is undefined. +.Pp +If the real user is not the super-user, then +.Fn write +clears the set-user-id bit on a file. +This prevents penetration of system security +by a user who +.Dq captures +a writable set-user-id file +owned by the super-user. +.Pp +When using non-blocking I/O on objects such as sockets that are subject +to flow control, +.Fn write +and +.Fn writev +may write fewer bytes than requested; +the return value must be noted, +and the remainder of the operation should be retried when possible. +.Sh IMPLEMENTATION NOTES +.Pp +In the non-threaded library +.Fn write +is implemented as the +.Va write +syscall. +.Pp +In the threaded library, the +.Va write +syscall is assembled to +.Fn _thread_sys_write +and +.Fn write +is implemented as a function which locks +.Va d +for read and write, then calls +.Fn _thread_sys_write . +If the call to +.Fn _thread_sys_write +would block, a context switch is performed. Before returning, +.Fn write +unlocks +.Va d . +.Pp +In the non-threaded library +.Fn writev +is implemented as the +.Va writev +syscall. +.Pp +In the threaded library, the +.Va writev +syscall is assembled to +.Fn _thread_sys_writev +and +.Fn writev +is implemented as a function which locks +.Va d +for read and write, then calls +.Fn _thread_sys_writev . +If the call to +.Fn _thread_sys_writev +would block, a context switch is performed. Before returning, +.Fn writev +unlocks +.Va d . +.Sh RETURN VALUES +Upon successful completion the number of bytes which were written +is returned. Otherwise a -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn Write , +.Fn writev , +and +.Fn pwrite +will fail and the file pointer will remain unchanged if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa D +is not a valid descriptor open for writing. +.It Bq Er EPIPE +An attempt is made to write to a pipe that is not open +for reading by any process. +.It Bq Er EPIPE +An attempt is made to write to a socket of type +.Dv SOCK_STREAM +that is not connected to a peer socket. +.It Bq Er EFBIG +An attempt was made to write a file that exceeds the process's +file size limit or the maximum file size. +.It Bq Er EFAULT +Part of +.Fa iov +or data to be written to the file +points outside the process's allocated address space. +.It Bq Er EINVAL +The pointer associated with +.Fa d +was negative. +.It Bq Er ENOSPC +There is no free space remaining on the file system +containing the file. +.It Bq Er EDQUOT +The user's quota of disk blocks on the file system +containing the file has been exhausted. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er EAGAIN +The file was marked for non-blocking I/O, +and no data could be written immediately. +.El +.Pp +In addition, +.Fn writev +may return one of the following errors: +.Bl -tag -width Er +.It Bq Er EDESTADDRREQ +The destination is no longer available when writing to a +.Ux +domain datagram socket on which +.Xr connect 2 +had been used to set a destination address. +.It Bq Er EINVAL +.Fa Iovcnt +was less than or equal to 0, or greater than +.Dv UIO_MAXIOV . +.It Bq Er EINVAL +One of the +.Fa iov_len +values in the +.Fa iov +array was negative. +.It Bq Er EINVAL +The sum of the +.Fa iov_len +values in the +.Fa iov +array overflowed a 32-bit integer. +.It Bq Er ENOBUFS +The mbuf pool has been completely exhausted when writing to a socket. +.El +.Pp +The +.Fn pwrite +call may also return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified file offset is invalid. +.It Bq Er ESPIPE +The file descriptor is associated with a pipe, socket, or FIFO. +.El +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr lseek 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr select 2 +.Sh STANDARDS +The +.Fn write +function call is expected to conform to +.St -p1003.1-90 . +The +.Fn writev +and +.Fn pwrite +functions are expected to conform to +.St -xpg4.2 . +.Sh HISTORY +The +.Fn pwrite +function call +appeared in +.At V.4 . +The +.Fn writev +function call +appeared in +.Bx 4.2 . +A +.Fn write +function call appeared in +.At v6 . |