diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:54:44 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:54:44 -0400 |
| commit | a9157ce950dfe2fc30795d43b9d79b9d1bffc48b (patch) | |
| tree | 9df484304b560466d145e662c1c254ff0e9ae0ba /static/openbsd/man2 | |
| parent | 160aa82b2d39c46ad33723d7d909cb4972efbb03 (diff) | |
docs: Added All OpenBSD Manuals
Diffstat (limited to 'static/openbsd/man2')
165 files changed, 36778 insertions, 0 deletions
diff --git a/static/openbsd/man2/__get_tcb.2 b/static/openbsd/man2/__get_tcb.2 new file mode 100644 index 00000000..904d6a5b --- /dev/null +++ b/static/openbsd/man2/__get_tcb.2 @@ -0,0 +1,66 @@ +.\" $OpenBSD: __get_tcb.2,v 1.7 2023/02/22 06:31:51 guenther Exp $ +.\" +.\" Copyright (c) 2011 Philip Guenther <guenther@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: February 22 2023 $ +.Dt __GET_TCB 2 +.Os +.Sh NAME +.Nm __get_tcb , +.Nm __set_tcb +.Nd get or set the address of the thread control block of the current thread +.Sh SYNOPSIS +.Ft void * +.Fn __get_tcb "void" +.Ft void +.Fn __set_tcb "void *" +.Sh DESCRIPTION +The +.Fn __get_tcb +and +.Fn __set_tcb +functions are for use by libpthread and other parts of the C +runtime to retrieve and set the address of the current thread's +thread control block (TCB). +This is used to locate per-thread data such as +.Va errno . +Each kernel-level thread in a process has a separate value for this +address, which can be obtained and changed via these system calls. +.Pp +The initial thread of a new process created using +.Xr fork 2 +or +.Xr vfork 2 +inherits the TCB address of the thread that created it. +A thread created using +.Xr __tfork 3 +starts with the TCB address specified in that call. +.Xr execve 2 +resets the thread's TCB address to zero. +.Pp +On some platforms, this address is also directly mapped to a CPU +register which can be accessed from userspace. +.Sh RETURN VALUES +.Fn __get_tcb +returns the address of the thread control block of the current thread. +.Sh SEE ALSO +.Xr __tfork 3 +.Sh HISTORY +The +.Fn __get_tcb +and +.Fn __set_tcb +system calls appeared in +.Ox 5.1 . diff --git a/static/openbsd/man2/__thrsigdivert.2 b/static/openbsd/man2/__thrsigdivert.2 new file mode 100644 index 00000000..e042c2bb --- /dev/null +++ b/static/openbsd/man2/__thrsigdivert.2 @@ -0,0 +1,126 @@ +.\" $OpenBSD: __thrsigdivert.2,v 1.6 2023/02/22 06:54:13 guenther Exp $ +.\" +.\" Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: February 22 2023 $ +.Dt __THRSIGDIVERT 2 +.Os +.Sh NAME +.Nm __thrsigdivert +.Nd synchronously accept a signal +.Sh SYNOPSIS +.In sys/time.h +.In signal.h +.Ft int +.Fn __thrsigdivert "sigset_t set" "siginfo_t *info" "const struct timespec *timeout" +.Sh DESCRIPTION +The +.Fn __thrsigdivert +function is used to implement +.Fn sigwait . +It selects a signal pending for the calling thread or process from +.Fa set , +atomically clears it from that set of pending signals, +and returns that signal number. +If prior to the call to +.Fn __thrsigdivert +there are multiple pending instances of a single signal number, +it is undefined whether upon successful return there are any remaining +pending signals for that signal number. +If no signal in +.Fa set +is pending at the time of the call, +the thread shall be suspended until one or more becomes pending. +The signals defined by +.Fa set +should have been blocked in all threads in the process at the time +of the call to +.Fn __thrsigdivert ; +otherwise the signal may be delivered to some thread that does not +have it blocked. +.Pp +If more than one thread is using +.Fn __thrsigdivert +to wait for the same signal, +no more than one of these threads shall return from +.Fn __thrsigdivert +for any given signal that is sent. +Which thread returns from +.Fn __thrsigdivert +if more than a single thread is waiting is unspecified. +.Pp +If the +.Fa info +argument is not +.Dv NULL , +then a +.Vt siginfo_t +will be stored there which has the selected signal number in its +.Fa si_signo +member and the cause of the signal in its +.Fa si_code +member. +.Pp +If the +.Fa timeout +argument is not +.Dv NULL +and no selected signal is currently pending, +then +.Fn __thrsigdivert +will wait no longer than the specified time period for a signal to +arrive before failing. +.Sh RETURN VALUES +If successful, +the number of the signal that was accepted is returned. +Otherwise, a value of -1 is returned and +.Dv errno +is set to indicate the error. +.Sh ERRORS +.Fn __thrsigdivert +will succeed unless: +.Bl -tag -width Er +.It Bq Er EWOULDBLOCK +The timeout was reached before a selected signal was received. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigprocmask 2 , +.Xr sigwait 3 +.Sh STANDARDS +The +.Fn __thrsigdivert +function is specific to +.Ox +and should not be used in portable applications. +.Sh HISTORY +A +.Fn thrsigdivert +syscall appeared in +.Ox 3.9 . +The +.Fa info +and +.Fa timeout +arguments were added in +.Ox 4.9 . +.Sh AUTHORS +.An -nosplit +The +.Fn thrsigdivert +syscall was created by +.An Ted Unangst Aq Mt tedu@OpenBSD.org . +This manual page was written by +.An Philip Guenther Aq Mt guenther@OpenBSD.org . diff --git a/static/openbsd/man2/__thrsleep.2 b/static/openbsd/man2/__thrsleep.2 new file mode 100644 index 00000000..28dc4483 --- /dev/null +++ b/static/openbsd/man2/__thrsleep.2 @@ -0,0 +1,219 @@ +.\" $OpenBSD: __thrsleep.2,v 1.7 2018/04/24 16:28:42 pirofti Exp $ +.\" +.\" Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: April 24 2018 $ +.Dt __THRSLEEP 2 +.Os +.Sh NAME +.Nm __thrsleep , +.Nm __thrwakeup +.Nd userspace thread sleep and wakeup +.Sh SYNOPSIS +.In sys/time.h +.Ft int +.Fn __thrsleep "const volatile void *id" "clockid_t clock_id" "const struct timespec *abstime" "void *lock" "const int *abort" +.Ft int +.Fn __thrwakeup "const volatile void *id" "int count" +.Sh DESCRIPTION +The +.Fn __thrsleep +and +.Fn __thrwakeup +functions provide thread sleep and wakeup primitives with which +synchronization primitives such as mutexes and condition variables +can be implemented. +.Fn __thrsleep +blocks the calling thread on the abstract +.Dq wait channel +identified by the +.Fa id +argument until another thread calls +.Fn __thrwakeup +with the same +.Fa id +value. +If the +.Fa abstime +argument is not +.Dv NULL , +then it specifies an absolute time, +measured against the +.Fa clock_id +clock, +after which +.Fn __thrsleep +should time out and return. +If the specified time is in the past then +.Fn __thrsleep +will return immediately without blocking. +.Pp +The +.Fa lock +argument, +if not +.Dv NULL , +points to a locked spinlock that will be unlocked by +.Fn __thrsleep +atomically with respect to calls to +.Fn __thrwakeup , +such that if another thread locks the spinlock before calling +.Fn __thrwakeup +with the same +.Fa id , +then the thread that called +.Fn __thrsleep +will be eligible for being woken up and unblocked. +.Pp +The +.Fa abort +argument, +if not +.Dv NULL , +points to an +.Vt int +that will be examined after unlocking the spinlock pointed to by +.Fa lock +and immediately before blocking. +If that +.Vt int +is non-zero then +.Fn __thrsleep +will immediately return +.Er EINTR +without blocking. +This provides a mechanism for a signal handler to keep a call to +.Fn __thrsleep +from blocking, +even if the signal is delivered immediately before the call. +.Pp +The +.Fn __thrwakeup +function unblocks one or more threads that are sleeping on the +wait channel identified by +.Fa id . +The number of threads unblocked is specified by the +.Fa count +argument, +except that if zero is specified then all threads sleeping on that +.Fa id +are unblocked. +.Sh RETURN VALUES +.Fn __thrsleep +will return zero if woken by a matching call to +.Fn __thrwakeup , +otherwise an error number will be returned to indicate the error. +.Pp +.Fn __thrwakeup +will return zero if at least one matching call to +.Fn __thrsleep +was unblocked, +otherwise an error number will be returned to indicate the error. +.Sh ERRORS +.Fn __thrsleep +and +.Fn __thrwakeup +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa ident +argument is +.Dv NULL . +.El +.Pp +In addition, +.Fn __thrsleep +may return one of the following errors: +.Bl -tag -width Er +.It Bq Er EWOULDBLOCK +The time specified by the +.Fa abstime +and +.Fa clock_id +arguments was reached. +.It Bq Er EINTR +A signal arrived or the +.Fa abort +argument pointed to a non-zero value. +.It Bq Er ECANCELED +A signal arrived and +.Fa SA_RESTART +was set. +.It Bq Er EINVAL +The +.Fa clock_id +argument is not a valid +.Xr clock_gettime 2 +clock id +or +.Fa abstime +specified a nanosecond value less than zero or greater than 1000 million. +.El +.Pp +.Fn __thrwakeup +may return the following error: +.Bl -tag -width Er +.It Bq Er ESRCH +No threads calling +.Fn __thrsleep +with the same +.Fa id +were found. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr pthread_cond_wait 3 , +.Xr pthread_mutex_lock 3 , +.Xr tsleep 9 +.Sh STANDARDS +The +.Fn __thrsleep +and +.Fn __thrwakeup +functions are specific to +.Ox +and should not be used in portable applications. +.Sh HISTORY +The +.Fn thrsleep +and +.Fn thrwakeup +syscalls appeared in +.Ox 3.9 . +The +.Fa clock_id +and +.Fa abstime +arguments were added in +.Ox 4.9 . +The functions were renamed to +.Fn __thrsleep +and +.Fn __thrwakeup +and the +.Fa abort +argument was added in +.Ox 5.1 +.Sh AUTHORS +.An -nosplit +The +.Fn thrsleep +and +.Fn thrwakeup +syscalls were created by +.An Ted Unangst Aq Mt tedu@OpenBSD.org . +This manual page was written by +.An Philip Guenther Aq Mt guenther@OpenBSD.org . diff --git a/static/openbsd/man2/_exit.2 b/static/openbsd/man2/_exit.2 new file mode 100644 index 00000000..223274da --- /dev/null +++ b/static/openbsd/man2/_exit.2 @@ -0,0 +1,139 @@ +.\" $OpenBSD: _exit.2,v 1.23 2022/02/18 00:15:53 jsg Exp $ +.\" $NetBSD: _exit.2,v 1.6 1995/02/27 12:31:34 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: February 18 2022 $ +.Dt _EXIT 2 +.Os +.Sh NAME +.Nm _exit , +.Nm _Exit +.Nd terminate the calling process +.Sh SYNOPSIS +.In unistd.h +.Ft void +.Fn _exit "int status" +.In stdlib.h +.Ft void +.Fn _Exit "int status" +.Sh DESCRIPTION +The +.Fn _exit +and +.Fn _Exit +functions terminate a process with the following consequences: +.Bl -bullet +.It +All threads in the process are terminated. +.It +All open file descriptors 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 +.Fa status +is set as defined by +.Xr wait 2 . +(Note that typically only the lower 8 bits of +.Fa status +are passed on to the parent, thus negative values have less meaning.) +.It +The parent process ID of all of the calling process's existing child +processes are set to 1; the initialization process (see the +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 Orphaned Process Group in +.Xr intro 2 ) , +and if any member of the orphaned group is stopped, the +.Dv SIGHUP +and +.Dv SIGCONT +signals 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., +and then calls +.Fn _exit . +.Sh RETURN VALUES +.Fn _exit +and +.Fn _Exit +can never return. +.Sh SEE ALSO +.Xr fork 2 , +.Xr intro 2 , +.Xr sigaction 2 , +.Xr wait 2 , +.Xr exit 3 , +.Xr sysexits 3 +.Sh STANDARDS +The +.Fn _exit +function conforms to +.St -p1003.1-2008 . +The +.Fn _Exit +function conforms to +.St -isoC-99 . +.Sh HISTORY +An +.Fn exit +system call first appeared in +.At v1 . +It accepts the +.Fa status +argument since +.At v2 . +An +.Fn _exit +variant first appeared in +.At v7 . +The +.Fn _Exit +function appeared in +.Ox 3.6 . diff --git a/static/openbsd/man2/accept.2 b/static/openbsd/man2/accept.2 new file mode 100644 index 00000000..5f2572a0 --- /dev/null +++ b/static/openbsd/man2/accept.2 @@ -0,0 +1,230 @@ +.\" $OpenBSD: accept.2,v 1.31 2025/08/04 04:59:31 guenther Exp $ +.\" $NetBSD: accept.2,v 1.7 1996/01/31 20:14:42 mycroft Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt ACCEPT 2 +.Os +.Sh NAME +.Nm accept , +.Nm accept4 +.Nd accept a connection on a socket +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn accept "int s" "struct sockaddr *addr" "socklen_t *addrlen" +.Ft int +.Fn accept4 "int s" "struct sockaddr *addr" "socklen_t *addrlen" "int flags" +.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 +call extracts the first connection request on the queue of pending +connections, creates a new socket with the same non-blocking I/O mode as +.Fa s , +and allocates a new file descriptor for the socket with the +close-on-exec and close-on-fork flags clear. +.Pp +The +.Fn accept4 +system call is similar, however the non-blocking I/O mode, +close-on-exec flag, +and close-on-fork flag on the new file descriptor are +determined by the +.Dv SOCK_NONBLOCK , SOCK_CLOEXEC , +and +.Dv SOCK_CLOFORK +flags, respectively, in the +.Fa flags +argument. +.Pp +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 structure +.Vt sockaddr_storage +exists for greater portability. +It is large enough to hold any of the types that may be returned in the +.Fa addr +parameter. +.Pp +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. +If +.Fa addrlen +does not point to enough space to hold the entire socket address, the +result will be truncated to the initial value of +.Fa addrlen +(in bytes). +This call is used with connection-based socket types, currently with +.Dv SOCK_STREAM . +.Pp +It is possible to +.Xr select 2 +or +.Xr poll 2 +a socket for the purposes of doing an +.Fn accept +by selecting it for read. +.Sh RETURN VALUES +If successful, +.Fn accept +and +.Fn accept4 +return a non-negative integer, the accepted socket file descriptor. +Otherwise, a value of \-1 is returned and +.Va errno +is set to indicate the error. +.Sh EXAMPLES +The following code uses struct +.Vt sockaddr_storage +to allocate enough space for the returned address: +.Bd -literal -offset indent +#include <sys/types.h> +#include <sys/socket.h> + +struct sockaddr_storage addr; +socklen_t len = sizeof(addr); +int retcode; + +retcode = accept(s, (struct sockaddr *)&addr, &len); +if (retcode == -1) + err(1, "accept"); +.Ed +.Sh ERRORS +.Fn accept +and +.Fn accept4 +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The descriptor is invalid. +.It Bq Er ENOTSOCK +The descriptor doesn't reference a socket. +.It Bq Er EOPNOTSUPP +The referenced socket is not of type +.Dv SOCK_STREAM . +.It Bq Er EINTR +A signal was caught before a connection arrived. +.It Bq Er EINVAL +The referenced socket is not listening for connections (that is, +.Xr listen 2 +has not yet been called). +.It Bq Er EFAULT +The +.Fa addr +or +.Fa addrlen +parameter is not in a valid part of the process address space. +.It Bq Er EWOULDBLOCK +The socket is marked non-blocking and no connections +are present to be accepted. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ECONNABORTED +A connection has been aborted. +.El +.Pp +In addition, +.Fn accept4 +will fail if +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa flags +is invalid. +.El +.Sh SEE ALSO +.Xr bind 2 , +.Xr connect 2 , +.Xr listen 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr socket 2 +.Sh STANDARDS +The +.Fn accept +and +.Fn accept4 +functions conform to +.St -p1003.1-2024 . +.Sh HISTORY +The +.Fn accept +system call first appeared in +.Bx 4.1c +and +.Fn accept4 +in +.Ox 5.7 . +.Sh CAVEATS +When +.Er EMFILE +or +.Er ENFILE +is returned, +new connections are neither dequeued nor discarded. +Thus considerable care is required in +.Xr select 2 +and +.Xr poll 2 +loops. diff --git a/static/openbsd/man2/access.2 b/static/openbsd/man2/access.2 new file mode 100644 index 00000000..fdb6537e --- /dev/null +++ b/static/openbsd/man2/access.2 @@ -0,0 +1,240 @@ +.\" $OpenBSD: access.2,v 1.27 2023/09/28 01:51:00 jsg Exp $ +.\" $NetBSD: access.2,v 1.7 1995/02/27 12:31:44 cgd 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. 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 +.\" +.Dd $Mdocdate: September 28 2023 $ +.Dt ACCESS 2 +.Os +.Sh NAME +.Nm access , +.Nm faccessat +.Nd check access permissions of a file or pathname +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn access "const char *path" "int amode" +.In fcntl.h +.In unistd.h +.Ft int +.Fn faccessat "int fd" "const char *path" "int amode" "int flag" +.Sh DESCRIPTION +The +.Fn access +function checks the accessibility of the file named by +.Fa path +for the access permissions indicated by +.Fa amode . +The +.Fa amode +argument is either the bitwise OR of one or more 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) is +used in place of the effective ID for verifying permission. +.Pp +If the invoking process has superuser privileges, +.Fn access +will always indicate success for +.Dv R_OK +and +.Dv W_OK , +regardless of the actual file permission bits. +Likewise, for +.Dv X_OK , +if the file has any of the execute bits set and +.Fa path +is not a directory, +.Fn access +will indicate success. +.Pp +The +.Fn faccessat +function is equivalent to +.Fn access +except that where +.Fa path +specifies a relative path, +the file whose accessibility is checked is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn faccessat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used. +If +.Fa flag +is also zero, the behavior is identical to a call to +.Fn access . +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_EACCESS -offset indent -compact +.It Dv AT_EACCESS +The checks for accessibility are performed using the effective user +and group IDs instead of the real user and group IDs. +.El +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 +.Dq owner +read, write, and execute mode bits, members of the file's group other +than the owner have permission checked with respect to the +.Dq group +mode bits, and all others have permissions checked with respect to the +.Dq other +mode bits. +.It Bq Er EPERM +Write access has been requested and the named file has its immutable +flag set (see +.Xr chflags 2 ) . +.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 EINVAL +An invalid value was specified for +.Fa amode . +.El +.Pp +Additionally, +.Fn faccessat +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_EACCESS . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr stat 2 +.Sh STANDARDS +The +.Fn access +and +.Fn faccessat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +.Fn access +first appeared as an internal kernel function in +.At v1 . +It became a system call, +first appearing outside of Bell Labs in the +.Dq 50 changes +tape for +.At v6 . +The first official release with the system call was PWB/UNIX 1.0. +It was also included in +.Bx 2 . +.Pp +The +.Fn faccessat +function appeared in +.Ox 5.0 . +.Sh CAVEATS +.Fn access +and +.Fn faccessat +should never be used for actual access control. +Doing so can result in a time of check vs. time of use security hole. diff --git a/static/openbsd/man2/acct.2 b/static/openbsd/man2/acct.2 new file mode 100644 index 00000000..b80de02c --- /dev/null +++ b/static/openbsd/man2/acct.2 @@ -0,0 +1,118 @@ +.\" $OpenBSD: acct.2,v 1.20 2021/01/03 18:10:27 rob Exp $ +.\" $NetBSD: acct.2,v 1.6 1995/02/27 12:31:47 cgd 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. 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 +.\" +.Dd $Mdocdate: January 3 2021 $ +.Dt ACCT 2 +.Os +.Sh NAME +.Nm acct +.Nd enable or disable process accounting +.Sh SYNOPSIS +.In 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 +.Fa file +is +.Dv NULL , +accounting is disabled. +If +.Fa file +is an existing, NUL-terminated pathname, record collection is enabled. +For every process initiated which terminates under normal conditions or +misbehaves in very specific ways (e.g. file access prevented by unveil), +an accounting record is appended to +.Fa file . +Abnormal conditions of termination are reboots or other +fatal system problems. +.Fn acct +is only available on kernels compiled with the +.Cm ACCOUNTING +option. +.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 superuser. +.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 +.Rv -std +.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 superuser. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 pathname 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 accton 8 , +.Xr sa 8 +.Sh HISTORY +An +.Fn acct +function call appeared in +.At v7 . diff --git a/static/openbsd/man2/adjfreq.2 b/static/openbsd/man2/adjfreq.2 new file mode 100644 index 00000000..183e65c6 --- /dev/null +++ b/static/openbsd/man2/adjfreq.2 @@ -0,0 +1,76 @@ +.\" $OpenBSD: adjfreq.2,v 1.8 2020/07/09 02:17:07 cheloha Exp $ +.\" +.\" Copyright (c) 2006 Otto Moerbeek +.\" +.\" 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 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 $Mdocdate: July 9 2020 $ +.Dt ADJFREQ 2 +.Os +.Sh NAME +.Nm adjfreq +.Nd correct the rate of the system clock +.Sh SYNOPSIS +.In sys/types.h +.In sys/time.h +.Ft int +.Fn adjfreq "const int64_t *freq" "int64_t *oldfreq" +.Sh DESCRIPTION +.Fn adjfreq +adjusts the rate in which time progresses if +.Fa freq +is non-null. +The unit of the rate of adjustment is nanoseconds per second, +shifted left 32 bits to allow for fractional values. +.Pp +If +.Fa oldfreq +is non-null, the current value is returned. +.Pp +Only the superuser may adjust the frequency. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn adjfreq +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +Either of the arguments point outside the process's allocated address space. +.It Bq Er EPERM +The +.Fa freq +argument is non-null and the process's effective user ID is not that +of the superuser. +.It Bq Er EINVAL +.Fa freq +is less than -500000 ppm or greater than 500000 ppm. +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr adjtime 2 , +.Xr gettimeofday 2 , +.Xr ntpd 8 +.Sh HISTORY +The +.Fn adjfreq +function call first appeared in +.Ox 4.0 . diff --git a/static/openbsd/man2/adjtime.2 b/static/openbsd/man2/adjtime.2 new file mode 100644 index 00000000..b7d3aab8 --- /dev/null +++ b/static/openbsd/man2/adjtime.2 @@ -0,0 +1,133 @@ +.\" $OpenBSD: adjtime.2,v 1.25 2019/03/26 16:02:54 cheloha Exp $ +.\" $NetBSD: adjtime.2,v 1.5 1995/10/12 15:40:44 jtc 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. 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 +.\" +.Dd $Mdocdate: March 26 2019 $ +.Dt ADJTIME 2 +.Os +.Sh NAME +.Nm adjtime +.Nd correct the time to allow synchronization of the system clock +.Sh SYNOPSIS +.In 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 delta +is +.Dv NULL , +no adjustment is done. +If +.Fa olddelta +is +.Pf non- Dv NULL , +the number of microseconds still to be corrected from the earlier call +is stored into +.Pf * Fa olddelta . +Setting the time with +.Xr settimeofday 2 +cancels any in-progress time adjustment. +.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 +Only the superuser may adjust the time using the +.Fn adjtime +function. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn adjtime +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +Either of the arguments point outside the process's allocated address space. +.It Bq Er EINVAL +The +.Fa delta +argument is +.Pf non- Dv NULL +and specifies a microsecond value less than zero or +greater than or equal to one million. +.It Bq Er EINVAL +The +.Fa delta +argument is +.Pf non- Dv NULL +and represents an adjustment greater than +.Dv INT64_MAX +microseconds or less than +.Dv INT64_MIN +microseconds. +.It Bq Er EPERM +The +.Fa delta +argument is +.Pf non- Dv NULL +and the process's effective user ID is not that of the superuser. +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr adjfreq 2 , +.Xr gettimeofday 2 , +.Xr ntpd 8 +.Sh HISTORY +The +.Fn adjtime +function call appeared in +.Bx 4.3 . +.Sh CAVEATS +Other operating systems restrict calling +.Fn adjtime +to the superuser and might not allow requesting the current +correction without specifying a new value. diff --git a/static/openbsd/man2/amd64_iopl.2 b/static/openbsd/man2/amd64_iopl.2 new file mode 100644 index 00000000..30ac17b9 --- /dev/null +++ b/static/openbsd/man2/amd64_iopl.2 @@ -0,0 +1,80 @@ +.\" $OpenBSD: amd64_iopl.2,v 1.9 2025/06/05 18:47:18 schwarze Exp $ +.\" $NetBSD: amd64_iopl.2,v 1.3 1996/02/27 22:57:25 jtc Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by John T. Kohl and Charles M. Hannum. +.\" +.\" 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 NETBSD FOUNDATION, INC. 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 $Mdocdate: June 5 2025 $ +.Dt AMD64_IOPL 2 amd64 +.Os +.Sh NAME +.Nm amd64_iopl +.Nd change the amd64 I/O privilege level +.Sh SYNOPSIS +.Lb libamd64 +.In sys/types.h +.In machine/sysarch.h +.Ft int +.Fn amd64_iopl "int iopl" +.Sh DESCRIPTION +.Fn amd64_iopl +sets the amd64 I/O privilege level to the value specified by +.Ar iopl . +.Pp +This call may only be made by the superuser. +Additionally, it is only permitted when the +.Xr securelevel 7 +is less than or equal to 0 or the +.Va machdep.allowaperture +sysctl has been set to a non-zero value. +.Sh RETURN VALUES +Upon successful completion, +.Fn amd64_iopl +returns 0. +Otherwise, a value of \-1 is returned and the global +variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn amd64_iopl +will fail if: +.Bl -tag -width [EINVAL] +.It Bq Er EPERM +The caller was not the superuser, or the securelevel is greater than zero and +.Va machdep.allowaperture +has not been set to a non-zero value. +.El +.Sh SEE ALSO +.Xr securelevel 7 +.Sh REFERENCES +.Rs +.%A Intel +.%T AMD64 Microprocessor Programmer's Reference Manual +.Re +.Sh WARNING +You can really hose your machine if you enable user-level I/O and +write to hardware ports without care. diff --git a/static/openbsd/man2/arm_drain_writebuf.2 b/static/openbsd/man2/arm_drain_writebuf.2 new file mode 100644 index 00000000..f89ca531 --- /dev/null +++ b/static/openbsd/man2/arm_drain_writebuf.2 @@ -0,0 +1,56 @@ +.\" $OpenBSD: arm_drain_writebuf.2,v 1.6 2025/06/10 12:52:51 schwarze Exp $ +.\" $NetBSD: arm_drain_writebuf.2,v 1.3 2004/02/13 09:56:47 wiz Exp $ +.\" +.\" Copyright (c) 1997 Mark Brinicombe +.\" 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 Mark Brinicombe +.\" 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 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 $Mdocdate: June 10 2025 $ +.Dt ARM_DRAIN_WRITEBUF 2 arm +.Os +.Sh NAME +.Nm arm_drain_writebuf +.Nd drains the CPU write buffer +.Sh SYNOPSIS +.Lb libarm +.In machine/sysarch.h +.Ft int +.Fn arm_drain_writebuf void +.Sh DESCRIPTION +.Fn arm_drain_writebuf +will make sure that all the entries in the processor write buffer are +written out to memory. +.Pp +Not all processors support this operation (currently only the SA110 does). +Those processes that do not, treat this function as a null-op. +.Sh ERRORS +.Fn arm_drain_writebuf +will never fail so will always return 0. +.Sh REFERENCES +StrongARM Data Sheet diff --git a/static/openbsd/man2/arm_sync_icache.2 b/static/openbsd/man2/arm_sync_icache.2 new file mode 100644 index 00000000..48d690ef --- /dev/null +++ b/static/openbsd/man2/arm_sync_icache.2 @@ -0,0 +1,71 @@ +.\" $OpenBSD: arm_sync_icache.2,v 1.5 2025/06/10 12:52:51 schwarze Exp $ +.\" $NetBSD: arm_sync_icache.2,v 1.5 2004/02/13 09:56:47 wiz Exp $ +.\" +.\" Copyright (c) 1996 Mark Brinicombe +.\" 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 Mark Brinicombe +.\" 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 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 $Mdocdate: June 10 2025 $ +.Dt ARM_SYNC_ICACHE 2 arm +.Os +.Sh NAME +.Nm arm_sync_icache +.Nd clean the CPU data cache and flush the CPU instruction cache +.Sh SYNOPSIS +.Lb libarm +.In machine/sysarch.h +.Ft int +.Fn arm_sync_icache "u_int addr" "int len" +.Sh DESCRIPTION +.Fn arm_sync_icache +will make sure that all the entries in the processor instruction cache +are synchronized with main memory and that any data in a write back cache +has been cleaned. +Some ARM processors (e.g. SA110) have separate instruction and data +caches, thus any dynamically generated or modified code needs to be +written back from any data caches to main memory and the instruction +cache needs to be synchronized with main memory. +.Pp +On such processors, +.Fn arm_sync_icache +will clean the data cache and invalidate the processor instruction cache +to force reloading from main memory. +On processors that have a shared instruction and data cache and have a +write through cache (e.g. ARM6), no action needs to be taken. +.Pp +The routine takes a start address +.Fa addr +and a length +.Fa len +to describe the area of memory that needs to be cleaned and synchronized. +.Sh ERRORS +.Fn arm_sync_icache +will never fail so will always return 0. +.Sh REFERENCES +StrongARM Data Sheet diff --git a/static/openbsd/man2/bind.2 b/static/openbsd/man2/bind.2 new file mode 100644 index 00000000..a6b5635f --- /dev/null +++ b/static/openbsd/man2/bind.2 @@ -0,0 +1,143 @@ +.\" $OpenBSD: bind.2,v 1.23 2022/03/31 17:27:16 naddy Exp $ +.\" $NetBSD: bind.2,v 1.8 1995/10/12 15:40:46 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: March 31 2022 $ +.Dt BIND 2 +.Os +.Sh NAME +.Nm bind +.Nd bind a name to a socket +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn bind "int s" "const struct sockaddr *name" "socklen_t namelen" +.Sh DESCRIPTION +.Fn bind +assigns a name to an unnamed socket. +When a socket is created with +.Xr socket 2 , +it exists in a name space (address family) but has no name assigned. +.Fn bind +requests that +.Fa name +be assigned to the socket. +.Fa namelen +indicates the amount of space pointed to by +.Fa name , +in bytes; the +.Fa sa_len +member of +.Fa name +is ignored. +.Sh NOTES +Binding a name in the +.Ux Ns -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 name binding vary between communication domains. +Consult the manual entries in section 4 for detailed information. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn bind +function will fail if: +.Bl -tag -width Er +.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 EINVAL +The socket is already bound to an address, or +.Fa namelen +is not a valid length for the supplied address. +.It Bq Er EAFNOSUPPORT +The family of the socket and that requested in +.Va name->sa_family +are not equivalent. +.It Bq Er ENOBUFS +Insufficient buffer space is available. +.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 name +parameter is not in a valid part of the user address space. +.El +.Pp +The following errors are specific to binding names in the +.Ux Ns -domain . +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.It Bq Er ENOENT +A prefix component of the pathname 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 STANDARDS +The +.Fn bind +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn bind +system call first appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/brk.2 b/static/openbsd/man2/brk.2 new file mode 100644 index 00000000..970e4217 --- /dev/null +++ b/static/openbsd/man2/brk.2 @@ -0,0 +1,154 @@ +.\" $OpenBSD: brk.2,v 1.24 2019/09/08 22:50:59 schwarze Exp $ +.\" $NetBSD: brk.2,v 1.7 1995/02/27 12:31:57 cgd 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. 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.2 (Berkeley) 12/11/93 +.\" +.Dd $Mdocdate: September 8 2019 $ +.Dt BRK 2 +.Os +.Sh NAME +.Nm brk , +.Nm sbrk +.Nd change data segment size +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn brk "void *addr" +.Ft void * +.Fn sbrk "int incr" +.Sh DESCRIPTION +.Bf -symbolic +The +.Fn brk +and +.Fn 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 +.Fn 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 +.Fa rlim_max +value returned from a call to +.Xr getrlimit 2 , +e.g., +.Ql etext + rlp->rlim_max +(see +.Xr end 3 +for the definition of +.Em etext ) . +.Sh RETURN VALUES +.Rv -std brk +.Pp +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 sbrk +will fail and no additional memory will be allocated if +one of the following are true: +.Bl -tag -width Er +.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 mmap 2 , +.Xr end 3 , +.Xr malloc 3 +.Sh HISTORY +A predecessor +.Fn break +appeared in +.At v1 . +The +.Fn sbrk +function call first appeared in +.At v4 +and +.Fn brk +in +.At v6 . +.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 . diff --git a/static/openbsd/man2/chdir.2 b/static/openbsd/man2/chdir.2 new file mode 100644 index 00000000..5250bc64 --- /dev/null +++ b/static/openbsd/man2/chdir.2 @@ -0,0 +1,130 @@ +.\" $OpenBSD: chdir.2,v 1.14 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: chdir.2,v 1.7 1995/02/27 12:32:00 cgd 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt CHDIR 2 +.Os +.Sh NAME +.Nm chdir , +.Nm fchdir +.Nd change current working directory +.Sh SYNOPSIS +.In 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 +.Pq 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 +.Pq 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 +.Rv -std +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 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 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. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.El +.Sh SEE ALSO +.Xr chroot 2 +.Sh STANDARDS +The +.Fn chdir +and +.Fn fchdir +functions are expected to conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn chdir +system call first appeared in +.At v1 , +and +.Fn fchdir +in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/chflags.2 b/static/openbsd/man2/chflags.2 new file mode 100644 index 00000000..5f9b8470 --- /dev/null +++ b/static/openbsd/man2/chflags.2 @@ -0,0 +1,228 @@ +.\" $OpenBSD: chflags.2,v 1.29 2022/08/04 06:20:24 jsg Exp $ +.\" $NetBSD: chflags.2,v 1.6 1995/02/27 12:32:03 cgd Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/9/93 +.\" +.Dd $Mdocdate: August 4 2022 $ +.Dt CHFLAGS 2 +.Os +.Sh NAME +.Nm chflags , +.Nm chflagsat , +.Nm fchflags +.Nd set file flags +.Sh SYNOPSIS +.In sys/stat.h +.Ft int +.Fn chflags "const char *path" "unsigned int flags" +.Ft int +.Fn fchflags "int fd" "unsigned int flags" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn chflagsat "int fd" "const char *path" "unsigned int flags" "int atflags" +.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 are the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width "SF_IMMUTABLE" -compact -offset indent +.It Dv UF_NODUMP +Do not dump the file. +.It Dv UF_IMMUTABLE +The file may not be changed. +.It Dv UF_APPEND +The file may only be appended to. +.It Dv SF_ARCHIVED +The file may be archived. +.It Dv SF_IMMUTABLE +The file may not be changed. +.It Dv SF_APPEND +The file may only be appended to. +.El +.Pp +The +.Dv UF_IMMUTABLE +and +.Dv UF_APPEND +flags may be set or unset by either the owner of a file or the superuser. +.Pp +The +.Dv SF_ARCHIVED , +.Dv SF_IMMUTABLE +and +.Dv SF_APPEND +flags may only be set or unset by the superuser. +They 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.) +.Pp +The +.Fn chflagsat +function is equivalent to +.Fn chflags +except in the case where +.Fa path +specifies a relative path. +In this case the file to be changed is determined relative to the directory +associated with the file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn chflagsat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used. +If +.Fa atflags +is also zero, the behavior is identical to a call to +.Fn chflags . +.Pp +The +.Fa atflags +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the flags of the symbolic link are changed. +.El +.Pp +The +.Fn fchflags +function is equivalent to +.Fn chflags +except that the file whose flags are changed is specified +by the file descriptor +.Fa fd . +.Sh RETURN VALUES +.Rv -std +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 superuser, or the effective user ID +is not the superuser and at least one of the super-user-only flags +for the named file would be changed. +.It Bq Er EOPNOTSUPP +The named file resides on a file system that does not support file +flags. +.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 EINVAL +The +.Fa flags +value is invalid. +.It Bq Er EINVAL +The descriptor references a block or character device and the effective +user ID is not the superuser. +.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 EINVAL +The descriptor references a block or character device and the effective +user ID is not the superuser. +.It Bq Er EINVAL +The +.Fa flags +value is invalid. +.It Bq Er EPERM +The effective user ID does not match the owner of the file and +the effective user ID is not the superuser, or the effective user ID +is not the superuser and at least one of the super-user-only flags +for the named file would be changed. +.It Bq Er EOPNOTSUPP +The named file resides on a file system that does not support file +flags. +.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 chflags 1 , +.Xr init 8 +.Sh HISTORY +The +.Fn chflags +and +.Fn fchflags +functions first appeared in +.Bx 4.3 Reno . +The +.Fn chflagsat +function first appeared in +.Fx 10.0 . +It was added to +.Ox +in +.Ox 5.7 . diff --git a/static/openbsd/man2/chmod.2 b/static/openbsd/man2/chmod.2 new file mode 100644 index 00000000..98f1212f --- /dev/null +++ b/static/openbsd/man2/chmod.2 @@ -0,0 +1,273 @@ +.\" $OpenBSD: chmod.2,v 1.29 2025/05/20 02:43:01 kn Exp $ +.\" $NetBSD: chmod.2,v 1.7 1995/02/27 12:32:06 cgd 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. 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 +.\" +.Dd $Mdocdate: May 20 2025 $ +.Dt CHMOD 2 +.Os +.Sh NAME +.Nm chmod , +.Nm fchmodat , +.Nm fchmod +.Nd change mode of file +.Sh SYNOPSIS +.In sys/stat.h +.Ft int +.Fn chmod "const char *path" "mode_t mode" +.Ft int +.Fn fchmod "int fd" "mode_t mode" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn fchmodat "int fd" "const char *path" "mode_t mode" "int flag" +.Sh DESCRIPTION +The +.Fn chmod +function sets the file permission bits of the file specified by the pathname +.Fa path +to +.Fa mode . +.Fn chmod +verifies that the process owner (user) either owns the specified file +or is the superuser. +.Pp +The +.Fa mode +argument is the bitwise OR of zero or more of the permission bit masks +from the following list: +.Bd -literal -offset indent +#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 /* save swapped text even after use */ +.Ed +.Pp +Mode +.Dv ISVTX +(the +.Em sticky bit ) +on a file has no effect, although the superuser can still set it. +If it 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 +Writing or changing the owner of a file turns off the set-user-ID and +set-group-ID bits unless the user is the superuser. +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. +.Pp +The +.Fn fchmodat +function is equivalent to +.Fn chmod +except in the case where +.Fa path +specifies a relative path. +In this case the file to be changed is determined relative to the directory +associated with the file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn fchmodat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used. +If +.Fa flag +is also zero, the behavior is identical to a call to +.Fn chmod . +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the mode of the symbolic link is changed. +.El +.Pp +The +.Fn fchmod +function is equivalent to +.Fn chmod +except that the file whose permissions are changed is specified +by the file descriptor +.Fa fd . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn chmod +and +.Fn fchmodat +functions 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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 EINVAL +.Fa mode +contains bits other than the file type and those described above. +.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 superuser. +.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 unprivileged user attempted to set a file's mode to +.Dv ISVTX . +.El +.Pp +Additionally, the +.Fn fchmodat +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_SYMLINK_NOFOLLOW . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EOPNOTSUPP +The +.Fa flag +argument specifies +.Dv AT_SYMLINK_NOFOLLOW +on a symbolic link and the file system does not support that operation. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Pp +.Fn fchmod +will fail and the file mode will be unchanged 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 EINVAL +.Fa mode +contains bits other than the file type and those described above. +.It Bq Er EPERM +The effective user ID does not match the owner of the file and +the effective user ID is not the superuser. +.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 , +.Fn fchmod , +and +.Fn fchmodat +functions are expected to conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn chmod +system call first appeared in +.At v1 ; +.Fn fchmod +in +.Bx 4.1c ; +and +.Fn fchmodat +has been available since +.Ox 5.0 . diff --git a/static/openbsd/man2/chown.2 b/static/openbsd/man2/chown.2 new file mode 100644 index 00000000..78efc612 --- /dev/null +++ b/static/openbsd/man2/chown.2 @@ -0,0 +1,265 @@ +.\" $OpenBSD: chown.2,v 1.28 2025/04/29 17:44:00 jmc Exp $ +.\" $NetBSD: chown.2,v 1.10 1995/10/12 15:40:47 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: April 29 2025 $ +.Dt CHOWN 2 +.Os +.Sh NAME +.Nm chown , +.Nm lchown , +.Nm fchownat , +.Nm fchown +.Nd change owner and group of a file or link +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn chown "const char *path" "uid_t owner" "gid_t group" +.Ft int +.Fn lchown "const char *path" "uid_t owner" "gid_t group" +.Ft int +.Fn fchown "int fd" "uid_t owner" "gid_t group" +.In fcntl.h +.In unistd.h +.Ft int +.Fn fchownat "int fd" "const char *path" "uid_t owner" "gid_t group" "int flag" +.Sh DESCRIPTION +The owner ID and group ID of the file (or link) 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 its +.Fa group +to one the owner is a member of. +The change +.Fa owner +capability is restricted to the superuser. +.Pp +By default, +.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. +.Pp +.Fn lchown +operates similarly to how +.Fn chown +operated on older systems, and does not follow symbolic links. +It allows the owner and group of a symbolic link to be set. +.Pp +The +.Fn fchownat +function is equivalent to either the +.Fn chown +or +.Fn lchown +function depending on the value of +.Fa flag +(see below), except that where +.Fa path +specifies a relative path, +the file whose ownership is changed is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn fchownat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn chown +or +.Fn lchown , +depending on whether or not the +.Dv AT_SYMLINK_NOFOLLOW +bit is set in +.Fa flag . +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the ownership of the symbolic link is changed. +.El +.Pp +.Fn fchown +is particularly useful when used in conjunction +with the file locking primitives (see +.Xr flock 2 ) . +.Pp +One of the owner or group IDs +may be left unchanged by specifying it as \-1. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn chown , +.Fn lchown , +and +.Fn fchownat +will fail and the file or link 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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 superuser. +.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 +Additionally, +.Fn fchownat +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_SYMLINK_NOFOLLOW . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.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 superuser. +.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 , +.Fn fchown , +.Fn fchownat , +and +.Fn lchown +functions are expected to conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn chown +system call first appeared in +.At v1 . +Since +.At v6 +it supports changing the group as well, +and in +.At v7 +.Fa group +was made a separate argument. +.Pp +The +.Fn fchown +system call first appeared in +.Bx 4.1c . +.Pp +The +.Fn chown +and +.Fn fchown +system calls were changed to follow symbolic links in +.Bx 4.4 ; +therefore, and for compatibility with +.At V.4 , +the +.Fn lchown +system call was added to +.Ox 2.1 . +.Pp +The +.Fn fchownat +system call has been available since +.Ox 5.0 . diff --git a/static/openbsd/man2/chroot.2 b/static/openbsd/man2/chroot.2 new file mode 100644 index 00000000..d9378c85 --- /dev/null +++ b/static/openbsd/man2/chroot.2 @@ -0,0 +1,123 @@ +.\" $OpenBSD: chroot.2,v 1.24 2022/03/31 17:27:16 naddy Exp $ +.\" $NetBSD: chroot.2,v 1.7 1995/02/27 12:32:12 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: March 31 2022 $ +.Dt CHROOT 2 +.Os +.Sh NAME +.Nm chroot +.Nd change root directory +.Sh SYNOPSIS +.In 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 +If the program is not currently running with an altered root directory, +it should be noted that +.Fn chroot +has no effect on the process's current directory. +.Pp +If the program is already running with an altered root directory, the +process's current directory is changed to the same new root directory. +This prevents the current directory from being further up the directory +tree than the altered root directory. +.Pp +This call is restricted to the superuser. +.Sh RETURN VALUES +.Rv -std +.Sh EXAMPLES +The following example changes the root directory to +.Va newroot , +sets the current directory to the new root, and drops some +setuid privileges. +There may be other privileges which need to be dropped as well. +.Bd -literal -offset indent +#include <err.h> +#include <unistd.h> + +if (chroot(newroot) != 0 || chdir("/") != 0) + err(1, "%s", newroot); +setresuid(getuid(), getuid(), getuid()); +.Ed +.Sh ERRORS +.Fn chroot +will fail and the root directory will be unchanged if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the pathname is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.It Bq Er ENOENT +The named directory does not exist. +.It Bq Er EACCES +Search permission is denied for any component of the pathname. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EFAULT +.Fa dirname +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 EPERM +The caller is not the superuser. +.El +.Sh SEE ALSO +.Xr chdir 2 +.Sh HISTORY +The +.Fn chroot +system call first appeared in +.At v7 . +.Sh CAVEATS +There are ways for a root process to escape from the chroot jail. +Changes to the directory hierarchy made from outside the chroot jail +may allow a restricted process to escape, even if it is unprivileged. +Passing directory file descriptors via +.Xr recvmsg 2 +from outside the chroot jail may also allow a process to escape. diff --git a/static/openbsd/man2/clock_gettime.2 b/static/openbsd/man2/clock_gettime.2 new file mode 100644 index 00000000..0ba8a685 --- /dev/null +++ b/static/openbsd/man2/clock_gettime.2 @@ -0,0 +1,355 @@ +.\" $OpenBSD: clock_gettime.2,v 1.32 2022/03/31 17:27:16 naddy 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. 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 $Mdocdate: March 31 2022 $ +.Dt CLOCK_GETTIME 2 +.Os +.Sh NAME +.Nm clock_gettime , +.Nm clock_settime , +.Nm clock_getres +.Nd get or set the time +.Sh SYNOPSIS +.In time.h +.Ft int +.Fn clock_gettime "clockid_t clock" "struct timespec *now" +.Ft int +.Fn clock_settime "clockid_t clock" "const struct timespec *now" +.Ft int +.Fn clock_getres "clockid_t clock" "struct timespec *res" +.Sh DESCRIPTION +The +.Fn clock_gettime +function reads the given +.Fa clock +and writes its absolute value to +.Fa now . +The +.Fa clock +may be a value returned by +.Xr clock_getcpuclockid 3 +or +.Xr pthread_getcpuclockid 3 , +or any of the following constants: +.Bl -tag -width CLOCK_MONOTONIC +.It Dv CLOCK_REALTIME +The Coordinated Universal Time +.Pq UTC +clock. +Its absolute value is the time elapsed since +Jan 1 1970 00:00:00 UTC +.Pq the Epoch . +The clock normally advances continuously, +though it may jump discontinuously if a process calls +.Xr settimeofday 2 +or +.Fn clock_settime +.Pq see below . +.It Dv CLOCK_MONOTONIC +The monotonic clock. +Its absolute value is meaningless. +The clock begins at an undefined positive point and advances continuously. +.It Dv CLOCK_BOOTTIME +The uptime clock. +Its absolute value is the time elapsed since the system booted. +The clock begins at zero and advances continuously. +.It Dv CLOCK_UPTIME +The runtime clock. +Its absolute value is the time elapsed since the system booted +less any time the system was suspended. +The clock begins at zero and advances while the system is not suspended. +.It Dv CLOCK_PROCESS_CPUTIME_ID +The process CPU clock. +Its absolute value begins at zero and advances while the calling process +is running in user or kernel mode. +.It Dv CLOCK_THREAD_CPUTIME_ID +The thread CPU clock. +Its absolute value begins at zero and advances while the calling thread +is running in user or kernel mode. +.El +.Pp +The +.Fn clock_settime +function sets the given +.Fa clock +to the absolute value +.Fa now . +Only the +.Dv CLOCK_REALTIME +clock may be set and only the superuser may set it. +If the system +.Xr securelevel 7 +is 2 or greater, the time may only be advanced. +This limitation is imposed to prevent a malicious superuser +from setting arbitrary timestamps on files. +.Pp +The +.Fn clock_getres +function retrieves the resolution of the given +.Fa clock +and writes it to +.Fa res +if +.Fa res +is +.Pf non- Dv NULL . +The +.Fa clock +may be any of the clocks accepted by +.Fn clock_gettime +as described earlier. +.Pp +The +.Fa now +and +.Fa res +arguments are +.Dv timespec +structures as defined in +.In sys/time.h : +.Bd -literal -offset indent +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +.Ed +.Sh RETURN VALUES +.Rv -std +.Sh EXAMPLES +Use the +.Dv CLOCK_REALTIME +clock to determine the time of day. +Its absolute value can be passed to functions like +.Xr gmtime 3 +and +.Xr strftime 3 +to produce a human-readable string: +.Bd -literal -offset indent +char str[64]; +struct timespec now; +struct tm *tmbuf; + +clock_gettime(CLOCK_REALTIME, &now); +tmbuf = gmtime(&now.tv_sec); +if (tmbuf == NULL) + err(1, "gmtime"); +if (strftime(str, sizeof(str), "%a %b %e %T %Y %Z", tmbuf) == 0) + err(1, "strftime"); +printf("%s (%lld.%09ld seconds since the Epoch)\\n", + str, (long long)now.tv_sec, now.tv_nsec); +.Ed +.Pp +Use the +.Dv CLOCK_MONOTONIC +clock to measure elapsed time. +The +.Xr timespecsub 3 +function simplifies arithmetic operations on +.Dv timespec +structures: +.Bd -literal -offset indent +struct timespec elapsed, start, stop, timeout; + +timeout.tv_sec = 2; +timeout.tv_nsec = 500000000; + +clock_gettime(CLOCK_MONOTONIC, &start); +nanosleep(&timeout, NULL); +clock_gettime(CLOCK_MONOTONIC, &stop); + +timespecsub(&stop, &start, &elapsed); +printf("nanosleep: expected %lld.%09ld actual %lld.%09ld\\n", + (long long)timeout.tv_sec, timeout.tv_nsec, + (long long)elapsed.tv_sec, elapsed.tv_nsec); +.Ed +.Pp +Use the +.Dv CLOCK_PROCESS_CPUTIME_ID +or +.Dv CLOCK_THREAD_CPUTIME_ID +clocks to measure CPU time instead of elapsed time: +.Bd -literal -offset indent +struct timespec cputime, start, stop; +volatile int i; + +clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); +for (i = 0; i < INT_MAX; i++) + continue; +clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop); + +timespecsub(&stop, &start, &cputime); +printf("CPU time: %lld.%09lds\\n", + (long long)cputime.tv_sec, cputime.tv_nsec); +.Ed +.Pp +How much time has elapsed since the system booted? +Has the system been suspended for any of that time? +.Bd -literal -offset indent +struct timespec diff, total, running; + +clock_gettime(CLOCK_BOOTTIME, &total); +clock_gettime(CLOCK_UPTIME, &running); +timespecsub(&total, &running, &diff); + +printf("Seconds since boot: %8lld.%09ld\\n", + (long long)total.tv_sec, total.tv_nsec); +printf("Seconds suspended: %8lld.%09ld\\n", + (long long)diff.tv_sec, diff.tv_nsec); +.Ed +.Pp +Set the +.Dv CLOCK_REALTIME +clock to Jan 1 00:00:00 2000 UTC: +.Bd -literal -offset indent +struct tm y2k; +struct timespec ts; + +y2k.tm_year = 100; /* 2000 */ +y2k.tm_mon = 0; /* January */ +y2k.tm_mday = 1; +y2k.tm_hour = 0; +y2k.tm_min = 0; +y2k.tm_sec = 0; + +ts.tv_nsec = 0; +ts.tv_sec = timegm(&y2k); +if (ts.tv_sec == -1) + err(1, "timegm"); + +if (clock_settime(CLOCK_REALTIME, &ts) == -1) + err(1, "clock_settime"); +.Ed +.Sh ERRORS +.Fn clock_gettime , +.Fn clock_settime , +and +.Fn clock_getres +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa clock +is invalid. +.It Bq Er EFAULT +.Fa now +or +.Fa res +reference invalid memory. +.El +.Pp +In addition, +.Fn clock_settime +may return the following errors: +.Bl -tag -width Er +.It Bq Er EPERM +A user other than the superuser attempted to set the time. +.It Bq Er EINVAL +The +.Fa clock +is not +.Dv CLOCK_REALTIME . +.It Bq Er EINVAL +.Fa now +specifies a nanosecond value less than zero or greater than or equal to +one billion. +.It Bq Er EINVAL +.Fa now +specifies a value outside the range of the given +.Fa clock . +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr adjtime 2 , +.Xr getitimer 2 , +.Xr gettimeofday 2 , +.Xr clock_getcpuclockid 3 , +.Xr ctime 3 , +.Xr pthread_getcpuclockid 3 , +.Xr strftime 3 , +.Xr time 3 , +.Xr timespecadd 3 , +.Xr securelevel 7 +.Sh STANDARDS +The +.Fn clock_gettime , +.Fn clock_settime , +and +.Fn clock_getres +functions conform to +.St -p1003.1-2008 . +.Pp +The +.Dv CLOCK_BOOTTIME +and +.Dv CLOCK_UPTIME +clocks are extensions to that specification. +.Sh HISTORY +The +.Fn clock_gettime , +.Fn clock_settime , +and +.Fn clock_getres +functions and the +.Dv CLOCK_REALTIME +clock first appeared in +.St -p1003.1b-93 +and were first available in +.Ox 2.1 . +.Pp +The +.Dv CLOCK_MONOTONIC +clock first appeared in +IEEE Std 1003.1j-2000 +.Pq Qo POSIX.1j Qc +and was first available in +.Ox 3.4 . +.Pp +The +.Dv CLOCK_PROCESS_CPUTIME_ID +and +.Dv CLOCK_THREAD_CPUTIME_ID +clocks first appeared in +IEEE Std 1003.1d-1999 +.Pq Qo POSIX.1d Qc +and were first available in +.Ox 5.4 . +.Pp +The +.Dv CLOCK_UPTIME +clock first appeared in +.Fx 7.0 +and was first available in +.Ox 5.5 . +.Pp +The +.Dv CLOCK_BOOTTIME +clock first appeared in +Linux 2.6.39 +and was first available in +.Ox 6.3 . diff --git a/static/openbsd/man2/close.2 b/static/openbsd/man2/close.2 new file mode 100644 index 00000000..d75d5a05 --- /dev/null +++ b/static/openbsd/man2/close.2 @@ -0,0 +1,133 @@ +.\" $OpenBSD: close.2,v 1.19 2022/04/15 03:04:52 deraadt Exp $ +.\" $NetBSD: close.2,v 1.5 1995/02/27 12:32:14 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: April 15 2022 $ +.Dt CLOSE 2 +.Os +.Sh NAME +.Nm close +.Nd delete a descriptor +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn close "int d" +.Sh DESCRIPTION +The +.Fn close +call deletes a descriptor +.Fa d +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; +and on the last close of a file holding an advisory lock, +the lock is released (see +.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 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 image is to then 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 since some of these descriptors may still +be needed should the +.Xr execve 2 +fail, it is necessary to arrange for them +to be closed when the +.Xr execve 2 +succeeds. +For this reason, the call +.Fn fcntl d F_SETFD FD_CLOEXEC +is provided, +which arranges that a descriptor will be closed after a successful +.Xr execve 2 ; +the call +.Fn fcntl d F_SETFD 0 +restores the default, +which is to not close the descriptor. +.Sh RETURN VALUES +.Rv -std +.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. +.It Bq Er EIO +An I/O error occurred while writing to the file system. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr closefrom 2 , +.Xr dup2 2 , +.Xr execve 2 , +.Xr fcntl 2 , +.Xr flock 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr socket 2 , +.Xr socketpair 2 +.Sh STANDARDS +.Fn close +conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn close +system call first appeared in +.At v1 . diff --git a/static/openbsd/man2/closefrom.2 b/static/openbsd/man2/closefrom.2 new file mode 100644 index 00000000..f1166083 --- /dev/null +++ b/static/openbsd/man2/closefrom.2 @@ -0,0 +1,67 @@ +.\" $OpenBSD: closefrom.2,v 1.10 2019/05/31 18:36:58 cheloha Exp $ +.\" +.\" Copyright (c) 2004 Ted Unangst. 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 $Mdocdate: May 31 2019 $ +.Dt CLOSEFROM 2 +.Os +.Sh NAME +.Nm closefrom +.Nd delete many descriptors +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn closefrom "int fd" +.Sh DESCRIPTION +The +.Fn closefrom +call deletes all descriptors numbered +.Fa fd +and higher from the per-process file descriptor table. +It is effectively the same as calling +.Xr close 2 +on each descriptor. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn closefrom +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is greater than all open file descriptors. +.It Bq Er EINTR +An interrupt was received. +.El +.Sh SEE ALSO +.Xr close 2 +.Sh STANDARDS +.Fn closefrom +is a +.Bx +and Solaris extension. +.Sh HISTORY +The +.Fn closefrom +function first appeared in Solaris 9 and has been available since +.Ox 3.5 . diff --git a/static/openbsd/man2/connect.2 b/static/openbsd/man2/connect.2 new file mode 100644 index 00000000..149c9a93 --- /dev/null +++ b/static/openbsd/man2/connect.2 @@ -0,0 +1,257 @@ +.\" $OpenBSD: connect.2,v 1.34 2019/06/20 14:19:25 deraadt Exp $ +.\" $NetBSD: connect.2,v 1.8 1995/10/12 15:40:48 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: June 20 2019 $ +.Dt CONNECT 2 +.Os +.Sh NAME +.Nm connect +.Nd initiate a connection on a socket +.Sh SYNOPSIS +.In 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. +.Fa namelen +indicates the amount of space pointed to by +.Fa name , +in bytes; the +.Fa sa_len +member of +.Fa name +is ignored. +Each communications space interprets the +.Fa name +parameter in its own way. +Generally, stream sockets may use +.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. +.Pp +If the socket is in non-blocking mode and the connection cannot be +completed immediately, or if it is interrupted by a signal, +.Fn connect +will return an error and the connection attempt will proceed +asynchronously. +Subsequent calls to +.Fn connect +will fail with errno set to +.Er EALREADY . +It is possible to use +.Xr select 2 +or +.Xr poll 2 +to determine when the connect operation has completed by checking the +socket for writability. +The success or failure of the connection attempt may be determined by using +.Xr getsockopt 2 +to check the socket error status with the +.Dv SO_ERROR +option at the +.Dv SOL_SOCKET +level. +If the connection was successful, the error value will be zero. +Otherwise, it will be one of the error values listed below. +.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 EXAMPLES +The following code connects to the host described by +.Fa name +and handles the case where +.Fn connect +is interrupted by a signal. +.Bd -literal -offset indent +#include <sys/socket.h> +#include <poll.h> +#include <errno.h> +#include <err.h> + +int +connect_wait(int s) +{ + struct pollfd pfd[1]; + int error = 0; + socklen_t len = sizeof(error); + + pfd[0].fd = s; + pfd[0].events = POLLOUT; + + if (poll(pfd, 1, -1) == -1) + return -1; + if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &len) == -1) + return -1; + if (error != 0) { + errno = error; + return -1; + } + return 0; +} + +\&... + +int retcode; + +\&... + +for (retcode = connect(s, name, namelen); + retcode == -1 && errno == EINTR; + retcode = connect_wait(s)) + continue; +if (retcode == -1) + err(1, "connect"); +.Ed +.Sh ERRORS +The +.Fn connect +call fails if: +.Bl -tag -width Er +.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 +No suitable address is available on the local 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 EINVAL +A TCP connection with a local broadcast, the all-ones or a +multicast address as the peer was attempted. +.It Bq Er ECONNREFUSED +The attempt to connect was forcefully rejected. +.It Bq Er EHOSTUNREACH +The destination address specified an unreachable host. +.It Bq Er EINTR +The connection attempt was interrupted by a signal. +The attempt will continue asynchronously as if the socket was non-blocking. +.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 Bq Er EALREADY +Either the socket is non-blocking or a previous call to +.Fn connect +was interrupted by a signal, and the connection attempt has not yet +been completed. +.It Bq Er EPERM +A TCP connection on a socket with socket option TCP_MD5SIG was +attempted without configuring the security parameters correctly. +.El +.Pp +The following errors are specific to connecting names in the +.Ux Ns -domain . +These errors may not apply in future versions of the +.Ux +IPC domain. +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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. +.It Bq Er EPROTOTYPE +The file described by +.Fa name +is of a different type than +.Fa s . +E.g., +.Fa s +may be of type +.Dv SOCK_STREAM +whereas +.Fa name +may refer to a socket of type +.Dv SOCK_DGRAM . +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr getsockname 2 , +.Xr getsockopt 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr socket 2 +.Sh STANDARDS +The +.Fn connect +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn connect +system call first appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/csh.2 b/static/openbsd/man2/csh.2 new file mode 100644 index 00000000..af767ea3 --- /dev/null +++ b/static/openbsd/man2/csh.2 @@ -0,0 +1,1302 @@ +.\" $OpenBSD: csh.2,v 1.12 2010/12/23 08:54:59 jmc Exp $ +.\" $NetBSD: csh.2,v 1.3 1995/03/21 09:03:35 cgd Exp $ +.\" +.\" 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. 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. +.\" +.\" @(#)csh.2 8.1 (Berkeley) 6/8/93 +.\" +.nr H1 1 +.NH +Details on the shell for terminal users +.NH 2 +Shell startup and termination +.PP +When you login, the shell is started by the system in your +.I home +directory and begins by reading commands from a file +.I \&.cshrc +in this directory. +All shells which you may start during your terminal session will +read from this file. +We will later see what kinds of commands are usefully placed there. +For now we need not have this file and the shell does not complain about +its absence. +.PP +A +.I "login shell" , +executed after you login to the system, +will, after it reads commands from +.I \&.cshrc , +read commands from a file +.I \&.login +also in your home directory. +This file contains commands which you wish to do each time you log in +to the UNIX system. +My +.I \&.login +file looks something like: +.DS +set ignoreeof +set mail=(/usr/spool/mail/bill) +echo "${prompt}users" ; users +alias ts \e + \'set noglob ; eval \`tset \-s \-m dialup:c100rv4pna \-m plugboard:?hp2621nl \!*\`\'; +ts; stty intr ^C kill ^U crt +set time=15 history=10 +if (\-e $mail) then + echo "${prompt}mail" + mail +endif +.DE +.PP +This file contains several commands to be executed by UNIX +each time I log in. +The first is a +.I set +command which is interpreted directly by the shell. It sets the shell +variable +.I ignoreeof +which causes the shell to not log me off if I hit ^D. Rather, +I use the +.I logout +command to log off the system. +By setting the +.I mail +variable, I ask the shell to watch for incoming mail to me. Every 5 minutes +the shell looks for this file and tells me if more mail has arrived there. +An alternative to this is to put the command +.DS +biff y +.DE +in place of this +.I set ; +this will cause me to be notified immediately when mail arrives, and to +be shown the first few lines of the new message. +.PP +I create an +.I alias +``ts'' which executes a +tset(1) command setting up the modes of the terminal. +The parameters to +.I tset +indicate the kinds of terminal which I usually use when not on a hardwired +port. I then execute ``ts'' and also use the +.I stty +command to change the interrupt character to ^C and the line kill +character to ^U. +.PP +Next I set the shell variable `time' to `15' causing the shell to automatically +print out statistics lines for commands which execute for at least 15 seconds +of CPU time. The variable `history' is set to 10 indicating that +I want the shell to remember the last 10 commands I type in its +.I "history list" , +(described later). +.PP +Finally, if my mailbox file exists, then I run the `mail' program to +process my mail. +.PP +When the `mail' program finishes, the shell will finish +processing my +.I \&.login +file and begin reading commands from the terminal, prompting for each with +`% '. +When I log off (by giving the +.I logout +command) the shell +will print `logout' and execute commands from the file `.logout' +if it exists in my home directory. +After that the shell will terminate and UNIX will log +me off the system. +If the system is not going down, I will receive a new login message. +In any case, after the `logout' message the shell is committed to terminating +and will take no further input from my terminal. +.NH 2 +Shell variables +.PP +The shell maintains a set of +.I variables . +We saw above the variables +.I history +and +.I time +which had values `10' and `15'. +In fact, each shell variable has as value an array of +zero or more +.I strings . +Shell variables may be assigned values by the set command. It has +several forms, the most useful of which was given above and is +.DS +set name=value +.DE +.PP +Shell variables may be used to store values which are to +be used in commands later through a substitution mechanism. +The shell variables most commonly referenced are, however, those which the +shell itself refers to. +By changing the values of these variables one can directly affect the +behavior of the shell. +.PP +One of the most important variables is the variable +.I path . +This variable contains a sequence of directory names where the shell +searches for commands. +The +.I set +command with no arguments +shows the value of all variables currently defined (we usually say +.I set ) +in the shell. +The default value for path will be shown by +.I set +to be +.DS +% set +.ta .75i +argv () +cwd /home/bill +home /home/bill +path (/bin /usr/bin .) +prompt % +shell /bin/csh +status 0 +term c100rv4pna +user bill +% +.so tabs +.DE +This output indicates that the variable path points to +`/bin', `/usr/bin', and the current directory `.'. +Commands which you may write might be in `.' (usually one of +your directories). +.\" Commands developed at Berkeley live in `/usr/ucb', +.\" while commands developed at Bell Laboratories live in `/bin' and `/usr/bin'. +Other commands may live in /bin and /usr/bin. +.PP +A number of locally developed programs on the system live in the directory +`/usr/local/bin'. +If we wish that all shells which we invoke to have +access to these new programs we can place the command +.DS +set path=(/bin /usr/bin /usr/local/bin .) +.DE +in our file +.I \&.cshrc +in our home directory. +Try doing this and then logging out and back in and do +.DS +set +.DE +again to see that the value assigned to +.I path +has changed. +.\" .FS \(dg +.\" Another directory that might interest you is /usr/new, which contains +.\" many useful user-contributed programs provided with Berkeley Unix. +.\" .FE +.PP +One thing you should be aware of is that the shell examines each directory +which you insert into your path and determines which commands are contained +there. Except for the current directory `.', which the shell treats specially, +this means that if commands are added to a directory in your search path after +you have started the shell, they will not necessarily be found by the shell. +If you wish to use a command which has been added in this way, you should +give the command +.DS +rehash +.DE +to the shell, which will cause it to recompute its internal table of command +locations, so that it will find the newly added command. +Since the shell has to look in the current directory `.' on each command, +placing it at the end of the path specification usually works equivalently +and reduces overhead. +.PP +Other useful built in variables are the variable +.I home , +which shows your home directory; +.I cwd , +which contains your current working directory; +and the variable +.I ignoreeof , +which can be set in your +.I \&.login +file to tell the shell not to exit when it receives an end-of-file from +a terminal (as described above). +The variable `ignoreeof' +is one of several variables which the shell does not care about the +value of, only whether they are +.I set +or +.I unset . +Thus to set this variable you simply do +.DS +set ignoreeof +.DE +and to unset it do +.DS +unset ignoreeof +.DE +These give the variable `ignoreeof' no value, but none is desired or required. +.PP +Finally, some other built-in shell variables of use are the +variables +.I noclobber +and +.I mail . +The metasyntax +.DS +> filename +.DE +which redirects the standard output of a command, +will overwrite and destroy the previous contents of the named file. +In this way you may accidentally overwrite a file which is valuable. +If you would prefer that the shell not overwrite files in this +way you can +.DS +set noclobber +.DE +in your +.I \&.login +file. +Then trying to do +.DS +date > now +.DE +would cause a diagnostic if `now' existed already. +You could type +.DS +date >! now +.DE +if you really wanted to overwrite the contents of `now'. +The `>!' is a special metasyntax indicating that clobbering the +file is ok.\(dg +.FS +\(dgThe space between the `!' and the word `now' is critical here, as `!now' +would be an invocation of the +.I history +mechanism, and have a totally different effect. +.FE +.NH 2 +The shell's history list +.PP +The shell can maintain a +.I "history list" +into which it places the words +of previous commands. +It is possible to use a notation to reuse commands or words +from commands in forming new commands. +This mechanism can be used to repeat previous commands or to +correct minor typing mistakes in commands. +.PP +The following figure gives a sample session involving typical usage of the +history mechanism of the shell. +.KF +.DS +% cat bug.c +main() + +{ + printf("hello); +} +% cc !$ +cc bug.c +bug.c:4: unterminated string or character constant +bug.c:4: possible real start of unterminated constant +% ed !$ +ed bug.c +29 +4s/);/"&/p + printf("hello"); +w +30 +q +% !c +cc bug.c +% a.out +hello% !e +ed bug.c +30 +4s/lo/lo\e\en/p + printf("hello\en"); +w +32 +q +% !c \-o bug +cc bug.c \-o bug +% size a.out bug +text data bss dec hex +1022 208 288 1518 5ee a.out +1022 208 288 1518 5ee bug +% ls \-l !* +ls \-l a.out bug +\(mirwxr\(mixr\(mix 1 bill 3932 Dec 19 09:41 a.out +\(mirwxr\(mixr\(mix 1 bill 3932 Dec 19 09:42 bug +% bug +hello +% cay -n bug.c +cay: Command not found. +% ^cay^cat +cat -n bug.c + 1 main() + 3 { + 4 printf("hello\en"); + 5 } +% !! | lpr +cat -n bug.c | lpr +% +.DE +.KE +In this example we have a very simple C program which has a bug (or two) +in it in the file `bug.c', which we `cat' out on our terminal. We then +try to run the C compiler on it, referring to the file again as `!$', +meaning the last argument to the previous command. Here the `!' is the +history mechanism invocation metacharacter, and the `$' stands for the last +argument, by analogy to `$' in the editor which stands for the end of the line. +The shell echoed the command, as it would have been typed without use of +the history mechanism, and then executed it. +The compilation yielded error diagnostics so we now run the editor on the +file we were trying to compile, fix the bug, and run the C compiler again, +this time referring to this command simply as `!c', which repeats the last +command which started with the letter `c'. If there were other +commands starting with `c' done recently we could have said `!cc' or even +`!cc:p' which would have printed the last command starting with `cc' +without executing it. +.PP +After this recompilation, we ran the resulting `a.out' file, and then +noting that there still was a bug, ran the editor again. After fixing +the program we ran the C compiler again, but tacked onto the command +an extra `\-o bug' telling the compiler to place the resultant binary in +the file `bug' rather than `a.out'. In general, the history mechanisms +may be used anywhere in the formation of new commands and other characters +may be placed before and after the substituted commands. +.PP +We then ran the `size' command to see how large the binary program images +we have created were, and then an `ls \-l' command with the same argument +list, denoting the argument list `\!*'. +Finally we ran the program `bug' to see that its output is indeed correct. +.PP +To make a numbered listing of the program we ran the `cat' command on the file `bug.c', with the `-n' flag. +Unfortunately, we mispelled `cat' as `cay'. +To correct this +we used a shell substitute, placing the old text and new text between `^' +characters. This is similar to the substitute command in the editor. +Finally, we repeated the same command with `!!', but sent its output to the +line printer. +.PP +There are other mechanisms available for repeating commands. The +.I history +command prints out a number of previous commands with numbers by which +they can be referenced. There is a way to refer to a previous command +by searching for a string which appeared in it, and there are other, +less useful, ways to select arguments to include in a new command. +A complete description of all these mechanisms +is given in the C shell manual pages in the UNIX Programmer's Manual. +.NH 2 +Aliases +.PP +The shell has an +.I alias +mechanism which can be used to make transformations on input commands. +This mechanism can be used to simplify the commands you type, +to supply default arguments to commands, +or to perform transformations on commands and their arguments. +The alias facility is similar to a macro facility. +Some of the features obtained by aliasing can be obtained also +using shell command files, but these take place in another instance +of the shell and cannot directly affect the current shells environment +or involve commands such as +.I cd +which must be done in the current shell. +.PP +As an example, suppose that there is a new version of the mail program +on the system called `newmail' +you wish to use, rather than the standard mail program which is called +`mail'. +If you place the shell command +.DS +alias mail newmail +.DE +in your +.I \&.cshrc +file, the shell will transform an input line of the form +.DS +mail bill +.DE +into a call on `newmail'. +More generally, suppose we wish the command `ls' to always show +sizes of files, that is, to always do `\-s'. +We can do +.DS +alias ls ls \-s +.DE +or even +.DS +alias dir ls \-s +.DE +creating a new command syntax `dir' +which does an `ls \-s'. +If we say +.DS +dir ~bill +.DE +then the shell will translate this to +.DS +ls \-s /home/bill +.DE +.PP +Thus the +.I alias +mechanism can be used to provide short names for commands, +to provide default arguments, +and to define new short commands in terms of other commands. +It is also possible to define aliases which contain multiple +commands or pipelines, showing where the arguments to the original +command are to be substituted using the facilities of the +history mechanism. +Thus the definition +.DS +alias cd \'cd \e!* ; ls \' +.DE +would do an +.I ls +command after each change directory +.I cd +command. +We enclosed the entire alias definition in `\'' characters to prevent +most substitutions from occurring and the character `;' from being +recognized as a metacharacter. +The `!' here is escaped with a `\e' to prevent it from being interpreted +when the alias command is typed in. +The `\e!*' here substitutes the entire argument list to the pre-aliasing +.I cd +command, without giving an error if there were no arguments. +The `;' separating commands is used here +to indicate that one command is to be done and then the next. +Similarly the definition +.DS +alias whois \'grep \e!^ /etc/passwd\' +.DE +defines a command which looks up its first argument in the password file. +.PP +.B Warning: +The shell currently reads the +.I \&.cshrc +file each time it starts up. If you place a large number of commands +there, shells will tend to start slowly. A mechanism for saving the shell +environment after reading the \fI\&.cshrc\fR file and quickly restoring it is +under development, but for now you should try to limit the number of +aliases you have to a reasonable number... 10 or 15 is reasonable, +50 or 60 will cause a noticeable delay in starting up shells, and make +the system seem sluggish when you execute commands from within the editor +and other programs. +.NH 2 +More redirection; >> and >& +.PP +There are a few more notations useful to the terminal user +which have not been introduced yet. +.PP +In addition to the standard output, commands also have a +.I "diagnostic output" +which is normally directed to the terminal even when the standard output +is redirected to a file or a pipe. +It is occasionally desirable to direct the diagnostic output along with +the standard output. +For instance if you want to redirect the output of a long running command +into a file and wish to have a record of any error diagnostic it produces +you can do +.DS +command >& file +.DE +The `>&' here tells the shell to route both the diagnostic output and the +standard output into `file'. +Similarly you can give the command +.DS +command |\|& lpr +.DE +to route both standard and diagnostic output through the pipe +to the line printer daemon +.I lpr .\(dd +.FS +\(dd A command of the form +.br +.ti +5 +command >&! file +.br +exists, and is used when +.I noclobber +is set and +.I file +already exists. +.FE +.PP +Finally, it is possible to use the form +.DS +command >> file +.DE +to place output at the end of an existing file.\(dg +.FS +\(dg If +.I noclobber +is set, then an error will result if +.I file +does not exist, otherwise the shell will create +.I file +if it doesn't exist. +A form +.br +.ti +5 +command >>! file +.br +makes it not be an error for file to not exist when +.I noclobber +is set. +.FE +.NH 2 +Jobs; Background, Foreground, or Suspended +.PP +When one or more commands +are typed together as a pipeline or as a sequence of commands separated by +semicolons, a single +.I job +is created by the shell consisting of these commands together as a unit. +Single commands without pipes or semicolons create the simplest jobs. +Usually, every line typed to the shell creates a job. +Some lines that create jobs (one per line) are +.DS +sort < data +ls \-s | sort \-n | head \-5 +mail harold +.DE +.PP +If the metacharacter `&' is typed +at the end of the commands, then the job is started as a +.I background +job. This means that the shell does not wait for it to complete but +immediately prompts and is ready for another command. The job runs +.I "in the background" +at the same time that normal jobs, called +.I foreground +jobs, continue to be read and executed by the shell one at a time. +Thus +.DS +du > usage & +.DE +would run the +.I du +program, which reports on the disk usage of your working directory (as well as +any directories below it), put the output into the file `usage' and return +immediately with a prompt for the next command without waiting for +.I du +to finish. The +.I du +program would continue executing in the background +until it finished, even though you can type and execute more commands in the +meantime. +When a background +job terminates, a message is typed by the shell just before the next prompt +telling you that the job has completed. +In the following example the +.I du +job finishes sometime during the +execution of the +.I mail +command and its completion is reported just before +the prompt after the +.I mail +job is finished. +.DS +% du > usage & +[1] 503 +% mail bill +How do you know when a background job is finished? +EOT +.ta 1.75i +[1] \- Done du > usage +% +.so tabs +.DE +If the job did not terminate normally, the `Done' message might say +something else like `Killed'. +If you want the +terminations of background jobs to be reported at the time they occur +(possibly interrupting the output of other foreground jobs), you can set +the +.I notify +variable. In the previous example this would mean that the +`Done' message might have come right in the middle of the message to +Bill. +Background jobs are unaffected by any signals from the keyboard like +the STOP, INTERRUPT, or QUIT signals mentioned earlier. +.PP +Jobs are recorded in a table inside the shell until they terminate. +In this table, the shell remembers the command names, arguments, and the +.I "process numbers" +of all commands in the job, as well as the working directory where the job was +started. +Each job in the table is either running +.I "in the foreground" +with the shell waiting for it to terminate, running +.I "in the background" , +or +.I suspended . +Only one job can be running in the foreground at one time, but several +jobs can be suspended or running in the background at once. As each job +is started, it is assigned a small identifying +number called the +.I "job number" +which can be used later to refer to the job in the commands described below. +Job numbers remain +the same until the job terminates and then are re-used. +.PP +When a job is started in the background using `&', its number, as well +as the process numbers of all its (top level) commands, is typed by the shell +before prompting you for another command. For example, +.DS +% ls \-s | sort \-n > usage & +[2] 2034 2035 +% +.DE +runs the `ls' program with the `\-s' option, pipes this output into +the `sort' program with the `\-n' option, which puts its output into the +file `usage'. +Since the `&' was at the end of the line, these two programs were started +together as a background job. After starting the job, the shell prints +the job number in brackets (2 in this case) followed by the process number +of each program started in the job. Then the shell immediately prompts for +a new command, leaving the job running simultaneously. +.PP +As mentioned in section 1.8, foreground jobs become +.I suspended +by typing ^Z, +which sends a STOP signal to the currently running +foreground job. A background job can become suspended by using the +.I stop +command described below. When jobs are suspended they merely stop +any further progress until started again, either in the foreground +or the background. The shell notices when a job becomes stopped and +reports this fact, much like it reports the termination of background jobs. +For foreground jobs this looks like +.DS +% du > usage +^Z +Suspended +% +.DE +The `Suspended' message is typed by the shell when it notices that the +.I du +program stopped. +For background jobs, using the +.I stop +command, it is +.DS +% sort usage & +[1] 2345 +% stop %1 +.ta 1.75i +[1] + Suspended (signal) sort usage +% +.so tabs +.DE +Suspending foreground jobs can be very useful when you need to temporarily +change what you are doing (execute other commands) and then return to +the suspended job. Also, foreground jobs can be suspended and then +continued as background jobs using the +.I bg +command, allowing you to continue other work and +stop waiting for the foreground job to finish. Thus +.DS +% du > usage +^Z +Stopped +% bg +[1] du > usage & +% +.DE +starts `du' in the foreground, stops it before it finishes, then continues +it in the background allowing more foreground commands to be executed. +This is especially helpful +when a foreground job ends up taking longer than you expected and you +wish you had started it in the background in the beginning. +.PP +All +.I "job control" +commands can take an argument that identifies a particular +job. +All job name arguments begin with the character `%', since some of the +job control commands also accept process numbers (printed by the +.I ps +command). +The default job (when no argument is given) is called the +.I current +job and is identified by a `+' in the output of the +.I jobs +command, which shows you which jobs you have. +When only one job is stopped or running in the background (the usual case) +it is always the current job; thus no argument is needed. +If a job is stopped while running in the foreground it becomes the +.I current +job and the existing current job becomes the +.I previous +job \- identified by a `\-' in the output of +.I jobs . +When the current job terminates, the previous job becomes the current job. +When given, the argument is either `%\-' (indicating +the previous job); `%#', where # is the job number; +`%pref' where pref is some unique prefix of the command name +and arguments of one of the jobs; or `%?' followed by some string found +in only one of the jobs. +.PP +The +.I jobs +command types the table of jobs, giving the job number, +commands and status (`Suspended' or `Running') of each background or +suspended job. With the `\-l' option the process numbers are also +typed. +.DS +% du > usage & +[1] 3398 +% ls \-s | sort \-n > myfile & +[2] 3405 +% mail bill +^Z +Stopped +% jobs +.ta 1.75i +[1] \(mi Running du > usage +[2] Running ls \-s | sort \-n > myfile +[3] \(pl Suspended mail bill +% fg %ls +ls \-s | sort \-n > myfile +% more myfile +.so tabs +.DE +.PP +The +.I fg +command runs a suspended or background job in the foreground. It is +used to restart a previously suspended job or change a background job +to run in the foreground (allowing signals or input from the terminal). +In the above example we used +.I fg +to change the `ls' job from the +background to the foreground since we wanted to wait for it to +finish before looking at its output file. +The +.I bg +command runs a suspended job in the background. It is usually used +after stopping the currently running foreground job with the +STOP signal. The combination of the STOP signal and the +.I bg +command changes a foreground job into a background job. +The +.I stop +command suspends a background job. +.PP +The +.I kill +command terminates a background or suspended job immediately. +In addition to jobs, it may be given process numbers as arguments, +as printed by +.I ps. +Thus, in the example above, the running +.I du +command could have been terminated by the command +.DS +% kill %1 +.ta 1.75i +[1] Terminated du > usage +% +.so tabs +.DE +.PP +The +.I notify +command (not the variable mentioned earlier) indicates that the termination +of a specific job should be +reported at the time it finishes instead of waiting for the next prompt. +.PP +If a job running in the background tries to read input from the terminal +it is automatically stopped. When such a job is then run in the +foreground, input can be given to the job. If desired, the job can +be run in the background again until it requests input again. +This is illustrated in the following sequence where the `s' command in the +text editor might take a long time. +.ID +.nf +% ed bigfile +120000 +1,$s/thisword/thatword/ +^Z +Suspended +% bg +[1] ed bigfile & +% + . . . some foreground commands +.ta 1.75i +[1] Suspended (tty input) ed bigfile +% fg +ed bigfile +w +120000 +q +% +.so tabs +.DE +So after the `s' command was issued, the `ed' job was stopped with ^Z +and then put in the background using +.I bg . +Some time later when the `s' command was finished, +.I ed +tried to read another command and was stopped because jobs +in the background cannot read from the terminal. The +.I fg +command returned the `ed' job to the foreground where it could once again +accept commands from the terminal. +.PP +The command +.DS +stty tostop +.DE +causes all background jobs run on your terminal to stop +when they are about to +write output to the terminal. This prevents messages from background +jobs from interrupting foreground job output and allows you to run +a job in the background without losing terminal output. It also +can be used for interactive programs that sometimes have long +periods without interaction. Thus each time it outputs a prompt for more +input it will stop before the prompt. It can then be run in the +foreground using +.I fg , +more input can be given and, if necessary stopped and returned to +the background. This +.I stty +command might be a good thing to put in your +.I \&.login +file if you do not like output from background jobs interrupting +your work. It also can reduce the need for redirecting the output +of background jobs if the output is not very big: +.DS +% stty tostop +% wc hugefile & +[1] 10387 +% ed text +\&. . . some time later +q +.ta 1.75i +[1] Stopped (tty output) wc hugefile +% fg wc +wc hugefile + 13371 30123 302577 +% stty \-tostop +.so tabs +.DE +Thus after some time the `wc' command, which counts the lines, words +and characters in a file, had one line of output. When it tried to +write this to the terminal it stopped. By restarting it in the +foreground we allowed it to write on the terminal exactly when we were +ready to look at its output. +Programs which attempt to change the mode of the terminal will also +block, whether or not +.I tostop +is set, when they are not in the foreground, as +it would be very unpleasant to have a background job change the state +of the terminal. +.PP +Since the +.I jobs +command only prints jobs started in the currently executing shell, +it knows nothing about background jobs started in other login sessions +or within shell files. The +.I ps +command can be used in this case to find out about background jobs not started +in the current shell. +.NH 2 +Working Directories +.PP +As mentioned in section 1.6, the shell is always in a particular +.I "working directory" . +The `change directory' command +.I chdir +(its +short form +.I cd +may also be used) +changes the working directory of the shell, +that is, changes the directory you +are located in. +.PP +It is useful to make a directory for each project you wish to work on +and to place all files related to that project in that directory. +The `make directory' command, +.I mkdir , +creates a new directory. +The +.I pwd +(`print working directory') command +reports the absolute pathname of the working directory of the shell, +that is, the directory you are +located in. +Thus in the example below: +.DS +% pwd +/home/bill +% mkdir newpaper +% chdir newpaper +% pwd +/home/bill/newpaper +% +.DE +the user has created and moved to the +directory +.I newpaper , +where, for example, he might +place a group of related files. +.PP +No matter where you have moved to in a directory hierarchy, +you can return to your `home' login directory by doing just +.DS +cd +.DE +with no arguments. +The name `..' always means the directory above the current one in +the hierarchy; thus +.DS +cd .. +.DE +changes the shell's working directory to the one directly above the +current one. +The name `..' can be used in any +pathname; thus, +.DS +cd ../programs +.DE +means +change to the directory `programs' contained in the directory +above the current one. +If you have several directories for different +projects under, say, your home directory, +this shorthand notation +permits you to switch easily between them. +.PP +The shell always remembers the pathname of its current working directory in +the variable +.I cwd . +The shell can also be requested to remember the previous directory when +you change to a new working directory. If the `push directory' command +.I pushd +is used in place of the +.I cd +command, the shell saves the name of the current working directory +on a +.I "directory stack" +before changing to the new one. +You can see this list at any time by typing the `directories' +command +.I dirs . +.ID +.nf +% pushd newpaper/references +~/newpaper/references ~ +% pushd /usr/lib/tmac +/usr/lib/tmac ~/newpaper/references ~ +% dirs +/usr/lib/tmac ~/newpaper/references ~ +% popd +~/newpaper/references ~ +% popd +~ +% +.DE +The list is printed in a horizontal line, reading left to right, +with a tilde (~) as +shorthand for your home directory\(emin this case `/home/bill'. +The directory stack is printed whenever there is more than one +entry on it and it changes. +It is also printed by a +.I dirs +command. +.I Dirs +is usually faster and more informative than +.I pwd +since it shows the current working directory as well as any +other directories remembered in the stack. +.PP +The +.I pushd +command with no argument +alternates the current directory with the first directory in the +list. +The `pop directory' +.I popd +command without an argument returns you to the directory you were in prior to +the current one, discarding the previous current directory from the +stack (forgetting it). +Typing +.I popd +several times in a series takes you backward through the directories +you had been in (changed to) by the +.I pushd +command. +There are other options to +.I pushd +and +.I popd +to manipulate the contents of the directory stack and to change +to directories not at the top of the stack; see the +.I csh +manual page for details. +.PP +Since the shell remembers the working directory in which each job +was started, it warns you when you might be confused by restarting +a job in the foreground which has a different working directory than the +current working directory of the shell. Thus if you start a background +job, then change the shell's working directory and then cause the +background job to run in the foreground, the shell warns you that the +working directory of the currently running foreground job is different +from that of the shell. +.DS +% dirs \-l +/home/bill +% cd myproject +% dirs +~/myproject +% ed prog.c +1143 +^Z +Suspended +% cd .. +% ls +myproject +textfile +% fg +ed prog.c (wd: ~/myproject) +.DE +This way the shell warns you when there +is an implied change of working directory, even though no cd command was +issued. In the above example the `ed' job was still in `/home/bill/project' +even though the shell had changed to `/home/bill'. +A similar warning is given when such a foreground job +terminates or is suspended (using the STOP signal) since +the return to the shell again implies a change of working directory. +.DS +% fg +ed prog.c (wd: ~/myproject) + . . . after some editing +q +(wd now: ~) +% +.DE +These messages are sometimes confusing if you use programs that change +their own working directories, since the shell only remembers which +directory a job is started in, and assumes it stays there. +The `\-l' option of +.I jobs +will type the working directory +of suspended or background jobs when it is different +from the current working directory of the shell. +.NH 2 +Useful built-in commands +.PP +We now give a few of the useful built-in commands of the shell describing +how they are used. +.PP +The +.I alias +command described above is used to assign new aliases and to show the +existing aliases. +With no arguments it prints the current aliases. +It may also be given only one argument such as +.DS +alias ls +.DE +to show the current alias for, e.g., `ls'. +.PP +The +.I echo +command prints its arguments. +It is often used in +.I "shell scripts" +or as an interactive command +to see what filename expansions will produce. +.PP +The +.I history +command will show the contents of the history list. +The numbers given with the history events can be used to reference +previous events which are difficult to reference using the +contextual mechanisms introduced above. +There is also a shell variable called +.I prompt . +By placing a `!' character in its value the shell will there substitute +the number of the current command in the history list. +You can use this number to refer to this command in a history substitution. +Thus you could +.DS +set prompt=\'\e! % \' +.DE +Note that the `!' character had to be +.I escaped +here even within `\'' characters. +.PP +The +.I limit +command is used to restrict use of resources. +With no arguments it prints the current limitations: +.DS +.ta 1i +cputime unlimited +filesize unlimited +datasize 5616 kbytes +stacksize 512 kbytes +coredumpsize unlimited +.so tabs +.DE +Limits can be set, e.g.: +.DS +limit coredumpsize 128k +.DE +Most reasonable units abbreviations will work; see the +.I csh +manual page for more details. +.PP +The +.I logout +command can be used to terminate a login shell which has +.I ignoreeof +set. +.PP +The +.I rehash +command causes the shell to recompute a table of where commands are +located. This is necessary if you add a command to a directory +in the current shell's search path and wish the shell to find it, +since otherwise the hashing algorithm may tell the shell that the +command wasn't in that directory when the hash table was computed. +.PP +The +.I repeat +command can be used to repeat a command several times. +Thus to make 5 copies of the file +.I one +in the file +.I five +you could do +.DS +repeat 5 cat one >> five +.DE +.PP +The +.I setenv +command can be used +to set variables in the environment. +Thus +.DS +setenv TERM adm3a +.DE +will set the value of the environment variable TERM +to +`adm3a'. +A user program +.I printenv +exists which will print out the environment. +It might then show: +.DS +% printenv +HOME=/home/bill +SHELL=/bin/csh +PATH=:/bin:/usr/bin:/usr/local/bin +TERM=adm3a +USER=bill +% +.DE +.PP +The +.I source +command can be used to force the current shell to read commands from +a file. +Thus +.DS +source .cshrc +.DE +can be used after editing in a change to the +.I \&.cshrc +file which you wish to take effect right away. +.PP +The +.I time +command can be used to cause a command to be timed no matter how much +CPU time it takes. +Thus +.DS +% time cp /etc/rc /home/bill/rc +0.0u 0.1s 0:01 8% 2+1k 3+2io 1pf+0w +% time wc /etc/rc /home/bill/rc + 52 178 1347 /etc/rc + 52 178 1347 /home/bill/rc + 104 356 2694 total +0.1u 0.1s 0:00 13% 3+3k 5+3io 7pf+0w +% +.DE +indicates that the +.I cp +command used a negligible amount of user time (u) +and about 1/10th of a system time (s); the elapsed time was 1 second (0:01), +there was an average memory usage of 2k bytes of program space and 1k +bytes of data space over the CPU time involved (2+1k); the program +did three disk reads and two disk writes (3+2io), and took one page fault +and was not swapped (1pf+0w). +The word count command +.I wc +on the other hand used 0.1 seconds of user time and 0.1 seconds of system +time in less than a second of elapsed time. +The percentage `13%' indicates that over the period when it was active +the command `wc' used an average of 13 percent of the available CPU +cycles of the machine. +.PP +The +.I unalias +and +.I unset +commands can be used +to remove aliases and variable definitions from the shell, and +.I unsetenv +removes variables from the environment. +.NH 2 +What else? +.PP +This concludes the basic discussion of the shell for terminal users. +There are more features of the shell to be discussed here, and all +features of the shell are discussed in its manual pages. +One useful feature which is discussed later is the +.I foreach +built-in command which can be used to run the same command +sequence with a number of different arguments. +.PP +If you intend to use UNIX a lot you should look through +the rest of this document and the csh manual pages (section1) to become familiar +with the other facilities which are available to you. +.bp diff --git a/static/openbsd/man2/dup.2 b/static/openbsd/man2/dup.2 new file mode 100644 index 00000000..82831ae9 --- /dev/null +++ b/static/openbsd/man2/dup.2 @@ -0,0 +1,217 @@ +.\" $OpenBSD: dup.2,v 1.21 2025/08/04 04:59:31 guenther Exp $ +.\" $NetBSD: dup.2,v 1.4 1995/02/27 12:32:21 cgd 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. 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 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt DUP 2 +.Os +.Sh NAME +.Nm dup , +.Nm dup2 , +.Nm dup3 +.Nd duplicate an existing file descriptor +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn dup "int oldd" +.Ft int +.Fn dup2 "int oldd" "int newd" +.In fcntl.h +.In unistd.h +.Ft int +.Fn dup3 "int oldd" "int newd" "int flags" +.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 3 . +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 and close-on-fork flags on the new file descriptor +are unset. +.Pp +In +.Fn dup2 , +the value of the new descriptor +.Fa newd +is specified. +If this descriptor is already in use, it is first deallocated as if a +.Xr close 2 +call had been done first. +When +.Fa newd +equals +.Fa oldd , +.Fn dup2 +just returns without affecting the close-on-exec or close-on-fork flags. +.Pp +In +.Fn dup3 , +the value of the new descriptor and the close-on-exec and close-on-fork +flags on +the new file descriptor are all specified: +.Fa newd +specifies the value and the +.Dv O_CLOEXEC +and +.Dv O_CLOFORK +bits in +.Fa flags +specify the close-on-exec and close-on-forks flag, respectively. +Unlike +.Fn dup2 , +if +.Fa oldd +and +.Fa newd +are equal then +.Fn dup3 +fails. +Otherwise, if +.Fa flags +is zero then +.Fn dup3 +is identical to a call to +.Fn dup2 . +.Sh RETURN VALUES +Upon successful completion, the value of the new descriptor is returned. +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 +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa oldd +is not a valid active descriptor. +.It Bq Er EMFILE +Too many descriptors are active. +.El +.Pp +.Fn dup2 +and +.Fn dup3 +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa oldd +is not a valid active descriptor or +.Fa newd +is negative or greater than or equal to the process's +.Dv RLIMIT_NOFILE +limit. +.It Bq Er EBUSY +A race condition with +.Xr accept 2 +or +.Xr open 2 +has been detected. +.It Bq Er EINTR +An interrupt was received. +.It Bq Er EIO +An I/O error occurred while writing to the file system. +.El +.Pp +In addition, +.Fn dup3 +will return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa oldd +is equal to +.Fa newd +or +.Fa flags +is invalid. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr close 2 , +.Xr fcntl 2 , +.Xr getrlimit 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr socket 2 , +.Xr socketpair 2 , +.Xr getdtablesize 3 +.Sh STANDARDS +The +.Fn dup , +.Fn dup2 , +and +.Fn dup3 +functions conform to +.St -p1003.1-2024 . +.Sh HISTORY +The +.Fn dup +system call first appeared in +.At v3 , +.Fn dup2 +in +.At v7 , +and +.Fn dup3 +in +.Ox 5.7 . diff --git a/static/openbsd/man2/execve.2 b/static/openbsd/man2/execve.2 new file mode 100644 index 00000000..463c3af0 --- /dev/null +++ b/static/openbsd/man2/execve.2 @@ -0,0 +1,356 @@ +.\" $OpenBSD: execve.2,v 1.60 2025/08/04 04:59:31 guenther Exp $ +.\" $NetBSD: execve.2,v 1.9 1995/02/27 12:32:25 cgd 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. 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.3 (Berkeley) 1/24/94 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt EXECVE 2 +.Os +.Sh NAME +.Nm execve +.Nd execute a file +.Sh SYNOPSIS +.In 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 elf 5 . +.Pp +An interpreter file begins with a line of the form: +.Pp +.D1 #! Ar interpreter Op Ar arg +.Pp +When an interpreter file is passed to +.Fn execve , +the system instead calls +.Fn execve +with the specified +.Ar interpreter . +If the optional +.Ar arg +is specified, it becomes the first argument to the +.Ar interpreter , +and the original +.Fa path +becomes the second argument; +otherwise, +.Fa path +becomes the first argument. +The original arguments are shifted over to become the subsequent arguments. +The zeroth argument, normally the name of the file being executed, is left +unchanged. +.Pp +The argument +.Fa argv +is a pointer to a null-terminated array of +character pointers to NUL-terminated character strings. +These strings construct the argument list to be made available to the new +process. +At least one non-null 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 NUL-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 , +except that the close-on-fork flag is cleared on all descriptors. +In the case of a new setuid or setgid executable being executed, if +file descriptors 0, 1, or 2 (representing stdin, stdout, and stderr) +are currently unallocated, these descriptors will be opened to point to +some system file like +.Pa /dev/null . +The intent is to ensure these descriptors are not unallocated, since +many libraries make assumptions about the use of these 3 file descriptors. +.Pp +Signals set to be ignored in the calling process, +with the exception of +.Dv SIGCHLD , +are set to be ignored in +the +new process. +Other signals +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 ) . +The set-user-ID and set-group-ID bits have no effect if the +new process image file is located on a file system mounted with +the nosuid flag. +The process will be started without the new permissions. +.Pp +The new process also inherits the following attributes from +the calling process: +.Pp +.Bl -tag -width controlling_terminal -offset indent -compact +.It process ID +see +.Xr getpid 2 +.It parent process ID +see +.Xr getppid 2 +.It process group ID +see +.Xr getpgrp 2 +.It session ID +see +.Xr getsid 2 +.It access groups +see +.Xr getgroups 2 +.It working directory +see +.Xr chdir 2 +.It root directory +see +.Xr chroot 2 +.It controlling terminal +see +.Xr termios 4 +.It resource usages +see +.Xr getrusage 2 +.It interval timers +see +.Xr getitimer 2 +(unless process image file is setuid or setgid, +in which case all timers are disabled) +.It resource limits +see +.Xr getrlimit 2 +.It file mode mask +see +.Xr umask 2 +.It signal mask +see +.Xr sigaction 2 , +.Xr sigprocmask 2 +.El +.Pp +When a program is executed as a result of an +.Fn execve +call, it is entered as follows: +.Pp +.Dl main(int argc, char **argv, char **envp) +.Pp +where +.Fa argc +is the number of elements in +.Fa argv +(the +.Dq arg count ) +and +.Fa argv +points to the array of character pointers +to the arguments themselves. +.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 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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 EACCES +The new process file is on a filesystem mounted with execution +disabled +.Pf ( Dv MNT_NOEXEC +in +.In sys/mount.h ) . +.It Bq Er EACCES +The new process file is marked with +.Xr ld 1 +.Fl z Cm wxneeded +to allow W^X violating operations, but it is located on a file +system which does not allow such operations (because it is mounted +without the +.Xr mount 8 +.Fl o Cm wxallowed +flag). +.It Bq Er EACCES +The parent used +.Xr pledge 2 +to declare an +.Va execpromise , +and that is not permitted for setuid or setgid images. +.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 by some process. +.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's argument list +is larger than the system-imposed limit. +The limit in the system as released is 524288 bytes +.Pq Dv ARG_MAX . +.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 EINVAL +.Fa argv +did not contain at least one element. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.It Bq Er ENFILE +During startup of an +.Ar interpreter , +the system file table was found to be full. +.El +.Sh SEE ALSO +.Xr _exit 2 , +.Xr fork 2 , +.Xr execl 3 , +.Xr exit 3 , +.Xr elf 5 , +.Xr environ 7 +.Sh STANDARDS +The +.Fn execve +function is expected to conform to +.St -p1003.1-2024 , +except that the +.Dv FD_CLOFORK +flag is cleared on all file descriptors. +(The behavior required by the standard is not safe and +was reported as a defect by +.Ox . ) +.Sh HISTORY +The predecessor of these functions, the former +.Fn exec +system call, first appeared in +.At v1 . +The +.Fn execve +function first appeared in +.At v7 . +.Sh CAVEATS +If a program is +.Em setuid +to a non-superuser, but is executed when the real +.Em uid +is +.Dq root , +then the process has some of the powers of a superuser as well. +.Pp +.St -p1003.1-2008 +permits +.Nm +to leave +.Dv SIGCHLD +as ignored in the new process; portable programs cannot rely on +.Nm +resetting it to the default disposition. diff --git a/static/openbsd/man2/fcntl.2 b/static/openbsd/man2/fcntl.2 new file mode 100644 index 00000000..c24b21f2 --- /dev/null +++ b/static/openbsd/man2/fcntl.2 @@ -0,0 +1,588 @@ +.\" $OpenBSD: fcntl.2,v 1.38 2025/08/04 15:08:16 schwarze Exp $ +.\" $NetBSD: fcntl.2,v 1.6 1995/02/27 12:32:29 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt FCNTL 2 +.Os +.Sh NAME +.Nm fcntl +.Nd file control +.Sh SYNOPSIS +.In fcntl.h +.Ft int +.Fn fcntl "int fd" "int cmd" "..." +.Sh DESCRIPTION +The +.Fn fcntl +system call provides control over the properties of a file that is already open. +The argument +.Fa fd +is a descriptor to be operated on by +.Fa cmd +as described below. +The third parameter is called +.Fa arg +and is technically a pointer to +.Fa void , +but is interpreted as an +.Vt int +by some commands, a pointer to a +.Vt struct flock +by others (see below), and ignored by the rest. +.Pp +The commands are: +.Bl -tag -width F_DUPFD_CLOEXEC +.It Dv F_DUPFD +Return a new descriptor as follows: +.Pp +.Bl -bullet -compact +.It +Lowest numbered available descriptor greater than or equal to +.Fa arg +(interpreted as an +.Vt int ) . +.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 +calls. +.El +.It Dv F_DUPFD_CLOEXEC +Like +.Dv F_DUPFD , +but the +.Dv FD_CLOEXEC +flag associated with the new file descriptor is set, so the file descriptor +is closed when +.Xr execve 2 +is called. +.It Dv F_DUPFD_CLOFORK +Like +.Dv F_DUPFD , +but the +.Dv FD_CLOFORK +flag associated with the new file descriptor is set, so the file descriptor +is closed in the child when +.Xr fork 2 +or +.Xr vfork 2 +is called. +.It Dv F_GETFD +Get the close-on-exec and close-on-fork flags associated with the +file descriptor +.Fa fd +as +.Dv FD_CLOEXEC +and +.Dv FD_CLOFORK . +If the returned value ANDed with +.Dv FD_CLOEXEC +is 0, +the file will remain open across +.Xr execve 2 , +otherwise the file will be closed upon execution of +.Xr execve 2 ; +if the returned value ANDed with +.Dv FD_CLOFORK +is 0, +the file will remain open across +.Xr fork 2 +and +.Xr vfork 2 , +otherwise the file will be closed upon execution of +.Xr fork 2 +or +.Xr vfork 2 +.Fa ( arg +is ignored). +.It Dv F_SETFD +Set the close-on-exec and close-on-fork flags associated with +.Fa fd +to +.Fa arg , +where +.Fa arg +(interpreted as an +.Vt int ) +is the bitwise OR of zero or more of +.Dv FD_CLOEXEC +and +.Dv FD_CLOFORK , +as described above. +.It Dv F_GETFL +Get file status flags associated with the file descriptor +.Fa fd , +as described below +.Fa ( arg +is ignored). +.It Dv F_SETFL +Set file status flags associated with the file descriptor +.Fa fd +to +.Fa arg +(interpreted as an +.Vt int ) . +.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 +(interpreted as an +.Vt int ) +as negative, otherwise +.Fa arg +is taken as a process ID. +.El +.Pp +The flags for the +.Dv F_GETFL +and +.Dv F_SETFL +commands 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. +.It Dv O_SYNC +Cause writes to be synchronous. +Data will be written to the physical device instead of +just being stored in the buffer cache; corresponds to the +.Dv O_SYNC +flag of +.Xr open 2 . +.El +.Pp +Several commands are available for doing advisory file locking; +they all operate on the following structure: +.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 +.Pp +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 +.Pq Dv F_RDLCK +or exclusive (or write) locks +.Pq Dv F_WRLCK , +as well as remove either type of lock +.Pq 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 area starting at +.Fa l_start Ns + Ns Fa l_len +and ending at +.Fa l_start Ns -1 +is locked. +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 +.Fn fcntl +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 RETURN VALUES +Upon successful completion, the value returned depends on +.Fa cmd +as follows: +.Bl -tag -width F_DUPFD_CLOEXEC -offset indent +.It Dv F_DUPFD +A new file descriptor. +.It Dv F_DUPFD_CLOEXEC +A new file descriptor. +.It Dv F_DUPFD_CLOFORK +A new file descriptor. +.It Dv F_GETFD +Value of file descriptor flags (only the +.Dv FD_CLOEXEC +and +.Dv FD_CLOFORK +bits are 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 +.Pq Fa l_type +is a shared lock +.Pq Dv F_RDLCK +or exclusive lock +.Pq 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 fd +is not a valid open file descriptor. +.Pp +The argument +.Fa cmd +is +.Dv F_SETLK +or +.Dv F_SETLKW , +the type of lock +.Pq Fa l_type +is a shared lock +.Pq Dv F_RDLCK , +and +.Fa fd +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 +.Pq Fa l_type +is an exclusive lock +.Pq Dv F_WRLCK , +and +.Fa fd +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_SETLK +or +.Dv F_SETLKW , +and the function was interrupted by a signal. +.It Bq Er EINVAL +The argument +.Fa cmd +is invalid. +.Pp +.Fa cmd +is +.Dv F_DUPFD +and +.Fa arg +is negative or greater than the maximum allowable number +(see +.Xr getdtablesize 3 ) . +.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 fd +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 open 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 EOVERFLOW +The argument +.Fa cmd +is +.Dv F_GETLK , +.Dv F_SETLK +or +.Dv F_SETLKW +and the segment length of a file to be locked is too large to be represented by +an +.Vt off_t . +.It Bq Er ESRCH +.Fa cmd +is +.Dv F_SETOWN +and the process ID given in +.Fa arg +is not in use. +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr execve 2 , +.Xr flock 2 , +.Xr open 2 , +.Xr sigaction 2 , +.Xr getdtablesize 3 +.Sh STANDARDS +The +.Fn fcntl +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn fcntl +system call first appeared in +.At III +and was reimplemented for +.Bx 4.2 . diff --git a/static/openbsd/man2/fhopen.2 b/static/openbsd/man2/fhopen.2 new file mode 100644 index 00000000..98cf710d --- /dev/null +++ b/static/openbsd/man2/fhopen.2 @@ -0,0 +1,131 @@ +.\" $OpenBSD: fhopen.2,v 1.9 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: fhopen.2,v 1.2 1999/12/02 21:42:36 kleink Exp $ +.\" +.\" 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 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 $Mdocdate: September 10 2015 $ +.Dt FHOPEN 2 +.Os +.Sh NAME +.Nm fhopen , +.Nm fhstat , +.Nm fhstatfs +.Nd access file via file handle +.Sh SYNOPSIS +.In sys/types.h +.In sys/stat.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 referred 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 +respectively, +.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 fstat 2 , +.Xr fstatfs 2 , +.Xr getfh 2 , +.Xr open 2 +.Sh HISTORY +The +.Fn fhopen , +.Fn fhstat , +and +.Fn fhstatfs +functions first appeared in +.Nx 1.5 . diff --git a/static/openbsd/man2/flock.2 b/static/openbsd/man2/flock.2 new file mode 100644 index 00000000..82483b12 --- /dev/null +++ b/static/openbsd/man2/flock.2 @@ -0,0 +1,151 @@ +.\" $OpenBSD: flock.2,v 1.21 2019/06/25 19:28:31 millert Exp $ +.\" $NetBSD: flock.2,v 1.5 1995/02/27 12:32:32 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: June 25 2019 $ +.Dt FLOCK 2 +.Os +.Sh NAME +.Nm flock +.Nd apply or remove an advisory lock on an open file +.Sh SYNOPSIS +.In fcntl.h +.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 . +The +.Fa operation +argument is one of: +.Pp +.Bl -tag -width LOCK_SH -offset indent -compact +.It Dv LOCK_SH +Apply a shared lock. +.It Dv LOCK_EX +Apply an exclusive lock. +.It Dv LOCK_UN +Remove an existing lock. +.El +.Pp +.Dv LOCK_SH +and +.Dv LOCK_EX +may be combined with the optional +.Dv LOCK_NB +for nonblocking mode. +.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 +.Fa operation +is the bitwise OR of +.Dv LOCK_NB +and +.Dv LOCK_SH +or +.Dv LOCK_EX , +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 RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn flock +call fails if: +.Bl -tag -width Er +.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 operation +has an invalid value. +.It Bq Er EOPNOTSUPP +The argument +.Fa fd +refers to a file that does not support locking. +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr dup 2 , +.Xr execve 2 , +.Xr fcntl 2 , +.Xr fork 2 , +.Xr open 2 +.Sh HISTORY +The +.Fn flock +system call first appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/fork.2 b/static/openbsd/man2/fork.2 new file mode 100644 index 00000000..cd1cedd2 --- /dev/null +++ b/static/openbsd/man2/fork.2 @@ -0,0 +1,145 @@ +.\" $OpenBSD: fork.2,v 1.18 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: fork.2,v 1.6 1995/02/27 12:32:36 cgd 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt FORK 2 +.Os +.Sh NAME +.Nm fork +.Nd create a new process +.Sh SYNOPSIS +.In 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, +which also does not match any existing process group 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 a single thread. +.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 has no +.Xr fcntl 2 Ns -style +file locks. +.It +The child process' resource utilizations +are set to 0; see +.Xr getrusage 2 . +.It +All interval timers are cleared; see +.Xr setitimer 2 . +.It +The child process' semaphore undo values are set to 0; see +.Xr semop 2 . +.It +The child process' pending signals set is empty. +.It +The child process has no memory locks; see +.Xr mlock 2 +and +.Xr mlockall 2 . +.El +.Pp +In general, the child process should call +.Xr _exit 2 +rather than +.Xr exit 3 . +Otherwise, any stdio buffers that exist both in the parent and child +will be flushed twice. +Similarly, +.Xr _exit 2 +should be used to prevent +.Xr atexit 3 +routines from being called twice (once in the parent and once in the child). +.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 limits on the total +number of processes or total number of threads +under execution would be exceeded. +These limits are configuration dependent. +.It Bq Er EAGAIN +The limit +.Dv RLIMIT_NPROC +on the total number of processes under execution by the user ID +would be exceeded. +.It Bq Er ENOMEM +There is insufficient swap space for the new process. +.El +.Sh SEE ALSO +.Xr execve 2 , +.Xr getrusage 2 , +.Xr wait 2 +.Sh STANDARDS +The +.Fn fork +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn fork +system call first appeared in +.At v1 . diff --git a/static/openbsd/man2/fsync.2 b/static/openbsd/man2/fsync.2 new file mode 100644 index 00000000..348c2625 --- /dev/null +++ b/static/openbsd/man2/fsync.2 @@ -0,0 +1,121 @@ +.\" $OpenBSD: fsync.2,v 1.15 2019/04/18 23:51:13 tedu Exp $ +.\" $NetBSD: fsync.2,v 1.4 1995/02/27 12:32:38 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: April 18 2019 $ +.Dt FSYNC 2 +.Os +.Sh NAME +.Nm fsync , +.Nm fdatasync +.Nd synchronize a file's in-core state with that on disk +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn fsync "int fd" +.Ft int +.Fn fdatasync "int fd" +.Sh DESCRIPTION +The +.Fn fsync +function 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 +The +.Fn fdatasync +function is similar to +.Fn fsync +except that it only guarantees modified data +.Pq and metadata necessary to read that data +is committed to storage. +Other file modifications may be left unsynchronized. +.Pp +.Fn fsync +and +.Fn fdatasync +should be used by programs that require a file to be in a known state, +for example, in building a simple transaction facility. +.Pp +If +.Fn fsync +or +.Fn fdatasync +fail with +.Er EIO , +the state of the on-disk data may have been only partially written. +To guard against potential inconsistency, future calls will continue failing +until all references to the file are closed. +.Sh RETURN VALUES +.Rv -std fsync fdatasync +.Sh ERRORS +The +.Fn fsync +and +.Fn fdatasync +functions fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is not a valid descriptor. +.It Bq Er EINVAL +.Fa fd +does not refer to a file which can be synchronized. +.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 sync 8 +.Sh STANDARDS +The +.Fn fsync +and +.Fn fdatasync +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn fsync +system call first appeared in +.Bx 4.1c , +and the +.Fn fdatasync +function has been available since +.Ox 5.4 . +.Sh BUGS +The +.Fn fdatasync +function is currently a wrapper around +.Fn fsync , +so it synchronizes more state than necessary. diff --git a/static/openbsd/man2/futex.2 b/static/openbsd/man2/futex.2 new file mode 100644 index 00000000..89c6d4a3 --- /dev/null +++ b/static/openbsd/man2/futex.2 @@ -0,0 +1,153 @@ +.\" $OpenBSD: futex.2,v 1.7 2023/11/09 09:13:32 jasper Exp $ +.\" +.\" Copyright (c) 2017 Martin Pieuchot +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: November 9 2023 $ +.Dt FUTEX 2 +.Os +.Sh NAME +.Nm futex +.Nd fast userspace locking primitive +.Sh SYNOPSIS +.In sys/time.h +.In sys/futex.h +.Ft int +.Fo futex +.Fa "volatile uint32_t *uaddr" +.Fa "int op" +.Fa "int val" +.Fa "const struct timespec *timeout" +.Fa "volatile uint32_t *uaddr2" +.Fc +.Sh DESCRIPTION +The +.Fn futex +syscall provides sleep and wakeup primitives related to a particular address. +.Pp +Three +.Fa op +operations are currently supported: +.Bl -tag -width FUTEX_REQUEUE -offset indent +.It Dv FUTEX_WAIT +If +.Fa val +is equal to +.Pf * Fa uaddr , +the calling thread is blocked on the +.Dq wait channel +identified by +.Fa uaddr +until +.Fa timeout +expires or until another thread issues a +.Dv FUTEX_WAKE +or +.Dv FUTEX_REQUEUE +operation with the same +.Fa uaddr +address. +.Fa uaddr2 +is ignored. +.It Dv FUTEX_WAKE +Unblocks +.Fa val +threads sleeping on the +wait channel identified by +.Fa uaddr . +.Fa timeout +and +.Fa uaddr2 +are ignored. +.It Dv FUTEX_REQUEUE +Similar to +.Dv FUTEX_WAKE +but also requeue remaining threads from the wait channel +.Fa uaddr +to +.Fa uaddr2 . +In this case, pass +.Fa "uint32_t val2" +as the fourth argument instead of +.Fa timeout . +At most that number of threads is requeued. +.El +.Sh RETURN VALUES +For +.Dv FUTEX_WAKE +and +.Dv FUTEX_REQUEUE , +.Fn futex +returns the number of woken threads. +.Pp +For +.Dv FUTEX_WAIT , +.Fn futex +returns zero if woken by a matching +.Dv FUTEX_WAKE +or +.Dv FUTEX_REQUEUE +call. +Otherwise, a value of \-1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn futex +will fail if: +.Bl -tag -width Er +.It Bq Er ENOSYS +The +.Fa op +argument is invalid. +.It Bq Er EFAULT +The userspace address +.Fa uaddr +is invalid. +.It Bq Er EAGAIN +The value pointed to by +.Fa uaddr +is not the same as the expected value +.Fa val . +.It Bq Er EINVAL +The +.Fa timeout +specified a second value less than zero, +or a nanosecond value less than zero or greater than or equal to 1000 million. +.It Bq Er ETIMEDOUT +The +.Fa timeout +expired before the thread was woken up. +.It Bq Er EINTR +A signal arrived. +.It Bq Er ECANCELED +A signal arrived and +.Fa SA_RESTART +was set. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr pthread_cond_wait 3 , +.Xr pthread_mutex_lock 3 , +.Xr tsleep 9 +.Rs +.%A Ulrich Drepper +.%T Futexes Are Tricky +.%U https://www.akkadia.org/drepper/futex.pdf +.%D November 5, 2011 +.Re +.Sh HISTORY +The +.Fn futex +syscall first appeared in Linux 2.5.7 and was added to +.Ox 6.2 . diff --git a/static/openbsd/man2/getdents.2 b/static/openbsd/man2/getdents.2 new file mode 100644 index 00000000..133ab9d3 --- /dev/null +++ b/static/openbsd/man2/getdents.2 @@ -0,0 +1,195 @@ +.\" $OpenBSD: getdents.2,v 1.4 2022/08/04 06:20:24 jsg Exp $ +.\" $NetBSD: getdirentries.2,v 1.7 1995/10/12 15:40:50 jtc Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/9/93 +.\" +.Dd $Mdocdate: August 4 2022 $ +.Dt GETDENTS 2 +.Os +.Sh NAME +.Nm getdents +.Nd get directory entries in a filesystem independent format +.Sh SYNOPSIS +.In dirent.h +.Ft int +.Fn getdents "int fd" "void *buf" "size_t nbytes" +.Sh DESCRIPTION +.Fn getdents +reads 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. +.Fa nbytes +must be greater than or equal to the +block size associated with the file (see +.Xr stat 2 ) . +Some filesystems may not support +.Fn getdents +with buffers smaller than this size. +.Pp +The data in the buffer is a series of +.Em dirent +structures each containing at least the following entries: +.Bd -literal -offset indent +ino_t d_fileno; +off_t d_off; +u_int16_t d_reclen; +u_int8_t d_type; +u_int8_t d_namlen; +char d_name[MAXNAMLEN + 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_off +entry is the file offset of the next entry. +The +.Fa d_reclen +entry is the length, in bytes, of the directory record. +.Pp +The +.Fa d_type +is the type of file, where the following are possible types: +.Dv DT_UNKNOWN , +.Dv DT_FIFO , +.Dv DT_CHR , +.Dv DT_DIR , +.Dv DT_BLK , +.Dv DT_REG , +.Dv DT_LNK , +and +.Dv DT_SOCK . +.Pp +The +.Fa d_namlen +entry specifies the length of the file name excluding the NUL byte. +Thus the actual size of +.Fa d_name +may vary from 1 to +.Dv MAXNAMLEN +\&+ 1. +.Pp +The +.Fa d_name +entry contains a NUL-terminated file name. +.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 +Invalid entries with +.Fa d_fileno +set to 0 may be returned among regular entries. +.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 getdents . +.Pp +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 , +the value of +.Fa d_off +from an entry, +or zero. +.Sh RETURN VALUES +If successful, the number of bytes actually transferred is returned. +A value of zero is returned when +the end of the directory has been reached. +Otherwise, \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn getdents +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 +Part of +.Fa buf +points outside the process's 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 I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr lseek 2 , +.Xr open 2 , +.Xr opendir 3 , +.Xr dirent 5 +.Sh STANDARDS +The +.Fn getdents +call is not a portable interface and should not be used directly by +applications. +Use +.Xr readdir 3 +instead. +.Sh HISTORY +The +.Fn getdirentries +function first appeared in +.Bx 4.3 Reno . +In +.Ox 5.5 +the +.Fa d_off +entry was added to +.Vt struct dirent +and +.Fn getdirentries +was replaced with +.Fn getdents . diff --git a/static/openbsd/man2/getdtablecount.2 b/static/openbsd/man2/getdtablecount.2 new file mode 100644 index 00000000..311c52a8 --- /dev/null +++ b/static/openbsd/man2/getdtablecount.2 @@ -0,0 +1,38 @@ +.\" $OpenBSD: getdtablecount.2,v 1.5 2015/05/31 23:54:25 schwarze Exp $ +.\" +.\" Copyright (c) 2012 Theo de Raadt +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: May 31 2015 $ +.Dt GETDTABLECOUNT 2 +.Os +.Sh NAME +.Nm getdtablecount +.Nd get descriptor table count +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getdtablecount void +.Sh DESCRIPTION +.Fn getdtablecount +returns the number of file descriptors the process currently has +open. +.Sh SEE ALSO +.Xr getrlimit 2 , +.Xr getdtablesize 3 +.Sh HISTORY +The +.Fn getdtablecount +function appeared in +.Ox 5.2 . diff --git a/static/openbsd/man2/getentropy.2 b/static/openbsd/man2/getentropy.2 new file mode 100644 index 00000000..54320698 --- /dev/null +++ b/static/openbsd/man2/getentropy.2 @@ -0,0 +1,70 @@ +.\" $OpenBSD: getentropy.2,v 1.11 2024/08/02 01:53:21 guenther Exp $ +.\" +.\" Copyright (c) 2014 Theo de Raadt +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: August 2 2024 $ +.Dt GETENTROPY 2 +.Os +.Sh NAME +.Nm getentropy +.Nd get entropy +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getentropy "void *buf" "size_t buflen" +.Sh DESCRIPTION +.Fn getentropy +fills a buffer with high-quality entropy, which can be used +as input for process-context pseudorandom generators like +.Xr arc4random 3 . +.Pp +The maximum buffer size permitted is +.Dv GETENTROPY_MAX +(256) bytes. +.Pp +.Fn getentropy +is not intended for regular code; use the +.Xr arc4random 3 +family of functions instead. +.Pp +The high-quality entropy data is provided by the +.Xr random 4 +subsystem. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn getentropy +will succeed unless: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa buf +parameter points to an +invalid address. +.It Bq Er EINVAL +Too many bytes requested. +.El +.Sh SEE ALSO +.Xr arc4random 3 +.Sh STANDARDS +The +.Fn getentropy +function conforms to +.St -p1003.1-2024 . +.Sh HISTORY +The +.Fn getentropy +function appeared in +.Ox 5.6 . diff --git a/static/openbsd/man2/getfh.2 b/static/openbsd/man2/getfh.2 new file mode 100644 index 00000000..814f040f --- /dev/null +++ b/static/openbsd/man2/getfh.2 @@ -0,0 +1,102 @@ +.\" $OpenBSD: getfh.2,v 1.20 2022/07/30 07:19:30 jsg Exp $ +.\" $NetBSD: getfh.2,v 1.7 1995/10/12 15:40:53 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: July 30 2022 $ +.Dt GETFH 2 +.Os +.Sh NAME +.Nm getfh +.Nd get file handle +.Sh SYNOPSIS +.In sys/types.h +.In 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 +.Fa path +in the file handle pointed to by +.Fa fhp . +This system call is restricted to the superuser. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn getfh +fails if one or more of the following are true: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix of +.Fa path +is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 EPERM +The effective user ID is not the superuser. +.It Bq Er EFAULT +.Fa fhp +or +.Fa path +points to an invalid address. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er EINVAL +A portion of +.Fa path +refers to a remote file system. +.It Bq Er EOPNOTSUPP +A portion of +.Fa path +refers to a remote file system. +.El +.Sh SEE ALSO +.Xr fhstat 2 +.Sh HISTORY +The +.Fn getfh +function first appeared in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/getfsstat.2 b/static/openbsd/man2/getfsstat.2 new file mode 100644 index 00000000..c3fc1e90 --- /dev/null +++ b/static/openbsd/man2/getfsstat.2 @@ -0,0 +1,149 @@ +.\" $OpenBSD: getfsstat.2,v 1.22 2022/07/30 07:19:30 jsg Exp $ +.\" $NetBSD: getfsstat.2,v 1.6 1995/06/29 11:40:44 cgd Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/9/93 +.\" +.Dd $Mdocdate: July 30 2022 $ +.Dt GETFSSTAT 2 +.Os +.Sh NAME +.Nm getfsstat +.Nd get list of all mounted file systems +.Sh SYNOPSIS +.In sys/types.h +.In sys/mount.h +.Ft int +.Fn getfsstat "struct statfs *buf" "size_t bufsize" "int flags" +.Sh DESCRIPTION +.Fn getfsstat +returns information about all mounted file systems. +.Fa buf +is a pointer to an array of +.Xr statfs 2 +structures defined as follows: +.Bd -literal +typedef struct { int32_t val[2]; } fsid_t; + +#define MFSNAMELEN 16 /* length of fs type name, including nul */ +#define MNAMELEN 90 /* length of buffer for returned name */ + +struct statfs { + u_int32_t f_flags; /* copy of mount flags */ + u_int32_t f_bsize; /* file system block size */ + u_int32_t f_iosize; /* optimal transfer block size */ + + /* unit is f_bsize */ + u_int64_t f_blocks; /* total data blocks in file system */ + u_int64_t f_bfree; /* free blocks in fs */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + + u_int64_t f_files; /* total file nodes in file system */ + u_int64_t f_ffree; /* free file nodes in fs */ + int64_t f_favail; /* free file nodes avail to non-root */ + + u_int64_t f_syncwrites; /* count of sync writes since mount */ + u_int64_t f_syncreads; /* count of sync reads since mount */ + u_int64_t f_asyncwrites; /* count of async writes since mount */ + u_int64_t f_asyncreads; /* count of async reads since mount */ + + fsid_t f_fsid; /* file system id */ + u_int32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the file system */ + u_int64_t f_ctime; /* last mount [-u] time */ + + char f_fstypename[MFSNAMELEN]; /* fs type name */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ + char f_mntfromname[MNAMELEN]; /* mounted file system */ + char f_mntfromspec[MNAMELEN]; /* special for mount request */ + union mount_info mount_info; /* per-filesystem mount options */ +}; +.Ed +.Pp +The buffer is filled with an array of +.Fa statfs +structures, one for each mounted file system +up to the size specified by +.Fa bufsize . +.Pp +If +.Fa buf +is +.Dv NULL , +.Fn getfsstat +returns just the number of mounted file systems. +.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 file system. +Thus, some of the information will be out of date, but +.Fn getfsstat +will not block waiting for information from a file system that is +unable to respond. +If no flags are provided, +.Dv MNT_WAIT +is assumed. +.Pp +Note that +.Fa f_fsid +will be empty unless the user is the superuser. +.Sh RETURN VALUES +Upon successful completion, the number of +.Fa statfs +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 Bq Er EFAULT +.Fa buf +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 statfs 2 , +.Xr fstab 5 , +.Xr mount 8 +.Sh HISTORY +The +.Fn getfsstat +function first appeared in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/getgid.2 b/static/openbsd/man2/getgid.2 new file mode 100644 index 00000000..9a67120a --- /dev/null +++ b/static/openbsd/man2/getgid.2 @@ -0,0 +1,90 @@ +.\" $OpenBSD: getgid.2,v 1.19 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: getgid.2,v 1.5 1995/02/27 12:32:53 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt GETGID 2 +.Os +.Sh NAME +.Nm getgid , +.Nm getegid +.Nd get group process identification +.Sh SYNOPSIS +.In 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 and the +.Fn getegid +function 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 group 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 getgroups 2 , +.Xr getresgid 2 , +.Xr getuid 2 , +.Xr setgid 2 , +.Xr setregid 2 +.Sh STANDARDS +The +.Fn getgid +and +.Fn getegid +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getgid +system call first appeared in +.At v4 , +and +.Fn getegid +in +.At v7 . diff --git a/static/openbsd/man2/getgroups.2 b/static/openbsd/man2/getgroups.2 new file mode 100644 index 00000000..c290ccee --- /dev/null +++ b/static/openbsd/man2/getgroups.2 @@ -0,0 +1,99 @@ +.\" $OpenBSD: getgroups.2,v 1.15 2019/07/08 18:48:30 anton Exp $ +.\" $NetBSD: getgroups.2,v 1.8 1995/02/27 12:32:57 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: July 8 2019 $ +.Dt GETGROUPS 2 +.Os +.Sh NAME +.Nm getgroups +.Nd get group access list +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getgroups "int gidsetlen" "gid_t *gidset" +.Sh DESCRIPTION +.Fn getgroups +gets the current group access list of the current 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 0, +.Fn getgroups +returns the number of groups without modifying the +.Fa gidset +array. +.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 getgid 2 , +.Xr setgid 2 , +.Xr setgroups 2 , +.Xr initgroups 3 +.Sh STANDARDS +The +.Fn getgroups +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getgroups +system call first appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/getitimer.2 b/static/openbsd/man2/getitimer.2 new file mode 100644 index 00000000..1e1d25dd --- /dev/null +++ b/static/openbsd/man2/getitimer.2 @@ -0,0 +1,176 @@ +.\" $OpenBSD: getitimer.2,v 1.33 2019/06/24 21:20:12 schwarze Exp $ +.\" $NetBSD: getitimer.2,v 1.6 1995/10/12 15:40:54 jtc Exp $ +.\" +.\" 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. 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.2 (Berkeley) 12/11/93 +.\" +.Dd $Mdocdate: June 24 2019 $ +.Dt GETITIMER 2 +.Os +.Sh NAME +.Nm getitimer , +.Nm setitimer +.Nd get/set value of interval timer +.Sh SYNOPSIS +.In sys/time.h +.Pp +.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 +.In sys/time.h . +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-null). +.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. +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. +.Sh RETURN VALUES +.Rv -std +.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 +An unrecognized value for +.Fa which +was specified. +.El +.Pp +In addition, +.Fn setitimer +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa value +or +.Fa ovalue +specified a time that was too large to be handled. +.El +.Sh SEE ALSO +.Xr clock_gettime 2 , +.Xr gettimeofday 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr sigaction 2 +.Sh STANDARDS +The +.Fn getitimer +and +.Fn setitimer +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getitimer +and +.Fn setitimer +system calls first appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/getlogin.2 b/static/openbsd/man2/getlogin.2 new file mode 100644 index 00000000..8594afce --- /dev/null +++ b/static/openbsd/man2/getlogin.2 @@ -0,0 +1,220 @@ +.\" $OpenBSD: getlogin.2,v 1.24 2023/02/22 06:39:39 guenther Exp $ +.\" $NetBSD: getlogin.2,v 1.4 1995/02/27 12:33:03 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: February 22 2023 $ +.Dt GETLOGIN 2 +.Os +.Sh NAME +.Nm getlogin , +.Nm getlogin_r , +.Nm setlogin +.Nd get or set login name +.Sh SYNOPSIS +.In unistd.h +.Ft char * +.Fn getlogin void +.Ft int +.Fn getlogin_r "char *name" "size_t namelen" +.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 +The +.Fn getlogin_r +routine is a reentrant version of +.Fn getlogin . +It is functionally identical to +.Fn getlogin +except that the caller must provide a buffer, +.Fa name , +in which to store the user's login name and a corresponding +length parameter, +.Fa namelen , +that specifies the size of the buffer. +The buffer should be large enough to store the login name and a trailing NUL +(typically +.Dv LOGIN_NAME_MAX +bytes). +.Pp +.Fn setlogin +sets the login name of the user associated with the current session to +.Fa name . +This call is restricted to the superuser, 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. +The +.Em ONLY +way to do this is via the +.Fn setsid +function. +The +.Fn daemon +function calls +.Fn setsid +which is an ideal way of detaching from a controlling terminal and +forking into the background. +.Pp +In particular, neither +.Fn ioctl ttyfd TIOCNOTTY ...\& +nor +.Fn setpgrp ...\& +is sufficient to create a new session. +.Pp +Once a parent process has called +.Fn setsid , +it is acceptable for some child of that process to then call +.Fn setlogin , +even though it is not the session leader. +Beware, however, that +.Em ALL +processes in the session will change their login name at the same time, +even the parent. +.Pp +This is different from traditional +.Ux +privilege inheritance and as such can be counter-intuitive. +.Pp +Since the +.Fn setlogin +routine 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 NUL-terminated string in a static buffer. +If the name has not been set, it returns +.Dv NULL . +If a call to +.Fn getlogin_r +succeeds, a value of 0 is returned, else the error number is returned. +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 +.Fn getlogin_r +and +.Fn setlogin +will succeed unless: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa name +argument points to an +invalid address. +.El +.Pp +In addition, +.Fn getlogin_r +may return the following error: +.Bl -tag -width Er +.It Bq Er ERANGE +The value of +.Fa namelen +is not large enough to store the user's login name and a trailing NUL. +.El +.Pp +.Fn setlogin +may return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa name +argument +pointed to a string that was too long. +Login names are limited to +.Dv LOGIN_NAME_MAX-1 +characters, currently 31. +.It Bq Er EPERM +The caller tried to set the login name and was not the superuser. +.El +.Sh SEE ALSO +.Xr setsid 2 +.Sh STANDARDS +The +.Fn getlogin +and +.Fn getlogin_r +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +A +.Fn getlogin +function which used +.Xr utmp 5 +first appeared in +.At v7 . +The +.Fn getlogin +and +.Fn setlogin +system calls first appeared in +.Bx 4.3 Reno . +.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. diff --git a/static/openbsd/man2/getpeername.2 b/static/openbsd/man2/getpeername.2 new file mode 100644 index 00000000..f507d168 --- /dev/null +++ b/static/openbsd/man2/getpeername.2 @@ -0,0 +1,143 @@ +.\" $OpenBSD: getpeername.2,v 1.27 2022/09/11 06:38:11 jmc Exp $ +.\" $NetBSD: getpeername.2,v 1.6 1995/10/12 15:40:56 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: September 11 2022 $ +.Dt GETPEERNAME 2 +.Os +.Sh NAME +.Nm getpeername +.Nd get name of connected peer +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn getpeername "int s" "struct sockaddr *name" "socklen_t *namelen" +.Sh DESCRIPTION +.Fn getpeername +returns the address information of the peer connected to socket +.Fa s . +One common use occurs when a process inherits an open socket, such as +TCP servers forked from +.Xr inetd 8 . +In this scenario, +.Fn getpeername +is used to determine the connecting client's IP address. +.Pp +.Fn getpeername +takes three parameters: +.Pp +.Fa s +contains the file descriptor of the socket whose peer should be looked up. +.Pp +.Fa name +points to a +.Vt sockaddr +structure that will hold the address information for the connected peer. +Normal use requires one to use a structure +specific to the protocol family in use, such as +.Vt sockaddr_in +(IPv4) or +.Vt sockaddr_in6 +(IPv6), cast to a (struct sockaddr *). +.Pp +For greater portability, especially with the newer protocol families, the new +.Vt struct sockaddr_storage +should be used. +.Vt sockaddr_storage +is large enough to hold any of the other sockaddr_* variants. +On return, it can be cast to the correct sockaddr type, +based on the protocol family contained in its ss_family field. +.Pp +.Fa namelen +indicates the amount of space pointed to by +.Fa name , +in bytes. +.Pp +If address information for the local end of the socket is required, the +.Xr getsockname 2 +function should be used instead. +.Pp +If +.Fa name +does not point to enough space to hold the entire socket address, the +result will be truncated to +.Fa namelen +bytes. +.Sh RETURN VALUES +If the call succeeds, a 0 is returned and +.Fa namelen +is set to the actual size of the socket address returned in +.Fa name . +Otherwise, +.Va errno +is set and a value of \-1 is returned. +.Sh ERRORS +On failure, +.Va errno +is set to one of the following: +.Bl -tag -width Er +.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 +or +.Fa namelen +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 , +.Xr getpeereid 3 +.Sh STANDARDS +The +.Fn getpeername +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getpeername +function call appeared in +.Bx 4.2 . diff --git a/static/openbsd/man2/getpgrp.2 b/static/openbsd/man2/getpgrp.2 new file mode 100644 index 00000000..b215c0b0 --- /dev/null +++ b/static/openbsd/man2/getpgrp.2 @@ -0,0 +1,114 @@ +.\" $OpenBSD: getpgrp.2,v 1.19 2022/10/13 21:37:05 jmc Exp $ +.\" $NetBSD: getpgrp.2,v 1.8 1995/02/27 12:33:09 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: October 13 2022 $ +.Dt GETPGRP 2 +.Os +.Sh NAME +.Nm getpgrp , +.Nm getpgid +.Nd get process group +.Sh SYNOPSIS +.In 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 +.Fa pid +process 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 +These calls are 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 controlling terminal. +.Sh ERRORS +.Fn getpgrp +always succeeds, however +.Fn getpgid +will succeed unless: +.Bl -tag -width Er +.It Bq Er EPERM +The current process and the process +.Fa pid +are not in the same session. +.It Bq Er ESRCH +There is no process with a process ID equal to +.Fa pid . +.El +.Sh SEE ALSO +.Xr setpgid 2 , +.Xr termios 4 +.Sh STANDARDS +The +.Fn getpgrp +and +.Fn getpgid +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +A +.Fn getpgrp +function call that took a +.Fa "pid_t pid" +argument appeared in +.Bx 4.0 . +This version, without an argument, is derived from its usage in +System V Release 4, and first appeared in +.Nx 0.9 . +.Pp +The +.Fn getpgid +function call is derived from its usage in System V Release 4, and +first appeared in +.Nx 1.2a . diff --git a/static/openbsd/man2/getpid.2 b/static/openbsd/man2/getpid.2 new file mode 100644 index 00000000..3207348d --- /dev/null +++ b/static/openbsd/man2/getpid.2 @@ -0,0 +1,76 @@ +.\" $OpenBSD: getpid.2,v 1.14 2022/12/30 23:12:12 jsg Exp $ +.\" $NetBSD: getpid.2,v 1.5 1995/02/27 12:33:12 cgd 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. 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 +.\" +.Dd $Mdocdate: December 30 2022 $ +.Dt GETPID 2 +.Os +.Sh NAME +.Nm getpid , +.Nm getppid +.Nd get parent or calling process identification +.Sh SYNOPSIS +.In 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. +Though the ID is guaranteed to be unique, it should +.Em NOT +be used for constructing temporary file names; see +.Xr mkstemp 3 +instead. +.Pp +.Fn getppid +returns the process ID of the parent of the calling process. +.Sh RETURN VALUES +These functions are always successful, and no return value is +reserved to indicate an error. +.Sh SEE ALSO +.Xr gethostid 3 +.Sh STANDARDS +.Fn getpid +and +.Fn getppid +conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getpid +system call first appeared in +.At v5 . +The +.Fn getppid +function appeared in +.At 32v . diff --git a/static/openbsd/man2/getpriority.2 b/static/openbsd/man2/getpriority.2 new file mode 100644 index 00000000..426dd80c --- /dev/null +++ b/static/openbsd/man2/getpriority.2 @@ -0,0 +1,158 @@ +.\" $OpenBSD: getpriority.2,v 1.15 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: getpriority.2,v 1.4 1995/02/27 12:33:15 cgd 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt GETPRIORITY 2 +.Os +.Sh NAME +.Nm getpriority , +.Nm setpriority +.Nd get/set process scheduling priority +.Sh SYNOPSIS +.In sys/resource.h +.Ft int +.Fn getpriority "int which" "id_t who" +.Ft int +.Fn setpriority "int which" "id_t 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. +Priority values outside the range \-20 to 20 are truncated to the +appropriate limit. +Only the superuser 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 +In addition, +.Fn setpriority +will fail if: +.Bl -tag -width Er +.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-superuser attempted to lower a process priority. +.El +.Sh SEE ALSO +.Xr nice 1 , +.Xr fork 2 , +.Xr renice 8 +.Sh STANDARDS +The +.Fn getpriority +and +.Fn setpriority +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The predecessor of these functions, the former +.Fn nice +system call, appeared in +.At v3 +and was removed in +.Bx 4.3 Reno . +The +.Fn getpriority +and +.Fn setpriority +system calls appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/getrlimit.2 b/static/openbsd/man2/getrlimit.2 new file mode 100644 index 00000000..b05debe4 --- /dev/null +++ b/static/openbsd/man2/getrlimit.2 @@ -0,0 +1,238 @@ +.\" $OpenBSD: getrlimit.2,v 1.29 2022/09/11 06:38:11 jmc Exp $ +.\" $NetBSD: getrlimit.2,v 1.8 1995/10/12 15:40:58 jtc 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. 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 +.\" +.Dd $Mdocdate: September 11 2022 $ +.Dt GETRLIMIT 2 +.Os +.Sh NAME +.Nm getrlimit , +.Nm setrlimit +.Nd control maximum system resource consumption +.Sh SYNOPSIS +.In 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) +.Pa core +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 includes memory allocated via +.Xr malloc 3 +and all other anonymous memory mapped via +.Xr mmap 2 . +.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 setting is no longer enforced, but retained for compatibility. +.It Li RLIMIT_STACK +The maximum size (in bytes) of the stack segment for a process, +which defines how far a process's stack segment may be extended. +Stack extension is performed automatically by the system, +and is only used by the main thread of a process. +.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; /* hard limit */ +}; +.Ed +.Pp +Only the superuser 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 +A value of +.Dv RLIM_SAVED_CUR +or +.Dv RLIM_SAVED_MAX +will be stored in +.Fa rlim_cur +or +.Fa rlim_max +respectively by +.Fn getrlimit +if the value for the current or maximum resource limit cannot be stored in an +.Vt rlim_t . +The values +.Dv RLIM_SAVED_CUR +and +.Dv RLIM_SAVED_MAX +should not be used in a call to +.Fn setrlimit +unless they were returned by a previous call to +.Fn getrlimit . +.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 +and +.Ic ulimit +is the +.Xr sh 1 +equivalent. +.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 than 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 +.Rv -std +.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 EINVAL +An unrecognized value for +.Fa resource +was specified. +.El +.Pp +In addition, +.Fn setrlimit +may return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The new +.Fa rlim_cur +is greater than the new +.Fa rlim_max . +.It Bq Er EPERM +The new +.Fa rlim_max +is greater than the current maximum limit value, +and the caller is not the superuser. +.El +.Sh SEE ALSO +.Xr csh 1 , +.Xr sh 1 , +.Xr quotactl 2 , +.Xr sigaction 2 , +.Xr sigaltstack 2 , +.Xr sysctl 2 +.Sh STANDARDS +The +.Fn getrlimit +and +.Fn setrlimit +functions conform to +.St -p1003.1-2008 . +.Pp +The +.Dv RLIMIT_MEMLOCK , +.Dv RLIMIT_NPROC , +and +.Dv RLIMIT_RSS +resources are non-standard extensions. +.Sh HISTORY +The +.Fn getrlimit +and +.Fn setrlimit +system calls first appeared in +.Bx 4.1c . +.Sh BUGS +The +.Dv RLIMIT_AS +resource is missing. diff --git a/static/openbsd/man2/getrtable.2 b/static/openbsd/man2/getrtable.2 new file mode 100644 index 00000000..12b2dbd9 --- /dev/null +++ b/static/openbsd/man2/getrtable.2 @@ -0,0 +1,66 @@ +.\" $OpenBSD: getrtable.2,v 1.5 2023/02/22 06:31:51 guenther Exp $ +.\" +.\" Copyright (c) 2009 Reyk Floeter <reyk@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: February 22 2023 $ +.Dt GETRTABLE 2 +.Os +.Sh NAME +.Nm getrtable , +.Nm setrtable +.Nd get or set the default routing table of the current process +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.Ft int +.Fn getrtable "void" +.Ft int +.Fn setrtable "int rtableid" +.Sh DESCRIPTION +.Fn getrtable +and +.Fn setrtable +manipulate the routing table and routing domain associated with the current +process. +.Pp +Only the superuser is allowed to change the process routing table if +it is already set to a non-zero value. +.Sh RETURN VALUES +.Fn getrtable +returns the routing table of the current process. +Upon successful completion, +.Fn setrtable +returns 0 if the call succeeds, \-1 if it fails. +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa rtableid +argument is not a valid routing table. +.It Bq Er EPERM +The user is not the superuser and the routing table of the +calling process is already set to a non-zero value. +.El +.Sh SEE ALSO +.Xr getsockopt 2 , +.Xr route 8 +.Sh HISTORY +The +.Fn getrtable +and +.Fn setrtable +system calls appeared in +.Ox 4.8 . diff --git a/static/openbsd/man2/getrusage.2 b/static/openbsd/man2/getrusage.2 new file mode 100644 index 00000000..35eccf70 --- /dev/null +++ b/static/openbsd/man2/getrusage.2 @@ -0,0 +1,192 @@ +.\" $OpenBSD: getrusage.2,v 1.18 2024/07/17 13:29:05 claudio Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: July 17 2024 $ +.Dt GETRUSAGE 2 +.Os +.Sh NAME +.Nm getrusage +.Nd get information about resource utilization +.Sh SYNOPSIS +.In sys/resource.h +.Ft int +.Fn getrusage "int who" "struct rusage *rusage" +.Sh DESCRIPTION +.Fn getrusage +returns resource usage information for argument +.Fa who , +which can be one of the following: +.Bl -tag -width RUSAGE_CHILDREN -offset indent +.It Dv RUSAGE_SELF +Resources used by the current process. +.It Dv RUSAGE_CHILDREN +Resources used by all the terminated children of the current process which +were waited upon. +If the child is never waited for, the resource information for the child +process is discarded. +.It Dv RUSAGE_THREAD +Resources used by the current thread. +.El +.Pp +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 +.Dq integral +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. +.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 +.Dq reclaiming +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 +.Dq swapped +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 +.Rv -std +.Sh ERRORS +.Fn getrusage +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 clock_gettime 2 , +.Xr gettimeofday 2 , +.Xr wait 2 +.Sh STANDARDS +The +.Fn getrusage +function conforms to +.St -p1003.1-2008 . +.Pp +The +.Dv RUSAGE_THREAD +flag is an extension to that specification. +.Sh HISTORY +A predecessor to +.Fn getrusage , +.Fn times , +first appeared in +.At v3 . +The +.Fn getrusage +system call first appeared in +.Bx 4.1c . +.Pp +The +.Dv RUSAGE_THREAD +flag has been available since +.Ox 4.8 . +.Sh BUGS +There is no way to obtain information about a child process +that has not yet terminated or has not been waited for by the parent. diff --git a/static/openbsd/man2/getsid.2 b/static/openbsd/man2/getsid.2 new file mode 100644 index 00000000..049c6ed9 --- /dev/null +++ b/static/openbsd/man2/getsid.2 @@ -0,0 +1,83 @@ +.\" $OpenBSD: getsid.2,v 1.12 2015/09/10 17:55:21 schwarze Exp $ +.\" +.\" 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. +.\" +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt GETSID 2 +.Os +.Sh NAME +.Nm getsid +.Nd get process session +.Sh SYNOPSIS +.In 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 +.Va errno +to indicate an error. +.Sh ERRORS +.Fn getsid +will succeed unless: +.Bl -tag -width Er +.It Bq Er EPERM +The current process and the process +.Fa pid +are not in the same session. +.It Bq Er ESRCH +There is no process with a process ID equal to +.Fa pid . +.El +.Sh SEE ALSO +.Xr getpgid 2 , +.Xr getpgrp 2 , +.Xr setpgid 2 , +.Xr setsid 2 , +.Xr termios 4 +.Sh STANDARDS +.Fn getsid +conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getsid +function call is derived from its usage in +.At V , +and is mandated by +.St -xpg4 . diff --git a/static/openbsd/man2/getsockname.2 b/static/openbsd/man2/getsockname.2 new file mode 100644 index 00000000..bd681a44 --- /dev/null +++ b/static/openbsd/man2/getsockname.2 @@ -0,0 +1,162 @@ +.\" $OpenBSD: getsockname.2,v 1.32 2022/09/11 06:38:11 jmc Exp $ +.\" $NetBSD: getsockname.2,v 1.6 1995/10/12 15:41:00 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: September 11 2022 $ +.Dt GETSOCKNAME 2 +.Os +.Sh NAME +.Nm getsockname +.Nd get socket name +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn getsockname "int s" "struct sockaddr *name" "socklen_t *namelen" +.Sh DESCRIPTION +.Fn getsockname +returns the locally bound address information for a specified socket. +.Pp +Common uses of this function are as follows: +.Bl -bullet +.It +When +.Xr bind 2 +is called with a port number of 0 (indicating the kernel should pick +an ephemeral port), +.Fn getsockname +is used to retrieve the kernel-assigned port number. +.It +When a process calls +.Xr bind 2 +on a wildcard IP address, +.Fn getsockname +is used to retrieve the local IP address for the connection. +.It +When a function wishes to know the address family of a socket, +.Fn getsockname +can be used. +.El +.Pp +.Fn getsockname +takes three parameters: +.Pp +.Fa s +contains the file descriptor for the socket to be looked up. +.Pp +.Fa name +points to a +.Vt sockaddr +structure which will hold the resulting address information. +Normal use requires one to use a structure +specific to the protocol family in use, such as +.Vt sockaddr_in +(IPv4) or +.Vt sockaddr_in6 +(IPv6), cast to a (struct sockaddr *). +.Pp +For greater portability (such as newer protocol families) the new +structure sockaddr_storage exists. +.Vt sockaddr_storage +is large enough to hold any of the other sockaddr_* variants. +On return, it should be cast to the correct sockaddr type, +according to the current protocol family. +.Pp +.Fa namelen +indicates the amount of space pointed to by +.Fa name , +in bytes. +Upon return, +.Fa namelen +is set to the actual size of the returned address information. +.Pp +If the address of the destination socket for a given socket connection is +needed, the +.Xr getpeername 2 +function should be used instead. +.Pp +If +.Fa name +does not point to enough space to hold the entire socket address, the +result will be truncated to +.Fa namelen +bytes. +.Sh RETURN VALUES +On success, +.Fn getsockname +returns a 0, and +.Fa namelen +is set to the actual size of the socket address returned in +.Fa name . +Otherwise, +.Va errno +is set, and a value of \-1 is returned. +.Sh ERRORS +If +.Fn getsockname +fails, +.Va errno +is set to one of the following: +.Bl -tag -width Er +.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 +or +.Fa namelen +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 getpeername 2 , +.Xr socket 2 , +.Xr getpeereid 3 +.Sh STANDARDS +The +.Fn getsockname +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getsockname +function call appeared in +.Bx 4.2 . diff --git a/static/openbsd/man2/getsockopt.2 b/static/openbsd/man2/getsockopt.2 new file mode 100644 index 00000000..eb9c89e4 --- /dev/null +++ b/static/openbsd/man2/getsockopt.2 @@ -0,0 +1,541 @@ +.\" $OpenBSD: getsockopt.2,v 1.62 2024/04/02 14:23:15 claudio Exp $ +.\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $ +.\" +.\" 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. 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.3 (Berkeley) 4/19/94 +.\" +.Dd $Mdocdate: April 2 2024 $ +.Dt GETSOCKOPT 2 +.Os +.Sh NAME +.Nm getsockopt , +.Nm setsockopt +.Nd get or set options on sockets +.Sh SYNOPSIS +.In 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 +TCP protocol, +.Fa level +should be set to the protocol number of 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 +.Dv NULL . +.Pp +.Fa optname +and any specified options are passed uninterpreted to the appropriate +protocol module for interpretation. +The include file +.In sys/socket.h +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 +.Vt 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 +.Vt struct linger +parameter, defined in +.In sys/socket.h , +which specifies the desired state of the option and the +linger interval (see below). +.Dv SO_SNDTIMEO +and +.Dv SO_RCVTIMEO +use a +.Vt struct timeval +parameter, defined in +.In sys/time.h . +.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 . +.Pp +.Bl -tag -width SO_OOBINLINE -offset indent -compact +.It Dv SO_DEBUG +enables recording of debugging information +.It Dv SO_REUSEADDR +enables local address reuse +.It Dv SO_REUSEPORT +enables duplicate address and port bindings +.It Dv SO_KEEPALIVE +enables keep connections alive +.It Dv SO_DONTROUTE +enables routing bypass; not supported +.It Dv SO_LINGER +linger on close if data present +.It Dv SO_BROADCAST +enables permission to transmit broadcast messages +.It Dv SO_OOBINLINE +enables reception of out-of-band data in band +.It Dv SO_BINDANY +enables binding to any address +.It Dv SO_SNDBUF +set buffer size for output +.It Dv SO_RCVBUF +set buffer size for input +.It Dv SO_SNDLOWAT +set minimum count for output +.It Dv SO_RCVLOWAT +set minimum count for input +.It Dv SO_SNDTIMEO +set timeout value for output +.It Dv SO_RCVTIMEO +set timeout value for input +.It Dv SO_TIMESTAMP +enables reception of a timestamp with datagrams +.It Dv SO_RTABLE +set the routing table used for route lookups +.It Dv SO_SPLICE +splice two sockets together or get data length +.It Dv SO_ZEROIZE +clear all memory containing user supplied data +.It Dv SO_TYPE +get the type of the socket (get only) +.It Dv SO_ERROR +get and clear error on the socket (get only) +.It Dv SO_DOMAIN +get the domain of the socket (get only) +.It Dv SO_PROTOCOL +get the protocol of the socket (get only) +.It Dv SO_ACCEPTCONN +get listening status of the socket (get only) +.It Dv SO_PEERCRED +get the credentials from other side of connection (get only) +.El +.Pp +.Dv SO_DEBUG +enables debugging in the underlying protocol modules. +Transliterate the protocol trace with +.Xr trpt 8 . +.Dv SO_REUSEADDR +indicates that the rules used in validating addresses supplied in a +.Xr bind 2 +call should allow reuse of local addresses +by callers with the same user ID (or the superuser). +.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. +.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 measured in seconds, +termed the linger interval, is specified 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. +.Pp +.Dv SO_BINDANY +allows the socket to be bound to addresses +which are not local to the machine, so it +can be used to make a transparent proxy. +Note that this option is limited to the superuser. +In order to receive packets for these addresses, +.Dv SO_BINDANY +needs to be combined with matching outgoing +.Xr pf 4 +rules with the +.Ar divert-reply +parameter. +For example, with the following rule the socket receives packets +for 192.168.0.10 even if it is not a local address: +.Pp +.Dl pass out inet from 192.168.0.10 divert-reply +.Pp +.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 limit on these values. +.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 +or +.Xr poll 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 than that returned. +.Pp +.Dv SO_SNDTIMEO +is an option to set a timeout value for output operations. +It accepts a +.Vt 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 was 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 +.Vt 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 +If the +.Dv SO_TIMESTAMP +option is enabled on a +.Dv SOCK_DGRAM +socket, the +.Xr recvmsg 2 +call will return a timestamp corresponding to when the datagram was +received. +The msg_control field in the msghdr structure points to a buffer +that contains a cmsghdr structure followed by a struct timeval. +The cmsghdr fields have the following values: +.Bd -literal -offset indent +cmsg_len = CMSG_LEN(sizeof(struct timeval)) +cmsg_level = SOL_SOCKET +cmsg_type = SCM_TIMESTAMP +.Ed +.Pp +The +.Dv SO_RTABLE +option gets or sets the routing table which will be used by the socket +for address lookups. +If a protocol family of the socket doesn't support switching routing tables, +the +.Er ENOPROTOOPT +error is returned. +Only the superuser is allowed to change the routing table if it is already +set to a non-zero value. +A socket's chosen routing table is initialized from the process's configuration, +previously selected using +.Xr setrtable 2 . +.Pp +.Dv SO_SPLICE +can splice together two TCP or UDP sockets for unidirectional +zero-copy data transfers. +Splice also the other way around to get bidirectional data flow. +Both sockets must be of the same type. +In the first form, +.Fn setsockopt +is called with the source socket +.Fa s +and the drain socket's +.Vt int +file descriptor as +.Fa optval . +In the second form, +.Fa optval +is a +.Vt struct splice +with the drain socket in +.Va sp_fd , +a positive maximum number of bytes or 0 in +.Va sp_max +and an idle timeout +.Va sp_idle +in the form of a +.Vt struct timeval . +If \-1 is given as drain socket, the source socket +.Fa s +gets unspliced. +Otherwise the spliced data transfer continues within the kernel +until the optional maximum is reached, one of the connections +terminates, idle timeout expires or an error occurs. +A successful +.Xr select 2 , +.Xr poll 2 , +or +.Xr kqueue 2 +operation testing the ability to read from the source socket indicates +that the splicing has terminated. +When one of the sockets gets closed, splicing ends. +The error status can be examined with +.Dv SO_ERROR +at the source socket. +The +.Er ELOOP +error is set if userland created a loop by splicing sockets connected +to localhost. +The +.Er ETIMEDOUT +error is set if there was no data transferred between two sockets +during the +.Va sp_idle +period of time. +The +.Er EFBIG +error is set after exactly +.Va sp_max +bytes have been transferred. +Note that if a maximum is given, it is only guaranteed that no more +bytes are transferred. +A short splice can happen, but then a second call to splice will +transfer the remaining data immediately. +The +.Dv SO_SPLICE +option with +.Fn getsockopt +and an +.Vt off_t +value as +.Fa optval +can be used to retrieve the number of bytes transferred so far from the +source socket +.Fa s . +A successful new splice resets this number. +.Pp +Userland may write sensitive data into a socket. +If +.Dv SO_ZEROIZE +is set, overwrite kernel memory after sending data. +.Pp +Finally, +.Dv SO_TYPE , +.Dv SO_DOMAIN , +.Dv SO_PROTOCOL , +.Dv SO_ERROR , +.Dv SO_ACCEPTCONN , +and +.Dv SO_PEERCRED +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_DOMAIN +returns the domain of the socket, such as +.Dv AF_INET . +.Dv SO_PROTOCOL +returns the protocol of the socket such as +.Dv IPPROTO_TCP . +.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. +.Dv SO_ACCEPTCONN +returns whether the socket is currently accepting connections, that is, +whether or not +.Xr listen 2 +was called. +.Dv SO_PEERCRED +fetches the +.Va struct sockpeercred +credentials from the other side of the connection +(currently only possible on +.Dv AF_UNIX +sockets). +These credentials are from the time that +.Xr bind 2 , +.Xr connect 2 +or +.Xr socketpair 2 +were called. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width Er +.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 EOPNOTSUPP +The option is unsupported. +.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 connect 2 , +.Xr getrtable 2 , +.Xr ioctl 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr socket 2 , +.Xr getprotoent 3 , +.Xr divert 4 , +.Xr pf.conf 5 , +.Xr protocols 5 , +.Xr sosplice 9 +.Sh STANDARDS +The +.Fn getsockopt +and +.Fn setsockopt +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getsockopt +system call appeared in +.Bx 4.1c . +.Sh BUGS +Several of the socket options should be handled at lower levels of the system. diff --git a/static/openbsd/man2/getthrid.2 b/static/openbsd/man2/getthrid.2 new file mode 100644 index 00000000..7c812610 --- /dev/null +++ b/static/openbsd/man2/getthrid.2 @@ -0,0 +1,80 @@ +.\" $OpenBSD: getthrid.2,v 1.4 2016/03/30 06:58:06 jmc Exp $ +.\" $NetBSD: getpid.2,v 1.5 1995/02/27 12:33:12 cgd 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. 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 +.\" +.Dd $Mdocdate: March 30 2016 $ +.Dt GETTHRID 2 +.Os +.Sh NAME +.Nm getthrid +.Nd get thread identifier +.Sh SYNOPSIS +.In unistd.h +.Ft pid_t +.Fn getthrid void +.Sh DESCRIPTION +.Fn getthrid +returns the thread ID of the calling thread. +This is used in the implementation of the thread library +.Pq Fl lpthread +and can appear in the output of system utilities such as +.Xr ps 1 +and +.Xr kdump 1 . +.Pp +Thread IDs are not a stable interface and should not be used directly +by applications except for correlation with system utility output. +Applications should use the +.Vt pthread_t +values from +.Xr pthread_self 3 +and +.Xr pthread_create 3 +to identify threads within the process itself. +.Sh RETURN VALUES +This function is always successful, and no return value is +reserved to indicate an error. +.Sh SEE ALSO +.Xr getpid 2 , +.Xr __tfork 3 , +.Xr pthread_create 3 , +.Xr pthread_self 3 +.Sh STANDARDS +The +.Fn getthrid +syscall is specific to +.Ox +and should not be used in portable applications. +.Sh HISTORY +The +.Fn getthrid +syscall appeared in +.Ox 3.9 . diff --git a/static/openbsd/man2/getthrname.2 b/static/openbsd/man2/getthrname.2 new file mode 100644 index 00000000..5b360a55 --- /dev/null +++ b/static/openbsd/man2/getthrname.2 @@ -0,0 +1,135 @@ +.\" $OpenBSD: getthrname.2,v 1.3 2025/12/03 17:09:23 kurt Exp $ +.\" +.\" Copyright (c) 2023 Philip Guenther <guenther@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: December 3 2025 $ +.Dt GETTHRNAME 2 +.Os +.Sh NAME +.Nm getthrname , +.Nm setthrname +.Nd get or set thread name +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fo getthrname +.Fa "pid_t tid" +.Fa "char *name" +.Fa "size_t namelen" +.Fc +.Ft int +.Fo setthrname +.Fa "pid_t tid" +.Fa "const char *name" +.Fc +.Sh DESCRIPTION +The +.Fn getthrname +system call stores the name of +.Fa tid , +a thread in the current process, +into the buffer +.Fa name , +which must be of at least +.Fa namelen +bytes long. +The buffer should be at least +.Dv _MAXCOMLEN +bytes long. +The +.Fn setthrname +system call sets the name of +.Fa tid +to the supplied +.Fa name . +The name will be silently truncated to +.Dv _MAXCOMLEN +- 1 bytes. +For both functions, if +.Fa tid +is zero then the current thread is operated on. +.Pp +Thread names have no inherent meaning in the system and are +intended for display and debugging only. +They are not secret but rather are visible to other processes using +.Xr sysctl 2 +or +.Xr kvm_getprocs 3 +and in +.Ic ps Fl H +output. +.Pp +After +.Xr execve 2 , +the name of the process's only thread is reset to the empty string. +Similarly, additional threads created with +.Xr __tfork 3 +start with the empty name. +After +.Xr fork 2 , +the new process's only thread has the same name as the thread that +invoked +.Xr fork 2 . +.Sh RETURN VALUES +Upon successful completion, the value 0 is returned; +otherwise the error number is returned. +.Sh ERRORS +.Fn getthrname +and +.Fn setthrname +will succeed unless: +.Bl -tag -width Er +.It Bq Er EFAULT +The +.Fa name +argument points to an +invalid address. +.El +.Pp +In addition, +.Fn getthrname +may return the following error: +.Bl -tag -width Er +.It Bq Er ERANGE +The value of +.Fa namelen +is not large enough to store the thread name and a trailing NUL. +.El +.Sh SEE ALSO +.Xr execve 2 , +.Xr fork 2 , +.Xr sysctl 2 , +.Xr __tfork 3 , +.Xr kvm_getprocs 3 , +.Xr pthread_get_name_np 3 , +.Xr pthread_set_name_np 3 +.Sh STANDARDS +The +.Fn getthrname +and +.Fn setthrname +system calls are specific to +.Ox ; +.Xr pthread_get_name_np 3 +and +.Xr pthread_set_name_np 3 +operate on the same thread name in a more portable way. +.Sh HISTORY +The +.Fn getthrname +and +.Fn setthrname +system calls first appeared in +.Ox 7.3 . diff --git a/static/openbsd/man2/gettimeofday.2 b/static/openbsd/man2/gettimeofday.2 new file mode 100644 index 00000000..24a4ca49 --- /dev/null +++ b/static/openbsd/man2/gettimeofday.2 @@ -0,0 +1,205 @@ +.\" $OpenBSD: gettimeofday.2,v 1.33 2022/03/31 17:27:16 naddy 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. 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 +.\" +.Dd $Mdocdate: March 31 2022 $ +.Dt GETTIMEOFDAY 2 +.Os +.Sh NAME +.Nm gettimeofday , +.Nm settimeofday +.Nd get or set the time of day +.Sh SYNOPSIS +.In sys/time.h +.Ft int +.Fn gettimeofday "struct timeval *now" "struct timezone *tz" +.Ft int +.Fn settimeofday "const struct timeval *now" "const struct timezone *tz" +.Sh DESCRIPTION +The +.Fn gettimeofday +function writes the absolute value of the system's Coordinated Universal Time +.Pq UTC +clock to +.Fa now +unless +.Fa now +is +.Dv NULL . +.Pp +The UTC clock's absolute value is the time elapsed since +Jan 1 1970 00:00:00 +0000 +.Pq the Epoch . +The clock normally advances continuously, +though it may jump discontinuously if a process calls +.Fn settimeofday +or +.Xr clock_settime 2 . +For this reason, +.Fn gettimeofday +is not generally suitable for measuring elapsed time. +Whenever possible, +use +.Xr clock_gettime 2 +to measure elapsed time with one of the system's monotonic clocks instead. +.Pp +The +.Fn settimeofday +function sets the system's UTC clock to the absolute value +.Fa now +unless +.Fa now +is +.Dv NULL . +Only the superuser may set the clock. +If the system +.Xr securelevel 7 +is 2 or greater, the clock may only be advanced. +This limitation prevents a malicious superuser +from setting arbitrary timestamps on files. +Setting the clock cancels any ongoing +.Xr adjtime 2 +adjustment. +.Pp +The structure pointed to by +.Fa now +is defined in +.In sys/time.h +as: +.Bd -literal +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +.Ed +.Pp +The +.Fa tz +argument is historical: +the system no longer maintains timezone information in the kernel. +The +.Fa tz +argument should always be +.Dv NULL . +.Fn gettimeofday +zeroes +.Fa tz +if it is not +.Dv NULL . +.Fn settimeofday +ignores the contents of +.Fa tz +if it is not +.Dv NULL . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn gettimeofday +and +.Fn settimeofday +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +.Fa now +or +.Fa tz +are not +.Dv NULL +and reference invalid memory. +.El +.Pp +.Fn settimeofday +will also fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa now +specifies a microsecond value less than zero or greater than or equal to +one million. +.It Bq Er EPERM +The caller is not the superuser. +.It Bq Er EPERM +The system +.Xr securelevel 7 +is 2 or greater and +.Fa now +specifies a time in the past. +.El +.Sh SEE ALSO +.Xr date 1 , +.Xr adjtime 2 , +.Xr clock_gettime 2 , +.Xr getitimer 2 , +.Xr ctime 3 , +.Xr time 3 , +.Xr timeradd 3 +.Sh STANDARDS +The +.Fn gettimeofday +function conforms to +.St -p1003.1-2008 . +.Pp +The +.Fn settimeofday +function is non-standard, +though many systems offer it. +.Sh HISTORY +As predecessors of these functions, +former system calls +.Fn time +and +.Fn stime +first appeared in +.At v1 , +and +.Fn ftime +first appeared in +.At v7 . +The +.Fn gettimeofday +and +.Fn settimeofday +system calls first appeared in +.Bx 4.1c . +.Sh CAVEATS +Setting the time with +.Fn settimeofday +is dangerous; if possible use +.Xr adjtime 2 +instead. +Many daemon programming techniques utilize time-delta techniques +using the results from +.Fn gettimeofday +instead of from +.Xr clock_gettime 2 +on the +.Dv CLOCK_MONOTONIC +clock. +Time jumps can cause these programs to malfunction in unexpected ways. +If the time must be set, consider rebooting the machine for safety. diff --git a/static/openbsd/man2/getuid.2 b/static/openbsd/man2/getuid.2 new file mode 100644 index 00000000..75a26f1b --- /dev/null +++ b/static/openbsd/man2/getuid.2 @@ -0,0 +1,89 @@ +.\" $OpenBSD: getuid.2,v 1.16 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: getuid.2,v 1.6 1995/02/27 12:33:37 cgd 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt GETUID 2 +.Os +.Sh NAME +.Nm getuid , +.Nm geteuid +.Nd get user identification +.Sh SYNOPSIS +.In unistd.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 getresuid 2 , +.Xr setreuid 2 , +.Xr setuid 2 +.Sh STANDARDS +The +.Fn getuid +and +.Fn geteuid +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn getuid +system call first appeared in +.At v1 , +and +.Fn geteuid +in +.At v7 . diff --git a/static/openbsd/man2/i386_get_fsbase.2 b/static/openbsd/man2/i386_get_fsbase.2 new file mode 100644 index 00000000..4293df96 --- /dev/null +++ b/static/openbsd/man2/i386_get_fsbase.2 @@ -0,0 +1,85 @@ +.\" $OpenBSD: i386_get_fsbase.2,v 1.6 2025/06/05 18:47:18 schwarze Exp $ +.\" $NetBSD: i386_get_ioperm.2,v 1.3 1996/02/27 22:57:17 jtc Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by John T. Kohl and Charles M. Hannum. +.\" +.\" 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 NETBSD FOUNDATION, INC. 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 $Mdocdate: June 5 2025 $ +.Dt I386_GET_FSBASE 2 i386 +.Os +.Sh NAME +.Nm i386_get_fsbase , +.Nm i386_set_fsbase +.Nd manage i386 per-thread %fs base address +.Sh SYNOPSIS +.Lb libi386 +.In sys/types.h +.In machine/sysarch.h +.Ft int +.Fn i386_get_fsbase "void **base" +.Ft int +.Fn i386_set_fsbase "void *base" +.Sh DESCRIPTION +.Fn i386_get_fsbase +copies the current base address of the segment that, by default, +is referenced by the %fs selector into the memory referenced by +.Fa base . +.Pp +.Fn i386_set_fsbase +sets the base address of the segment that, by default, is referenced +by %fs to the address +.Fa base . +.Pp +The segment base address is local to each thread. +The initial thread of a new process inherits its segment base address +from the parent thread. +.Xr __tfork 3 +sets the initial segment base address for threads that it creates. +.Sh RETURN VALUES +Upon successful completion, +.Fn i386_get_fsbase +and +.Fn i386_set_fsbase +return 0. +Otherwise, a value of \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn i386_get_fsbase +will fail if: +.Bl -tag -width [EINVAL] +.It Bq Er EFAULT +.Fa base +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr fork 2 , +.Xr __tfork 3 +.Rs +.%A Intel +.%T i386 Microprocessor Programmer's Reference Manual +.Re diff --git a/static/openbsd/man2/i386_get_gsbase.2 b/static/openbsd/man2/i386_get_gsbase.2 new file mode 100644 index 00000000..fce09f61 --- /dev/null +++ b/static/openbsd/man2/i386_get_gsbase.2 @@ -0,0 +1,95 @@ +.\" $OpenBSD: i386_get_gsbase.2,v 1.6 2025/06/05 18:47:18 schwarze Exp $ +.\" $NetBSD: i386_get_ioperm.2,v 1.3 1996/02/27 22:57:17 jtc Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by John T. Kohl and Charles M. Hannum. +.\" +.\" 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 NETBSD FOUNDATION, INC. 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 $Mdocdate: June 5 2025 $ +.Dt I386_GET_GSBASE 2 i386 +.Os +.Sh NAME +.Nm i386_get_gsbase , +.Nm i386_set_gsbase +.Nd manage i386 per-thread %gs base address +.Sh SYNOPSIS +.Lb libi386 +.In sys/types.h +.In machine/sysarch.h +.Ft int +.Fn i386_get_gsbase "void **base" +.Ft int +.Fn i386_set_gsbase "void *base" +.Sh DESCRIPTION +.Fn i386_get_gsbase +copies the current base address of the segment that, by default, +is referenced by the %gs selector into the memory referenced by +.Fa base . +.Pp +.Fn i386_set_gsbase +sets the base address of the segment that, by default, is referenced +by %gs to the address +.Fa base . +.Pp +The segment base address is local to each thread. +The initial thread of a new process inherits its segment base address +from the parent thread. +.Xr __tfork 3 +sets the initial segment base address for threads that it creates. +.Sh RETURN VALUES +Upon successful completion, +.Fn i386_get_gsbase +and +.Fn i386_set_gsbase +return 0. +Otherwise, a value of \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn i386_get_gsbase +will fail if: +.Bl -tag -width [EINVAL] +.It Bq Er EFAULT +.Fa base +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr fork 2 , +.Xr __tfork 3 +.Rs +.%A Intel +.%T i386 Microprocessor Programmer's Reference Manual +.Re +.Sh WARNING +The ELF Thread-Local Storage ABI reserves %gs for its own use and +requires that the dynamic linker and thread library set it to +reference data-structures internal to and shared between them. +Programs should use the __thread storage class keyword instead of +using these calls. +To be maximally portable, +programs that require per-thread data should use the +.Fn pthread_key_create +interface. diff --git a/static/openbsd/man2/i386_iopl.2 b/static/openbsd/man2/i386_iopl.2 new file mode 100644 index 00000000..0a71f129 --- /dev/null +++ b/static/openbsd/man2/i386_iopl.2 @@ -0,0 +1,80 @@ +.\" $OpenBSD: i386_iopl.2,v 1.20 2025/06/05 18:47:18 schwarze Exp $ +.\" $NetBSD: i386_iopl.2,v 1.3 1996/02/27 22:57:25 jtc Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by John T. Kohl and Charles M. Hannum. +.\" +.\" 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 NETBSD FOUNDATION, INC. 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 $Mdocdate: June 5 2025 $ +.Dt I386_IOPL 2 i386 +.Os +.Sh NAME +.Nm i386_iopl +.Nd change the i386 I/O privilege level +.Sh SYNOPSIS +.Lb libi386 +.In sys/types.h +.In machine/sysarch.h +.Ft int +.Fn i386_iopl "int iopl" +.Sh DESCRIPTION +.Fn i386_iopl +sets the i386 I/O privilege level to the value specified by +.Ar iopl . +.Pp +This call may only be made by the superuser. +Additionally, it is only permitted when the +.Xr securelevel 7 +is less than or equal to 0 or the +.Va machdep.allowaperture +sysctl has been set to a non-zero value. +.Sh RETURN VALUES +Upon successful completion, +.Fn i386_iopl +returns 0. +Otherwise, a value of \-1 is returned and the global +variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn i386_iopl +will fail if: +.Bl -tag -width [EINVAL] +.It Bq Er EPERM +The caller was not the superuser, or the securelevel is greater than zero and +.Va machdep.allowaperture +has not been set to a non-zero value. +.El +.Sh SEE ALSO +.Xr securelevel 7 +.Sh REFERENCES +.Rs +.%A Intel +.%T i386 Microprocessor Programmer's Reference Manual +.Re +.Sh WARNING +You can really hose your machine if you enable user-level I/O and +write to hardware ports without care. diff --git a/static/openbsd/man2/inb.2 b/static/openbsd/man2/inb.2 new file mode 100644 index 00000000..6d9f5fdb --- /dev/null +++ b/static/openbsd/man2/inb.2 @@ -0,0 +1,133 @@ +.\" $OpenBSD: inb.2,v 1.9 2025/06/08 12:48:44 schwarze Exp $ +.\" +.\" Copyright (c) 2002 Matthieu Herrb +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" +.\" - Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" - 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 COPYRIGHT HOLDERS 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 +.\" COPYRIGHT HOLDERS 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 $Mdocdate: June 8 2025 $ +.Dt LIBALPHA 2 alpha +.Os +.Sh NAME +.Nm dense_base , +.Nm inb , +.Nm inl , +.Nm inw , +.Nm ioperm , +.Nm map_memory , +.Nm outb , +.Nm outl , +.Nm outw , +.Nm readb , +.Nm readl , +.Nm readw , +.Nm unmap_memory , +.Nm writeb , +.Nm writel , +.Nm writew +.Nd Alpha devices I/O ports and memory access functions +.Sh SYNOPSIS +.Lb libalpha +.Ft u_int64_t +.Fn dense_base "void" +.Ft u_int8_t +.Fn inb "u_int32_t port" +.Ft u_int32_t +.Fn inl "u_int32_t port" +.Ft u_int16_t +.Fn inw "u_int32_t port" +.Ft int +.Fn ioperm "unsigned long from" "unsigned long num" "int on" +.Ft void * +.Fn map_memory "u_int32_t address" "u_int32_t size" +.Ft void +.Fn outb "u_int32_t port" "u_int8_t val" +.Ft void +.Fn outl "u_int32_t port" "u_int32_t val" +.Ft void +.Fn outw "u_int32_t port" "u_int16_t val" +.Ft u_int8_t +.Fn readb "void *handle" "u_int32_t offset" +.Ft u_int32_t +.Fn readl "void *handle" "u_int32_t offset" +.Ft u_int16_t +.Fn readw "void *handle" "u_int32_t offset" +.Ft void +.Fn unmap_memory "void *handle" "u_int32_t size" +.Ft void +.Fn writeb "void *handle" "u_int32_t offset" "u_int8_t val" +.Ft void +.Fn writel "void *handle" "u_int32_t offset" "u_int32_t val" +.Ft void +.Fn writew "void *handle" "u_int32_t offset" "u_int16_t val" +.Sh DESCRIPTION +The functions in libalpha give userland programs access to the I/O +ports on the OpenBSD/alpha platform. +.Pp +The +.Fn in* +functions return data read from the specified I/O port. +.Pp +The +.Fn out* +functions write data to the specified I/O port. +.Pp +.Fn ioperm +enables access to the specified port numbers if +.Fa on +is +.Dv TRUE +and disables access if +.Fa on +is +.Dv FALSE . +.Pp +The +.Fn map_memory +function allows a user program to map part of a device memory. +.Pp +The +.Fn unmap_memory +function unmaps memory that was previously mapped by +.Fn map_memory . +.Pp +The +.Fn read* +functions read data from device memory previously mapped by +.Fn map_memory . +.Pp +The +.Fn write* +functions write data to the device memory previously mapped by +.Fn map_memory . +.Sh HISTORY +These functions originally appeared in +.Fx . +.Sh CAVEATS +Only BWX bus access method is supported for now. +Machines requiring +swiz type access are not supported. +.Pp +Root credentials are needed to use these functions. diff --git a/static/openbsd/man2/intro.2 b/static/openbsd/man2/intro.2 new file mode 100644 index 00000000..5483d8fb --- /dev/null +++ b/static/openbsd/man2/intro.2 @@ -0,0 +1,793 @@ +.\" $OpenBSD: intro.2,v 1.79 2025/07/18 17:19:45 schwarze Exp $ +.\" $NetBSD: intro.2,v 1.6 1995/02/27 12:33:41 cgd Exp $ +.\" +.\" 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. 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.3 (Berkeley) 12/11/93 +.\" +.Dd $Mdocdate: July 18 2025 $ +.Dt INTRO 2 +.Os +.Sh NAME +.Nm intro , +.Nm errno +.Nd introduction to system calls and error numbers +.Sh SYNOPSIS +.In errno.h +.Sh DESCRIPTION +The manual pages in section 2 provide an overview of the system calls, +their error returns, and other common definitions and concepts. +.Pp +Programs may be restricted to a subset of system calls with +.Xr pledge 2 . +.\".Pp +.\".Sy System call restart +.\".Pp +.\"<more later...> +.Sh DIAGNOSTICS +Nearly all of the system calls provide an error number via the identifier +.Va errno , +which expands to an addressable location of type +.Vt int . +The address of +.Va errno +in each thread is guaranteed to be unique for the lifetime of the thread. +Applications must use +.Va errno +as defined in +.In errno.h +and not attempt to use a custom 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 +.In sys/errno.h . +.Bl -hang -width Ds +.It Er 0 Em "Undefined 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 which corresponds to the given process ID. +.It Er 4 EINTR Em "Interrupted system call" . +An asynchronous signal (such as +.Dv SIGINT +or +.Dv SIGQUIT ) +was caught by the thread 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 (overwritten) by any subsequent errors. +.It Er 6 ENXIO Em "Device not configured" . +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 "Argument list too long" . +The number of bytes used for the argument and environment +list of the new process exceeded the limit +.Dv ARG_MAX . +.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). +.It Er 10 ECHILD Em "\&No child processes" . +A +.Xr wait 2 , +.Xr waitid 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 "Block device required" . +A block device operation was attempted on a non-block device or file. +.It Er 16 EBUSY Em "Device 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 "Cross-device 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 file descriptor or 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 request for an open cannot be satisfied +until at least one has been closed. +The +.Xr sysctl 2 +variable +.Va kern.maxfiles +contains the current limit. +.It Er 24 EMFILE Em "Too many open files" . +The maximum number of file descriptors allowable for this process +has been reached and a request for an open cannot be satisfied +until at least one has been closed. +.Xr getdtablesize 3 +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" . +An attempt was made either to execute a pure procedure (shared text) +file which was open for writing by another process, +or to open with write access a pure procedure file that is currently +being executed. +.It Er 27 EFBIG Em "File too large" . +The size of a file exceeded the maximum. +(The system-wide maximum file size is 2**63 bytes. +Each file system may impose a lower limit for files contained within it.) +.It Er 28 ENOSPC Em "\&No space left on device" . +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 FIFO. +.It Er 30 EROFS Em "Read-only file system" . +An attempt was made to modify a file or create a directory +on a file system that was read-only at the time. +.It Er 31 EMLINK Em "Too many links" . +The maximum allowable number of hard links to a single file has been +exceeded (see +.Xr pathconf 2 +for how to obtain this value). +.It Er 32 EPIPE Em "Broken pipe" . +A write on a pipe, socket or 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 "Result too large" . +A result of the function was too large to fit in the +available space (perhaps exceeded precision). +.It Er 35 EAGAIN No = Er EWOULDBLOCK 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 Internet 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 +NS addresses with Internet protocols. +.It Er 48 EADDRINUSE Em "Address already in use" . +Only one usage of each address is normally permitted. +.It Er 49 EADDRNOTAVAIL Em "Can't 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" . +A 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 "Can't 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 59 ETOOMANYREFS Em "Too many references: can't splice" . +Not used in +.Ox . +.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 pathname lookup involved more than 32 +.Pq Dv SYMLOOP_MAX +symbolic links. +.It Er 63 ENAMETOOLONG Em "File name too long" . +A component of a pathname exceeded 255 +.Pq Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded 1024 +.Pq Dv PATH_MAX +bytes. +.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" . +Not used in +.Ox . +.It Er 68 EUSERS Em "Too many users" . +The quota system ran out of table entries. +.It Er 69 EDQUOT Em "Disk 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. +.It Er 70 ESTALE Em "Stale NFS file handle" . +An attempt was made to access an open file on an NFS filesystem which +is now unavailable as referenced by the file descriptor. +This may indicate the file was deleted on the NFS server or some other +catastrophic event occurred. +.It Er 71 EREMOTE Em "Too many levels of remote in path" . +Not used in +.Ox . +.It Er 72 EBADRPC Em "RPC struct is bad" . +Exchange of +.Xr rpc 3 +information was unsuccessful. +.It Er 73 ERPCMISMATCH Em "RPC version wrong" . +The version of +.Xr rpc 3 +on the remote peer is not compatible with the local version. +.It Er 74 EPROGUNAVAIL Em "RPC program not available" . +The requested +.Xr rpc 3 +program is not registered on the remote host. +.It Er 75 EPROGMISMATCH Em "Program version wrong" . +The requested version of the +.Xr rpc 3 +program is not available on the remote host. +.It Er 76 EPROCUNAVAIL Em "Bad procedure for program" . +An +.Xr rpc 3 +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 contains invalid data or set to invalid modes. +.It Er 80 EAUTH Em "Authentication error" . +Attempted to use an invalid authentication ticket to mount a +NFS filesystem. +.It Er 81 ENEEDAUTH Em "Need authenticator" . +An authentication ticket must be obtained before the given +NFS filesystem may be mounted. +.It Er 82 EIPSEC Em "IPsec processing failure" . +IPsec subsystem error. +Not used in +.Ox . +.It Er 83 ENOATTR Em "Attribute not found" . +A UFS Extended Attribute is not found for the specified pathname. +.It Er 84 EILSEQ Em "Illegal byte sequence" . +An illegal sequence of bytes was used when using wide characters. +.It Er 85 ENOMEDIUM Em "\&No medium found" . +Attempted to use a removable media device with no medium present. +.It Er 86 EMEDIUMTYPE Em "Wrong medium type" . +Attempted to use a removable media device with incorrect or incompatible +medium. +.It Er 87 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 88 ECANCELED Em "Operation canceled" . +The requested operation was canceled. +.It Er 89 EIDRM Em "Identifier removed" . +An IPC identifier was removed while the current thread was waiting on it. +.It Er 90 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 91 ENOTSUP Em "Not supported" . +The operation has requested an unsupported value. +.It Er 92 EBADMSG Em "Bad message" . +A corrupted message was detected. +.It Er 93 ENOTRECOVERABLE Em "State not recoverable" . +The state protected by a robust mutex is not recoverable. +.It Er 94 EOWNERDEAD Em "Previous owner died" . +The owner of a robust mutex terminated while holding the mutex lock. +.It Er 95 EPROTO Em "Protocol error" . +A device-specific protocol error occurred. +.El +.Sh DEFINITIONS +.Bl -tag -width Ds +.It Process +A process is a collection of one or more threads, +plus the resources shared by those threads such as process ID, +address space, +user IDs and group IDs, +and root directory and current working directory. +.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 ksh 1 +and +.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. +.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 ksh 1 , +.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 Thread +A thread is a preemptively scheduled flow of control within a process, +with its own set of register values, +floating point environment, +thread ID, +signal mask, +pending signal set, +alternate signal stack, +thread control block address, +resource utilization, +errno variable location, +and values for thread-specific keys. +A process initially has just one thread, +a duplicate of the thread in the parent process that created this process. +.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 of 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 +.Dq 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 superuser.) +.It Superuser +A process is recognized as a +.Em superuser +process and is granted special privileges if its effective user ID is 0. +.It Special Processes +The processes with process IDs of 0 and 1 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. +.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 NAME_MAX +characters may be used to name +an ordinary file, special file, or directory. +.Pp +These characters may be arbitrary eight-bit values, +excluding 0 (NUL) and the 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. +.Pp +Note also that +.Dv NAME_MAX +is an upper limit fixed by the kernel, meant to be used for sizing buffers. +Some filesystems may have additional restrictions. +These can be queried using +.Xr pathconf 2 +and +.Xr fpathconf 2 . +.It Pathname +A pathname is a NUL-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 pathname must be less than 1024 +.Pq Dv PATH_MAX +characters. +Additional restrictions may apply, depending upon the filesystem, to be +queried with +.Xr pathconf 2 +or +.Xr fpathconf 2 +if needed. +.Pp +If a pathname 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 is invalid. +.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 superuser. +(Note: even the superuser 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 +.Dq other users +allow access. +.Pp +Otherwise, permission is denied. +.It Sockets and Address Families +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. +.El +.Sh SEE ALSO +.Xr pledge 2 , +.Xr intro 3 , +.Xr perror 3 +.Sh STANDARDS +Most of the macro names that resolve to error numbers +are required to be defined by +.St -p1003.1-2024 . +In some cases, the standard requires certain kinds of failures +to be reported with certain error numbers. +It some cases, it allows certain kinds of failures +to optionally be reported with certain error numbers. +In some cases, it is entirely silent about whether and how +the system should report problems. +.Pp +The following defined constants are extensions to the standard: +.Er EAUTH , +.Er EBADRPC , +.Er EFTYPE , +.Er EHOSTDOWN , +.Er EIPSEC , +.Er EMEDIUMTYPE , +.Er ENEEDAUTH , +.Er ENOATTR , +.Er ENOMEDIUM , +.Er ENOTBLK , +.Er EPFNOSUPPORT , +.Er EPROCLIM , +.Er EPROCUNAVAIL , +.Er EPROGMISMATCH , +.Er EPROGUNAVAIL , +.Er EREMOTE , +.Er ERPCMISMATCH , +.Er ESHUTDOWN , +.Er ETOOMANYREFS , +and +.Er EUSERS . +.Sh HISTORY +An +.Nm +manual for section 2 first appeared in +.At v5 . +.Sh BUGS +Since some error numbers are only loosely defined, and since which error +numbers any given function can set often varies from system to system, +programs usually need to make a fallback decision when receiving an +unexpected error number, typically treating it as a hard failure, +or less commonly just ignoring it. +Making portable decisions based on error numbers is only possible +for some specific error numbers being set by some specific functions. diff --git a/static/openbsd/man2/ioctl.2 b/static/openbsd/man2/ioctl.2 new file mode 100644 index 00000000..b9a084c2 --- /dev/null +++ b/static/openbsd/man2/ioctl.2 @@ -0,0 +1,171 @@ +.\" $OpenBSD: ioctl.2,v 1.20 2022/09/11 06:38:11 jmc Exp $ +.\" $NetBSD: ioctl.2,v 1.5 1995/02/27 12:33:47 cgd 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. 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 +.\" +.Dd $Mdocdate: September 11 2022 $ +.Dt IOCTL 2 +.Os +.Sh NAME +.Nm ioctl +.Nd control device +.Sh SYNOPSIS +.In 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. +.Pp +The argument +.Fa d +must be an open file descriptor. +The third argument is called +.Fa arg +and contains additional information needed by this device +to perform the requested function. +.Fa arg +is either an +.Vt int +or a pointer to a device-specific data structure, depending upon +the given +.Fa request . +.Pp +An +.Nm +.Fa request +has encoded in it whether the argument is an +.Dq in +parameter +or +.Dq out +parameter, and the size of the third argument +.Pq Fa arg +in bytes. +Macros and defines used in specifying an ioctl +.Fa request +are located in the file +.In sys/ioctl.h . +.Sh GENERIC IOCTLS +Some ioctls are applicable to any file descriptor. +These include: +.Bl -tag -width "xxxxxx" +.It Dv FIOCLEX +Set close-on-exec flag. +The file will be closed when +.Xr execve 2 +is invoked. +.It Dv FIONCLEX +Clear close-on-exec flag. +The file will remain open across +.Xr execve 2 . +.El +.Pp +Some generic ioctls are not implemented for all types of file +descriptors. +These include: +.Bl -tag -width "xxxxxx" +.It Dv FIONREAD Fa "int *" +Get the number of bytes that are immediately available for reading. +.It Dv FIONBIO Fa "int *" +Set non-blocking I/O mode if the argument is non-zero. +In non-blocking mode, +.Xr read 2 +or +.Xr write 2 +calls return \-1 and set +.Va errno +to +.Er EAGAIN +immediately when no data is available. +.It Dv FIOASYNC Fa "int *" +Set asynchronous I/O mode if the argument is non-zero. +In asynchronous mode, the process or process group specified by +.Dv FIOSETOWN +will start receiving +.Dv SIGIO +signals when data is available. +The +.Dv SIGIO +signal will be delivered when data is available on the file +descriptor. +.It Dv FIOSETOWN, FIOGETOWN Fa "int *" +Set/get the process or the process group (if negative) that should receive +.Dv SIGIO +signals when data is available. +.El +.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 Er +.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 arg +is not valid. +.It Bq Er EFAULT +.Fa arg +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr cdio 1 , +.Xr chio 1 , +.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/static/openbsd/man2/issetugid.2 b/static/openbsd/man2/issetugid.2 new file mode 100644 index 00000000..7da2203c --- /dev/null +++ b/static/openbsd/man2/issetugid.2 @@ -0,0 +1,106 @@ +.\" $OpenBSD: issetugid.2,v 1.21 2015/09/10 17:55:21 schwarze 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. 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 $Mdocdate: September 10 2015 $ +.Dt ISSETUGID 2 +.Os +.Sh NAME +.Nm issetugid +.Nd is current executable running setuid or setgid +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn issetugid void +.Sh DESCRIPTION +The +.Fn issetugid +function returns 1 if the process was made setuid or setgid as +the result of the last or other previous +.Fn execve +system calls. +Otherwise it returns 0. +.Pp +This system call exists so that library routines (inside libtermlib, libc, +or other libraries) can guarantee safe behavior when used inside +setuid or setgid programs. +Some library routines may be passed insufficient information and hence +not know whether the current program was started setuid or setgid +because higher level calling code may have made changes to the uid, euid, +gid, or egid. +Hence these low-level library routines are unable to determine if they +are being run with elevated or normal privileges. +.Pp +In particular, it is wise to use this call to determine if a +pathname returned from a +.Fn getenv +call may safely be used to +.Fn open +the specified file. +Quite often this is not wise because the status of the effective uid +is not known. +.Pp +The +.Fn issetugid +system call's result is unaffected by calls to +.Fn setuid , +.Fn setgid , +or other such calls. +In case of a +.Fn fork , +the child process inherits the same status. +.Pp +The status of +.Fn issetugid +is only affected by +.Fn execve . +If a child process executes a new executable file, a new issetugid +status will be determined. +This status is based on the existing process's uid, euid, gid, +and egid permissions and on the modes of the executable file. +If the new executable file modes are setuid or setgid, or if +the existing process is executing the new image with +uid != euid or gid != egid, the new process will be considered +issetugid. +.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 setegid 2 , +.Xr seteuid 2 , +.Xr setgid 2 , +.Xr setuid 2 , +.Xr getenv 3 +.Sh HISTORY +The +.Fn issetugid +function call first appeared in +.Ox 2.0 . diff --git a/static/openbsd/man2/kbind.2 b/static/openbsd/man2/kbind.2 new file mode 100644 index 00000000..bbb2f49c --- /dev/null +++ b/static/openbsd/man2/kbind.2 @@ -0,0 +1,120 @@ +.\" $OpenBSD: kbind.2,v 1.4 2021/11/21 23:44:55 jan Exp $ +.\" +.\" Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: November 21 2021 $ +.Dt KBIND 2 +.Os +.Sh NAME +.Nm kbind +.Nd update protected memory for lazy-binding +.Sh SYNOPSIS +.In sys/unistd.h +.Bd -literal +struct __kbind { + void *kb_addr; + size_t kb_size; +}; +#define KBIND_BLOCK_MAX 2 /* powerpc and sparc64 need 2 blocks */ +#define KBIND_DATA_MAX 24 /* sparc64 needs 6, four-byte words */ +.Ed +.Pp +.Ft int +.Fn kbind "const struct __kbind *param" "size_t psize" "int64_t cookie" +.Sh DESCRIPTION +The +.Nm +syscall updates the contents of one or more blocks of the process's memory +with the supplied replacement data. +This is used to efficiently and securely perform lazy-binding. +.Pp +.Fa param +points to an array of +.Vt __kbind +structures giving the addresses and lengths to update. +The last +.Vt __kbind +structure is immediately followed in the same order by the source +data for the blocks to copy. +.Fa psize +specifies the total length of the parameters: both the +.Vt __kbind +structures and the associated source data. +There may be at most +.Dv KBIND_BLOCK_MAX +.Vt __kbind +structures and each block may be at most +.Dv KBIND_DATA_MAX +bytes in size. +.Pp +.Nm +updates memory +.Do +as if +.Dc +the thread temporarily made the memory writable with +.Xr mprotect 2 . +If the process does not have write access to the underlying memory object, +.Nm +will fail without making the requested change. +.Pp +.Nm +is currently intended for use by +.Xr ld.so 1 +only. +It is therefore not provided as a function and two security checks +are performed to bind it (pun intended) to its use in +.Xr ld.so 1 : +the first time +.Nm +is used, the kernel records both the text address of the call and +the value of the +.Fa cookie +argument. +If those values differ in a later +.Nm +call, then the process is killed. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn kbind +will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Cannot allocate memory when updating a copy-on-write page. +.It Bq Er EINVAL +The parameters are inconsistent or exceed +.Nm +limits. +.It Bq Er EFAULT +Part of the structures or additional data pointed to by +.Fa param +is outside the process's allocated address space, +or the underlying memory object is not writable. +.El +.Sh SEE ALSO +.Xr ld.so 1 , +.Xr mprotect 2 +.Sh STANDARDS +The +.Nm +syscall is specific to the +.Ox +dynamic linker and should not be used in portable applications. +.Sh HISTORY +The +.Nm +syscall appeared in +.Ox 5.8 . diff --git a/static/openbsd/man2/kill.2 b/static/openbsd/man2/kill.2 new file mode 100644 index 00000000..f12cc4b0 --- /dev/null +++ b/static/openbsd/man2/kill.2 @@ -0,0 +1,168 @@ +.\" $OpenBSD: kill.2,v 1.26 2020/02/08 01:09:57 jsg Exp $ +.\" $NetBSD: kill.2,v 1.7 1995/02/27 12:33:53 cgd 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. 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 +.\" +.Dd $Mdocdate: February 8 2020 $ +.Dt KILL 2 +.Os +.Sh NAME +.Nm kill +.Nd send signal to a process +.Sh SYNOPSIS +.In 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 superuser). +A single exception is the signal +.Dv SIGCONT , +which may always be sent +to any process with the same session ID as the caller. +.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 3 . +.It \&If Fa pid No \&is -1 : +If the user has superuser privileges, +the signal is sent to all processes excluding +system processes and the process sending the signal. +If the user is not the superuser, 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. +.It \&If Fa pid No \&is negative but not -1 : +.Fa sig +is sent to all processes whose process group ID +is equal to the absolute value of +.Fa pid ; +this is a variant of +.Xr killpg 3 . +.El +.Pp +If the value of +.Fa pid +causes +.Fa sig +to be sent to the calling process, either +.Fa sig +or at least one pending unblocked signal will be delivered before +.Fn kill +returns unless +.Fa sig +is blocked in the calling thread, +.Fa sig +is unblocked in another thread, or another thread is waiting for +.Fa sig +in +.Fn sigwait . +.Pp +Setuid and setgid processes are dealt with slightly differently. +For the non-root user, to prevent attacks against such processes, some signal +deliveries are not permitted and return the error +.Er EPERM . +The following signals are allowed through to this class of processes: +.Dv SIGKILL , +.Dv SIGINT , +.Dv SIGTERM , +.Dv SIGSTOP , +.Dv SIGTTIN , +.Dv SIGTTOU , +.Dv SIGTSTP , +.Dv SIGHUP , +.Dv SIGUSR1 , +.Dv SIGUSR2 . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn kill +will fail and no signal will be sent if: +.Bl -tag -width Er +.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 EPERM +The sending process is not the superuser 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 none of the members +of the group could be signaled. +.El +.Sh SEE ALSO +.Xr getpgrp 2 , +.Xr getpid 2 , +.Xr sigaction 2 , +.Xr killpg 3 , +.Xr raise 3 +.Sh STANDARDS +The +.Fn kill +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn kill +system call first appeared in +.At v2 . +The +.Fa sig +argument was introduced in +.At v4 . diff --git a/static/openbsd/man2/kqueue.2 b/static/openbsd/man2/kqueue.2 new file mode 100644 index 00000000..fb51db1a --- /dev/null +++ b/static/openbsd/man2/kqueue.2 @@ -0,0 +1,706 @@ +.\" $OpenBSD: kqueue.2,v 1.52 2025/05/10 09:44:39 visa Exp $ +.\" +.\" Copyright (c) 2000 Jonathan Lemon +.\" 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 ``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: src/lib/libc/sys/kqueue.2,v 1.18 2001/02/14 08:48:35 guido Exp $ +.\" +.Dd $Mdocdate: May 10 2025 $ +.Dt KQUEUE 2 +.Os +.Sh NAME +.Nm kqueue , +.Nm kqueue1 , +.Nm kevent , +.Nm EV_SET +.Nd kernel event notification mechanism +.Sh SYNOPSIS +.In sys/types.h +.In sys/event.h +.In sys/time.h +.Ft int +.Fn kqueue "void" +.Ft int +.Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout" +.Fn EV_SET "&kev" ident filter flags fflags data udata +.In sys/types.h +.In sys/event.h +.In sys/time.h +.In fcntl.h +.Ft int +.Fn kqueue1 "int flags" +.Sh DESCRIPTION +.Fn kqueue +provides a generic method of notifying the user when an event +happens or a condition holds, based on the results of small +pieces of kernel code termed +.Dq filters . +A kevent is identified by the (ident, filter) pair; there may only +be one unique kevent per kqueue. +.Pp +The filter is executed upon the initial registration of a kevent +in order to detect whether a preexisting condition is present, and is also +executed whenever an event is passed to the filter for evaluation. +If the filter determines that the condition should be reported, +then the kevent is placed on the kqueue for the user to retrieve. +.Pp +The filter is also run when the user attempts to retrieve the kevent +from the kqueue. +If the filter indicates that the condition that triggered +the event no longer holds, the kevent is removed from the kqueue and +is not returned. +.Pp +Multiple events which trigger the filter do not result in multiple +kevents being placed on the kqueue; instead, the filter will aggregate +the events into a single +.Vt struct kevent . +Calling +.Xr close 2 +on a file descriptor will remove any kevents that reference the descriptor. +.Pp +.Fn kqueue +creates a new kernel event queue and returns a descriptor. +The queue is not inherited by a child created with +.Xr fork 2 . +Similarly, kqueues cannot be passed across UNIX-domain sockets. +.Pp +The +.Fn kqueue1 +function is identical to +.Fn kqueue +except that the close-on-exec flag on the new file descriptor +is determined by the +.Dv O_CLOEXEC +flag +in the +.Fa flags +argument. +.Pp +.Fn kevent +is used to register events with the queue, and return any pending +events to the user. +.Fa changelist +is a pointer to an array of +.Vt kevent +structures, as defined in +.In sys/event.h . +All changes contained in the +.Fa changelist +are applied before any pending events are read from the queue. +.Fa nchanges +gives the size of +.Fa changelist . +.Fa eventlist +is a pointer to an array of +.Vt kevent +structures. +.Fa nevents +determines the size of +.Fa eventlist . +When +.Fa nevents +is zero, +.Fn kevent +will return immediately even if there is a +.Fa timeout +specified, unlike +.Xr select 2 . +If +.Fa timeout +is not +.Dv NULL , +it specifies a maximum interval to wait +for an event, which will be interpreted as a +.Vt struct timespec . +If +.Fa timeout +is +.Dv NULL , +.Fn kevent +waits indefinitely. +To effect a poll, the +.Fa timeout +argument should not be +.Dv NULL , +pointing to a zero-valued +.Vt struct timespec . +The same array may be used for the +.Fa changelist +and +.Fa eventlist . +.Pp +.Fn EV_SET +is a macro which is provided for ease of initializing a +.Vt kevent +structure. +.Pp +The +.Vt kevent +structure is defined as: +.Bd -literal +struct kevent { + uintptr_t ident; /* identifier for this event */ + short filter; /* filter for event */ + u_short flags; /* action flags for kqueue */ + u_int fflags; /* filter flag value */ + int64_t data; /* filter data value */ + void *udata; /* opaque user data identifier */ +}; +.Ed +.Pp +The fields of +.Vt struct kevent +are: +.Bl -tag -width XXXfilter +.It Fa ident +Value used to identify this event. +The exact interpretation is determined by the attached filter, +but often is a file descriptor. +.It Fa filter +Identifies the kernel filter used to process this event. +The pre-defined system filters are described below. +.It Fa flags +Actions to perform on the event. +.It Fa fflags +Filter-specific flags. +.It Fa data +Filter-specific data value. +.It Fa udata +Opaque user-defined value passed through the kernel unchanged. +.El +.Pp +The +.Fa flags +field can contain the following values: +.Bl -tag -width XXXEV_ONESHOT +.It Dv EV_ADD +Adds the event to the kqueue. +Re-adding an existing event will modify the parameters of the original event, +and not result in a duplicate entry. +Adding an event automatically enables it, unless overridden by the +.Dv EV_DISABLE +flag. +.It Dv EV_ENABLE +Permit +.Fn kevent +to return the event if it is triggered. +.It Dv EV_DISABLE +Disable the event so +.Fn kevent +will not return it. +The filter itself is not disabled. +.It Dv EV_DISPATCH +Disable the event source immediately after delivery of an event. +See +.Dv EV_DISABLE +above. +.It Dv EV_DELETE +Removes the event from the kqueue. +Events which are attached to file descriptors are automatically deleted +on the last close of the descriptor. +.It Dv EV_RECEIPT +Causes +.Fn kevent +to return with +.Dv EV_ERROR +set without draining any pending events after updating events in the kqueue. +When a filter is successfully added, the +.Fa data +field will be zero. +This flag is useful for making bulk changes to a kqueue. +.It Dv EV_ONESHOT +Causes the event to return only the first occurrence of the filter +being triggered. +After the user retrieves the event from the kqueue, it is deleted. +.It Dv EV_CLEAR +After the event is retrieved by the user, its state is reset. +This is useful for filters which report state transitions +instead of the current state. +Note that some filters may automatically set this flag internally. +.It Dv EV_EOF +Filters may set this flag to indicate filter-specific EOF condition. +.It Dv EV_ERROR +See +.Sx RETURN VALUES +below. +.El +.Pp +The predefined system filters are listed below. +Arguments may be passed to and from the filter via the +.Fa fflags +and +.Fa data +fields in the +.Vt kevent +structure. +.Bl -tag -width EVFILT_SIGNAL +.It Dv EVFILT_READ +Takes a descriptor as the identifier, and returns whenever +there is data available to read. +The behavior of the filter is slightly different depending +on the descriptor type. +.Bl -tag -width 2n +.It Sockets +Sockets which have previously been passed to +.Xr listen 2 +return when there is an incoming connection pending. +.Fa data +contains the size of the listen backlog. +.Pp +Other socket descriptors return when there is data to be read, +subject to the +.Dv SO_RCVLOWAT +value of the socket buffer. +This may be overridden with a per-filter low water mark at the +time the filter is added by setting the +.Dv NOTE_LOWAT +flag in +.Fa fflags , +and specifying the new low water mark in +.Fa data . +On return, +.Fa data +contains the number of bytes in the socket buffer. +.Pp +If the read direction of the socket has shutdown, then the filter +also sets +.Dv EV_EOF +in +.Fa flags , +and returns the socket error (if any) in +.Fa fflags . +It is possible for EOF to be returned (indicating the connection is gone) +while there is still data pending in the socket buffer. +.It Vnodes +Returns when the file pointer is not at the end of file. +.Fa data +contains the offset from current position to end of file, +and may be negative. +If +.Dv NOTE_EOF +is set in +.Fa fflags , +.Fn kevent +will also return when the file pointer is at the end of file. +The end of file condition is indicated by the presence of +.Dv NOTE_EOF +in +.Fa fflags +on return. +.It "FIFOs, Pipes" +Returns when there is data to read; +.Fa data +contains the number of bytes available. +.Pp +When the last writer disconnects, the filter will set +.Dv EV_EOF +in +.Fa flags . +This may be cleared by passing in +.Dv EV_CLEAR , +at which point the filter will resume waiting for data to become +available before returning. +.It "BPF devices" +Returns when the BPF buffer is full, the BPF timeout has expired, or +when the BPF has +.Dq immediate mode +enabled and there is any data to read; +.Fa data +contains the number of bytes available. +.El +.It Dv EVFILT_EXCEPT +Takes a descriptor as the identifier, and returns whenever one of the +specified exceptional conditions has occurred on the descriptor. +Conditions are specified in +.Fa fflags . +Currently, a filter can monitor the reception of out-of-band data +on a socket or pseudo terminal with +.Dv NOTE_OOB . +.It Dv EVFILT_WRITE +Takes a descriptor as the identifier, and returns whenever +it is possible to write to the descriptor. +For sockets, pipes, and FIFOs, +.Fa data +will contain the amount of space remaining in the write buffer. +The filter will set +.Dv EV_EOF +when the reader disconnects, and for the FIFO case, +this may be cleared by use of +.Dv EV_CLEAR . +Note that this filter is not supported for vnodes or BPF devices. +.Pp +For sockets, the low water mark and socket error handling is +identical to the +.Dv EVFILT_READ +case. +.\".It Dv EVFILT_AIO +.\"The sigevent portion of the AIO request is filled in, with +.\".Va sigev_notify_kqueue +.\"containing the descriptor of the kqueue that the event should +.\"be attached to, +.\".Va sigev_value +.\"containing the udata value, and +.\".Va sigev_notify +.\"set to +.\".Dv SIGEV_KEVENT . +.\"When the aio_* function is called, the event will be registered +.\"with the specified kqueue, and the +.\".Va ident +.\"argument set to the +.\".Li struct aiocb +.\"returned by the aio_* function. +.\"The filter returns under the same conditions as aio_error. +.\".Pp +.\"Alternatively, a kevent structure may be initialized, with +.\".Va ident +.\"containing the descriptor of the kqueue, and the +.\"address of the kevent structure placed in the +.\".Va aio_lio_opcode +.\"field of the AIO request. +.\"However, this approach will not work on architectures with 64-bit pointers, +.\"and should be considered deprecated. +.It Dv EVFILT_VNODE +Takes a file descriptor as the identifier and the events to watch for in +.Fa fflags , +and returns when one or more of the requested events occurs on the descriptor. +The events to monitor are: +.Bl -tag -width XXNOTE_RENAME +.It Dv NOTE_DELETE +.Xr unlink 2 +was called on the file referenced by the descriptor. +.It Dv NOTE_WRITE +A write occurred on the file referenced by the descriptor. +.It Dv NOTE_EXTEND +The file referenced by the descriptor was extended. +.It Dv NOTE_TRUNCATE +The file referenced by the descriptor was truncated. +.It Dv NOTE_ATTRIB +The file referenced by the descriptor had its attributes changed. +.It Dv NOTE_LINK +The link count on the file changed. +.It Dv NOTE_RENAME +The file referenced by the descriptor was renamed. +.It Dv NOTE_REVOKE +Access to the file was revoked via +.Xr revoke 2 +or the underlying file system was unmounted. +.El +.Pp +On return, +.Fa fflags +contains the events which triggered the filter. +.It Dv EVFILT_PROC +Takes the process ID to monitor as the identifier and the events to watch for +in +.Fa fflags , +and returns when the process performs one or more of the requested events. +If a process can normally see another process, it can attach an event to it. +The events to monitor are: +.Bl -tag -width XXNOTE_TRACKERR +.It Dv NOTE_EXIT +The process has exited. +The exit status will be stored in +.Fa data +in the same format as the status set by +.Xr wait 2 . +.It Dv NOTE_FORK +The process has called +.Xr fork 2 . +.It Dv NOTE_EXEC +The process has executed a new process via +.Xr execve 2 +or similar call. +.It Dv NOTE_TRACK +Follow a process across +.Xr fork 2 +calls. +The parent process will return with +.Dv NOTE_FORK +set in the +.Fa fflags +field, while the child process will return with +.Dv NOTE_CHILD +set in +.Fa fflags +and the parent PID in +.Fa data . +.It Dv NOTE_TRACKERR +This flag is returned if the system was unable to attach an event to +the child process, usually due to resource limitations. +.El +.Pp +On return, +.Fa fflags +contains the events which triggered the filter. +.It Dv EVFILT_SIGNAL +Takes the signal number to monitor as the identifier and returns +when the given signal is delivered to the process. +This coexists with the +.Xr signal 3 +and +.Xr sigaction 2 +facilities, and has a lower precedence. +The filter will record all attempts to deliver a signal to a process, +even if the signal has been marked as +.Dv SIG_IGN . +Event notification happens after normal signal delivery processing. +.Fa data +returns the number of times the signal has occurred since the last call to +.Fn kevent . +This filter automatically sets the +.Dv EV_CLEAR +flag internally. +.It Dv EVFILT_TIMER +Establishes an arbitrary timer identified by +.Fa ident . +When adding a timer, +.Fa data +specifies the timeout period in units described below or, if +.Dv NOTE_ABSTIME +is set in +.Va fflags , +the absolute time at which the timer should fire. +The timer will repeat unless +.Dv EV_ONESHOT +is set in +.Va flags +or +.Dv NOTE_ABSTIME +is set in +.Va fflags . +On return, +.Fa data +contains the number of times the timeout has expired since the last call to +.Fn kevent . +This filter automatically sets +.Dv EV_CLEAR +in +.Va flags +for periodic timers. +Timers created with +.Dv NOTE_ABSTIME +remain activated on the kqueue once the absolute time has passed unless +.Dv EV_CLEAR +or +.Dv EV_ONESHOT +are also specified. +.Pp +The filter accepts the following flags in the +.Va fflags +argument: +.Bl -tag -width NOTE_MSECONDS +.It Dv NOTE_SECONDS +The timer value in +.Va data +is expressed in seconds. +.It Dv NOTE_MSECONDS +The timer value in +.Va data +is expressed in milliseconds. +.It Dv NOTE_USECONDS +The timer value in +.Va data +is expressed in microseconds. +.It Dv NOTE_NSECONDS +The timer value in +.Va data +is expressed in nanoseconds. +.It Dv NOTE_ABSTIME +The timer value is an absolute time with +.Dv CLOCK_REALTIME +as the reference clock. +.El +.Pp +Note that +.Dv NOTE_SECONDS , +.Dv NOTE_MSECONDS , +.Dv NOTE_USECONDS , +and +.Dv NOTE_NSECONDS +are mutually exclusive; behavior is undefined if more than one are specified. +If a timer value unit is not specified, the default is +.Dv NOTE_MSECONDS . +.Pp +If an existing timer is re-added, the existing timer and related pending events +will be cancelled. +The timer will be re-started using the timeout period +.Fa data . +.It Dv EVFILT_DEVICE +Takes a descriptor as the identifier and the events to watch for in +.Fa fflags , +and returns when one or more of the requested events occur on the +descriptor. +The events to monitor are: +.Bl -tag -width XXNOTE_CHANGE +.It Dv NOTE_CHANGE +A device change event has occurred, +e.g. an HDMI cable has been plugged in to a port. +.El +.Pp +On return, +.Fa fflags +contains the events which triggered the filter. +.It Dv EVFILT_USER +Establishes a user event identified by +.Va ident +which is not associated with any kernel mechanism but is triggered by +user level code. +The lower 24 bits of the +.Va fflags +may be used for user defined flags and manipulated using the following: +.Bl -tag -width XXNOTE_FFLAGSMASK +.It Dv NOTE_FFNOP +Ignore the input +.Va fflags . +.It Dv NOTE_FFAND +Bitwise AND +.Va fflags . +.It Dv NOTE_FFOR +Bitwise OR +.Va fflags . +.It Dv NOTE_FFCOPY +Copy +.Va fflags . +.It Dv NOTE_FFCTRLMASK +Control mask for +.Va fflags . +.It Dv NOTE_FFLAGSMASK +User defined flag mask for +.Va fflags . +.El +.Pp +A user event is triggered for output with the following: +.Bl -tag -width XXNOTE_FFLAGSMASK +.It Dv NOTE_TRIGGER +Cause the event to be triggered. +.El +.Pp +On return, +.Va fflags +contains the user defined flags in the lower 24 bits. +.El +.Sh RETURN VALUES +.Fn kqueue +and +.Fn kqueue1 +create a new kernel event queue and returns a file descriptor. +If there was an error creating the kernel event queue, a value of -1 is +returned and +.Va errno +set. +.Pp +.Fn kevent +returns the number of events placed in the +.Fa eventlist , +up to the value given by +.Fa nevents . +If an error occurs while processing an element of the +.Fa changelist +and there is enough room in the +.Fa eventlist , +then the event will be placed in the +.Fa eventlist +with +.Dv EV_ERROR +set in +.Fa flags +and the system error in +.Fa data . +Otherwise, -1 will be returned, and +.Va errno +will be set to indicate the error condition. +If the time limit expires, then +.Fn kevent +returns 0. +.Sh ERRORS +The +.Fn kqueue +and +.Fn kqueue1 +functions fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +The kernel failed to allocate enough memory for the kernel queue. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.El +.Pp +In addition, +.Fn kqueue1 +fails if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa flags +is invalid. +.El +.Pp +The +.Fn kevent +function fails if: +.Bl -tag -width Er +.It Bq Er EACCES +The process does not have permission to register a filter. +.It Bq Er EFAULT +There was an error reading or writing the +.Vt kevent +structure. +.It Bq Er EBADF +The specified descriptor is invalid. +.It Bq Er EINTR +A signal was delivered before the timeout expired and before any +events were placed on the kqueue for return. +.It Bq Er EINVAL +The specified time limit or filter is invalid. +.It Bq Er ENOENT +The event could not be found to be modified or deleted. +.It Bq Er ENOMEM +No memory was available to register the event. +.It Bq Er ESRCH +The specified process to attach to does not exist. +.El +.Sh SEE ALSO +.Xr clock_gettime 2 , +.Xr poll 2 , +.Xr read 2 , +.Xr select 2 , +.Xr sigaction 2 , +.Xr wait 2 , +.Xr write 2 , +.Xr signal 3 +.Sh HISTORY +The +.Fn kqueue +and +.Fn kevent +functions first appeared in +.Fx 4.1 +and have been available since +.Ox 2.9 . +.Sh AUTHORS +The +.Fn kqueue +system and this manual page were written by +.An Jonathan Lemon Aq Mt jlemon@FreeBSD.org . diff --git a/static/openbsd/man2/ktrace.2 b/static/openbsd/man2/ktrace.2 new file mode 100644 index 00000000..75bd466e --- /dev/null +++ b/static/openbsd/man2/ktrace.2 @@ -0,0 +1,232 @@ +.\" $OpenBSD: ktrace.2,v 1.43 2023/02/23 01:34:27 deraadt Exp $ +.\" $NetBSD: ktrace.2,v 1.2 1995/02/27 12:33:58 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: February 23 2023 $ +.Dt KTRACE 2 +.Os +.Sh NAME +.Nm ktrace +.Nd process tracing +.Sh SYNOPSIS +.In sys/types.h +.In sys/ktrace.h +.Ft int +.Fn ktrace "const char *tracefile" "int ops" "int trpoints" "pid_t 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 superuser can trace setuid or setgid programs. +This function is only available on kernels compiled with the +.Cm KTRACE +option. +.Pp +.Fa tracefile +gives the pathname of the file to be used for tracing. +The file must exist, be writable by the calling process, and +not be a symbolic link. +If tracing points are being disabled (see +.Dv KTROP_CLEAR +below), +.Fa tracefile +must be +.Dv NULL . +.Pp +Trace records are always appended to the file, ignoring the file offset, +so the caller will usually want to truncate the file before calling +these functions. +.Pp +The +.Fa ops +parameter specifies the requested ktrace operation. +The defined operations are: +.Pp +.Bl -tag -width KTRFLAG_DESCEND -offset indent -compact +.It Dv KTROP_SET +Enable trace points specified in +.Fa trpoints . +.It Dv KTROP_CLEAR +Disable trace points specified in +.Fa trpoints . +.It Dv KTROP_CLEARFILE +Stop all tracing to the trace file. +.It Dv KTRFLAG_DESCEND +The tracing change should apply to the +specified process and all its current children. +.El +.Pp +The +.Fa trpoints +parameter specifies the trace points of interest. +The defined trace points are: +.Pp +.Bl -tag -width KTRFAC_EXECARGS -offset indent -compact +.It Dv KTRFAC_SYSCALL +Trace system calls. +.It Dv KTRFAC_SYSRET +Trace return values from system calls. +.It Dv KTRFAC_NAMEI +Trace name lookup operations. +.It Dv KTRFAC_GENIO +Trace all I/O +(note that this option can generate much output). +.It Dv KTRFAC_PSIG +Trace posted signals. +.It Dv KTRFAC_STRUCT +Trace various structs. +.It Dv KTRFAC_USER +Trace user data coming from +.Xr utrace 2 +calls. +.It Dv KTRFAC_EXECARGS +Trace argument vector in +.Xr execve 2 +calls. +.It Dv KTRFAC_EXECENV +Trace environment vector in +.Xr execve 2 +calls. +.It Dv KTRFAC_PLEDGE +Trace violations of +.Xr pledge 2 +restrictions. +.It Dv KTRFAC_INHERIT +Inherit tracing to future children. +.El +.Pp +The +.Fa pid +parameter refers to a process ID. +If it is negative, +it refers to a process group ID. +.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 { + uint ktr_type; /* trace record type */ + pid_t ktr_pid; /* process id */ + pid_t ktr_tid; /* thread id */ + struct timespec ktr_time; /* timestamp */ + char ktr_comm[MAXCOMLEN+1]; /* command name */ + size_t ktr_len; /* length of buf */ +}; +.Ed +.Pp +The +.Fa ktr_len +field specifies the length of the +.Fa ktr_type +data that follows this header. +The +.Fa ktr_pid , ktr_tid , +and +.Fa ktr_comm +fields specify the process, thread, and command generating the record. +The +.Fa ktr_time +field gives the time (with nanosecond resolution) +that the record was generated. +.Pp +The generic header is followed by +.Fa ktr_len +bytes of a +.Fa ktr_type +record. +The type specific records are defined in the +.In sys/ktrace.h +include file. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn ktrace +will fail if: +.Bl -tag -width EINVALAA +.It Bq Er EINVAL +No trace points were selected. +.It Bq Er EPERM +The tracing process is not the superuser and either its effective +user ID does not match the real user ID of the receiving process, +its effective group ID does not match the real group ID of the +receiving process, +the receiving process is currently being traced by the superuser, +or the receiving process has changed its UIDs or GIDs. +When tracing multiple processes, +this error is returned if none of the targeted processes could be traced. +When clearing a trace file with +.Dv KTROP_CLEARFILE , +this error is returned if it could not stop tracing any of the processes +tracing to the file. +.It Bq Er ESRCH +No process can be found corresponding to that specified by +.Fa pid . +.It Bq Er EACCES +The named file is a device or FIFO. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Pp +Additionally, +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 or the +path refers to a symbolic link. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er EFAULT +.Fa tracefile +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr kdump 1 , +.Xr ktrace 1 , +.Xr utrace 2 +.Sh HISTORY +A +.Fn ktrace +function call first appeared in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/link.2 b/static/openbsd/man2/link.2 new file mode 100644 index 00000000..0047f6e1 --- /dev/null +++ b/static/openbsd/man2/link.2 @@ -0,0 +1,268 @@ +.\" $OpenBSD: link.2,v 1.31 2024/07/18 15:38:57 millert Exp $ +.\" $NetBSD: link.2,v 1.7 1995/02/27 12:34:01 cgd 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. 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 +.\" +.Dd $Mdocdate: July 18 2024 $ +.Dt LINK 2 +.Os +.Sh NAME +.Nm link , +.Nm linkat +.Nd make hard link to a file +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn link "const char *name1" "const char *name2" +.In fcntl.h +.In unistd.h +.Ft int +.Fn linkat "int fd1" "const char *name1" "int fd2" "const char *name2" "int flag" +.Sh DESCRIPTION +The +.Fn link +function 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 +For the hard link to succeed, +.Fa name1 +must exist and not be a directory, and both +.Fa name1 +and +.Fa name2 +must be in the same file system. +.Pp +The +.Fn linkat +function is equivalent to +.Fn link +except that where +.Fa name1 +or +.Fa name2 +specifies a relative path, +the directory entries linked are resolved relative to +the directories associated with file descriptors +.Fa fd1 +or +.Fa fd2 +(respectively) instead of the current working directory. +.Pp +If +.Fn linkat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd1 +or +.Fa fd2 +parameter, the current working directory is used for resolving the respective +.Fa name1 +or +.Fa name2 +argument. +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_FOLLOW -offset indent -compact +.It Dv AT_SYMLINK_FOLLOW +If +.Fa name1 +names a symbolic link, +a new link for the target of the symbolic link is created. +.El +.Pp +If the +.Dv AT_SYMLINK_FOLLOW +flag is clear and +.Fa name1 +names a symbolic link, a new link is created for the symbolic link +.Fa name1 +and not its target. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn link +and +.Fn linkat +will fail and no link will be created if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of either path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 +.Dv LINK_MAX . +.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 EPERM +The file named by +.Fa name1 +is flagged immutable or append-only. +.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. +.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 +.Pp +Additionally, +.Fn linkat +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_SYMLINK_FOLLOW . +.It Bq Er EBADF +The +.Fa name1 +or +.Fa name2 +argument specifies a relative path and the +.Fa fd1 +or +.Fa fd2 +argument, respectively, is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa name1 +or +.Fa name2 +argument specifies a relative path and the +.Fa fd1 +or +.Fa fd2 +argument, respectively, +is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa name1 +or +.Fa name2 +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd1 +or +.Fa fd2 +file descriptor, respectively, references. +.El +.Sh SEE ALSO +.Xr ln 1 , +.Xr readlink 2 , +.Xr symlink 2 , +.Xr unlink 2 +.Sh STANDARDS +The +.Fn link +and +.Fn linkat +functions are expected to conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn link +system call first appeared in +.At v1 . +The +.Fn linkat +function appeared in +.Ox 5.0 . diff --git a/static/openbsd/man2/listen.2 b/static/openbsd/man2/listen.2 new file mode 100644 index 00000000..f8c72cff --- /dev/null +++ b/static/openbsd/man2/listen.2 @@ -0,0 +1,109 @@ +.\" $OpenBSD: listen.2,v 1.15 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: listen.2,v 1.7 1996/02/16 20:38:45 phil Exp $ +.\" +.\" 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. 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. +.\" +.\" @(#)listen.2 8.2 (Berkeley) 12/11/93 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt LISTEN 2 +.Os +.Sh NAME +.Nm listen +.Nd listen for connections on a socket +.Sh SYNOPSIS +.In 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. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn listen +will fail if: +.Bl -tag -width Er +.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 . +.It Bq Er EINVAL +The socket is already connected. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr connect 2 , +.Xr socket 2 , +.Xr sysctl 8 +.Sh STANDARDS +The +.Fn listen +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn listen +system call first appeared in +.Bx 4.1c . +.Sh BUGS +The +.Fa backlog +is currently limited (silently) to the value of the kern.somaxconn +sysctl, which defaults to 128. diff --git a/static/openbsd/man2/lseek.2 b/static/openbsd/man2/lseek.2 new file mode 100644 index 00000000..3a70ec0d --- /dev/null +++ b/static/openbsd/man2/lseek.2 @@ -0,0 +1,144 @@ +.\" $OpenBSD: lseek.2,v 1.17 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: lseek.2,v 1.6 1995/02/27 12:34:09 cgd 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt LSEEK 2 +.Os +.Sh NAME +.Nm lseek +.Nd reposition read/write file offset +.Sh SYNOPSIS +.In 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 pointer +.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 pointer will remain unchanged if: +.Bl -tag -width Er +.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 or the resulting offset would be negative +on a file system or special device that does not allow negative +offsets to be used. +.El +.Sh SEE ALSO +.Xr dup 2 , +.Xr open 2 +.Sh STANDARDS +The +.Fn lseek +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +A +.Fn seek +system call first appeared in +.At v1 . +In +.At v7 +it was renamed to +.Fn lseek +for +.Dq long seek +due to a larger +.Fa offset +argument type. +.Sh BUGS +This document's use of +.Fa whence +is incorrect English, but is maintained for historical reasons. diff --git a/static/openbsd/man2/madvise.2 b/static/openbsd/man2/madvise.2 new file mode 100644 index 00000000..d62f110f --- /dev/null +++ b/static/openbsd/man2/madvise.2 @@ -0,0 +1,144 @@ +.\" $OpenBSD: madvise.2,v 1.23 2024/01/21 17:46:03 deraadt Exp $ +.\" $NetBSD: madvise.2,v 1.7 1995/12/27 21:17:02 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: January 21 2024 $ +.Dt MADVISE 2 +.Os +.Sh NAME +.Nm madvise , +.Nm posix_madvise +.Nd give advice about use of memory +.Sh SYNOPSIS +.In sys/mman.h +.Ft int +.Fn madvise "void *addr" "size_t len" "int behav" +.Ft int +.Fn posix_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 +.Fn posix_madvise +interface has the same effect, but returns the error value +instead of only setting +.Va errno . +.Pp +The possible behaviors are: +.Bl -tag -width MADV_SEQUENTIAL +.It Dv MADV_NORMAL +No further special treatment needed. +.It Dv MADV_RANDOM +Expect random page access patterns. +.It Dv MADV_SEQUENTIAL +Expect sequential page references. +.It Dv MADV_WILLNEED +The pages will be referenced soon. +.It Dv MADV_DONTNEED +The pages will not be referenced soon. +.It Dv MADV_SPACEAVAIL +Ensure that resources are reserved. +.It Dv MADV_FREE +The pages don't contain any useful data and can be recycled. +.El +.Pp +Portable programs that call the +.Fn posix_madvise +interface should use the aliases +.Dv POSIX_MADV_NORMAL , POSIX_MADV_RANDOM , +.Dv POSIX_MADV_SEQUENTIAL , POSIX_MADV_WILLNEED , +and +.Dv POSIX_MADV_DONTNEED +rather than the flags described above. +.Sh RETURN VALUES +.Rv -std madvise +.Pp +If successful, the +.Fn posix_madvise +function will return zero. +Otherwise an error number will be returned to indicate the error. +.Sh ERRORS +.Fn madvise +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified +.Fa behav +argument was invalid. +.It Bq Er EINVAL +The +.Fa addr +parameter was not page aligned or +.Fa addr +and +.Fa size +specify a region that would extend beyond the end of the address space. +.It Bq Er EPERM +The +.Fa addr +and +.Fa len +parameters specify a region which contains at least one page marked immutable. +.El +.Sh SEE ALSO +.Xr mimmutable 2 , +.Xr minherit 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munmap 2 +.Sh STANDARDS +The +.Fn posix_madvise +system call conforms to +.St -p1003.1-2008 . +.Pp +The +.Er EPERM +failure conditions described are an extension to this specification. +.Sh HISTORY +The +.Fn madvise +function first appeared in SunOS 4.0 and has been available since +.Ox 2.7 . +The +.Fn posix_madvise +function first appeared in +.Ox 4.8 . +.Sh BUGS +The +.Dv MADV_WILLNEED +behavior is ignored. +The +.Dv MADV_SPACEAVAIL +behavior is not implemented and will always fail. diff --git a/static/openbsd/man2/mimmutable.2 b/static/openbsd/man2/mimmutable.2 new file mode 100644 index 00000000..96b7641a --- /dev/null +++ b/static/openbsd/man2/mimmutable.2 @@ -0,0 +1,90 @@ +.\" $OpenBSD: mimmutable.2,v 1.5 2024/01/21 17:46:03 deraadt Exp $ +.\" +.\" 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. 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. +.\" +.\" @(#)mimmutable.2 8.1 (Berkeley) 6/9/93 +.\" +.Dd $Mdocdate: January 21 2024 $ +.Dt MIMMUTABLE 2 +.Os +.Sh NAME +.Nm mimmutable +.Nd control the immutability of pages +.Sh SYNOPSIS +.In sys/mman.h +.Ft int +.Fn mimmutable "void *addr" "size_t len" +.Sh DESCRIPTION +The +.Fn mimmutable +system call +changes currently mapped pages in the region to be marked immutable, +which means their protection or mapping may not be changed in the future. +Most requests to +.Xr madvise 2 , +.Xr minherit 2 , +.Xr mmap 2 , +.Xr mprotect 2 , +.Xr msync 2 , and +.Xr munmap 2 +to pages marked immutable will return with error +.Er EPERM . +.Pp +Unmapped pages in the region do not retain immutability, but this +behaviour should not be relied upon. +.Pp +Not all implementations will guarantee that the immutable characteristic +can be set on a page basis; +the granularity of changes may be as large as an entire region. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn mimmutable +system call 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 EPERM +At least one page has inheritance of +.Dv MAP_INHERIT_ZERO . +.El +.Sh SEE ALSO +.Xr minherit 2 , +.Xr mmap 2 , +.Xr mprotect 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn mimmutable +function first appeared in +.Ox 7.3 . diff --git a/static/openbsd/man2/minherit.2 b/static/openbsd/man2/minherit.2 new file mode 100644 index 00000000..e814a0a7 --- /dev/null +++ b/static/openbsd/man2/minherit.2 @@ -0,0 +1,108 @@ +.\" $OpenBSD: minherit.2,v 1.17 2024/01/21 17:46:03 deraadt Exp $ +.\" +.\" 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. 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 $Mdocdate: January 21 2024 $ +.Dt MINHERIT 2 +.Os +.Sh NAME +.Nm minherit +.Nd control the inheritance of pages +.Sh SYNOPSIS +.In 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 . +A page's inheritance characteristic controls how it will be mapped +in child processes as created by +.Xr fork 2 . +.Pp +The possible inheritance characteristics are: +.Pp +.Bl -tag -width MAP_INHERIT_SHARE -offset indent -compact +.It Dv MAP_INHERIT_NONE +Pages are not mapped in the child process. +.It Dv MAP_INHERIT_COPY +Private copy of pages are mapped in the child process. +.It Dv MAP_INHERIT_SHARE +Mapped pages are shared between the parent and child processes. +.It Dv MAP_INHERIT_ZERO +New anonymous pages (initialized to all zero bytes) +are mapped in the child process. +.El +.Pp +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 +.Rv -std +.Sh ERRORS +The +.Fn minherit +system call will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The +.Fa addr +and +.Fa len +parameters specify a region that contains +at least one page which is immutable, or +.Dv MAP_INHERIT_ZERO +is being requested on a page without +.Dv PROT_WRITE +permission. +.It Bq Er EINVAL +The virtual address range specified by the +.Fa addr +and +.Fa len +arguments is not valid. +.It Bq Er EINVAL +The +.Fa inherit +argument is invalid. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mimmutable 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn minherit +function first appeared in +.Ox 2.0 . diff --git a/static/openbsd/man2/mkdir.2 b/static/openbsd/man2/mkdir.2 new file mode 100644 index 00000000..f080bacf --- /dev/null +++ b/static/openbsd/man2/mkdir.2 @@ -0,0 +1,201 @@ +.\" $OpenBSD: mkdir.2,v 1.18 2017/03/23 18:40:01 millert Exp $ +.\" $NetBSD: mkdir.2,v 1.8 1995/02/27 12:34:22 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: March 23 2017 $ +.Dt MKDIR 2 +.Os +.Sh NAME +.Nm mkdir , +.Nm mkdirat +.Nd make a directory file +.Sh SYNOPSIS +.In sys/stat.h +.Ft int +.Fn mkdir "const char *path" "mode_t mode" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn mkdirat "int fd" "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. +.Pp +The +.Fn mkdirat +function is equivalent to +.Fn mkdir +except that where +.Fa path +specifies a relative path, +the newly created directory is created relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn mkdirat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn mkdir . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn mkdir +and +.Fn mkdirat +will fail and no directory will be 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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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, +or write permission is denied +on the parent directory of the directory to be created. +.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 +.Pp +Additionally, +.Fn mkdirat +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr stat 2 , +.Xr umask 2 +.Sh STANDARDS +The +.Fn mkdir +and +.Fn mkdirat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +A +.Fn mkdir +system call first appeared in +.At v1 . +It was renamed to +.Fn makdir +in +.At v2 . +However, it did not exist from +.At v4 +to +.Bx 4.1 ; +in those releases, +.Xr mknod 2 +had to be used. +Since +.Fn mkdir +reappeared in +.Bx 4.1c , +it no longer requires superuser privileges and it automatically creates the +.Sq \&. +and +.Sq \&.. +directory entries. +.Pp +The +.Fn mkdirat +system call has been available since +.Ox 5.0 . diff --git a/static/openbsd/man2/mkfifo.2 b/static/openbsd/man2/mkfifo.2 new file mode 100644 index 00000000..3ccc36d4 --- /dev/null +++ b/static/openbsd/man2/mkfifo.2 @@ -0,0 +1,181 @@ +.\" $OpenBSD: mkfifo.2,v 1.15 2015/05/31 23:54:25 schwarze Exp $ +.\" $NetBSD: mkfifo.2,v 1.8 1995/02/27 12:34:27 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 31 2015 $ +.Dt MKFIFO 2 +.Os +.Sh NAME +.Nm mkfifo , +.Nm mkfifoat +.Nd make a FIFO file +.Sh SYNOPSIS +.In sys/stat.h +.Ft int +.Fn mkfifo "const char *path" "mode_t mode" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn mkfifoat "int fd" "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. +.Pp +The +.Fn mkfifoat +function is equivalent to +.Fn mkfifo +except that where +.Fa path +specifies a relative path, +the newly created FIFO is created relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn mkfifoat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn mkfifo . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn mkfifo +and +.Fn mkfifoat +will fail and no FIFO will be created if: +.Bl -tag -width Er +.It Bq Er EOPNOTSUPP +The kernel has not been configured to support FIFOs. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 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 +.Pp +Additionally, +.Fn mkfifoat +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr stat 2 , +.Xr umask 2 +.Sh STANDARDS +The +.Fn mkfifo +and +.Fn mkfifoat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn mkfifoat +function appeared in +.Ox 5.0 . diff --git a/static/openbsd/man2/mknod.2 b/static/openbsd/man2/mknod.2 new file mode 100644 index 00000000..e34ebf01 --- /dev/null +++ b/static/openbsd/man2/mknod.2 @@ -0,0 +1,214 @@ +.\" $OpenBSD: mknod.2,v 1.21 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: mknod.2,v 1.6 1995/02/27 12:34:33 cgd 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt MKNOD 2 +.Os +.Sh NAME +.Nm mknod , +.Nm mknodat +.Nd make a special file node +.Sh SYNOPSIS +.In sys/stat.h +.Ft int +.Fn mknod "const char *path" "mode_t mode" "dev_t dev" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev" +.Sh DESCRIPTION +The +.Fn mknod +function creates +.Fa path +with a file type and mode of +.Fa mode , +as modified by +.Xr umask 2 . +Only FIFO and device special files are supported by this implementation. +.Pp +If +.Fa mode +is the bitwise OR of +.Dv S_IFIFO +and zero or more file permissions, and +.Fa dev +is zero, then a FIFO is created. +If +.Fa mode +is the bitwise OR of +.Dv S_IFCHR +or +.Dv S_IFBLK +and zero or more file permissions, then a character or block device +special (respectively) is created with major and minor device numbers +extracted from +.Fa dev . +.Pp +The +.Fn mknodat +function is equivalent to +.Fn mknod +except that where +.Fa path +specifies a relative path, +the newly created device special file is created relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn mknodat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn mknod . +.Pp +Creating a device special file with +.Fn mknod +or +.Fn mknodat +requires superuser privileges. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn mknod +and +.Fn mknodat +will fail and the file will be not created if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa mode +is an invalid file type or +.Fa dev +is an invalid value for that file type. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 +.Fa mode +is a device special and the process's effective user ID is not superuser. +.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 +The process is running within an alternate root directory, as +created by +.Xr chroot 2 . +.El +.Pp +Additionally, +.Fn mknodat +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr chroot 2 , +.Xr mkfifo 2 , +.Xr stat 2 , +.Xr umask 2 +.Sh STANDARDS +The +.Fn mknod +and +.Fn mknodat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn mknod +system call first appeared in +.At v4 , +and +.Fn mknodat +has been available since +.Ox 5.0 . diff --git a/static/openbsd/man2/mlock.2 b/static/openbsd/man2/mlock.2 new file mode 100644 index 00000000..d3e11871 --- /dev/null +++ b/static/openbsd/man2/mlock.2 @@ -0,0 +1,162 @@ +.\" $OpenBSD: mlock.2,v 1.20 2019/01/11 18:46:30 deraadt Exp $ +.\" $NetBSD: mlock.2,v 1.3 1995/06/24 10:42:03 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: January 11 2019 $ +.Dt MLOCK 2 +.Os +.Sh NAME +.Nm mlock , +.Nm munlock +.Nd lock (unlock) physical pages in memory +.Sh SYNOPSIS +.In 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 +.Xr munmap 2 +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 +.Dq wired pages +limit and the per-process +.Li RLIMIT_MEMLOCK +resource limit. +.Sh RETURN VALUES +.Rv -std mlock munlock +.Sh ERRORS +.Fn mlock +will fail if: +.Bl -tag -width Er +.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 +.Pp +.Fn munlock +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The address given is not page aligned or +.Fa addr +and +.Fa size +specify a region that would extend beyond the end of the address space. +.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 minherit 2 , +.Xr mlockall 2 , +.Xr mmap 2 , +.Xr munmap 2 , +.Xr setrlimit 2 , +.Xr getpagesize 3 +.Sh HISTORY +The +.Fn mlock +and +.Fn munlock +functions first appeared in +.Bx 4.4 . +.Sh BUGS +Unlike Sun's 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. diff --git a/static/openbsd/man2/mlockall.2 b/static/openbsd/man2/mlockall.2 new file mode 100644 index 00000000..234ec5f3 --- /dev/null +++ b/static/openbsd/man2/mlockall.2 @@ -0,0 +1,124 @@ +.\" $OpenBSD: mlockall.2,v 1.10 2019/01/11 18:46:30 deraadt Exp $ +.\" $NetBSD: mlockall.2,v 1.6 2000/06/26 17:00:02 kleink Exp $ +.\" +.\" Copyright (c) 1999 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jason R. Thorpe of the Numerical Aerospace Simulation 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 $Mdocdate: January 11 2019 $ +.Dt MLOCKALL 2 +.Os +.Sh NAME +.Nm mlockall , +.Nm munlockall +.Nd lock (unlock) the address space of a process +.Sh SYNOPSIS +.In sys/mman.h +.Ft int +.Fn mlockall "int flags" +.Ft int +.Fn munlockall "void" +.Sh DESCRIPTION +The +.Fn mlockall +system call locks into memory the physical pages associated with the +address space of a process until the address space is unlocked, the +process exits, or execs another program image. +.Pp +The following flags affect the behavior of +.Fn mlockall : +.Bl -tag -width MCL_CURRENT +.It Dv MCL_CURRENT +Lock all pages currently mapped into the process's address space. +.It Dv MCL_FUTURE +Lock all pages mapped into the process's address space in the future, +at the time the mapping is established. +Note that this may cause future mappings to fail if those mappings +cause resource limits to be exceeded. +.El +.Pp +Since physical memory is a potentially scarce resource, processes are +limited in how much they can lock down. +A single process can lock the minimum of a system-wide +.Dq wired pages +limit and the per-process +.Dv RLIMIT_MEMLOCK +resource limit. +.Pp +The +.Fn munlockall +call unlocks any locked memory regions in the process address space. +Any regions mapped after an +.Fn munlockall +call will not be locked. +.Sh RETURN VALUES +.Rv -std mlockall munlockall +.Sh ERRORS +.Fn mlockall +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa flags +argument is zero or includes unimplemented flags. +.It Bq Er ENOMEM +Locking all of the pages currently mapped would exceed either +the system or per-process +limit for locked memory. +.It Bq Er EAGAIN +Some or all of the memory mapped into the process's address space +could not be locked when the call was made. +.It Bq Er EPERM +The calling process does not have the appropriate privileges to perform +the requested operation. +.El +.Sh SEE ALSO +.Xr mlock 2 , +.Xr mmap 2 , +.Xr munmap 2 , +.Xr setrlimit 2 +.Sh STANDARDS +The +.Fn mlockall +and +.Fn munlockall +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn mlockall +and +.Fn munlockall +functions first appeared in +.Ox 2.9 . +.Sh BUGS +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 only as a single page +in the system limit. diff --git a/static/openbsd/man2/mmap.2 b/static/openbsd/man2/mmap.2 new file mode 100644 index 00000000..9ad47579 --- /dev/null +++ b/static/openbsd/man2/mmap.2 @@ -0,0 +1,377 @@ +.\" $OpenBSD: mmap.2,v 1.70 2022/10/07 16:31:36 jmc Exp $ +.\" $NetBSD: mmap.2,v 1.5 1995/06/24 10:48:59 cgd Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/4/93 +.\" +.Dd $Mdocdate: October 7 2022 $ +.Dt MMAP 2 +.Os +.Sh NAME +.Nm mmap +.Nd map files or devices into memory +.Sh SYNOPSIS +.In 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 contents of +.Fa fd , +starting at +.Fa offset , +to be mapped in memory at the given +.Fa addr . +The mapping will extend at least +.Fa len +bytes, subject to page alignment restrictions. +.Pp +The +.Fa addr +argument describes the address where the system should place the mapping. +If the +.Dv MAP_FIXED +flag is specified, the allocation will happen at the specified address, +replacing any previously established mappings in its range. +Otherwise, the mapping will be placed at the available spot at +.Fa addr ; +failing that it will be placed "close by". +If +.Fa addr +is +.Dv NULL , +the system can pick any address. +Except for +.Dv MAP_FIXED +mappings, the system will never replace existing mappings. +.Pp +The +.Fa len +argument describes the minimum amount of bytes the mapping will span. +Since +.Fn mmap +maps pages into memory, +.Fa len +may be rounded up to hit a page boundary. +If +.Fa len +is 0, the mapping will fail with +.Er EINVAL . +.Pp +If an +.Fa fd +and +.Fa offset +are specified, the resulting address may end up not on a page boundary, +in order to align the page offset in the +.Fa addr +to the page offset in +.Fa offset . +.Pp +The protections (region accessibility) are specified in the +.Fa prot +argument. +It should either be +.Dv PROT_NONE +.Pq no permissions +or the bitwise OR of one or more of the following values: +.Pp +.Bl -tag -width "PROT_WRITEXX" -offset indent -compact +.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 OR'ing the following values. +Exactly one of the first two values must be specified: +.Bl -tag -width MAP_ANONYMOUS -offset indent +.It Dv MAP_PRIVATE +Modifications are private. +.It Dv MAP_SHARED +Modifications are shared. +.El +.Pp +Any combination of the following flags may additionally be used: +.Bl -tag -width MAP_ANONYMOUS -offset indent +.It Dv MAP_ANON +Map anonymous memory not associated with any specific file. +The file descriptor used for creating +.Dv MAP_ANON +must currently be \-1 indicating no name is associated with the +region. +.It Dv MAP_ANONYMOUS +Synonym for +.Dv MAP_ANON . +.It Dv MAP_FIXED +Demand that the mapping is placed at +.Fa addr , +rather than having the system select a location. +.Fa addr , +.Fa len +and +.Fa offset +(in the case of +.Fa fd +mappings) +must be multiples of the page size. +Existing mappings in the address range will be replaced. +Use of this option is discouraged. +.It Dv MAP_STACK +Indicate that the mapping is used as a stack. +This flag must be used in combination with +.Dv MAP_ANON +and +.Dv MAP_PRIVATE . +.It Dv MAP_CONCEAL +Exclude the mapping from core dumps. +.El +.Pp +Finally, the following flags are also provided for +source compatibility with code written for other operating systems, +but are not recommended for use in new +.Ox +code: +.Bl -tag -width MAP_ANONYMOUS -offset indent +.It Dv MAP_COPY +Modifications are private and, unlike +.Dv MAP_PRIVATE , +modifications made by others are not visible. +On +.Ox +this behaves just like +.Dv MAP_PRIVATE . +.It Dv MAP_FILE +Mapped from a regular file, character special file, or block special file +specified by file descriptor +.Fa fd . +On +.Ox +and all systems conforming to +.St -p1003.1-2008 +this is the default mapping type and need not be specified. +.It Dv MAP_HASSEMAPHORE +Notify the kernel that the region may contain semaphores and that special +handling may be necessary. +On +.Ox +this flag is ignored. +.It Dv MAP_INHERIT +Permit regions to be inherited across +.Xr execve 2 +system calls. +On +.Ox +this flag is ignored. +.It Dv MAP_TRYFIXED +Attempt to use the hint provided by +.Fa addr . +On +.Ox +this is the default behavior. +.El +.Pp +The +.Xr close 2 +function does not unmap pages; see +.Xr munmap 2 +for further information. +.Sh RETURN VALUES +The +.Fn mmap +function returns a pointer to the mapped region if successful; +otherwise the value +.Dv MAP_FAILED +is returned and the global variable +.Va errno +is set to indicate the error. +A successful return from +.Fn mmap +will never return the value +.Dv MAP_FAILED . +.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_PRIVATE +and +.Dv MAP_SHARED +were both specified. +.It Bq Er EINVAL +.Dv MAP_FIXED +was specified and the +.Fa addr +parameter was not page aligned. +.It Bq Er EINVAL +.Fa addr +and +.Fa len +specified a region that would extend beyond the end of the address space. +.It Bq Er EINVAL +.Fa fd +did not specify a regular, character special, or block special file. +.It Bq Er EINVAL +.Fa fd +specified a character special or block special file and the underlying +device does not support memory mapping. +.It Bq Er EINVAL +The allocation +.Fa len +was 0. +.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. +.It Bq Er ENOTSUP +The accesses requested in the +.Fa prot +argument are not allowed. +In particular, +.Dv PROT_WRITE | PROT_EXEC +mappings are not permitted unless the filesystem is mounted +.Cm wxallowed +and the process is link-time tagged with +.Cm wxneeded . +(See also +.Dv kern.wxabort +in +.Xr sysctl 2 +for a method to diagnose failure). +.It Bq Er EPERM +The +.Fa addr +and +.Fa len +parameters +specify a region which contains at least one page marked immutable. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mimmutable 2 , +.Xr mlock 2 , +.Xr mprotect 2 , +.Xr mquery 2 , +.Xr msync 2 , +.Xr munmap 2 , +.Xr getpagesize 3 , +.Xr core 5 +.Sh STANDARDS +The +.Fn mmap +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +.\" A mmap() system call stub appeared in 4.1c BSD, +.\" but the functionality wasn't implemented. +A fully functional +.Fn mmap +system call first appeared in SunOS 4.0 +and has been available since +.Bx 4.3 Net/2 . +.Sh CAVEATS +.St -p1003.1-2008 +specifies that references to pages beyond the end of a mapped object +shall generate a +.Dv SIGBUS +signal; however, on some architectures +.Ox +generates a +.Dv SIGSEGV +signal in this case instead. +.Pp +Additionally, +.St -p1003.1-2008 +specifies that +.Fn mmap +shall fail with +.Er EINVAL +if neither +.Dv MAP_PRIVATE +nor +.Dv MAP_SHARED +is specified by +.Fa flags ; +however, for compatibility with old programs, +.Ox +instead defaults to +.Dv MAP_SHARED +for mappings of character special files, and to +.Dv MAP_PRIVATE +for all other mappings. +New programs should not rely on this behavior. +.Sh BUGS +Due to a limitation of the current vm system (see +.Xr uvm_init 9 ) , +mapping descriptors +.Dv PROT_WRITE +without also specifying +.Dv PROT_READ +is useless +(results in a segmentation fault when first accessing the mapping). +This means that such descriptors must be opened with +.Dv O_RDWR , +which requires both read and write permissions on the underlying +object. diff --git a/static/openbsd/man2/mount.2 b/static/openbsd/man2/mount.2 new file mode 100644 index 00000000..851e73ff --- /dev/null +++ b/static/openbsd/man2/mount.2 @@ -0,0 +1,434 @@ +.\" $OpenBSD: mount.2,v 1.53 2025/08/06 13:23:27 schwarze Exp $ +.\" $NetBSD: mount.2,v 1.12 1996/02/29 23:47:48 jtc Exp $ +.\" +.\" 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. 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.2 (Berkeley) 12/11/93 +.\" +.Dd $Mdocdate: August 6 2025 $ +.Dt MOUNT 2 +.Os +.Sh NAME +.Nm mount , +.Nm unmount +.Nd mount or dismount a filesystem +.Sh SYNOPSIS +.In sys/types.h +.In 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 +.Fa dir . +The argument +.Fa data +describes the filesystem object to be mounted. +The argument +.Fa type +tells the kernel how to interpret +.Fa data +(see +.Fa type +below). +The contents of the filesystem +become available through the new mount point +.Fa dir . +Any files in +.Fa 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 +.Fa 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 superuser may not write to it. +.It Dv MNT_NOATIME +Do not update the access time on files in the filesystem unless +the modification or status change times are also being updated. +.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_NODEV +Do not interpret special files on the filesystem. +.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_SOFTDEP +Use soft dependencies on an FFS filesystem. +This flag is provided for compatibility only and has no effect on +.Ox . +.It Dv MNT_WXALLOWED +Processes that ask for memory to be made writeable plus executable +using the +.Xr mmap 2 +and +.Xr mprotect 2 +system calls are killed by default. +This option allows those processes to continue operation. +The option is typically used on the +.Pa /usr/local +filesystem. +.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, +most filesystems will not allow a change from read-write to read-only. +.Pp +The +.Fa type +argument defines the type of the filesystem. +The types of filesystems known to the system are defined in +.In sys/mount.h . +.Fa data +is a pointer to a structure that contains the type +specific arguments to mount. +The currently supported types of filesystems and +their type specific data are: +.Pp +.Dv MOUNT_CD9660 +.Bd -literal -offset indent -compact +struct iso_args { + char *fspec; /* block special device to mount */ + struct export_args export_info; + /* network export info */ + int flags; /* mounting flags, see below */ +}; +#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/ +#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */ +#define ISOFSMNT_EXTATT 0x00000004 /* enable extended attributes */ +#define ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet Ext.*/ +#define ISOFSMNT_SESS 0x00000010 /* use iso_args.sess */ +.Ed +.Pp +.Dv MOUNT_FFS +.Bd -literal -offset indent -compact +struct ufs_args { + char *fspec; /* block special file to mount */ + struct export_args export_info; + /* network export information */ +}; +.Ed +.Pp +.Dv MOUNT_MFS +.Bd -literal -offset indent -compact +struct mfs_args { + char *fspec; /* name to export for statfs */ + struct export_args export_info; + /* if we can export an MFS */ + caddr_t base; /* base of filesystem in mem */ + u_long size; /* size of filesystem */ +}; +.Ed +.Pp +.Dv MOUNT_MSDOS +.Bd -literal -offset indent -compact +struct msdosfs_args { + char *fspec; /* blocks special holding fs to mount */ + struct export_args export_info; + /* network export information */ + uid_t uid; /* uid that owns msdosfs files */ + gid_t gid; /* gid that owns msdosfs files */ + mode_t mask; /* mask to be applied for msdosfs perms */ + int flags; /* see below */ +}; + +/* + * Msdosfs mount options: + */ +#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ +#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ +#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ +.Ed +.Pp +.Dv MOUNT_NFS +.Bd -literal -offset indent -compact +struct nfs_args { + int version; /* args structure version */ + struct sockaddr *addr; /* file server address */ + int addrlen; /* length of address */ + int sotype; /* Socket type */ + int proto; /* and Protocol */ + u_char *fh; /* File handle to be mounted */ + int fhsize; /* Size, in bytes, of fh */ + int flags; /* flags */ + int wsize; /* write size in bytes */ + int rsize; /* read size in bytes */ + int readdirsize; /* readdir size in bytes */ + int timeo; /* initial timeout in .1 secs */ + int retrans; /* times to retry send */ + int maxgrouplist; /* Max. size of group list */ + int readahead; /* # of blocks to readahead */ + int leaseterm; /* Term (sec) of lease */ + int deadthresh; /* Retrans threshold */ + char *hostname; /* server's name */ + int acregmin; /* Attr cache file recently modified */ + int acregmax; /* ac file not recently modified */ + int acdirmin; /* ac for dir recently modified */ + int acdirmax; /* ac for dir not recently modified */ +}; +.Ed +.Pp +.Dv MOUNT_NTFS +.Bd -literal -offset indent -compact +struct ntfs_args { + char *fspec; /* block special device to mount */ + struct export_args export_info; + /* network export information */ + uid_t uid; /* uid that owns ntfs files */ + gid_t gid; /* gid that owns ntfs files */ + mode_t mode; /* mask to be applied for ntfs perms */ + u_long flag; /* additional flags */ +}; + +/* + * ntfs mount options: + */ +#define NTFS_MFLAG_CASEINS 0x00000001 +#define NTFS_MFLAG_ALLNAMES 0x00000002 +.Ed +.Pp +.Dv MOUNT_UDF +.Bd -literal -offset indent -compact +struct udf_args { + char *fspec; /* block special device to mount */ +}; +.Ed +.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 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. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn mount +will fail when one of the following occurs: +.Bl -tag -width [ENAMETOOLONG] +.It Bq Er EPERM +The caller is not the superuser. +.It Bq Er ENAMETOOLONG +The pathname exceeded +.Dv MNAMELEN +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 +.Fa dir +is not a directory, +or a path prefix of +.Fa fspec +is not a directory. +.It Bq Er EINVAL +An argument given was invalid. +.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. +.It Bq Er EOPNOTSUPP +.Fa type +is not supported by the kernel. +.El +.Pp +The following errors can occur for a +.Dq ufs +filesystem mount: +.Bl -tag -width [ENOTBLK] +.It Bq Er ENODEV +A component of ufs_args +.Fa fspec +does not exist. +.It Bq Er ENOTBLK +.Fa fspec +is not a block device. +.It Bq Er ENXIO +The major device number of +.Fa fspec +is out of range (this indicates no device driver exists +for the associated hardware). +.It Bq Er EBUSY +.Fa fspec +is already mounted. +.It Bq Er EINVAL +The super block for the filesystem had a bad magic number, an out of range +block size, or an invalid combination of flags. +.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 +.Fa fspec +points outside the process's allocated address space. +.It Bq Er EROFS +The filesystem was not unmounted cleanly and +.Dv MNT_FORCE +was not specified. +.It Bq Er EROFS +An attempt was made to mount a +.Bx 4.2 +filesystem without the +.Dv MNT_RDONLY +flag. +.El +.Pp +The following errors can occur for an +.Em NFS +filesystem mount: +.Bl -tag -width [ETIMEDOUT] +.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 [EMFILE] +.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 +.Fn unmount +may fail with one of the following errors: +.Bl -tag -width [ENAMETOOLONG] +.It Bq Er EPERM +The caller is not the superuser. +.It Bq Er ENOTDIR +A component of the path is not a directory. +.It Bq Er EINVAL +An argument given was invalid. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 +.Sh SEE ALSO +.Xr statfs 2 , +.Xr mount 8 , +.Xr mount_mfs 8 , +.Xr umount 8 +.Sh HISTORY +The +.Fn mount +and +.Fn umount +system calls first appeared in +.At v1 ; +.Fn umount +was renamed to +.Fn unmount +in +.Bx 4.3 Reno . +.Pp +The +.Fa flags +argument is supported by +.Fn mount +since +.At v5 +and by +.Fn unmount +since +.Bx 4.3 Reno . +The current calling convention involving +.Fa type +and +.Fa data +arguments was introduced by +.Bx 4.3 Reno +as well. +.Sh BUGS +Some of the error codes need translation to more obvious messages. diff --git a/static/openbsd/man2/mprotect.2 b/static/openbsd/man2/mprotect.2 new file mode 100644 index 00000000..1c33f68b --- /dev/null +++ b/static/openbsd/man2/mprotect.2 @@ -0,0 +1,145 @@ +.\" $OpenBSD: mprotect.2,v 1.28 2024/01/21 17:00:42 deraadt Exp $ +.\" $NetBSD: mprotect.2,v 1.6 1995/10/12 15:41:08 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: January 21 2024 $ +.Dt MPROTECT 2 +.Os +.Sh NAME +.Nm mprotect +.Nd control the protection of pages +.Sh SYNOPSIS +.In sys/mman.h +.Ft int +.Fn mprotect "void *addr" "size_t len" "int prot" +.Sh DESCRIPTION +The +.Fn mprotect +system call sets the access protections for the pages that contain +the address range +.Fa addr +through +.Fa addr +\&+ +.Fa len +\- 1 +(inclusive). +If +.Fa len +is 0, no action is taken on the page that contains +.Fa addr . +.Pp +The protections (region accessibility) are specified in the +.Fa prot +argument. +It should either be +.Dv PROT_NONE +.Pq no permissions +or the bitwise OR of one or more of the following values: +.Pp +.Bl -tag -width "PROT_WRITEXX" -offset indent -compact +.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 +Not all implementations will guarantee protection on a page basis; +the granularity of protection changes may be as large as an entire region. +Nor will all implementations guarantee to give exactly the requested +permissions; more permissions may be granted than requested by +.Fa prot . +However, if +.Dv PROT_WRITE +was not specified then the page will not be writable. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn mprotect +will fail if: +.Bl -tag -width Er +.It Bq Er EACCES +The process does not have sufficient access to the underlying memory +object to provide the requested protection. +.It Bq Er ENOMEM +The process has locked future pages with +.Fn mlockall MCL_FUTURE , +a page being protected is not currently accessible, +and making it accessible and locked would exceed process or system limits. +.It Bq Er ENOTSUP +The accesses requested in the +.Fa prot +argument are not allowed. +In particular, +.Dv PROT_WRITE | PROT_EXEC +mappings are not permitted in most binaries (see +.Dv kern.wxabort +in +.Xr sysctl 2 +for more information). +.It Bq Er EINVAL +The +.Fa prot +argument is invalid or the specified address range would wrap around. +.It Bq Er EPERM +The +.Fa addr +and +.Fa len +parameters +specify a region which contains at least one page marked immutable. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mimmutable 2 , +.Xr msync 2 , +.Xr munmap 2 +.Sh STANDARDS +The +.Fn mprotect +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn mprotect +function has been available since +.Bx 4.3 Net/2 . +.Sh CAVEATS +The +.Ox +implementation of +.Fn mprotect +does not require +.Fa addr +to be page-aligned, +although other implementations may. diff --git a/static/openbsd/man2/mquery.2 b/static/openbsd/man2/mquery.2 new file mode 100644 index 00000000..7da8cda2 --- /dev/null +++ b/static/openbsd/man2/mquery.2 @@ -0,0 +1,133 @@ +.\" $OpenBSD: mquery.2,v 1.13 2022/03/31 17:27:16 naddy Exp $ +.\" +.\" Copyright (c) 2003 Artur Grabowski <art@openbsd.org> +.\" 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. 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 ``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 $Mdocdate: March 31 2022 $ +.Dt MQUERY 2 +.Os +.Sh NAME +.Nm mquery +.Nd provide mapping hints to applications +.Sh SYNOPSIS +.In sys/mman.h +.Ft void * +.Fn mquery "void *addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset" +.Sh DESCRIPTION +The +.Fn mquery +system call checks the existing memory mappings of a process and returns +hints to the caller about where to put a memory mapping. +This hint can be later used when performing memory mappings with the +.Xr mmap 2 +system call with +.Dv MAP_FIXED +in the flags. +The +.Fa addr +argument should be a memory location that which the caller specifies the +preferred address. +The +.Fa size +argument specifies the requested size of the memory area the caller +is looking for. +The +.Fa fd +and +.Fa off +arguments specify the file that will be mapped and the offset in it, +this is the same as the corresponding arguments to +.Xr mmap 2 . +.Pp +The behavior of the function depends on the +.Fa flags +argument. +If set to +.Dv MAP_FIXED , +the pointer +.Fa addr +is used as a fixed hint and +.Fn mquery +will return +.Dv MAP_FAILED +and set +.Va errno +to +.Er ENOMEM +if there is not +.Fa size +bytes free after that address. +Otherwise it will return the hint addr. +If no flags are set, +.Fn mquery +will use +.Fa addr +as a starting point in memory and will search forward to find +a memory area with +.Fa size +bytes free and that will be suitable for creating a mapping for the +file and offset specified in the +.Fa fd +and +.Fa off +arguments. +When no such area can be found, +.Fn mquery +will return +.Dv MAP_FAILED +and set +.Va errno +to indicate the error. +.Sh RETURN VALUES +When a memory range satisfying the request is found, +.Fn mquery +returns the available address. +Otherwise, +.Dv MAP_FAILED +is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn mquery +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Dv MAP_FIXED +was specified and the requested memory area is unavailable. +.It Bq Er ENOMEM +There was not enough memory left after the hint specified. +.It Bq Er EBADF +.Fa fd +is not a valid open file descriptor. +.El +.Sh SEE ALSO +.Xr mmap 2 +.Sh STANDARDS +The +.Fn mquery +function should not be used in portable applications. +.Sh HISTORY +The +.Fn mquery +function first appeared in +.Ox 3.4 . diff --git a/static/openbsd/man2/msgctl.2 b/static/openbsd/man2/msgctl.2 new file mode 100644 index 00000000..f041c78d --- /dev/null +++ b/static/openbsd/man2/msgctl.2 @@ -0,0 +1,209 @@ +.\" $OpenBSD: msgctl.2,v 1.19 2024/04/30 17:03:14 op Exp $ +.\" $NetBSD: msgctl.2,v 1.2 1997/03/27 08:20:35 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: April 30 2024 $ +.Dt MSGCTL 2 +.Os +.Sh NAME +.Nm msgctl +.Nd message control operations +.Sh SYNOPSIS +.In sys/msg.h +.Ft int +.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf" +.Sh DESCRIPTION +The +.Fn msgctl +system call performs some control operations on the message queue specified +by +.Fa msqid . +.Pp +Each message queue has a data structure associated with it, parts of which +may be altered by +.Fn msgctl +and parts of which determine the actions of +.Fn msgctl . +The data structure is defined in +.In sys/msg.h +and contains (amongst others) the following members: +.Bd -literal +struct msqid_ds { + struct ipc_perm msg_perm; /* msg queue permission bits */ + msglen_t msg_cbytes; /* # of bytes in use on the queue */ + msgqnum_t msg_qnum; /* # of msgs in the queue */ + msglen_t msg_qbytes; /* max # of bytes on the queue */ + pid_t msg_lspid; /* pid of last msgsnd() */ + pid_t msg_lrpid; /* pid of last msgrcv() */ + time_t msg_stime; /* time of last msgsnd() */ + time_t msg_rtime; /* time of last msgrcv() */ + time_t msg_ctime; /* time of last msgctl() */ +}; +.Ed +.Pp +The +.Vt ipc_perm +structure used inside the +.Vt msqid_ds +structure is defined in +.In sys/ipc.h +and looks like this: +.Bd -literal +struct ipc_perm { + uid_t cuid; /* creator user id */ + gid_t cgid; /* creator group id */ + uid_t uid; /* user id */ + gid_t gid; /* group id */ + mode_t mode; /* permission (9 bits, see chmod(2)) */ + u_short seq; /* sequence # (to generate unique id) */ + key_t key; /* user specified msg/sem/shm key */ +}; +.Ed +.Pp +The operation to be performed by +.Fn msgctl +is specified in +.Fa cmd +and is one of: +.Bl -tag -width IPC_RMIDX +.It Dv IPC_STAT +Gather information about the message queue and place it in the +structure pointed to by +.Fa buf . +.It Dv IPC_SET +Set the value of the +.Fa msg_perm.uid , +.Fa msg_perm.gid , +.Fa msg_perm.mode +and +.Fa msg_qbytes +fields in the structure associated with +.Fa msqid . +The values are taken from the corresponding fields in the structure +pointed to by +.Fa buf . +This operation can only be executed by the superuser, or a process that +has an effective user ID equal to either +.Fa msg_perm.cuid +or +.Fa msg_perm.uid +in the data structure associated with the message queue. +The value of +.Fa msg_qbytes +can only be increased by the superuser. +Values for +.Fa msg_qbytes +that exceed the system limit +.Pf ( Dv MSGMNB +from +.In sys/msg.h ) +are silently truncated to that limit. +.It Dv IPC_RMID +Remove the message queue specified by +.Fa msqid +and destroy the data associated with it. +Only the superuser or a process with an effective UID equal to the +.Fa msg_perm.cuid +or +.Fa msg_perm.uid +values in the data structure associated with the queue can do this. +.El +.Pp +The permission to read from or write to a message queue (see +.Xr msgsnd 2 +and +.Xr msgrcv 2 ) +is determined by the +.Fa msg_perm.mode +field in the same way as is +done with files (see +.Xr chmod 2 ) , +but the effective UID can match either the +.Fa msg_perm.cuid +field or the +.Fa msg_perm.uid +field, and the +effective GID can match either +.Fa msg_perm.cgid +or +.Fa msg_perm.gid . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn msgctl +will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +.Fa cmd +is equal to +.Dv IPC_SET +or +.Dv IPC_RMID +and the caller is not the superuser, nor does +the effective UID match either the +.Fa msg_perm.uid +or +.Fa msg_perm.cuid +fields of the data structure associated with the message queue. +.Pp +An attempt is made to increase the value of +.Fa msg_qbytes +through +.Dv IPC_SET +but the caller is not the superuser. +.It Bq Er EACCES +The command is +.Dv IPC_STAT +and the caller has no read permission for this message queue. +.It Bq Er EINVAL +.Fa msqid +is not a valid message queue identifier. +.Pp +.Fa cmd +is not a valid command. +.It Bq Er EFAULT +.Fa buf +specifies an invalid address. +.El +.Sh SEE ALSO +.Xr msgget 2 , +.Xr msgrcv 2 , +.Xr msgsnd 2 +.Sh STANDARDS +The +.Fn msgctl +function conforms to the X/Open System Interfaces option of +.St -p1003.1-2008 . +.Sh HISTORY +Message queues first appeared in +.At V.1 +and have been available since +.Nx 1.0 . diff --git a/static/openbsd/man2/msgget.2 b/static/openbsd/man2/msgget.2 new file mode 100644 index 00000000..1fb3a99f --- /dev/null +++ b/static/openbsd/man2/msgget.2 @@ -0,0 +1,142 @@ +.\" $OpenBSD: msgget.2,v 1.14 2019/07/18 13:32:40 schwarze Exp $ +.\" $NetBSD: msgget.2,v 1.1 1995/10/16 23:49:19 jtc Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: July 18 2019 $ +.Dt MSGGET 2 +.Os +.Sh NAME +.Nm msgget +.Nd get message queue +.Sh SYNOPSIS +.In sys/msg.h +.Ft int +.Fn msgget "key_t key" "int msgflg" +.Sh DESCRIPTION +.Fn msgget +returns the message queue identifier associated with +.Fa key . +A message queue identifier is a unique integer greater than zero. +.Pp +A message queue is created if either +.Fa key +is equal to +.Dv IPC_PRIVATE , +or +.Fa key +does not have a message queue identifier associated with it, and the +.Dv IPC_CREAT +bit is set in +.Fa msgflg . +.Pp +If a new message queue is created, the data structure associated with it (the +.Vt msqid_ds +structure, see +.Xr msgctl 2 ) +is initialized as follows: +.Bl -bullet +.It +.Fa msg_perm.cuid +and +.Fa msg_perm.uid +are set to the effective UID of the calling process. +.It +.Fa msg_perm.gid +and +.Fa msg_perm.cgid +are set to the effective GID of the calling process. +.It +.Fa msg_perm.mode +is set to the lower 9 bits of +.Fa msgflg . +.It +.Fa msg_cbytes , +.Fa msg_qnum , +.Fa msg_lspid , +.Fa msg_lrpid , +.Fa msg_rtime , +and +.Fa msg_stime +are set to 0. +.It +.Fa msg_qbytes +is set to the system wide maximum value for the number of bytes in a queue +.Pq Dv MSGMNB . +.It +.Fa msg_ctime +is set to the current time. +.El +.Sh RETURN VALUES +Upon successful completion a positive message queue identifier is returned. +Otherwise, \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EACCES +A message queue is already associated with +.Fa key +and the caller has no permission to access it. +.It Bq Er EEXIST +Both +.Dv IPC_CREAT +and +.Dv IPC_EXCL +are set in +.Fa msgflg , +and a message queue is already associated with +.Fa key . +.It Bq Er ENOSPC +A new message queue could not be created because the system limit for +the number of message queues has been reached. +.It Bq Er ENOENT +.Dv IPC_CREAT +was not set in +.Fa msgflg +and no message queue associated with +.Fa key +was found. +.El +.Sh SEE ALSO +.Xr msgctl 2 , +.Xr msgrcv 2 , +.Xr msgsnd 2 , +.Xr ftok 3 +.Sh STANDARDS +The +.Fn msgget +function conforms to the X/Open System Interfaces option of +.St -p1003.1-2008 . +.Sh HISTORY +Message queues first appeared in +.At V.1 +and have been available since +.Nx 1.0 . diff --git a/static/openbsd/man2/msgrcv.2 b/static/openbsd/man2/msgrcv.2 new file mode 100644 index 00000000..3474f967 --- /dev/null +++ b/static/openbsd/man2/msgrcv.2 @@ -0,0 +1,207 @@ +.\" $OpenBSD: msgrcv.2,v 1.18 2019/07/18 13:45:03 schwarze Exp $ +.\" $NetBSD: msgrcv.2,v 1.2 1997/03/27 08:20:37 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: July 18 2019 $ +.Dt MSGRCV 2 +.Os +.Sh NAME +.Nm msgrcv +.Nd receive a message from a message queue +.Sh SYNOPSIS +.In sys/msg.h +.Ft int +.Fn msgrcv "int msqid" "void *msgp" "size_t msgsz" "long msgtyp" "int msgflg" +.Sh DESCRIPTION +The +.Fn msgrcv +function receives a message from the message queue specified in +.Fa msqid , +and places it into the structure pointed to by +.Fa msgp . +This structure should consist of the following members: +.Bd -literal + long mtype; /* message type */ + char mtext[1]; /* body of message */ +.Ed +.Pp +.Fa mtype +is an integer greater than 0 that can be used for selecting messages, +.Fa mtext +is an array of bytes, with a size up to that of the system limit +.Pq Dv MSGMAX . +.Pp +The value of +.Fa msgtyp +has one of the following meanings: +.Bl -bullet +.It +.Fa msgtyp +is greater than 0. +The first message of type +.Fa msgtyp +will be received. +.It +.Fa msgtyp +is equal to 0. +The first message on the queue will be received. +.It +.Fa msgtyp +is less than 0. +The first message of the lowest message type that is +less than or equal to the absolute value of +.Fa msgtyp +will be received. +.El +.Pp +.Fa msgsz +specifies the maximum length of the requested message. +If the received message has a length greater than +.Fa msgsz +it will be silently truncated if the +.Dv MSG_NOERROR +flag is set in +.Fa msgflg , +otherwise an error will be returned. +.Pp +If no matching message is present on the message queue specified by +.Fa msqid , +the behavior of +.Fn msgrcv +depends on whether the +.Dv IPC_NOWAIT +flag is set in +.Fa msgflg +or not. +If +.Dv IPC_NOWAIT +is set, +.Fn msgrcv +will immediately return a value of \-1, and set +.Va errno +to +.Er EAGAIN . +If +.Dv IPC_NOWAIT +is not set, the calling process will be blocked +until: +.Bl -bullet +.It +A message of the requested type becomes available on the message queue. +.It +The message queue is removed, in which case \-1 will be returned, and +.Va errno +set to +.Er EIDRM . +.It +A signal is received and caught. +\-1 is returned, and +.Va errno +set to +.Er EINTR . +.El +.Pp +If a message is successfully received, the data structure associated with +.Fa msqid +is updated as follows: +.Bl -bullet +.It +.Fa msg_cbytes +is decremented by the size of the message. +.It +.Fa msg_lrpid +is set to the pid of the caller. +.It +.Fa msg_lrtime +is set to the current time. +.It +.Fa msg_qnum +is decremented by 1. +.El +.Sh RETURN VALUES +Upon successful completion, +.Fn msgrcv +returns the number of bytes received into the +.Fa mtext +field of the structure pointed to by +.Fa msgp . +Otherwise, \-1 is returned, and +.Va errno +set to indicate the error. +.Sh ERRORS +.Fn msgrcv +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa msqid +is not a valid message queue identifier. +.Pp +.Fa msgsz +is less than 0. +.It Bq Er E2BIG +A matching message was received, but its size was greater than +.Fa msgsz +and the +.Dv MSG_NOERROR +flag was not set in +.Fa msgflg . +.It Bq Er EACCES +The calling process does not have read access to the message queue. +.It Bq Er EFAULT +.Fa msgp +points to an invalid address. +.It Bq Er EINTR +The system call was interrupted by the delivery of a signal. +.It Bq Er ENOMSG +There is no message of the requested type available on the message queue, +and +.Dv IPC_NOWAIT +is set in +.Fa msgflg . +.It Bq Er EIDRM +The message queue was removed while +.Fn msgrcv +was waiting for a message of the requested type to become available on it. +.El +.Sh SEE ALSO +.Xr msgctl 2 , +.Xr msgget 2 , +.Xr msgsnd 2 +.Sh STANDARDS +The +.Fn msgrcv +function conforms to the X/Open System Interfaces option of +.St -p1003.1-2008 . +.Sh HISTORY +Message queues first appeared in +.At V.1 +and have been available since +.Nx 1.0 . diff --git a/static/openbsd/man2/msgsnd.2 b/static/openbsd/man2/msgsnd.2 new file mode 100644 index 00000000..54d710ab --- /dev/null +++ b/static/openbsd/man2/msgsnd.2 @@ -0,0 +1,168 @@ +.\" $OpenBSD: msgsnd.2,v 1.21 2019/07/18 13:45:03 schwarze Exp $ +.\" $NetBSD: msgsnd.2,v 1.2 1997/03/27 08:20:36 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: July 18 2019 $ +.Dt MSGSND 2 +.Os +.Sh NAME +.Nm msgsnd +.Nd send a message to a message queue +.Sh SYNOPSIS +.In sys/msg.h +.Ft int +.Fn msgsnd "int msqid" "const void *msgp" "size_t msgsz" "int msgflg" +.Sh DESCRIPTION +The +.Fn msgsnd +function sends a message to the message queue specified by +.Fa msqid . +.Fa msgp +points to a structure containing the message. +This structure should consist of the following members: +.Bd -literal -offset indent +long mtype; /* message type */ +char mtext[1]; /* body of message */ +.Ed +.Pp +.Fa mtype +is an integer greater than 0 that can be used for selecting messages (see +.Xr msgrcv 2 ) ; +.Fa mtext +is an array of +.Fa msgsz +bytes, with a size between 0 and that of the system limit +.Pq Dv MSGMAX . +.Pp +If the number of bytes already on the message queue plus +.Fa msgsz +is bigger than the maximum number of bytes on the message queue +.Po Fa msg_qbytes , + see +.Xr msgctl 2 +.Pc , +or the number of messages on all queues system-wide is already equal to +the system limit, +.Fa msgflg +determines the action of +.Fn msgsnd . +If +.Fa msgflg +has +.Dv IPC_NOWAIT +mask set in it, the call will return immediately. +If +.Fa msgflg +does not have +.Dv IPC_NOWAIT +set in it, the call will block until: +.Bl -bullet +.It +The condition which caused the call to block does no longer exist. +The message will be sent. +.It +The message queue is removed, in which case \-1 will be returned, and +.Va errno +is set to +.Er EIDRM . +.It +The caller catches a signal. +The call returns with +.Va errno +set to +.Er EINTR . +.El +.Pp +After a successful call, the data structure associated with the message +queue is updated in the following way: +.Bl -bullet +.It +.Fa msg_cbytes +is incremented by the size of the message. +.It +.Fa msg_qnum +is incremented by 1. +.It +.Fa msg_lspid +is set to the pid of the calling process. +.It +.Fa msg_stime +is set to the current time. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn msgsnd +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa msqid +is not a valid message queue identifier. +.Pp +.Fa mtype +is less than 1. +.Pp +.Fa msgsz +is greater than +.Fa msg_qbytes . +.It Bq Er EACCES +The calling process does not have write access to the message queue. +.It Bq Er EAGAIN +There was no space for this message either on the queue, or in the whole +system, and +.Dv IPC_NOWAIT +was set in +.Fa msgflg . +.It Bq Er EFAULT +.Fa msgp +points to an invalid address. +.It Bq Er EINTR +The system call was interrupted by the delivery of a signal. +.It Bq Er EIDRM +The message queue was removed while +.Fn msgsnd +was waiting for a resource to become available in order to deliver the +message. +.El +.Sh SEE ALSO +.Xr msgctl 2 , +.Xr msgget 2 , +.Xr msgrcv 2 +.Sh STANDARDS +The +.Fn msgsnd +function conforms to the X/Open System Interfaces option of +.St -p1003.1-2008 . +.Sh HISTORY +Message queues first appeared in +.At V.1 +and have been available since +.Nx 1.0 . diff --git a/static/openbsd/man2/msync.2 b/static/openbsd/man2/msync.2 new file mode 100644 index 00000000..2660fa69 --- /dev/null +++ b/static/openbsd/man2/msync.2 @@ -0,0 +1,120 @@ +.\" $OpenBSD: msync.2,v 1.30 2024/01/21 17:46:03 deraadt Exp $ +.\" $NetBSD: msync.2,v 1.8 1995/10/12 15:41:09 jtc Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/9/93 +.\" +.Dd $Mdocdate: January 21 2024 $ +.Dt MSYNC 2 +.Os +.Sh NAME +.Nm msync +.Nd synchronize a mapped region +.Sh SYNOPSIS +.In sys/mman.h +.Ft int +.Fn msync "void *addr" "size_t len" "int flags" +.Sh DESCRIPTION +The +.Fn msync +system call writes all pages with shared modifications +in the specified region starting from +.Fa addr +and continuing for +.Fa len +bytes. +.Fa addr +should be a multiple of the page size. +Any required synchronization of memory caches +will also take place at this time. +Filesystem operations on a file that is mapped for shared modifications +are unpredictable except after an +.Fn msync . +.Pp +The +.Fa flags +argument is the bitwise OR of zero or more of the following values: +.Bd -literal -offset indent +MS_ASYNC Perform asynchronous writes. +MS_SYNC Perform synchronous writes. +MS_INVALIDATE Invalidate cached data after writing. +.Ed +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The following errors may be reported: +.Bl -tag -width Er +.It Bq Er EBUSY +The +.Dv MS_INVALIDATE +flag was specified and a portion of the specified region +was locked with +.Xr mlock 2 . +.It Bq Er EINVAL +The specified +.Fa flags +argument was invalid. +.It Bq Er EINVAL +The +.Fa addr +parameter was not page aligned or +.Fa addr +and +.Fa size +specify a region that would extend beyond the end of the address space. +.It Bq Er EPERM +The +.Fa addr +and +.Fa len +parameters specify a region which contains at least one page marked immutable. +.It Bq Er ENOMEM +Addresses in the specified region are outside the range allowed +for the address space of the process, or specify one or more pages +which are unmapped. +.It Bq Er EIO +An I/O error occurred while writing. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mimmutable 2 , +.Xr minherit 2 , +.Xr mprotect 2 , +.Xr munmap 2 +.Sh HISTORY +The +.Fn msync +function has been available since +.Bx 4.3 Net/2 . +It was modified to conform to +.St -p1003.1b-93 +.Sh BUGS +Writes are currently done synchronously even if the +.Dv MS_ASYNC +flag is specified. diff --git a/static/openbsd/man2/munmap.2 b/static/openbsd/man2/munmap.2 new file mode 100644 index 00000000..23d96524 --- /dev/null +++ b/static/openbsd/man2/munmap.2 @@ -0,0 +1,104 @@ +.\" $OpenBSD: munmap.2,v 1.21 2024/01/21 17:00:42 deraadt Exp $ +.\" $NetBSD: munmap.2,v 1.5 1995/02/27 12:35:03 cgd Exp $ +.\" +.\" 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. 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.2 (Berkeley) 4/15/94 +.\" +.Dd $Mdocdate: January 21 2024 $ +.Dt MUNMAP 2 +.Os +.Sh NAME +.Nm munmap +.Nd remove a mapping +.Sh SYNOPSIS +.In 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 +.Rv -std +.Sh ERRORS +.Fn munmap +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa addr +and +.Fa len +parameters +specify a region that would extend beyond the end of the address space, +or some part of the region being unmapped is not part of the currently +valid address space. +.It Bq Er EPERM +The +.Fa addr +and +.Fa len +parameters +specify a region which contains at least one page marked immutable. +.El +.Sh SEE ALSO +.Xr madvise 2 , +.Xr mimmutable 2 , +.Xr mlock 2 , +.Xr mlockall 2 , +.Xr mmap 2 , +.Xr mprotect 2 , +.Xr msync 2 , +.Xr getpagesize 3 +.Sh STANDARDS +When +.Fa len +is non-zero, the +.Fn munmap +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn munmap +system call has been available since +.Bx 4.3 Net/2 . +.Sh CAVEATS +.St -p1003.1-2008 +specifies that +.Fn munmap +shall fail with +.Er EINVAL +if +.Fa len +is 0. +.Ox +performs no action in this case. diff --git a/static/openbsd/man2/nanosleep.2 b/static/openbsd/man2/nanosleep.2 new file mode 100644 index 00000000..50e273b2 --- /dev/null +++ b/static/openbsd/man2/nanosleep.2 @@ -0,0 +1,135 @@ +.\" $OpenBSD: nanosleep.2,v 1.19 2022/03/31 17:27:16 naddy 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. 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 $Mdocdate: March 31 2022 $ +.Dt NANOSLEEP 2 +.Os +.Sh NAME +.Nm nanosleep +.Nd high resolution sleep +.Sh SYNOPSIS +.In time.h +.Ft int +.Fn nanosleep "const struct timespec *timeout" "struct timespec *remainder" +.Sh DESCRIPTION +The +.Fn nanosleep +function suspends execution of the calling thread for at least the given +.Fa timeout . +Delivery of an unmasked signal terminates this sleep early, +even if +.Dv SA_RESTART +is set with +.Xr sigaction 2 +for the interrupting signal. +.Sh RETURN VALUES +If +.Fn nanosleep +sleeps the full +.Fa timeout +without interruption, it returns 0. +Unless +.Fa remainder +is +.Dv NULL , +it is set to zero. +.Pp +If +.Fn nanosleep +is interrupted by a signal, it returns \-1 and the global variable +.Va errno +is set to +.Dv EINTR . +Unless +.Fa remainder +is +.Dv NULL , +it is set to the unslept portion of the +.Fa timeout . +.Pp +Otherwise, +.Fn nanosleep +returns \-1 and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn nanosleep +will fail if: +.Bl -tag -width Er +.It Bq Er EINTR +The call is interrupted by the delivery of a signal. +.It Bq Er EINVAL +.Fa timeout +specifies a nanosecond value less than zero or greater than or equal to +one billion, +or a second value less than zero. +.It Bq Er EFAULT +.Fa timeout +points to memory that is not a valid part of the process address space. +.It Bq Er EFAULT +.Fa remainder +is not +.Dv NULL +and points to memory that is not a valid part of the process address space. +.El +.Sh SEE ALSO +.Xr sleep 1 , +.Xr sigaction 2 , +.Xr sleep 3 +.Sh STANDARDS +The +.Fn nanosleep +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The predecessor of this system call, +.Fn sleep , +first appeared in +.At v2 . +It was removed in +.At v7 +and replaced with a C library implementation based on +.Xr alarm 3 +and +.Xr signal 3 . +.Pp +The +.Fn nanosleep +function first appeared in +.St -p1003.1b-93 . +.Pp +This implementation of +.Fn nanosleep +first appeared in +.Nx 1.3 +and was ported to +.Ox 2.1 . diff --git a/static/openbsd/man2/nfssvc.2 b/static/openbsd/man2/nfssvc.2 new file mode 100644 index 00000000..6874138c --- /dev/null +++ b/static/openbsd/man2/nfssvc.2 @@ -0,0 +1,128 @@ +.\" $OpenBSD: nfssvc.2,v 1.25 2022/07/30 07:19:30 jsg Exp $ +.\" $NetBSD: nfssvc.2,v 1.6 1995/02/27 12:35:08 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: July 30 2022 $ +.Dt NFSSVC 2 +.Os +.Sh NAME +.Nm nfssvc +.Nd NFS services +.Sh SYNOPSIS +.In unistd.h +.In nfs/nfs.h +.Ft int +.Fn nfssvc "int flags" "void *argstructp" +.Sh DESCRIPTION +The +.Fn nfssvc +function is used by NFS daemons to pass information into 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 two structures depending on which bits are set in +flags. +.Pp +To enter an +.Xr nfsd 8 +daemon into the kernel, +.Fn nfssvc +is called with the flag +.Dv NFSSVC_NFSD +and a pointer to a structure: +.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_int32_t nsd_haddr; /* IP address of client */ + struct xucred 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 verifier */ + u_char *nsd_verfstr; + struct timeval nsd_timestamp; /* timestamp from verifier */ + u_int32_t nsd_ttl; /* credential ttl (sec) */ +}; +.Ed +.Pp +To add further sockets for processing by the +.Xr nfsd 8 +server daemons the master +.Xr nfsd 8 +daemon calls +.Fn nfssvc +with the flag +.Dv NFSSVC_ADDSOCK +and a pointer to a structure: +.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 +.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 Er +.It Bq Er EPERM +The caller is not the superuser. +.It Bq Er EINVAL +The flag argument consisted of incompatible or otherwise +unsupported bits. +.El +.Sh SEE ALSO +.Xr mount_nfs 8 , +.Xr nfsd 8 , +.Xr sysctl 8 +.Sh HISTORY +The +.Fn nfssvc +function first appeared in +.Bx 4.3 Reno . +.Sh BUGS +The +.Fn nfssvc +system call is designed specifically for the NFS +support daemons and as such is specific to their requirements. +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/static/openbsd/man2/open.2 b/static/openbsd/man2/open.2 new file mode 100644 index 00000000..560e7345 --- /dev/null +++ b/static/openbsd/man2/open.2 @@ -0,0 +1,505 @@ +.\" $OpenBSD: open.2,v 1.58 2026/04/08 12:08:25 jsg Exp $ +.\" $NetBSD: open.2,v 1.8 1995/02/27 12:35:14 cgd 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. 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 +.\" +.Dd $Mdocdate: April 8 2026 $ +.Dt OPEN 2 +.Os +.Sh NAME +.Nm open , +.Nm __pledge_open , +.Nm openat +.Nd open or create a file for reading or writing +.Sh SYNOPSIS +.In fcntl.h +.Ft int +.Fn open "const char *path" "int flags" ... +.Ft int +.Fn __pledge_open "const char *path" "int flags" ... +.Ft int +.Fn openat "int fd" "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 which case the file is created with a mode +specified by an additional argument of type +.Vt mode_t +as described in +.Xr chmod 2 +and modified by the process' umask value (see +.Xr umask 2 ) . +.Pp +The +.Fa flags +specified are a bitwise OR of the following values. +Exactly one of the first three values (file access modes) must be specified: +.Pp +.Bl -tag -width O_DIRECTORY -offset indent -compact +.It Dv O_RDONLY +Open for reading only. +.It Dv O_WRONLY +Open for writing only. +.It Dv O_RDWR +Open for reading and writing. +.El +.Pp +Any combination of the following flags may additionally be used: +.Pp +.Bl -tag -width O_DIRECTORY -offset indent -compact +.It Dv O_NONBLOCK +Do not block on open or for data to become available. +.It Dv O_APPEND +Append on each write. +.It Dv O_CREAT +Create file if it does not exist. +An additional argument of type +.Vt mode_t +must be supplied to the call. +.It Dv O_TRUNC +Truncate size to 0. +.It Dv O_EXCL +Error if +.Dv O_CREAT +is set and file exists. +.It Dv O_SYNC +Perform synchronous I/O operations. +.It Dv O_SHLOCK +Atomically obtain a shared lock. +.It Dv O_EXLOCK +Atomically obtain an exclusive lock. +.It Dv O_NOFOLLOW +If last path element is a symlink, don't follow it. +.It Dv O_CLOEXEC +Set +.Dv FD_CLOEXEC +(the close-on-exec flag) +on the new file descriptor. +.It Dv O_CLOFORK +Set +.Dv FD_CLOFORK +(the close-on-fork flag) +on the new file descriptor. +.It Dv O_DIRECTORY +Error if +.Fa path +does not name a directory. +.El +.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 +and a writing mode are 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 either of +.Dv O_EXCL +or +.Dv O_NOFOLLOW +are 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, do not wait for the device or file to be ready or +available. +If 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. +This flag also has the effect of making all subsequent I/O on the open file +non-blocking. +If the +.Dv O_SYNC +flag is set, all I/O operations on the file will be done synchronously. +.Pp +A FIFO should either be opened with +.Dv O_RDONLY +or with +.Dv O_WRONLY . +The behavior for opening a FIFO with +.Dv O_RDWR +is undefined. +.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 +.Fn open +is successful, 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 3 +returns the current system limit. +.Pp +The +.Fn __pledge_open +function is equivalent to +.Fn open +except it is only called by specific libc internal functions to +indicate intent to the kernel, which will allow opening of specific +files in specific +.Xr pledge 2 +settings. +The +.Fn __pledge_open +symbol is not exported, but will show up in +.Xr kdump 1 +output. +.Pp +The +.Fn openat +function is equivalent to +.Fn open +except that where +.Fa path +specifies a relative path, +the file to be opened is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn openat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn open . +.Sh RETURN VALUES +If successful, +.Fn open +returns a non-negative integer, termed a file descriptor. +Otherwise, a value of \-1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn open +and +.Fn openat +functions will fail if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er ENOTDIR +.Dv O_DIRECTORY +is specified and +.Fa path +does not name a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 pathname 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 +.Fa 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, +or the +.Dv O_NOFOLLOW +flag was specified and the target is a symbolic link. +.It Bq Er EISDIR +The named file is a directory, and the arguments specify +it is to be opened for writing. +.It Bq Er EISDIR +The named file is a directory, and the flags specified +.Dv O_CREAT +without +.Dv O_DIRECTORY . +If +.Dv O_EXCL +is also specified, see +.Er EEXIST +which is returned instead. +.It Bq Er EINVAL +The +.Fa flags +specified for opening the file are not valid. +.It Bq Er EINVAL +O_CREAT and O_DIRECTORY were specified. +.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, the +.Dv O_NONBLOCK +and +.Dv O_WRONLY +flags are set, and no process has the file open for reading. +.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 EWOULDBLOCK +.Dv O_NONBLOCK +and one of +.Dv O_SHLOCK +or +.Dv O_EXLOCK +is specified and the file is already locked. +.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 EPERM +The file named by +.Fa path +is flagged append-only but +.Dv O_APPEND +was not specified in +.Fa flags . +.It Bq Er EOPNOTSUPP +An attempt was made to open a socket (not currently implemented). +.It Bq Er EBUSY +An attempt was made to open a terminal device that requires exclusive +access and the specified device has already be opened. +.El +.Pp +Additionally, the +.Fn openat +function will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr chflags 2 , +.Xr chmod 2 , +.Xr close 2 , +.Xr dup 2 , +.Xr flock 2 , +.Xr lseek 2 , +.Xr read 2 , +.Xr umask 2 , +.Xr write 2 , +.Xr getdtablesize 3 +.Sh STANDARDS +The +.Fn open +and +.Fn openat +functions conform to +.St -p1003.1-2008 . +.Pp +.Dv POSIX +specifies three different flavors for synchronous I/O: +.Dv O_SYNC , +.Dv O_DSYNC , +and +.Dv O_RSYNC . +In +.Ox , +these are all equivalent. +.Pp +The +.Dv O_SHLOCK +and +.Dv O_EXLOCK +flags are non-standard extensions and should not be used if portability +is of concern. +.Sh HISTORY +An +.Fn open +system call first appeared in +.At v1 . +The +.Fa flags +argument has been supported since +.Bx 4.2 . +Before that, a dedicated +.Fn creat +system call had to be used to create new files; +it appeared in +.At v1 , +was deprecated in +.Bx 4.3 Reno , +and removed in +.Ox 5.0 . +.Pp +The +.Fn openat +system call has been available since +.Ox 5.0 . +.Pp +The internal +.Fn __pledge_open +system call first appeared in +.Ox 7.9 . +.Sh CAVEATS +The +.Dv O_TRUNC +flag requires that one of +.Dv O_RDWR +or +.Dv O_WRONLY +also be specified, else +.Er EINVAL +is returned. diff --git a/static/openbsd/man2/pathconf.2 b/static/openbsd/man2/pathconf.2 new file mode 100644 index 00000000..8be0618a --- /dev/null +++ b/static/openbsd/man2/pathconf.2 @@ -0,0 +1,299 @@ +.\" $OpenBSD: pathconf.2,v 1.26 2024/05/18 05:20:22 guenther Exp $ +.\" $NetBSD: pathconf.2,v 1.2 1995/02/27 12:35:22 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 18 2024 $ +.Dt PATHCONF 2 +.Os +.Sh NAME +.Nm pathconf , +.Nm pathconfat , +.Nm fpathconf +.Nd get configurable pathname variables +.Sh SYNOPSIS +.In unistd.h +.Ft long +.Fn pathconf "const char *path" "int name" +.Ft long +.Fn fpathconf "int fd" "int name" +.In fcntl.h +.Ft long +.Fn pathconfat "int fd" "const char *path" "int name" "int flag" +.Sh DESCRIPTION +The +.Fn pathconf , +.Fn pathconfat , +and +.Fn fpathconf +functions provide 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 +.In unistd.h . +.Pp +The available values are as follows: +.Bl -tag -width "123456" +.It Dv _PC_LINK_MAX +The maximum file link count. +.It Dv _PC_MAX_CANON +The maximum number of bytes in a terminal canonical input line. +.It Dv _PC_MAX_INPUT +The maximum number of bytes for which space is available in +a terminal input queue. +.It Dv _PC_NAME_MAX +The maximum number of bytes in a file name. +.It Dv _PC_PATH_MAX +The maximum number of bytes in a pathname. +.It Dv _PC_PIPE_BUF +The maximum number of bytes which will be written atomically to a pipe. +.It Dv _PC_CHOWN_RESTRICTED +Returns 1 if appropriate privileges are required for the +.Xr chown 2 +system call, otherwise 0. +.St -p1003.1-2001 +requires appropriate privilege in all cases, but this behavior was +optional in prior editions of the standard. +.It Dv _PC_NO_TRUNC +Returns 1 if attempts to use pathname components longer than +.Brq Dv NAME_MAX +will result in an +.Bq Er ENAMETOOLONG +error; otherwise, such components will be truncated to +.Brq Dv NAME_MAX . +.St -p1003.1-2001 +requires the error in all cases, but this behavior was optional in prior +editions of the standard, and some non-POSIX-compliant file systems do not +support this behavior. +.It Dv _PC_VDISABLE +Returns the terminal character disabling value. +.It Dv _PC_2_SYMLINKS +Returns 1 if the filesystem supports the creation of symbolic links +within the specified directory; the meaning of +.Dv _PC_2_SYMLINKS +is unspecified for non-directory files. +.It Dv _PC_ALLOC_SIZE_MIN +Minimum number of bytes of storage allocated for any portion of a file. +.It Dv _PC_ASYNC_IO +Returns 1 if asynchronous I/O is supported, otherwise 0. +.It Dv _PC_FILESIZEBITS +Number of bits needed to represent the maximum file size. +.It Dv _PC_PRIO_IO +Returns 1 if prioritized I/O is supported, otherwise 0. +.It Dv _PC_REC_INCR_XFER_SIZE +Recommended increment for file transfer sizes between _PC_REC_MIN_XFER_SIZE +and _PC_REC_MAX_XFER_SIZE. +.It Dv _PC_REC_MAX_XFER_SIZE +Maximum recommended file transfer size. +.It Dv _PC_REC_MIN_XFER_SIZE +Minimum recommended file transfer size. +.It Dv _PC_REC_XFER_ALIGN +Recommended file transfer buffer alignment. +.It Dv _PC_SYMLINK_MAX +Maximum number of bytes in a symbolic link. +.It Dv _PC_SYNC_IO +Returns 1 if synchronized I/O is supported, otherwise 0. +.It Dv _PC_TIMESTAMP_RESOLUTION +The resolution in nanoseconds of file timestamps. +.El +.Pp +The +.Fn pathconfat +function is equivalent to +.Fn pathconf +except in the case where +.Fa path +specifies a relative path. +In this case the file to be changed is determined relative to the directory +associated with the file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn pathconfat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used. +If +.Fa flag +is also zero, the behavior is identical to a call to +.Fn pathconf . +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the system variable for the symbolic +link is queried. +.El +.Sh RETURN VALUES +If the call to +.Fn pathconf , +.Fn pathconfat , +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 , +.Fn pathconfat , +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. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.El +.Pp +.Fn pathconf +and +.Fn pathconfat +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 +.Dv NAME_MAX +characters (but see +.Dv _PC_NO_TRUNC +above), or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 path +points outside the process's allocated address space. +.El +.Pp +Additionally, the +.Fn pathconfat +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_SYMLINK_NOFOLLOW . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Pp +.Fn fpathconf +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is not a valid open file descriptor. +.El +.Sh SEE ALSO +.Xr sysctl 2 , +.Xr sysconf 3 +.Sh STANDARDS +The +.Fn pathconf +and +.Fn fpathconf +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn pathconf +and +.Fn fpathconf +functions first appeared in +.Bx 4.4 . +The +.Fn pathconfat +function first appeared in +.Ox 7.6 . diff --git a/static/openbsd/man2/pinsyscalls.2 b/static/openbsd/man2/pinsyscalls.2 new file mode 100644 index 00000000..a6f4679e --- /dev/null +++ b/static/openbsd/man2/pinsyscalls.2 @@ -0,0 +1,83 @@ +.\" $OpenBSD: pinsyscalls.2,v 1.6 2025/04/06 20:20:11 kettenis Exp $ +.\" +.\" Copyright (c) 2023 Theo de Raadt <deraadt@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: April 6 2025 $ +.Dt PINSYSCALLS 2 +.Os +.Sh NAME +.Nm pinsyscalls +.Nd pin system call entry to precise locations in the address space +.Sh SYNOPSIS +.In sys/types.h +.Ft int +.Fn pinsyscalls "void *start" "size_t len" "u_int *pintable" "int npins" +.Sh DESCRIPTION +The +.Fn pinsyscalls +system call specifies the +.Va start +to +.Va start + len +address space range where the system call entry instructions are found, +and a +.Va npins Ns +-sized array of u_int entries (indexed by the system call number) +which are offsets from the +.Va start . +.Pp +This provides the precise location for the system call instruction +required for each system call number. +Attempting to use a different system call entry instruction to perform +a non-corresponding system call operation will fail with signal +.Dv SIGABRT . +.Pp +.Fn pinsyscalls +is only called by the shared library linker +.Xr ld.so 1 +to tell the kernel where the text / executable region containing +system calls is found in the dynamic library +.Pa libc.so +(the filename is actually /usr/lib/libc.so.major.minor). +This has to happen before additional threads are created. +.Pp +A similar setup operation is done automatically by the kernel for +the system calls found in +.Xr ld.so 1 +and in static executables. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn pinsyscalls +will fail if: +.Bl -tag -width Er +.It Bq Er E2BIG +Implausible number of system calls provided. +.It Bq Er ENOMEM +Insufficient memory to service the request. +.It Bq Er EPERM +A static binary tried to call +.Fn pinsyscalls , or it was called a second time. +.It Bq Er EPERM +Process is multi-threaded. +.It Bq Er ERANGE +At least one system call offset is beyond the bounds of +.Ar len . +.El +.Sh HISTORY +The +.Fn pinsyscalls +system call first appeared in +.Ox 7.5 . diff --git a/static/openbsd/man2/pipe.2 b/static/openbsd/man2/pipe.2 new file mode 100644 index 00000000..da192bbf --- /dev/null +++ b/static/openbsd/man2/pipe.2 @@ -0,0 +1,147 @@ +.\" $OpenBSD: pipe.2,v 1.20 2025/08/04 17:34:07 schwarze Exp $ +.\" $NetBSD: pipe.2,v 1.6 1995/02/27 12:35:27 cgd 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. 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 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt PIPE 2 +.Os +.Sh NAME +.Nm pipe , +.Nm pipe2 +.Nd create descriptor pair for interprocess communication +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn pipe "int fildes[2]" +.In fcntl.h +.In unistd.h +.Ft int +.Fn pipe2 "int fildes[2]" "int flags" +.Sh DESCRIPTION +The +.Fn pipe +function creates a +.Em pipe , +which is an object allowing unidirectional data flow, +and allocates a pair of file descriptors. +The first descriptor connects to the +.Em read end +of the pipe, +and the second connects to 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 whose read or write end has been 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 +.Fn pipe2 +function is identical to +.Fn pipe +except that the non-blocking I/O mode, +close-on-exec flag, +and close-on-fork flag of both new file descriptors are determined by the +.Dv O_NONBLOCK , O_CLOEXEC , +and +.Dv O_CLOFORK +flags in the +.Fa flags +argument, respectively. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn pipe +and +.Fn pipe2 +will succeed unless: +.Bl -tag -width Er +.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 +.Pp +In addition, +.Fn pipe2 +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa flags +is invalid. +.El +.Sh SEE ALSO +.Xr sh 1 , +.Xr fork 2 , +.Xr read 2 , +.Xr socketpair 2 , +.Xr write 2 +.Sh STANDARDS +The +.Fn pipe +and +.Fn pipe2 +functions conform to +.St -p1003.1-2024 . +.Pp +As an extension, the pipe provided is actually capable of moving +data bidirectionally. +This is compatible with SVR4. +However, this is non-POSIX behaviour which should not be relied on, +for reasons of portability. +.Sh HISTORY +A +.Fn pipe +function call appeared in +.At v3 . +Since +.At v4 , +it allocates two distinct file descriptors. +The +.Fn pipe2 +function appeared in +.Ox 5.7 . diff --git a/static/openbsd/man2/pledge.2 b/static/openbsd/man2/pledge.2 new file mode 100644 index 00000000..23b63c14 --- /dev/null +++ b/static/openbsd/man2/pledge.2 @@ -0,0 +1,670 @@ +.\" $OpenBSD: pledge.2,v 1.83 2026/04/01 02:34:37 jsg Exp $ +.\" +.\" Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: April 1 2026 $ +.Dt PLEDGE 2 +.Os +.Sh NAME +.Nm pledge +.Nd restrict system operations +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn pledge "const char *promises" "const char *execpromises" +.Sh DESCRIPTION +The +.Fn pledge +system call separates the POSIX feature set into a group of approximately +3 dozen subsystems. +By calling +.Fn pledge +the program can declare which subsystems it will need in the +future in a space-separated string called +.Ar promises . +Subsystems not listed become unavailable, and most attempts to use operations +in that subsystem result in the process being killed with an uncatchable +.Dv SIGABRT , +delivering a core file if possible. +.Pp +Subsequent calls to +.Fn pledge +can reduce the subsystems which still work, but previously +revoked subsystems cannot be re-activated. +.Pp +Passing +.Dv NULL +to +.Fa promises +or +.Fa execpromises +specifies to not change the current value. +.Pp +A few changes to POSIX behaviour come into effect on the first call to +.Fn pledge , +regardless of the +.Va promise +arguments: +.Bl -ohang -offset indent +.It Xr adjtime 2 : +Time cannot be changed. +Only the +.Va olddelta +argument works. +.It Xo +.Xr chmod 2 , +.Xr fchmod 2 , +.Xr fchmodat 2 , +.Xr chown 2 , +.Xr lchown 2 , +.Xr fchown 2 , +.Xr fchownat 2 , +.Xr mkfifo 2 , +and +.Xr mknod 2 : +.Xc +Setuid/setgid/sticky bits are ignored. +User or group cannot be changed. +The +.Cm fattr +promise +relaxes this behaviour slightly. +.It Xr ioctl 2 : +Only the +.Dv FIONREAD , +.Dv FIONBIO , +.Dv FIOCLEX , +and +.Dv FIONCLEX +operations are allowed by default. +All other ioctl operations are blocked, except for ones which are enabled +by specific +.Va promises : +.Cm audio , +.Cm bpf , +.Cm disklabel , +.Cm drm , +.Cm inet , +.Cm pf , +.Cm route , +.Cm wroute , +.Cm tape , +.Cm tty , +.Cm video , +and +.Cm vmm . +.It Xo +.Xr mmap 2 +and +.Xr mprotect 2 : +.Xc +.Dv PROT_EXEC +is not allowed, unless the +.Cm prot_exec +.Va promise +is requested. +.It Xr __pledge_open 2 : +A few system files can be opened directly by +.Li libc +internal code using this hidden symbol system call when +specific +.Fa promises +are requested, but applications cannot open those files themselves. +This works even when +.Cm rpath +or +.Cm wpath +are absent and +.Xr unveil 2 +cannot block opening the files. +These are the promises which can read special files: +.Va promises . +.Bl -tag -width "prot_exec" -offset indent +.It Cm stdio +.Pa /etc/localtime +.br +.Pa /usr/share/zoneinfo +(and files below) +.br +.Pa /dev/null +(for read and/or write) +.It Cm tty +.Pa /dev/tty +(for read and/or write) +.It Cm getpw +.Pa /etc/spwd.db +(refused with EPERM) +.br +.Pa /etc/pwd.db +.Pa /etc/group +.Pa /etc/netid +.It Cm dns +.Pa /etc/resolv.conf +.Pa /etc/hosts +.Pa /etc/services +.Pa /etc/protocols +.El +.It Fn pledge : +Can only reduce permissions for +.Fa promises +and +.Fa execpromises . +.It Xr sysctl 2 : +A small set of read-only operations are allowed, sufficient to +support: +.Xr getdomainname 3 , +.Xr gethostname 3 , +.Xr getifaddrs 3 , +.Xr uname 3 , +and system sensor readings. +Some +.Va promises +expose more read-only operations. +.El +.Pp +The +.Fa promises +argument is specified as a string, with space separated keywords. +Using +.Qq \& +restricts the process to the +.Xr _exit 2 +system call +(this can be used for pure computation operating on memory shared +with another process). +.Bl -tag -width "prot_exec" -offset indent +.It Cm stdio +This +.Va promise +provides access to basic memory management, actions upon already +open file descriptors, inspection of various process attributes, +timer resources, and other subsystems generally considered safe because +they only occur inside the process.. +Many of these interfaces are then used inside higher-level libc +functionality, which is why the name +.Cm stdio +was chosen. +The following system calls are permitted: +.Pp +.Xr clock_getres 2 , +.Xr clock_gettime 2 , +.Xr close 2 , +.Xr closefrom 2 , +.Xr dup 2 , +.Xr dup2 2 , +.Xr dup3 2 , +.Xr fchdir 2 , +.Xr fcntl 2 , +.Xr fstat 2 , +.Xr fsync 2 , +.Xr ftruncate 2 , +.Xr getdtablecount 2 , +.Xr getegid 2 , +.Xr getentropy 2 , +.Xr geteuid 2 , +.Xr getgid 2 , +.Xr getgroups 2 , +.Xr getitimer 2 , +.Xr getlogin 2 , +.Xr getpgid 2 , +.Xr getpgrp 2 , +.Xr getpid 2 , +.Xr getppid 2 , +.Xr getresgid 2 , +.Xr getresuid 2 , +.Xr getrlimit 2 , +.Xr getrtable 2 , +.Xr getsid 2 , +.Xr getthrid 2 , +.Xr gettimeofday 2 , +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr kevent 2 , +.Xr kqueue 2 , +.Xr kqueue1 2 , +.Xr lseek 2 , +.Xr madvise 2 , +.Xr minherit 2 , +.Xr mmap 2 , +.Xr mprotect 2 , +.Xr mquery 2 , +.Xr munmap 2 , +.Xr nanosleep 2 , +.Xr pipe 2 , +.Xr pipe2 2 , +.Xr poll 2 , +.Xr pread 2 , +.Xr preadv 2 , +.Xr profil 2 , +.Xr pwrite 2 , +.Xr pwritev 2 , +.Xr read 2 , +.Xr readv 2 , +.Xr recvfrom 2 , +.Xr recvmsg 2 , +.Xr select 2 , +.Xr sendmsg 2 , +.Xr sendsyslog 2 , +.Xr sendto 2 , +.Xr setitimer 2 , +.Xr shutdown 2 , +.Xr sigaction 2 , +.Xr sigprocmask 2 , +.Xr sigreturn 2 , +.Xr socketpair 2 , +.Xr umask 2 , +.Xr wait4 2 , +.Xr waitid 2 , +.Xr write 2 , +.Xr writev 2 +.Pp +.Xr sendto 2 +is only permitted if the destination socket address is +.Dv NULL . +.It Cm rpath +A number of system calls are allowed which allow path traversal, +reading +.Vt struct stat , +and opening files for read. +.It Cm wpath +Similar to +.Cm rpath , +but files can be opened for write. +.It Cm cpath +Similar to +.Cm wpath , +but files can also be created or removed. +.It Cm dpath +Similar to +.Cm cpath , +but special files can be created using: +.Pp +.Xr mkfifo 2 , +.Xr mknod 2 +.It Cm tmppath +No longer available. +This pledge was designed to satisfy the +.Xr mkstemp 3 +family of functions. +The limited filesystem access it provided is now disabled, so the +promise has been removed and will +return +.Er EINVAL . +It should be replaced by either +allowing use of the whole filesystem, meaning +.Qq rpath wpath cpath , +or use of +.Xr unveil 2 +with +.Fa path +.Qq /tmp +and +.Fa permissions +.Qq rwc . +.It Cm inet +The following system calls are allowed to operate in the +.Dv AF_INET +and +.Dv AF_INET6 +domains +(though +.Xr setsockopt 2 +has been substantially reduced in functionality): +.Pp +.Xr socket 2 , +.Xr listen 2 , +.Xr bind 2 , +.Xr connect 2 , +.Xr accept4 2 , +.Xr accept 2 , +.Xr getpeername 2 , +.Xr getsockname 2 , +.Xr setsockopt 2 , +.Xr getsockopt 2 +.It Cm mcast +In combination with +.Cm inet +give back functionality to +.Xr setsockopt 2 +for operating on multicast sockets. +.It Cm fattr +The following system calls are allowed to make explicit changes +to fields in +.Vt struct stat +relating to a file: +.Pp +.Xr utimes 2 , +.Xr futimes 2 , +.Xr utimensat 2 , +.Xr futimens 2 , +.Xr chmod 2 , +.Xr fchmod 2 , +.Xr fchmodat 2 , +.Xr chflags 2 , +.Xr chflagsat 2 , +.Xr chown 2 , +.Xr fchownat 2 , +.Xr lchown 2 , +.Xr fchown 2 , +.Xr utimes 2 +.It Cm chown +The +.Xr chown 2 +family is allowed to change the user or group on a file. +.It Cm flock +File locking via +.Xr fcntl 2 , +.Xr flock 2 , +.Xr lockf 3 , +and +.Xr open 2 +is allowed. +No distinction is made between shared and exclusive locks. +This promise is required for unlock as well as lock. +.It Cm unix +The following system calls are allowed to operate in the +.Dv AF_UNIX +domain: +.Pp +.Xr socket 2 , +.Xr listen 2 , +.Xr bind 2 , +.Xr connect 2 , +.Xr accept4 2 , +.Xr accept 2 , +.Xr getpeername 2 , +.Xr getsockname 2 , +.Xr setsockopt 2 , +.Xr getsockopt 2 +.Pp +The +.Xr bind 2 +call can create AF_UNIX sockets at any path even without +.Cm wpath , +and +.Xr connect 2 +can connect at any path +even without +.Cm rpath +or +.Cm wpath . +.It Cm dns +Some low-level behaviours required by the DNS resolver described in +.Xr res_init 3 +are permitted. +This includes +.Xr __pledge_open 2 +reading +.Xr hosts 5 , +.Xr protocols 5 , +.Xr resolv.conf 5 , +and +.Xr services 5 , +and exposing a few networking system calls: +.Xr socket 2 , +.Xr connect 2 , +.Xr sendto 2 , +.Xr recvfrom 2 +which can only operate on the specific socket type +.Dv SOCK_DNS . +The library resolver opens sockets with +.Dv SOCK_DNS +only on port 53, so the kernel can differentiate these operations +from regular sockets operations. +.It Cm getpw +This uses the special features of +.Xr __pledge_open 2 +to read required system files to support the +.Xr getpwnam 3 , +.Xr getgrnam 3 , +.Xr getgrouplist 3 , +and +.Xr initgroups 3 +family of functions, including lookups via the +.Xr yp 8 +protocol for YP and LDAP databases. +.It Cm sendfd +Allows sending of file descriptors using +.Xr sendmsg 2 . +File descriptors referring to directories may not be passed. +.It Cm recvfd +Allows receiving of file descriptors using +.Xr recvmsg 2 . +File descriptors referring to directories may not be passed. +.It Cm tape +Allow +.Dv MTIOCGET +and +.Dv MTIOCTOP +operations against tape drives. +.It Cm tty +In addition to allowing read-write operations on +.Pa /dev/tty , +this opens up a variety of +.Xr ioctl 2 +requests used by tty devices. +If +.Cm tty +is accompanied with +.Cm rpath , +.Xr revoke 2 +is permitted. +Otherwise only the following +.Xr ioctl 2 +requests are permitted: +.Pp +.Dv TIOCSPGRP , +.Dv TIOCGETA , +.Dv TIOCGPGRP , +.Dv TIOCGWINSZ , +.Dv TIOCSWINSZ , +.Dv TIOCSBRK , +.Dv TIOCCDTR , +.Dv TIOCSETA , +.Dv TIOCSETAW , +.Dv TIOCSETAF , +.Dv TIOCUCNTL +.It Cm proc +Allows the following process relationship operations: +.Pp +.Xr fork 2 , +.Xr vfork 2 , +.Xr kill 2 , +.Xr getpriority 2 , +.Xr setpriority 2 , +.Xr setrlimit 2 , +.Xr setpgid 2 , +.Xr setsid 2 +.It Cm exec +Allows a process to call +.Xr execve 2 . +Coupled with the +.Cm proc +promise, this allows a process to fork and execute another program. +If +.Fa execpromises +has been previously set the new program begins with those promises, +unless setuid/setgid bits are set in which case execution is blocked with +.Er EACCES . +Otherwise the new program starts running without pledge active, +and hopefully makes a new pledge soon. +.It Cm prot_exec +Allows the use of +.Dv PROT_EXEC +with +.Xr mmap 2 +and +.Xr mprotect 2 . +.It Cm settime +Allows the setting of system time, via the +.Xr settimeofday 2 , +.Xr adjtime 2 , +and +.Xr adjfreq 2 +system calls. +.It Cm ps +Allows enough +.Xr sysctl 2 +interfaces to allow inspection of processes operating on the system using +programs like +.Xr ps 1 . +.It Cm vminfo +Allows enough +.Xr sysctl 2 +interfaces to allow inspection of the system's virtual memory by +programs like +.Xr top 1 +and +.Xr vmstat 8 . +.It Cm id +Allows the following system calls which can change the rights of a +process: +.Pp +.Xr setuid 2 , +.Xr seteuid 2 , +.Xr setreuid 2 , +.Xr setresuid 2 , +.Xr setgid 2 , +.Xr setegid 2 , +.Xr setregid 2 , +.Xr setresgid 2 , +.Xr setgroups 2 , +.Xr setlogin 2 , +.Xr setrlimit 2 , +.Xr getpriority 2 , +.Xr setpriority 2 , +.Xr setrtable 2 +.It Cm pf +Allows a subset of +.Xr ioctl 2 +operations on the +.Xr pf 4 +device: +.Pp +.Dv DIOCADDRULE , +.Dv DIOCGETSTATUS , +.Dv DIOCNATLOOK , +.Dv DIOCRADDTABLES , +.Dv DIOCRCLRADDRS , +.Dv DIOCRCLRTABLES , +.Dv DIOCRCLRTSTATS , +.Dv DIOCRGETTSTATS , +.Dv DIOCRSETADDRS , +.Dv DIOCXBEGIN , +.Dv DIOCXCOMMIT +.It Cm route +Allow inspection of the routing table. +.It Cm wroute +Allow changes to the routing table. +.It Cm audio +Allows a subset of +.Xr ioctl 2 +operations on +.Xr audio 4 +devices +(see +.Xr sio_open 3 +for more information): +.Pp +.Dv AUDIO_GETPOS , +.Dv AUDIO_GETPAR , +.Dv AUDIO_SETPAR , +.Dv AUDIO_START , +.Dv AUDIO_STOP , +.Dv AUDIO_MIXER_DEVINFO , +.Dv AUDIO_MIXER_READ , +.Dv AUDIO_MIXER_WRITE +.It Cm video +Allows a subset of +.Xr ioctl 2 +operations on +.Xr video 4 +devices: +.Pp +.Dv VIDIOC_DQBUF , +.Dv VIDIOC_ENUM_FMT , +.Dv VIDIOC_ENUM_FRAMEINTERVALS , +.Dv VIDIOC_ENUM_FRAMESIZES , +.Dv VIDIOC_G_CTRL , +.Dv VIDIOC_G_PARM , +.Dv VIDIOC_QBUF , +.Dv VIDIOC_QUERYBUF , +.Dv VIDIOC_QUERYCAP , +.Dv VIDIOC_QUERYCTRL , +.Dv VIDIOC_S_CTRL , +.Dv VIDIOC_S_FMT , +.Dv VIDIOC_S_PARM , +.Dv VIDIOC_STREAMOFF , +.Dv VIDIOC_STREAMON , +.Dv VIDIOC_TRY_FMT , +.Dv VIDIOC_REQBUFS +.It Cm bpf +Allow +.Dv BIOCGSTATS +operation for statistics collection from a +.Xr bpf 4 +device. +.It Cm unveil +Allow +.Xr unveil 2 +to be called. +.It Cm error +Rather than killing the process upon violation, indicate error with +.Er ENOSYS . +.Pp +Also when +.Fn pledge +is called with higher +.Fa promises +or +.Fa execpromises , +those changes will be ignored and return success. +This is useful when a parent enforces +.Fa execpromises +but an execve'd child has a different idea. +.El +.Pp +A process currently running with pledge has state +.Sq p +in +.Xr ps 1 +output; a process that was terminated due to a pledge violation +is accounted by +.Xr lastcomm 1 +with the +.Sq P +flag. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn pledge +will fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +.Fa promises +or +.Fa execpromises +points outside the process's allocated address space. +.It Bq Er EINVAL +.Fa promises +is malformed or contains invalid keywords. +.It Bq Er EPERM +This process is attempting to increase permissions. +.El +.Sh HISTORY +The +.Fn pledge +system call first appeared in +.Ox 5.9 . diff --git a/static/openbsd/man2/poll.2 b/static/openbsd/man2/poll.2 new file mode 100644 index 00000000..c829c272 --- /dev/null +++ b/static/openbsd/man2/poll.2 @@ -0,0 +1,364 @@ +.\" $OpenBSD: poll.2,v 1.42 2025/11/10 16:04:30 job Exp $ +.\" +.\" Copyright (c) 1994 Jason R. Thorpe +.\" 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 Jason R. Thorpe. +.\" 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 +.\" +.Dd $Mdocdate: November 10 2025 $ +.Dt POLL 2 +.Os +.Sh NAME +.Nm poll , +.Nm ppoll +.Nd synchronous I/O multiplexing +.Sh SYNOPSIS +.In poll.h +.Ft int +.Fn poll "struct pollfd *fds" "nfds_t nfds" "int timeout" +.Ft int +.Fn ppoll "struct pollfd *fds" "nfds_t nfds" "const struct timespec * restrict timeout" "const sigset_t * restrict mask" +.Sh DESCRIPTION +.Fn poll +provides a mechanism for multiplexing I/O across a set of file +descriptors. +It is similar in function to +.Xr select 2 . +Unlike +.Xr select 2 , +however, it is possible to only pass in data corresponding to the +file descriptors for which events are wanted. +This makes +.Fn poll +more efficient than +.Xr select 2 +in most cases. +.Pp +The arguments are as follows: +.Bl -tag -width timeout +.It Fa fds +Points to an array of +.Vt pollfd +structures, which are defined as: +.Bd -literal -offset indent +struct pollfd { + int fd; + short events; + short revents; +}; +.Ed +.Pp +The +.Fa fd +member is an open file descriptor. +If +.Fa fd +is -1, +the +.Vt pollfd +structure is considered unused, and +.Fa revents +will be cleared. +.Pp +The +.Fa events +and +.Fa revents +members are bitmasks of conditions to monitor and conditions found, +respectively. +.It Fa nfds +An unsigned integer specifying the number of +.Vt pollfd +structures in the array. +.It Fa timeout +Maximum interval to wait for the poll to complete, in milliseconds. +If this value is 0, +.Fn poll +will return immediately. +If this value is +.Dv INFTIM Pq -1 , +.Fn poll +will block indefinitely until a condition is found. +.El +.Pp +The calling process sets the +.Fa events +bitmask and +.Fn poll +sets the +.Fa revents +bitmask. +Each call to +.Fn poll +resets the +.Fa revents +bitmask for accuracy. +The condition flags in the bitmasks are defined as: +.Bl -tag -width POLLRDNORM +.It Dv POLLIN +Data other than high-priority data may be read without blocking. +.It Dv POLLRDNORM +Normal data may be read without blocking. +.It Dv POLLRDBAND +Priority data may be read without blocking. +.It Dv POLLNORM +Same as +.Dv POLLRDNORM . +This flag is provided for source code compatibility with older +programs and should not be used in new code. +.It Dv POLLPRI +High-priority data may be read without blocking. +.It Dv POLLOUT +Normal data may be written without blocking. +.It Dv POLLWRNORM +Same as +.Dv POLLOUT . +.It Dv POLLWRBAND +Priority data may be written. +.It Dv POLLERR +An error has occurred on the device or socket. +This flag is only valid in the +.Fa revents +bitmask; it is ignored in the +.Fa events +member. +.It Dv POLLHUP +The device or socket has been disconnected. +This event and +.Dv POLLOUT +are mutually-exclusive; a descriptor can never be writable if a hangup has +occurred. +However, this event and +.Dv POLLIN , +.Dv POLLRDNORM , +.Dv POLLRDBAND , +or +.Dv POLLPRI +are not mutually-exclusive. +This flag is only valid in the +.Fa revents +bitmask; it is ignored in the +.Fa events +member. +.It Dv POLLNVAL +The corresponding file descriptor is invalid. +This flag is only valid in the +.Fa revents +bitmask; it is ignored in the +.Fa events +member. +.El +.Pp +The significance and semantics of normal, priority, and high-priority +data are device-specific. +For example, on +.Ox , +the +.Dv POLLPRI +and +.Dv POLLRDBAND +flags may be used to detect when out-of-band socket data may be read +without blocking. +.Pp +The +.Fn ppoll +function is similar to +.Fn poll +except that it specifies the timeout using a timespec structure, +and a null pointer is used to specify an indefinite timeout +instead of +.Dv INFTIM . +Also, if +.Fa mask +is a non-null pointer, +.Fn ppoll +atomically sets the calling thread's signal mask to the signal set +pointed to by +.Fa mask +for the duration of the function call. +In this case, the original signal mask will be restored before +.Fn ppoll +returns. +.Sh RETURN VALUES +Upon error, +.Fn poll +and +.Fn ppoll +return \-1 and set the global variable +.Va errno +to indicate the error. +If the timeout interval was reached before any events occurred, +they return 0. +Otherwise, they return the number of +.Vt pollfd +structures for which +.Fa revents +is non-zero. +.Sh IDIOMS +Care must be taken when converting code from +.Xr select 2 +to +.Fn poll +as they have slightly different semantics. +The first semantic difference is that, unlike +.Xr select 2 , +.Fn poll +has a way of indicating that one or more file descriptors are invalid +by setting a flag in the +.Fa revents +field of corresponding entry of +.Fa fds , +whereas +.Xr select 2 +returns an error (-1) if any of the descriptors with bits set in +the +.Vt fd_set +are invalid. +The second difference is that on EOF there is no guarantee that +.Dv POLLIN +will be set in +.Fa revents , +the caller must also check for +.Dv POLLHUP . +This differs from +.Xr select 2 +where EOF is considered as a read event. +.Pp +Consider the following usage of +.Xr select 2 +that implements a read from the standard input with a +60 second time out: +.Bd -literal -offset indent +struct timeval timeout; +fd_set readfds; +char buf[BUFSIZ]; +int nready; + +timeout.tv_sec = 60; +timeout.tv_usec = 0; +FD_ZERO(&readfds); +FD_SET(STDIN_FILENO, &readfds); +nready = select(STDIN_FILENO + 1, &readfds, NULL, NULL, &timeout); +if (nready == -1) + err(1, "select"); +if (nready == 0) + errx(1, "time out"); +if (FD_ISSET(STDIN_FILENO, &readfds)) { + if (read(STDIN_FILENO, buf, sizeof(buf)) == -1) + err(1, "read"); +} +.Ed +.Pp +This can be converted to +.Fn poll +as follows: +.Bd -literal -offset indent +struct pollfd pfd[1]; +char buf[BUFSIZ]; +int nready; + +pfd[0].fd = STDIN_FILENO; +pfd[0].events = POLLIN; +nready = poll(pfd, 1, 60 * 1000); +if (nready == -1) + err(1, "poll"); +if (nready == 0) + errx(1, "time out"); +if (pfd[0].revents & (POLLERR|POLLNVAL)) + errx(1, "bad fd %d", pfd[0].fd); +if (pfd[0].revents & (POLLIN|POLLHUP)) { + if (read(STDIN_FILENO, buf, sizeof(buf)) == -1) + err(1, "read"); +} +.Ed +.Sh ERRORS +.Fn poll +and +.Fn ppoll +will fail if: +.Bl -tag -width Er +.It Bq Er EAGAIN +The kernel failed to allocate memory for temporary data structures; +a later call may succeed. +.It Bq Er EFAULT +.Fa fds +points outside the process's allocated address space. +.It Bq Er EINTR +A signal was caught before any polled events occurred +and before the timeout elapsed. +.It Bq Er EINVAL +.Fa nfds +was greater than the number of available +file descriptors. +.It Bq Er EINVAL +The timeout passed was invalid. +.El +.Sh SEE ALSO +.Xr clock_gettime 2 , +.Xr getrlimit 2 , +.Xr read 2 , +.Xr select 2 , +.Xr write 2 +.Sh STANDARDS +The +.Fn poll +and +.Fn ppoll +functions conform to +.St -p1003.1-2024 . +.Sh HISTORY +A +.Fn poll +system call appeared in +.At V.3 . +The +.Fn ppoll +function appeared in +.Ox 5.4 . +.Sh CAVEATS +The +.Dv POLLWRBAND +flag is accepted but ignored by the kernel. +.Pp +Because +.Ox +does not implement STREAMS, +there is no distinction between some of the fields in the +.Fa events +and +.Fa revents +bitmasks. +As a result, the +.Dv POLLIN , +.Dv POLLNORM , +and +.Dv POLLRDNORM +flags are equivalent. +Similarly, the +.Dv POLLPRI +and +.Dv POLLRDBAND +flags are also equivalent. diff --git a/static/openbsd/man2/profil.2 b/static/openbsd/man2/profil.2 new file mode 100644 index 00000000..0976efa7 --- /dev/null +++ b/static/openbsd/man2/profil.2 @@ -0,0 +1,183 @@ +.\" $OpenBSD: profil.2,v 1.17 2025/07/13 23:38:55 jsg Exp $ +.\" $NetBSD: profil.2,v 1.3 1995/11/22 23:07:23 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: July 13 2025 $ +.Dt PROFIL 2 +.Os +.Sh NAME +.Nm profil +.Nd control process profiling +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn profil "void *buf" "size_t buflen" "size_t samplesize" "u_long offset" "u_int scale" "int dirfd" +.Sh DESCRIPTION +The +.Fn profil +function is only available inside programs compiled with the +.Fl pg +compiler / linker option. +.Fl pg +selects the profiling version of the C-run-time code +.Pa ( gcrt0.o ) , +which places an ELF note into the binary which enables the system call. +The profiling subsystem only works with static binaries, so the +.Fl static +link option is also required. +.Pp +The first call to +.Fn profil +happens at startup inside +.Pa gcrt0.o +and sets up a region of memory +.Fa buf +that is +.Fa buflen +bytes long to contain a +.Va struct gmonhdr , +a samples buffer of size +.Fa samplesize , +and a sufficiently-sized arc-table. +.Pp +.Fa dirfd +can indicate the path for placing the output file +(environment variable +.Ev PROFDIR +is the usual choice). +Otherwise, \-1 indicates the current (starting) directory location. +.Pp +Program execution then continues with profiling operational. +During execution, profiling can be selectively stopped and restarted using +.Xr moncontrol 3 . +.Pp +While profiling is enabled, at every clock tick, the kernel updates an +appropriate count in the samples buffer. +.Pp +The samples buffer contains +.Fa samplesize +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 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. +.Pp +At normal program termination, the C-run-time completes the data in the +buffer to final format, and proceeds into +.Xr _exit 2 . +The kernel then constructs a pathname +.Pa gmon.progname.pid.out +and stores the data to the filesystem (either at the starting directory, +or the optional directory indicated by the environment variable +.Ev PROFDIR ) . +.Pp +Further processing is then done using +.Xr gprof 1 . +.Sh RETURN VALUES +.Rv -std +.Sh FILES +.Bl -tag -width gmon.progname.pid.out -compact +.It Pa /usr/lib/gcrt0.o +profiling C run-time startup file +.It Pa gmon.progname.pid.out +conventional name for profiling output file +.El +.Sh ERRORS +The following error may be reported: +.Bl -tag -width Er +.It Bq Er EPERM +The program was not linked with +.Fl pg . +.It Bq Er EALREADY +An attempt was made to change the profile buffer. +.It Bq Er EBADF +The +.Fa dirfd +argument is not a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa dirfd +argument does not refer to a directory. +.It Bq Er EINVAL +The +.Fa scale +value is too large. +.El +.Sh SEE ALSO +.Xr gprof 1 +.Sh HISTORY +The +.Fn profil +system call first appeared in +.At v5 . +.Pp +Historically, profile information was written to the file by the C-run-time +exit processing code using +.Xr open 2 , +.Xr write 2 , +and such \(em which is incompatible with modern privilege separation practices +like +.Xr chroot 2 , +.Xr pledge 2 , +.Xr setresuid 2 , +and +.Xr unveil 2 . +This replacement +.Fn profil +interface was redesigned so the kernel writes out the profiling information +on behalf of the terminating process. +.Sh BUGS +The +.Fa samples +argument should really be a vector of type +.Fa "unsigned short" . diff --git a/static/openbsd/man2/ptrace.2 b/static/openbsd/man2/ptrace.2 new file mode 100644 index 00000000..9b4b083f --- /dev/null +++ b/static/openbsd/man2/ptrace.2 @@ -0,0 +1,668 @@ +.\" $OpenBSD: ptrace.2,v 1.44 2024/11/27 05:25:56 anton Exp $ +.\" $NetBSD: ptrace.2,v 1.3 1996/02/23 01:39:41 jtc Exp $ +.\" +.\" This file is in the public domain. +.Dd $Mdocdate: November 27 2024 $ +.Dt PTRACE 2 +.Os +.Sh NAME +.Nm ptrace +.Nd process tracing and debugging +.Sh SYNOPSIS +.In sys/types.h +.In sys/ptrace.h +.Ft int +.Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data" +.Sh DESCRIPTION +.Fn ptrace +provides tracing and debugging facilities. +It allows one process (the +.Em tracing +process) to control another (the +.Em traced +process). +Most of the time, the traced process runs normally, but when +it receives a signal +.Po +see +.Xr sigaction 2 +.Pc , +it stops. +The tracing process is expected to notice this via +.Xr wait 2 +or the delivery of a +.Dv SIGCHLD +signal, examine the state of the stopped process, and cause it to +terminate or continue as appropriate. +.Fn ptrace +is the mechanism by which all this happens. +.Fn ptrace +is only available on kernels compiled with the +.Cm PTRACE +option. +.Pp +The +.Fa request +argument specifies what operation is being performed; the meaning of +the rest of the arguments depends on the operation, but except for one +special case noted below, all +.Fn ptrace +calls are made by the tracing process, and the +.Fa pid +argument specifies the process ID of the traced process. +.Fa request +can be: +.Bl -tag -width 12n +.It Dv PT_TRACE_ME +This request is the only one used by the traced process; it declares +that the process expects to be traced by its parent. +All the other arguments are ignored. +(If the parent process does not expect to trace the child, it will +probably be rather confused by the results; once the traced process stops, +it cannot be made to continue except via +.Fn ptrace . ) +When a process has used this request and calls +.Xr execve 2 +or any of the routines built on it +.Po +such as +.Xr execv 3 +.Pc , +it will stop before executing the first instruction of the new image. +Also, any setuid or setgid bits on the executable being executed will +be ignored. +.It Dv PT_READ_I , Dv PT_READ_D +These requests read a single +.Vt int +of data from the traced process' address space. +Traditionally, +.Fn ptrace +has allowed for machines with distinct address spaces for instruction +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 +.Ox +implementation, these two requests operate in the same address space. +The +.Fa addr +argument specifies the address (in the traced process' virtual address +space) at which the read is to be done. +This address does not have to meet any alignment constraints. +The value read is returned as the return value from +.Fn ptrace . +.It Dv PT_WRITE_I , Dv PT_WRITE_D +These requests parallel +.Dv PT_READ_I +and +.Dv PT_READ_D , +except that they write rather than read. +.Dv PT_WRITE_I +may be necessary to ensure that instruction caches are flushed appropriately. +The +.Fa data +argument supplies the value to be written. +.\" .It Dv PT_READ_U +.\" This request reads an +.\" .Li int +.\" from the traced process' user structure. +.\" The +.\" .Fa addr +.\" argument specifies the location of the int relative to the base of the +.\" user structure; it will usually be an integer value cast to +.\" .Li caddr_t +.\" either explicitly or via the presence of a prototype for +.\" .Fn ptrace . +.\" Unlike +.\" .Dv PT_READ_I +.\" and +.\" .Dv PT_READ_D , +.\" .Fa addr +.\" must be aligned on an +.\" .Li int +.\" boundary. +.\" The value read is returned as the return value from +.\" .Fn ptrace . +.\" .It Dv PT_WRITE_U +.\" This request writes an +.\" .Li int +.\" into the traced process' user structure. +.\" .Fa addr +.\" specifies the offset, just as for +.\" .Dv PT_READ_U , +.\" and +.\" .Fa data +.\" specifies the value to be written, just as for +.\" .Dv PT_WRITE_I +.\" and +.\" .Dv PT_WRITE_D . +.It Dv PT_CONTINUE +The traced process continues execution. +.Fa addr +is an address specifying the place where execution is to be resumed (a +new value for the program counter), or +.Li (caddr_t)1 +to indicate that execution is to pick up where it left off. +.Fa data +provides a signal number to be delivered to the traced process as it +resumes execution, or 0 if no signal is to be sent. +.It Dv PT_KILL +The traced process terminates, as if +.Dv PT_CONTINUE +had been used with +.Dv SIGKILL +given as the signal to be delivered. +.It Dv PT_ATTACH +This request allows a process to gain control of an otherwise unrelated +process and begin tracing it. +It does not need any cooperation from the to-be-traced process. +In this case, +.Fa pid +specifies the process ID of the to-be-traced process, and the other two +arguments are ignored. +This request requires that the target process must have the same real UID +as the tracing process, and that it must not be executing a set-user-ID +or set-group-ID executable. +Additionally, if the +.Dv kern.global_ptrace +sysctl is 0, then the target process must be a descendant of the tracing +process. +(If the tracing process is running as root, these restrictions do not apply.) +The tracing process will see the newly traced process stop and may then +control it as if it had been traced all along. +.It Dv PT_DETACH +This request is like +.Dv PT_CONTINUE , +except that it does not allow +specifying an alternate place to continue execution, and after it +succeeds, the traced process is no longer traced and continues +execution normally. +.It Dv PT_IO +This request is a more general interface that can be used instead of +.Dv PT_READ_D , +.Dv PT_WRITE_D , +.Dv PT_READ_I +and +.Dv PT_WRITE_I . +The I/O request is encoded in a +.Dq Li "struct ptrace_io_desc" +defined as: +.Bd -literal -offset indent +struct ptrace_io_desc { + int piod_op; + void *piod_offs; + void *piod_addr; + size_t piod_len; +}; +.Ed +.Pp +Where +.Fa piod_offs +is the offset within the traced process where the I/O operation should be +made, +.Fa piod_addr +is the buffer in the parent and +.Fa piod_len +is the length of the I/O request. +The +.Fa piod_op +member specifies what operation needs to be done. +Possible values are: +.Pp +.Bl -tag -width Ds -offset indent -compact +.It PIOD_READ_D +.It PIOD_WRITE_D +.It PIOD_READ_I +.It PIOD_WRITE_I +.It PIOD_READ_AUXV +.El +.Pp +See also the description of +.Dv PT_READ_I +for the difference between D and I spaces. +The +.Dv PIOD_READ_AUXV +operation can be used to read from the ELF auxiliary vector. +A pointer to the descriptor is passed in +.Fa addr . +On return the +.Fa piod_len +field in the descriptor will be updated with the actual number of bytes +transferred. +If the requested I/O could not be successfully performed, +.Fn ptrace +will return +.Li -1 +and set +.Va errno . +.It Dv PT_SET_EVENT_MASK +This request can be used to specify which events in the traced process +should be reported to the tracing process. +These events are specified in a +.Dq Li "struct ptrace_event" +defined as: +.Bd -literal -offset indent +typedef struct ptrace_event { + int pe_set_event; +} ptrace_event_t; +.Ed +.Pp +Where +.Fa pe_set_event +is the set of events to be reported. +This set is formed by OR'ing together the following values: +.Bl -tag -width 18n +.It PTRACE_FORK +Report +.Xr fork 2 . +.El +.Pp +A pointer to this structure is passed in +.Fa addr . +The +.Fa data +argument should be set to +.Li sizeof(struct ptrace_event) . +.It Dv PT_GET_EVENT_MASK +This request can be used to determine which events in the traced +process will be reported. +The information is read into the +.Dq Li struct ptrace_event +pointed to by +.Fa addr . +The +.Fa data +argument should be set to +.Li sizeof(struct ptrace_event) . +.It Dv PT_GET_PROCESS_STATE +This request reads the state information associated with the event +that stopped the traced process. +The information is reported in a +.Dq Li "struct ptrace_state" +defined as: +.Bd -literal -offset indent +typedef struct ptrace_state { + int pe_report_event; + pid_t pe_other_pid; +} ptrace_state_t; +.Ed +.Pp +Where +.Fa pe_report_event +is the event being reported. +If the event being reported is +.Dv PTRACE_FORK , +.Fa pe_other_pid +will be set to the process ID of the other end of the fork. +A pointer to this structure is passed in +.Fa addr . +The +.Fa data +argument should be set to +.Li sizeof(struct ptrace_state) . +.It Dv PT_GET_THREAD_FIRST +This request reads the thread ID of the traced process' first thread into the +.Dq Li struct ptrace_thread_state +pointed to by +.Fa addr . +The +.Fa data +argument should be set to +.Li sizeof(struct ptrace_thread_state) . +.It Dv PT_GET_THREAD_NEXT +This request is just like +.Dv PT_GET_THREAD_FIRST , +except it returns the thread ID of the subsequent thread. +The +.Dq Li struct ptrace_thread_state +pointed to by +.Fa addr +must be initialized by a previous +.Dv PT_GET_THREAD_FIRST +or +.Dv PT_GET_THREAD_NEXT +request. +.El +.Pp +Additionally, machine-specific requests can exist. +Depending on the architecture, the following requests may be available +under +.Ox : +.Bl -tag -width 12n +.It Dv PT_GETREGS Pq all platforms +This request reads the traced process' machine registers into the +.Dq Li struct reg +(defined in +.In machine/reg.h ) +pointed to by +.Fa addr . +.It Dv PT_SETREGS Pq all platforms +This request is the converse of +.Dv PT_GETREGS ; +it loads the traced process' machine registers from the +.Dq Li struct reg +(defined in +.In 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 +.\" .In sys/param.h , +.\" .In sys/user.h , +.\" and +.\" .In 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 +.\" .Li -1 , +.\" .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 +.\" .Li syscall_nargs ) . +.\" 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. +.It Xo Dv PT_STEP +.No (not available on sparc64) +.Xc +The traced process continues execution, as in request +.Dv PT_CONTINUE ; +however, execution stops as soon as possible after execution of at least +one instruction +.Pq single-step . +.\" mips64 (fp registers in the main reg structure) +.It Xo Dv PT_GETFPREGS +.No (not available on luna88k or mips64) +.Xc +This request reads the traced process' floating-point registers into +the +.Dq Li struct fpreg +(defined in +.In machine/reg.h ) +pointed to by +.Fa addr . +.It Xo Dv PT_SETFPREGS +.No (not available on luna88k or mips64) +.Xc +This request is the converse of +.Dv PT_GETFPREGS ; +it loads the traced process' floating-point registers from the +.Dq Li struct fpreg +(defined in +.In machine/reg.h ) +pointed to by +.Fa addr . +.It Dv PT_GETXMMREGS Pq i386 only +This request reads the traced process' XMM registers into the +.Dq Li struct xmmregs +(defined in +.In machine/reg.h ) +pointed to by +.Fa addr . +.It Dv PT_SETXMMREGS Pq i386 only +This request is the converse of +.Dv PT_GETXMMREGS ; +it loads the traced process' XMM registers from the +.Dq Li struct xmmregs +(defined in +.In machine/reg.h ) +pointed to by +.Fa addr . +.It Dv PT_WCOOKIE Pq sparc64 only +This request reads the traced process' +.Sq window cookie +into the +.Vt int +pointed to by +.Fa addr . +The window cookie needs to be +.Sq XOR'ed +to stack-saved program counters. +.It Dv PT_GETXSTATE_INFO Pq amd64 only +This request can be used to obtain details about the traced process XSAVE area, +specified in a +.Dq Li "struct ptrace_xstate_info" +defined as follows: +.Bd -literal -offset indent +struct ptrace_xstate_info { + uint64_t xsave_mask; + uint32_t xsave_len; +}; +.Ed +.Pp +The +.Fa xsave_mask +field denotes the enabled XSAVE components. +The +.Fa xsave_len +field denotes the size of XSAVE area intended to be used with the +.Dv PT_GETXSTATE +and +.Dv PT_SETXSTATE +requests. +.Pp +A pointer to +.Dq Li "struct ptrace_xstate_info" +must be passed in +.Fa addr +and the +.Fa data +argument must be set to +.Li sizeof(struct ptrace_xstate_info) . +.It Dv PT_GETXSTATE Pq amd64 only +This request can be used to read the XSAVE area of the traced process. +A pointer to a buffer must be passed in +.Fa addr +with a capacity of the length obtained using the +.Dv PT_GETXSTATE_INFO +request. +The +.Fa data +argument must reflect the same length. +.It Dv PT_SETXSTATE Pq amd64 only +This request can be used to write the XSAVE area of the traced process. +Only changes to the x87, SSE and AVX state components are honored. +A pointer to a buffer must be passed in +.Fa addr +with a capacity of the length obtained using the +.Dv PT_GETXSTATE_INFO +request. +The +.Fa data +argument must reflect the same length. +.El +.Sh ERRORS +Some requests can cause +.Fn ptrace +to return +.Li -1 +as a non-error value; to disambiguate, +.Va errno +is set to zero and this should be checked. +The possible errors are: +.Bl -tag -width 4n +.It Bq Er ESRCH +No process having the specified process ID exists. +.It Bq Er EINVAL +.Bl -bullet -compact +.It +A process attempted to use +.Dv PT_ATTACH +on itself. +.It +The +.Fa request +was not one of the legal requests. +.\" .It +.\" The +.\" .Fa addr +.\" to +.\" .Dv PT_READ_U +.\" or +.\" .Dv PT_WRITE_U +.\" was not +.\" .Li int Ns \&-aligned. +.It +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 , +.Dv PT_SETREGS , +.Dv PT_GETFPREGS , +or +.Dv PT_SETFPREGS +was attempted on a process with no valid register set. +(This is normally true only of system processes.) +.El +.It Bq Er EBUSY +.Bl -bullet -compact +.It +.Dv PT_ATTACH +was attempted on a process that was already being traced. +.It +A request attempted to manipulate a process that was being traced by +some process other than the one making the request. +.It +A request (other than +.Dv PT_ATTACH ) +specified a process that wasn't stopped and waited for. +.El +.It Bq Er EPERM +.Bl -bullet -compact +.It +A request (other than +.Dv PT_ATTACH ) +attempted to manipulate a process that wasn't being traced at all. +.It +An attempt was made to use +.Dv PT_ATTACH +on a process in violation of the requirements listed under +.Dv PT_ATTACH +above. +.It +An attempt was made to use +.Dv PT_ATTACH +on a system process. +.El +.It Bq Er ENOTSUP +.Dv PT_GETXSTATE_INFO , +.Dv PT_GETXSTATE , +or +.Dv PT_SETXSTATE +was attempted on a CPU lacking support for XSAVE. +.El +.Sh HISTORY +The +.Fn ptrace +system call first appeared in +.At v6 . +.Sh BUGS +On several RISC architectures (such as luna88k and sparc64), +the PC is set to the provided PC value for +.Dv PT_CONTINUE +and similar calls, and the remainder of the execution pipeline registers +are set to the following instructions, even if the instruction at PC +is a branch instruction. +Using +.Dv PT_GETREGS +and +.Dv PT_SETREGS +to modify the PC, passing +.Li (caddr_t)1 +to +.Fn ptrace , +should be able to sidestep this. +.\" .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 . diff --git a/static/openbsd/man2/quotactl.2 b/static/openbsd/man2/quotactl.2 new file mode 100644 index 00000000..e5ddf698 --- /dev/null +++ b/static/openbsd/man2/quotactl.2 @@ -0,0 +1,212 @@ +.\" $OpenBSD: quotactl.2,v 1.16 2022/09/11 06:38:11 jmc Exp $ +.\" $NetBSD: quotactl.2,v 1.8 1995/02/27 12:35:43 cgd Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/4/93 +.\" +.Dd $Mdocdate: September 11 2022 $ +.Dt QUOTACTL 2 +.Os +.Sh NAME +.Nm quotactl +.Nd manipulate filesystem quotas +.Sh SYNOPSIS +.In ufs/ufs/quota.h +.In unistd.h +.Ft int +.Fn quotactl "const char *path" "int cmd" "int id" "char *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 . +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 ffs +filesystem. +For +.Dq ffs , +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 +and group identifiers. +The +.Dq ffs +specific commands are: +.Bl -tag -width Q_QUOTAON +.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 superuser 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 superuser 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 +.Vt struct dqblk +structure. +.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 +.Vt struct dqblk +structure. +The usage fields of +.Vt struct dqblk +structure are ignored. +This call is restricted to the superuser. +.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 +.Vt struct dqblk +structure. +Only the usage fields are used. +This call is restricted to the superuser. +.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 +.Rv -std +.Sh ERRORS +A +.Fn quotactl +call will fail if: +.Bl -tag -width Er +.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 a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 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 superuser. +.El +.Sh SEE ALSO +.Xr quota 1 , +.Xr fstab 5 , +.Xr edquota 8 , +.Xr quotacheck 8 , +.Xr quotaon 8 , +.Xr repquota 8 +.Sh HISTORY +The +.Fn quotactl +function call appeared in +.Bx 4.3 Reno . +.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 . diff --git a/static/openbsd/man2/read.2 b/static/openbsd/man2/read.2 new file mode 100644 index 00000000..c60f84ab --- /dev/null +++ b/static/openbsd/man2/read.2 @@ -0,0 +1,282 @@ +.\" $OpenBSD: read.2,v 1.38 2021/11/21 23:44:55 jan Exp $ +.\" $NetBSD: read.2,v 1.6 1995/02/27 12:35:47 cgd 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. 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 +.\" +.Dd $Mdocdate: November 21 2021 $ +.Dt READ 2 +.Os +.Sh NAME +.Nm read , +.Nm readv , +.Nm pread , +.Nm preadv +.Nd read input +.Sh SYNOPSIS +.In unistd.h +.Ft ssize_t +.Fn read "int d" "void *buf" "size_t nbytes" +.Ft ssize_t +.Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset" +.Pp +.In sys/uio.h +.Ft ssize_t +.Fn readv "int d" "const struct iovec *iov" "int iovcnt" +.In sys/types.h +.In sys/uio.h +.Ft ssize_t +.Fn preadv "int d" "const struct iovec *iov" "int iovcnt" "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 +and +.Fn preadv +perform the same functions, but read from the specified position +.Fa offset +in the file without modifying the file pointer. +.Pp +For +.Fn readv +and +.Fn preadv , +the +.Fa iovec +structure is defined as: +.Bd -literal -offset indent +struct iovec { + void *iov_base; + size_t iov_len; +}; +.Ed +.Pp +Each +.Fa iovec +entry specifies the base address and length of an area +in memory where data should be placed. +.Fn readv +and +.Fn preadv +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 , +.Fn pread , +and +.Fn preadv +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 +Note that +.Fn readv +and +.Fn preadv +will fail if the value of +.Fa iovcnt +exceeds the constant +.Dv IOV_MAX . +.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 , +.Fn pread , +and +.Fn preadv +will fail if: +.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 +Part of +.Fa buf +points outside the process's allocated address space. +.It Bq Er EINTR +A read from a slow device +(i.e. one that might block for an arbitrary amount of time) +was interrupted by the delivery of a signal +before any data arrived. +.It Bq Er EIO +An I/O error occurred while reading from the file system. +.It Bq Er EISDIR +The underlying file is a directory. +.El +.Pp +In addition, +.Fn read +and +.Fn readv +may return the following errors: +.Bl -tag -width Er +.It Bq Er EAGAIN +The file was marked for non-blocking I/O, +and no data were ready to be read. +.It Bq Er ENOTCONN +The file is a socket associated with a connection-oriented protocol +and has not been connected. +.It Bq Er EIO +The process is a member of a background process attempting to read +from its controlling terminal, the process is ignoring or blocking +the +.Dv SIGTTIN +signal or the process group is orphaned. +.El +.Pp +.Fn read +and +.Fn pread +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa nbytes +was larger than +.Dv SSIZE_MAX . +.El +.Pp +.Fn pread +and +.Fn preadv +may return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa offset +was negative. +.It Bq Er ESPIPE +.Fa d +is associated with a pipe, socket, FIFO, or tty. +.El +.Pp +.Fn readv +and +.Fn preadv +may return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa iovcnt +was less than or equal to 0, or greater than +.Dv IOV_MAX . +.It Bq Er EINVAL +The sum of the +.Fa iov_len +values in the +.Fa iov +array overflowed an +.Vt ssize_t . +.It Bq Er EFAULT +Part of +.Fa iov +points outside the process's allocated address space. +.El +.Sh SEE ALSO +.Xr dup 2 , +.Xr fcntl 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr socket 2 , +.Xr socketpair 2 +.Sh STANDARDS +The +.Fn read , +.Fn readv , +and +.Fn pread +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +A +.Fn read +system call first appeared in +.At v1 ; +.Fn readv +in +.Bx 4.1c ; +.Fn pread +in +.At V.4 ; +and +.Fn preadv +in +.Ox 2.7 . +.Sh CAVEATS +Error checks should explicitly test for \-1. +Code such as +.Bd -literal -offset indent +while ((nr = read(fd, buf, sizeof(buf))) > 0) +.Ed +.Pp +is not maximally portable, as some platforms allow for +.Fa nbytes +to range between +.Dv SSIZE_MAX +and +.Dv SIZE_MAX +\- 2, in which case the return value of an error-free +.Fn read +may appear as a negative number distinct from \-1. +Proper loops should use +.Bd -literal -offset indent +while ((nr = read(fd, buf, sizeof(buf))) != -1 && nr != 0) +.Ed diff --git a/static/openbsd/man2/readlink.2 b/static/openbsd/man2/readlink.2 new file mode 100644 index 00000000..8b64a734 --- /dev/null +++ b/static/openbsd/man2/readlink.2 @@ -0,0 +1,169 @@ +.\" $OpenBSD: readlink.2,v 1.19 2015/05/31 23:54:25 schwarze Exp $ +.\" $NetBSD: readlink.2,v 1.7 1995/02/27 12:35:54 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 31 2015 $ +.Dt READLINK 2 +.Os +.Sh NAME +.Nm readlink , +.Nm readlinkat +.Nd read value of a symbolic link +.Sh SYNOPSIS +.In unistd.h +.Ft ssize_t +.Fn readlink "const char *restrict path" "char *restrict buf" "size_t bufsiz" +.In fcntl.h +.In unistd.h +.Ft ssize_t +.Fn readlinkat "int fd" "const char *path" "char *buf" "size_t bufsiz" +.Sh DESCRIPTION +The +.Fn readlink +function places the contents of the symbolic link +.Fa path +in the buffer +.Fa buf , +which has size +.Fa bufsiz . +.Fn readlink +does not append a +.Dv NUL +character to +.Fa buf . +.Pp +The +.Fn readlinkat +function is equivalent to +.Fn readlink +except that where +.Fa path +specifies a relative path, +the symbolic link whose contents are read is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn readlinkat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn readlink . +.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 +and +.Fn readlinkat +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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 +or +.Fa path +extends outside the process's allocated address space. +.El +.Pp +Additionally, +.Fn readlinkat +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr lstat 2 , +.Xr stat 2 , +.Xr symlink 2 , +.Xr symlink 7 +.Sh STANDARDS +The +.Fn readlink +and +.Fn readlinkat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn readlink +system call first appeared in +.Bx 4.1c . +The +.Fn readlinkat +system call has been available since +.Ox 5.0 . diff --git a/static/openbsd/man2/reboot.2 b/static/openbsd/man2/reboot.2 new file mode 100644 index 00000000..ebc13dd5 --- /dev/null +++ b/static/openbsd/man2/reboot.2 @@ -0,0 +1,163 @@ +.\" $OpenBSD: reboot.2,v 1.19 2017/04/15 18:55:27 guenther Exp $ +.\" $NetBSD: reboot.2,v 1.5 1995/02/27 12:36:02 cgd 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. 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 +.\" +.Dd $Mdocdate: April 15 2017 $ +.Dt REBOOT 2 +.Os +.Sh NAME +.Nm reboot +.Nd reboot system or halt processor +.Sh SYNOPSIS +.In unistd.h +.In sys/reboot.h +.Ft int +.Fn reboot "int howto" +.Sh DESCRIPTION +.Fn reboot +reboots the system. +Only the superuser 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 +.In 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 (0,0)bsd , +where +.Em xx +is the default disk name, +without prompting for the file name. +.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. +.It Dv RB_POWERDOWN +If used in conjunction with +.Dv RB_HALT , +and if the system hardware supports the function, the system will be +powered off. +.It Dv RB_USERREQ +By default, the system will halt if +.Fn reboot +is called during startup (before the system has finished autoconfiguration), +even if +.Dv RB_HALT +is not specified. +This is because +.Xr panic 9 Ns s +during startup will probably just repeat on the next boot. +Use of this option implies that the user has requested the action +specified (for example, using the +.Xr ddb 4 +.Ic boot reboot +command), +so the system will reboot if a halt is not explicitly requested. +.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 ddb 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_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. +.Pp +When no options are given (i.e., +.Dv RB_AUTOBOOT +is used), the system is +rebooted from file +.Pa /bsd +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 ) . +.It Dv RB_TIMEBAD +Don't update the hardware clock from the system clock, +presumably because the system clock is suspect. +.El +.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 superuser. +.El +.Sh SEE ALSO +.Xr ddb 4 , +.Xr crash 8 , +.Xr halt 8 , +.Xr init 8 , +.Xr reboot 8 , +.Xr savecore 8 , +.Xr boot 9 , +.Xr panic 9 +.Sh HISTORY +The +.Fn reboot +system call finally appeared in +.Bx 4.0 . +.Sh BUGS +Not all platforms support all possible arguments. diff --git a/static/openbsd/man2/recv.2 b/static/openbsd/man2/recv.2 new file mode 100644 index 00000000..0f3d2367 --- /dev/null +++ b/static/openbsd/man2/recv.2 @@ -0,0 +1,448 @@ +.\" $OpenBSD: recv.2,v 1.53 2026/03/11 14:42:43 deraadt Exp $ +.\" $NetBSD: recv.2,v 1.6 1995/02/27 12:36:08 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: March 11 2026 $ +.Dt RECV 2 +.Os +.Sh NAME +.Nm recv , +.Nm recvfrom , +.Nm recvmsg , +.Nm recvmmsg +.Nd receive a message from a socket +.Sh SYNOPSIS +.In 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" +.Ft int +.Fn recvmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "int flags" "struct timespec *timeout" +.Sh DESCRIPTION +.Fn recv , +.Fn recvfrom , +.Fn recvmsg , +and +.Fn recvmmsg +are used to receive messages from a socket, +.Fa s . +.Fn recv +is normally used only on a +.Em connected +socket (see +.Xr connect 2 ) . +.Fn recvfrom , +.Fn recvmsg , +and +.Fn recvmmsg +may be used to receive +data on a socket whether or not it is connection-oriented. +.Pp +.Fn recv +is identical to +.Fn recvfrom +with a null +.Fa from +parameter. +.Pp +If +.Fa from +is non-null 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 +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 +or +.Xr poll 2 +system calls may be used to determine when more data arrive. +.Pp +The +.Fa flags +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width "MSG_CMSG_CLOEXECXX" -offset indent -compact +.It Dv MSG_OOB +process out-of-band data +.It Dv MSG_PEEK +peek at incoming message +.It Dv MSG_WAITALL +wait for full request or error +.It Dv MSG_DONTWAIT +don't block +.It Dv MSG_CMSG_CLOEXEC +set the close-on-exec flag on received file descriptors +.It Dv MSG_CMSG_CLOFORK +set the close-on-fork flag on received file descriptors +.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 +.Dv 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 +.Dv 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. +The +.Dv MSG_DONTWAIT +flag requests the call to return when it would block otherwise. +If no data is available, +.Va errno +is set to +.Er EAGAIN . +This flag is not available in strict ANSI or C99 compilation mode. +The +.Dv MSG_CMSG_CLOEXEC +and +.Dv MSG_CMSG_CLOFORK +flags request that any file descriptors received as ancillary data with +.Fn recvmsg +and +.Fn recvmmsg +(see below) +have their close-on-exec flag or close-on-fork flag, respectively, set. +.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 +.In sys/socket.h : +.Bd -literal +struct msghdr { + void *msg_name; /* optional address */ + socklen_t msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + unsigned int msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* ancillary data, see below */ + socklen_t 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 source 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 { + socklen_t cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by u_char cmsg_data[]; */ +}; +.Ed +.Pp +See +.Xr CMSG_DATA 3 +for how these messages are constructed and decomposed. +.Pp +Open file descriptors are now passed as ancillary data for +.Dv AF_UNIX +domain and +.Xr socketpair 2 +sockets, with +.Fa cmsg_level +set to +.Dv SOL_SOCKET +and +.Fa cmsg_type +set to +.Dv SCM_RIGHTS . +.Pp +The +.Fa msg_flags +field is set on return according to the message received. +It will contain zero or more of the following values: +.Pp +.Bl -tag -width MSG_CTRUNC -offset indent -compact +.It Dv MSG_OOB +Returned to indicate that expedited or out-of-band data was received. +.It Dv MSG_EOR +Indicates end-of-record; +the data returned completed a record (generally used with sockets of type +.Dv SOCK_SEQPACKET ) . +.It Dv MSG_TRUNC +Indicates that +the trailing portion of a datagram was discarded because the datagram +was larger than the buffer supplied. +.It Dv MSG_CTRUNC +Indicates that some +control data were discarded due to lack of space in the buffer +for ancillary data. +.It Dv MSG_BCAST +Indicates that the packet was received as broadcast. +.It Dv MSG_MCAST +Indicates that the packet was received as multicast. +.El +.Pp +The +.Fn recvmmsg +call uses an array of the +.Fa mmsghdr +structure of length +.Fa vlen +to group multiple +.Fa msghdr +structures into a single system call. +.Fa vlen +is capped at maximum +.Dv 1024 +messages that are received in a single call. +The +.Fa flags +field allows setting +.Dv MSG_WAITFORONE +to wait for one +.Fa msghdr , +and set +.Dv MSG_DONTWAIT +for all subsequent messages. +A provided +.Fa timeout +limits the time spent in the function but it does not limit the +time spent in lower parts of the kernel. +.Pp +The +.Fa mmsghdr +structure has the following form, as defined in +.In sys/socket.h : +.Bd -literal +struct mmsghdr { + struct msghdr msg_hdr; + unsigned int msg_len; +}; +.Ed +.Pp +Here +.Fa msg_len +indicated the number of bytes received for each +.Fa msg_hdr +member. +.Sh RETURN VALUES +The +.Fn recv , +.Fn recvfrom , +and +.Fn recvmsg +calls return the number of bytes received, or \-1 if an error occurred. +The +.Fn recvmmsg +call returns the number of messages received, or \-1 +if an error occurred before the first message has been received. +.Sh ERRORS +.Fn recv , +.Fn recvfrom , +.Fn recvmsg , +and +.Fn recvmmsg +fail if: +.Bl -tag -width "[EHOSTUNREACH]" +.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. +.It Bq Er EHOSTUNREACH +A socket operation was attempted to an unreachable host. +.It Bq Er EHOSTDOWN +A socket operation failed +because the destination host was down. +.It Bq Er ENETDOWN +A socket operation encountered a dead network. +.It Bq Er ECONNREFUSED +The socket is associated with a connection-oriented protocol +and the connection was forcefully rejected (see +.Xr connect 2 ) . +.El +.Pp +In addition, +.Fn recv +and +.Fn recvfrom +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa len +was larger than +.Dv SSIZE_MAX . +.El +.Pp +And +.Fn recvmsg +and +.Fn recvmmsg +may return one of the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The sum of the +.Fa iov_len +values in the +.Fa msg_iov +array overflowed an +.Em ssize_t . +.It Bq Er EPERM +An unacceptable file descriptor type is received in ancillary data. +.It Bq Er EMSGSIZE +The +.Fa msg_iovlen +member of +.Fa msg +was less than 0 or larger than +.Dv IOV_MAX . +.It Bq Er EMSGSIZE +The receiving program did not have sufficient +free file descriptor slots. +The descriptors are closed +and any pending data can be returned +by another call to +.Fn recvmsg . +.El +.Sh SEE ALSO +.Xr connect 2 , +.Xr fcntl 2 , +.Xr getsockopt 2 , +.Xr poll 2 , +.Xr read 2 , +.Xr select 2 , +.Xr socket 2 , +.Xr socketpair 2 , +.Xr CMSG_DATA 3 , +.Xr sockatmark 3 +.Sh STANDARDS +The +.Fn recv , +.Fn recvfrom , +and +.Fn recvmsg +functions conform to +.St -p1003.1-2024 . +The +.Dv MSG_DONTWAIT , +.Dv MSG_BCAST , +and +.Dv MSG_MCAST +flags are extensions to that specification. +.Sh HISTORY +The +.Fn recv +function call appeared in +.Bx 4.1c . +The +.Fn recvmmsg +syscall first appeared in Linux 2.6.33 and was added to +.Ox 7.2 . +.Sh CAVEATS +Calling +.Fn recvmsg +with a control message having no or an empty scatter/gather array +exposes variations in implementations. +To avoid these, always use an +.Fa iovec +with at least a one-byte buffer and set +.Fa msg_iov +and an +.Fa msg_iovlen +to use this vector. diff --git a/static/openbsd/man2/rename.2 b/static/openbsd/man2/rename.2 new file mode 100644 index 00000000..4a27805b --- /dev/null +++ b/static/openbsd/man2/rename.2 @@ -0,0 +1,296 @@ +.\" $OpenBSD: rename.2,v 1.22 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: rename.2,v 1.7 1995/02/27 12:36:15 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt RENAME 2 +.Os +.Sh NAME +.Nm rename , +.Nm renameat +.Nd change the name of a file +.Sh SYNOPSIS +.In stdio.h +.Ft int +.Fn rename "const char *from" "const char *to" +.In fcntl.h +.In stdio.h +.Ft int +.Fn renameat "int fromfd" "const char *from" "int tofd" "const char *to" +.Sh DESCRIPTION +The +.Fn rename +function 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 if +.Fa to +already exists, 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. +.Pp +The +.Fn renameat +function is equivalent to +.Fn rename +except that where +.Fa from +or +.Fa to +specifies a relative path, +the directory entry names used are resolved relative to +the directories associated with file descriptors +.Fa fromfd +or +.Fa tofd +(respectively) instead of the current working directory. +.Pp +If +.Fn renameat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fromfd +or +.Fa tofd +parameter, the current working directory is used for resolving the respective +.Fa from +or +.Fa to +argument. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn rename +and +.Fn renameat +will fail and neither of the argument files will be +affected if: +.Bl -tag -width Er +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 change requires writing in a directory that denies write +permission. +.It Bq Er EACCES +The +.Fa from +argument is a directory and 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 EMLINK +The link count on the source file or destination directory is at the maximum. +A rename cannot be completed under these conditions. +.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 +.Fa from +or +.Fa to +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 +.Pp +Additionally, +.Fn renameat +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa from +or +.Fa to +argument specifies a relative path and the +.Fa fromfd +or +.Fa tofd +argument, respectively, is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa from +or +.Fa to +argument specifies a relative path and the +.Fa fromfd +or +.Fa tofd +argument, respectively, +is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa from +or +.Fa to +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fromfd +or +.Fa tofd +file descriptor, respectively, references. +.El +.Sh SEE ALSO +.Xr mv 1 , +.Xr open 2 , +.Xr symlink 7 +.Sh STANDARDS +The +.Fn rename +and +.Fn renameat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn renameat +function appeared in +.Ox 5.0 . +.Sh CAVEATS +The system can deadlock if a loop in the file system graph is present. +This loop takes the form of an entry in directory +.Sq Pa a , +say +.Sq Pa a/foo , +being a hard link to directory +.Sq Pa b , +and an entry in +directory +.Sq Pa b , +say +.Sq Pa b/bar , +being a hard link +to directory +.Sq 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. diff --git a/static/openbsd/man2/revoke.2 b/static/openbsd/man2/revoke.2 new file mode 100644 index 00000000..8fcaf75e --- /dev/null +++ b/static/openbsd/man2/revoke.2 @@ -0,0 +1,108 @@ +.\" $OpenBSD: revoke.2,v 1.16 2021/06/30 18:46:49 schwarze Exp $ +.\" $NetBSD: revoke.2,v 1.3 1995/10/12 15:41:11 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: June 30 2021 $ +.Dt REVOKE 2 +.Os +.Sh NAME +.Nm revoke +.Nd revoke file access +.Sh SYNOPSIS +.In 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 tty device named by +.Fa path . +Subsequent operations on any such descriptors +fail, with the exceptions that a +.Fn read +from a tty 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 superuser. +The +.Fn revoke +function is used to prepare a terminal device for a new login session, +preventing any access by a previous user of the terminal. +The +.Xr pty 4 +subsystem has this as an implicit operation, but hardwired +.Xr tty 4 +require the operation. +.Sh RETURN VALUES +.Rv -std +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.It Bq Er ENOENT +The named file or a component of the pathname does not exist. +.It Bq Er ENOTTY +.Fa path +is not associated with a tty special device. +.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 EPERM +The caller is neither the owner of the file nor the superuser. +.El +.Sh SEE ALSO +.Xr close 2 +.Sh HISTORY +The +.Fn revoke +function was introduced in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/rmdir.2 b/static/openbsd/man2/rmdir.2 new file mode 100644 index 00000000..355b3314 --- /dev/null +++ b/static/openbsd/man2/rmdir.2 @@ -0,0 +1,129 @@ +.\" $OpenBSD: rmdir.2,v 1.16 2022/02/18 00:15:53 jsg Exp $ +.\" $NetBSD: rmdir.2,v 1.7 1995/02/27 12:36:30 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: February 18 2022 $ +.Dt RMDIR 2 +.Os +.Sh NAME +.Nm rmdir +.Nd remove a directory file +.Sh SYNOPSIS +.In 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 \&.. . +.Pp +There is no +.Fn rmdirat +function; +to remove a directory with a path relative to the directory associated +with a file descriptor use the +.Xr unlinkat 2 +function with the +.Dv AT_REMOVEDIR +flag. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The named file is removed unless: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 directory +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 EPERM +The directory to be removed or the directory containing it has its +immutable or append-only flag set (see +.Xr chflags 2 ) . +.It Bq Er EBUSY +The directory to be removed is the mount point +for a mounted file system. +.It Bq Er EINVAL +The last path element of the directory to be removed consists of +.Ql \&. . +.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 rmdir 1 , +.Xr chflags 2 , +.Xr mkdir 2 , +.Xr unlink 2 +.Sh STANDARDS +The +.Fn rmdir +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn rmdir +function call appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/sched_yield.2 b/static/openbsd/man2/sched_yield.2 new file mode 100644 index 00000000..ca7c6df7 --- /dev/null +++ b/static/openbsd/man2/sched_yield.2 @@ -0,0 +1,49 @@ +.\" $OpenBSD: sched_yield.2,v 1.1 2014/11/14 00:24:28 guenther Exp $ +.\" +.\" Copyright (c) 2014 Philip Guenther <guenther@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: November 14 2014 $ +.Dt SCHED_YIELD 2 +.Os +.Sh NAME +.Nm sched_yield +.Nd yield the processor +.Sh SYNOPSIS +.In sched.h +.Ft int +.Fn sched_yield void +.Sh DESCRIPTION +The +.Fn sched_yield +function makes the current thread yield the processor and be put at +the end of its run queue without altering its priority. +.Sh RETURN VALUES +.Rv -std +.Sh STANDARDS +The +.Fn sched_yield +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn sched_yield +system call appeared in +.Ox 4.2 . +.Sh CAVEATS +The effect of +.Fn sched_yield +is only precisely defined for real-time scheduling classes, +none of which are currently supported by +.Ox . diff --git a/static/openbsd/man2/select.2 b/static/openbsd/man2/select.2 new file mode 100644 index 00000000..3dc9d35a --- /dev/null +++ b/static/openbsd/man2/select.2 @@ -0,0 +1,248 @@ +.\" $OpenBSD: select.2,v 1.45 2022/01/21 16:18:16 deraadt Exp $ +.\" $NetBSD: select.2,v 1.5 1995/06/27 22:32:28 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: January 21 2022 $ +.Dt SELECT 2 +.Os +.Sh NAME +.Nm select , +.Nm pselect , +.Nm FD_SET , +.Nm FD_CLR , +.Nm FD_ISSET , +.Nm FD_ZERO +.Nd synchronous I/O multiplexing +.Sh SYNOPSIS +.In sys/select.h +.Ft int +.Fn select "int nfds" "fd_set *readfds" "fd_set *writefds" "fd_set *exceptfds" "struct timeval *timeout" +.Ft int +.Fn pselect "int nfds" "fd_set *readfds" "fd_set *writefds" "fd_set *exceptfds" "const struct timespec *timeout" "const sigset_t *mask" +.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. +Exceptional conditions include the presence of out-of-band data +on a socket. +The first +.Fa nfds +descriptors are checked in each set; +i.e., the descriptors from 0 through +.Fa nfds Ns -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-null pointer, it specifies a maximum interval to wait for the +selection to complete. +If +.Fa timeout +is a null pointer, the select blocks indefinitely. +To effect a poll, the +.Fa timeout +argument should be non-null, pointing to a zero-valued timeval structure. +.Fa timeout +is not changed by +.Fn select , +and may be reused on subsequent calls; however, it is good style to +re-initialize it before each invocation of +.Fn select . +.Pp +Any of +.Fa readfds , +.Fa writefds , +and +.Fa exceptfds +may be given as null pointers if no descriptors are of interest. +.Pp +The +.Fn pselect +function is similar to +.Fn select +except that it specifies the timeout using a timespec structure. +Also, if +.Fa mask +is a non-null pointer, +.Fn pselect +atomically sets the calling thread's signal mask to the signal set +pointed to by +.Fa mask +for the duration of the function call. +In this case, the original signal mask will be restored before +.Fn pselect +returns. +.Sh RETURN VALUES +If successful, +.Fn select +and +.Fn pselect +return the number of ready descriptors that are contained in +the descriptor sets. +If a descriptor is included in multiple descriptor sets, +each inclusion is counted separately. +If the time limit expires before any descriptors become ready, +they return 0. +.Pp +Otherwise, if +.Fn select +or +.Fn pselect +return with an error, including one due to an interrupted call, +they return \-1, +and the descriptor sets will be unmodified. +.Sh ERRORS +An error return from +.Fn select +or +.Fn pselect +indicates: +.Bl -tag -width Er +.It Bq Er EFAULT +One or more of +.Fa readfds , +.Fa writefds , +or +.Fa exceptfds +points outside the process's allocated address space. +.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 descriptors became ready. +.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 less than 0. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr clock_gettime 2 , +.Xr connect 2 , +.Xr gettimeofday 2 , +.Xr poll 2 , +.Xr read 2 , +.Xr recv 2 , +.Xr send 2 , +.Xr write 2 , +.Xr getdtablesize 3 +.Sh STANDARDS +The +.Fn select +and +.Fn pselect +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn select +system call first appeared in +.Bx 4.1c . +The +.Fn pselect +system call has been available since +.Ox 5.4 . +.Sh BUGS +Although the provision of +.Xr getdtablesize 3 +was intended to allow user programs to be written independent +of the kernel limit on the number of open files, the dimension +of a sufficiently large bit field for select remains a problem. +If descriptor values greater than FD_SETSIZE are possible in +a program, use +.Xr poll 2 +instead. +.Pp +.Fn select +should probably have been designed to return the time remaining from the +original timeout, if any, by modifying the time value in place. +Even though some systems stupidly act in this different way, it is +unlikely this semantic will ever be commonly implemented, as the +change causes massive source code compatibility problems. +Furthermore, recent new standards have dictated the current behaviour. +In general, due to the existence of those brain-damaged +non-conforming systems, it is unwise to assume that the timeout +value will be unmodified by the +.Fn select +call, and the caller should reinitialize it on each invocation. +Calculating the delta is easily done by calling +.Xr gettimeofday 2 +before and after the call to +.Fn select , +and using +.Xr timersub 3 . diff --git a/static/openbsd/man2/semctl.2 b/static/openbsd/man2/semctl.2 new file mode 100644 index 00000000..63121717 --- /dev/null +++ b/static/openbsd/man2/semctl.2 @@ -0,0 +1,242 @@ +.\" $OpenBSD: semctl.2,v 1.18 2021/11/21 23:44:55 jan Exp $ +.\" $NetBSD: semctl.2,v 1.2 1997/03/27 08:20:40 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: November 21 2021 $ +.Dt SEMCTL 2 +.Os +.Sh NAME +.Nm semctl +.Nd semaphore control operations +.Sh SYNOPSIS +.In sys/sem.h +.Ft int +.Fn semctl "int semid" "int semnum" "int cmd" "union semun arg" +.Sh DESCRIPTION +The +.Fn semctl +system call provides a number of control operations on the semaphore specified +by +.Fa semnum +and +.Fa semid . +The operation to be performed is specified in +.Fa cmd +(see below). +.Fa arg +is a union of the following fields: +.Bd -literal + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_{STAT,SET} */ + u_short *array; /* array for GETALL & SETALL */ +.Ed +.Pp +The +.Bf -literal +semid_ds +.Ef +structure used in the +.Dv IPC_SET +and +.Dv IPC_STAT +commands is defined as follows in +.In sys/sem.h : +.Bd -literal +struct semid_ds { + struct ipc_perm sem_perm; /* operation permissions */ + struct sem *sem_base; /* semaphore set */ + u_short sem_nsems; /* number of sems in set */ + time_t sem_otime; /* last operation time */ + time_t sem_ctime; /* last change time */ +}; +.Ed +.Pp +The +.Bf -literal +ipc_perm +.Ef +structure used inside the +.Bf -literal +semid_ds +.Ef +structure is defined in +.In sys/ipc.h +and looks like this: +.Bd -literal +struct ipc_perm { + uid_t cuid; /* creator user id */ + gid_t cgid; /* creator group id */ + uid_t uid; /* user id */ + gid_t gid; /* group id */ + mode_t mode; /* r/w permission (see chmod(2)) */ + u_short seq; /* sequence # */ + /* (to generate unique msg/sem/shm id) */ + key_t key; /* user specified msg/sem/shm key */ +}; +.Ed +.Pp +.Fn semctl +provides the following operations: +.Bl -tag -width IPC_RMIDX +.It Dv GETVAL +Return the value of the semaphore. +.It Dv SETVAL +Set the value of the semaphore to +.Va arg.val . +.It Dv GETPID +Return the pid of the last process that did an operation on this semaphore. +.It Dv GETNCNT +Return the number of processes waiting to acquire the semaphore. +.It Dv GETZCNT +Return the number of processes waiting for the value of the semaphore to +reach 0. +.It Dv GETALL +Return the values for all the semaphores associated with +.Fa semid . +.It Dv SETALL +Set the values for all the semaphores that are associated with the semaphore +identifier +.Fa semid +to the corresponding values in +.Va arg.array . +.It Dv IPC_STAT +Gather statistics about a semaphore and place the information in the +.Bf -literal +semid_ds +.Ef +structure pointed to by +.Fa arg.buf +(see above). +.It Dv IPC_SET +Set the value of the +.Va sem_perm.uid , +.Va sem_perm.gid +and +.Va sem_perm.mode +fields in the structure associated with the semaphore. +The values are taken from the corresponding fields in the structure +pointed to by +.Fa arg.buf . +This operation can only be executed by the superuser, or a process that +has an effective user ID equal to either +.Va sem_perm.cuid +or +.Va sem_perm.uid +in the data structure associated with the message queue. +.It Dv IPC_RMID +Remove the semaphores associated with +.Fa semid +from the system and destroy the data structures associated with it. +Only the superuser or a process with an effective UID equal to the +.Va sem_perm.cuid +or +.Va sem_perm.uid +values in the data structure associated with the semaphore can do this. +.El +.Pp +The permission to read or change a message queue (see +.Xr semop 2 ) +is determined by the +.Va sem_perm.mode +field in the same way as is +done with files (see +.Xr chmod 2 ) , +but the effective UID can match either the +.Va sem_perm.cuid +field or the +.Va sem_perm.uid +field, and the +effective GID can match either +.Va sem_perm.cgid +or +.Va sem_perm.gid . +.Sh RETURN VALUES +For the +.Dv GETVAL , +.Dv GETPID , +.Dv GETNCNT , +and +.Dv GETZCNT +operations, +.Fn semctl +returns one of the values described above if successful. +All other operations will make +.Fn semctl +return 0 if no errors occur. +Otherwise \-1 is returned and +.Va errno +set to reflect the error. +.Sh ERRORS +.Fn semctl +will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +.Fa cmd +is equal to +.Dv IPC_SET +or +.Dv IPC_RMID +and the caller is not the superuser, nor does +the effective UID match either the +.Va sem_perm.uid +or +.Va sem_perm.cuid +fields of the data structure associated with the message queue. +.It Bq Er EACCES +The caller has no operation permission for this semaphore. +.It Bq Er EINVAL +.Fa semid +is not a valid message semaphore identifier. +.Pp +.Va cmd +is not a valid command. +.It Bq Er EFAULT +.Fa arg.buf +or +.Fa arg.array +specify an invalid address. +.It Bq Er ERANGE +.Fa cmd +is equal to +.Dv SETVAL +or +.Dv SETALL +and +.Va arg.val +or the values in +.Va arg.array +are greater than the system-imposed limit. +.El +.Sh SEE ALSO +.Xr ipcrm 1 , +.Xr ipcs 1 , +.Xr semget 2 , +.Xr semop 2 diff --git a/static/openbsd/man2/semget.2 b/static/openbsd/man2/semget.2 new file mode 100644 index 00000000..44dc62f4 --- /dev/null +++ b/static/openbsd/man2/semget.2 @@ -0,0 +1,154 @@ +.\" $OpenBSD: semget.2,v 1.20 2021/10/23 21:17:45 jmc Exp $ +.\" $NetBSD: semget.2,v 1.2 1997/03/27 08:20:41 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: October 23 2021 $ +.Dt SEMGET 2 +.Os +.Sh NAME +.Nm semget +.Nd get semaphore set +.Sh SYNOPSIS +.In sys/sem.h +.Ft int +.Fn semget "key_t key" "int nsems" "int semflg" +.Sh DESCRIPTION +The +.Fn semget +system call returns the semaphore identifier associated with +.Fa key . +.Pp +A new set containing +.Fa nsems +semaphores is created if either +.Fa key +is equal to +.Dv IPC_PRIVATE , +or +.Fa key +does not have a semaphore set associated with it and the +.Dv IPC_CREAT +bit is set in +.Fa semflg . +.Pp +The access modes of the created semaphores is specified in +.Fa semflg +as a bitwise OR of zero or more of the following values: +.Bd -literal -offset indent +SEM_A alter permission for owner +SEM_R read permission for owner + +SEM_A >> 3 alter permission for group +SEM_R >> 3 read permission for group + +SEM_A >> 6 alter permission for other +SEM_R >> 6 read permission for other +.Ed +.Pp +If a new set of semaphores is created, the data structure associated with it +(the +.Va semid_ds +structure, see +.Xr semctl 2 ) +is initialized as follows: +.Bl -bullet +.It +.Va sem_perm.cuid +and +.Va sem_perm.uid +are set to the effective UID of the calling process. +.It +.Va sem_perm.gid +and +.Va sem_perm.cgid +are set to the effective GID of the calling process. +.It +.Va sem_perm.mode +is set to the lower 9 bits of +.Fa semflg . +.It +.Va sem_nsems +is set to the value of +.Fa nsems . +.It +.Va sem_ctime +is set to the current time. +.It +.Va sem_otime +is set to 0. +.El +.Sh RETURN VALUES +.Fn semget +returns a non-negative semaphore identifier if successful. +Otherwise, \-1 is returned and +.Va errno +is set to reflect the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EACCES +The caller has no permission to access a semaphore set already associated with +.Fa key . +.It Bq Er EEXIST +Both +.Dv IPC_CREAT +and +.Dv IPC_EXCL +are set in +.Fa semflg , +and a semaphore set is already associated with +.Fa key . +.It Bq Er EINVAL +.Va nsems +is less than or equal to 0 or greater than the system limit for the +number in a semaphore set. +.Pp +A semaphore set associated with +.Fa key +exists, but has fewer semaphores than the number specified in +.Fa nsems . +.It Bq Er ENOSPC +A new set of semaphores could not be created because the system limit +for the number of semaphores or the number of semaphore sets has been +reached. +.It Bq Er ENOENT +.Dv IPC_CREAT +was not set in +.Fa semflg +and no semaphore set associated with +.Fa key +was found. +.El +.Sh SEE ALSO +.Xr ipcrm 1 , +.Xr ipcs 1 , +.Xr semctl 2 , +.Xr semop 2 , +.Xr ftok 3 diff --git a/static/openbsd/man2/semop.2 b/static/openbsd/man2/semop.2 new file mode 100644 index 00000000..cdbaf26e --- /dev/null +++ b/static/openbsd/man2/semop.2 @@ -0,0 +1,158 @@ +.\" $OpenBSD: semop.2,v 1.20 2021/10/23 21:17:45 jmc Exp $ +.\" $NetBSD: semop.2,v 1.1 1995/10/16 23:49:28 jtc Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: October 23 2021 $ +.Dt SEMOP 2 +.Os +.Sh NAME +.Nm semop +.Nd semaphore operations +.Sh SYNOPSIS +.In sys/sem.h +.Ft int +.Fn semop "int semid" "struct sembuf *sops" "size_t nsops" +.Sh DESCRIPTION +.Fn semop +provides a number of atomic operations on a set of semaphores. +The semaphore set is specified by +.Fa semid . +.Fa sops +is an array of semaphore operations, +.Fa nsops +is the number of operations in this array. +The +.Va sembuf +structures in the array contain the following members: +.Bd -literal + u_short sem_num; /* semaphore # */ + short sem_op; /* semaphore operation */ + short sem_flg; /* operation flags */ +.Ed +.Pp +Each operation (specified in +.Va sem_op ) +is applied to semaphore number +.Va sem_num +in the set of semaphores specified by +.Fa semid . +The value of +.Va sem_op +determines the action taken in the following way: +.Bl -bullet +.It +.Va sem_op +is less than 0. +The current process is blocked until the value of the +semaphore is greater than or equal to the absolute value of +.Va sem_op . +The absolute value of +.Va sem_op +is then subtracted from the value of the semaphore, and the calling +process continues. +Negative values of +.Va sem_op +are thus used to enter critical regions. +.It +.Va sem_op +is greater than 0. +Its value is added to the value of the specified semaphore. +This is used to leave critical regions. +.It +.Va sem_op +is equal to 0. +The calling process is blocked until the value of the specified +semaphore reaches 0. +.El +.Pp +The behavior of each operation is influenced by the flags set in +.Va sem_flg +in the following way: +.Bl -tag -width IPC_NOWAITX +.It Dv IPC_NOWAIT +In the case where the calling process would normally block, waiting +for a semaphore to reach a certain value, +.Dv IPC_NOWAIT +makes the +call return immediately, returning a value of \-1 and setting +.Va errno +to +.Er EAGAIN . +.It Dv SEM_UNDO +Keep track of the changes that this call makes to the value of a semaphore, +so that they can be undone when the calling process terminates. +This is useful to prevent other processes waiting on a semaphore to +block forever, should the process that has the semaphore locked +terminate in a critical section. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn semop +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +There is no semaphore associated with +.Fa semid . +.It Bq Er EIDRM +The semaphore set was removed while the process was waiting for one of +its semaphores to reach a certain value. +.It Bq Er EACCES +The calling process has no permission to access the specified semaphore set. +.It Bq Er E2BIG +The value of +.Fa nsops +is too big. +The maximum is specified in MAX_SOPS in +.In sys/sem.h . +.It Bq Er EFBIG +.Va sem_num +in one of the sem_buf structures is less than 0, or greater than the actual +number of semaphores in the set specified by +.Fa semid . +.It Bq Er ENOSPC +.Dv SEM_UNDO +was requested, and there is not enough space left in the kernel to +store the undo information. +.It Bq Er EAGAIN +The requested operation cannot immediately be performed, and +.Dv IPC_NOWAIT +was set in +.Va sem_flg . +.It Bq Er EFAULT +.Fa sops +points to an illegal address. +.El +.Sh SEE ALSO +.Xr ipcrm 1 , +.Xr ipcs 1 , +.Xr semctl 2 , +.Xr semget 2 diff --git a/static/openbsd/man2/send.2 b/static/openbsd/man2/send.2 new file mode 100644 index 00000000..960df1d1 --- /dev/null +++ b/static/openbsd/man2/send.2 @@ -0,0 +1,289 @@ +.\" $OpenBSD: send.2,v 1.35 2022/09/09 13:52:59 mbuhl Exp $ +.\" $NetBSD: send.2,v 1.6 1996/01/15 01:17:18 thorpej Exp $ +.\" +.\" 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. 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. +.\" +.\" @(#)send.2 8.2 (Berkeley) 2/21/94 +.\" +.Dd $Mdocdate: September 9 2022 $ +.Dt SEND 2 +.Os +.Sh NAME +.Nm send , +.Nm sendto , +.Nm sendmsg , +.Nm sendmmsg +.Nd send a message from a socket +.Sh SYNOPSIS +.In 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" +.Ft int +.Fn sendmmsg "int s" "const struct mmsghdr *mmsg" "unsigned int vlen" "int flags" +.Sh DESCRIPTION +.Fn send , +.Fn sendto , +.Fn sendmsg , +and +.Fn sendmmsg +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 , +.Fn sendmsg , +and +.Fn sendmmsg +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 +or +.Xr poll 2 +system calls 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: +.Pp +.Bl -tag -width "MSG_DONTROUTEXX" -offset indent -compact +.It Dv MSG_DONTROUTE +bypass routing tables, silently ignored +.It Dv MSG_DONTWAIT +don't block +.It Dv MSG_EOR +terminate the record (SOCK_SEQPACKET only) +.It Dv MSG_NOSIGNAL +don't send +.Dv SIGPIPE +.It Dv MSG_OOB +process out-of-band data +.El +.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_NOSIGNAL +is used to request not to send the +.Dv SIGPIPE +signal if an attempt to send is made on a socket that is shut down for +writing or no longer connected. +.Pp +See +.Xr recv 2 +for a description of the +.Fa msghdr +and +.Fa mmsghdr +structures. +.Sh RETURN VALUES +The +.Fn send , +.Fn sendto , +and +.Fn sendmsg +calls return the number of characters sent, or \-1 +if an error occurred. +The +.Fn sendmmsg +call returns the number of messages sent, or \-1 +if an error occurred before the first message has been sent. +.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 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 or the +.Dv MSG_DONTWAIT +flag is set 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 EACCES +The connection was blocked by +.Xr pf 4 , +or +.Dv SO_BROADCAST +is not set on the socket +and a broadcast address was given as the destination. +.It Bq Er EHOSTUNREACH +The destination address specified an unreachable host. +.It Bq Er EINVAL +The +.Fa flags +parameter is invalid. +.It Bq Er EHOSTDOWN +The destination address specified a host that is down. +.It Bq Er ENETDOWN +The destination address specified a network that is down. +.It Bq Er ECONNREFUSED +The destination host rejected the message (or a previous one). +This error can only be returned by connected sockets. +.It Bq Er ENOPROTOOPT +There was a problem sending the message. +This error can only be returned by connected sockets. +.It Bq Er EDESTADDRREQ +The socket is not connected, and no destination address was specified. +.It Bq Er EPIPE +The socket is shut down for writing or not longer connected and the +.Dv MSG_NOSIGNAL +flag is set. +.El +.Pp +In addition, +.Fn send +and +.Fn sendto +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa len +was larger than +.Dv SSIZE_MAX . +.El +.Pp +.Fn sendto +and +.Fn sendmsg +may return the following errors: +.Bl -tag -width Er +.It Bq Er EADDRNOTAVAIL +No suitable address is available on the local 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, and a destination address was specified. +.El +.Pp +.Fn sendmsg +may return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The sum of the +.Fa iov_len +values in the +.Fa msg_iov +array overflowed an +.Em ssize_t . +.It Bq Er EMSGSIZE +The +.Fa msg_iovlen +member of +.Fa msg +was less than 0 or larger than +.Dv IOV_MAX . +.It Bq Er EMFILE +The message contains control information utilizing +.Xr CMSG_DATA 3 +to pass file descriptors, but too many file descriptors +are already in-flight. +.El +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr getsockopt 2 , +.Xr poll 2 , +.Xr recv 2 , +.Xr select 2 , +.Xr socket 2 , +.Xr write 2 , +.Xr CMSG_DATA 3 +.Sh STANDARDS +The +.Fn send , +.Fn sendto , +and +.Fn sendmsg +functions conform to +.St -p1003.1-2008 . +The +.Dv MSG_DONTWAIT +and +.Dv MSG_NOSIGNAL +flags are extensions to that specification. +.Sh HISTORY +The +.Fn send +function call appeared in +.Bx 4.1c . +The +.Fn sendmmsg +syscall first appeared in Linux 3.0 and was added to +.Ox 7.2 . diff --git a/static/openbsd/man2/sendsyslog.2 b/static/openbsd/man2/sendsyslog.2 new file mode 100644 index 00000000..b1bd25a4 --- /dev/null +++ b/static/openbsd/man2/sendsyslog.2 @@ -0,0 +1,106 @@ +.\" $OpenBSD: sendsyslog.2,v 1.13 2021/03/09 15:08:23 bluhm Exp $ +.\" +.\" Copyright (c) 2017 Alexander Bluhm <bluhm@openbsd.org> +.\" Copyright (c) 2014 Theo de Raadt +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: March 9 2021 $ +.Dt SENDSYSLOG 2 +.Os +.Sh NAME +.Nm sendsyslog +.Nd send a message to syslogd +.Sh SYNOPSIS +.In sys/syslog.h +.In sys/types.h +.Ft int +.Fn sendsyslog "const char *msg" "size_t len" "int flags" +.Sh DESCRIPTION +The +.Fn sendsyslog +function is used to transmit a +.Xr syslog 3 +formatted message direct to +.Xr syslogd 8 +without requiring the allocation of a socket. +The +.Fa msg +is not NUL terminated and its +.Fa len +is limited to 8192 bytes. +If +.Dv LOG_CONS +is specified in the +.Fa flags +argument, and +.Xr syslogd 8 +is not accepting messages, the message will be sent to the console. +This is used internally by +.Xr syslog_r 3 , +so that messages can be sent during difficult situations. +If sending to +.Xr syslogd 8 +fails, up to 100 messages are stashed in the kernel. +After that, dropped messages are counted. +When +.Xr syslogd 8 +works again, before the next message, stashed messages and possibly +a warning with the drop counter, error number, and pid is logged. +.Pp +To receive messages from the kernel, +.Xr syslogd 8 +has to create a datagram socket pair and register one end. +This registration is done by opening the +.Pa /dev/klog +device and passing one file descriptor of the socket pair as argument +to +.Xr ioctl 2 Dv LIOCSFD +invoked on the klog file descriptor. +After that the messages can be read from the other end of the +socket pair. +By utilizing +.Pa /dev/klog +the access to log messages is limited to processes that may open +this device. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn sendsyslog +can fail if: +.Bl -tag -width Er +.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 ENOBUFS +The system was unable to allocate an internal buffer. +The operation may succeed when buffers become available. +.It Bq Er ENOTCONN +The message cannot be sent, likely because +.Xr syslogd 8 +is not running. +.El +.Sh SEE ALSO +.Xr syslog_r 3 , +.Xr syslogd 8 +.Sh HISTORY +The +.Fn sendsyslog +function call appeared in +.Ox 5.6 . +The +.Fa flags +argument was added in +.Ox 6.0 . diff --git a/static/openbsd/man2/setgroups.2 b/static/openbsd/man2/setgroups.2 new file mode 100644 index 00000000..0af926a1 --- /dev/null +++ b/static/openbsd/man2/setgroups.2 @@ -0,0 +1,85 @@ +.\" $OpenBSD: setgroups.2,v 1.14 2019/07/08 18:48:30 anton Exp $ +.\" $NetBSD: setgroups.2,v 1.7 1995/02/27 12:36:49 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: July 8 2019 $ +.Dt SETGROUPS 2 +.Os +.Sh NAME +.Nm setgroups +.Nd set group access list +.Sh SYNOPSIS +.In sys/types.h +.In 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_MAX . +.Pp +Only the superuser may set new groups. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn setgroups +call will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of +.Fa ngroups +is greater than +.Dv NGROUPS_MAX . +.It Bq Er EPERM +The caller is not the superuser. +.It Bq Er EFAULT +The address specified for +.Fa gidset +is outside the process +address space. +.El +.Sh SEE ALSO +.Xr getgroups 2 , +.Xr setgid 2 , +.Xr setregid 2 , +.Xr initgroups 3 +.Sh HISTORY +The +.Fn setgroups +system call first appeared in +.Bx 4.1c . diff --git a/static/openbsd/man2/setpgid.2 b/static/openbsd/man2/setpgid.2 new file mode 100644 index 00000000..4363d2a8 --- /dev/null +++ b/static/openbsd/man2/setpgid.2 @@ -0,0 +1,104 @@ +.\" $OpenBSD: setpgid.2,v 1.17 2014/12/14 07:42:50 schwarze Exp $ +.\" $NetBSD: setpgid.2,v 1.8 1995/02/27 12:36:55 cgd 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. 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 +.\" +.Dd $Mdocdate: December 14 2014 $ +.Dt SETPGID 2 +.Os +.Sh NAME +.Nm setpgid , +.Nm setpgrp +.Nd set process group +.Sh SYNOPSIS +.In 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 +.Fa pid +to the specified +.Fa pgrp . +If +.Fa pid +is zero, then the call applies to the current process. +If +.Fa pgrp +is zero, the process ID of the specified process is used. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn setpgid +will fail and the process group will not be altered if: +.Bl -tag -width Er +.It Bq Er EACCES +The value of the +.Fa pid +argument matches the process ID of a child process of the calling process, +and the child process has successfully executed one of the exec functions. +.It Bq Er EINVAL +The value of the +.Fa pgrp +argument is less than zero. +.It Bq Er EPERM +The requested process is a descendant of the calling process, and +is either a session leader or not in the same session as the calling +process. +.It Bq Er EPERM +The value of the +.Fa pgrp +argument is neither the PID of the process indicated by the +.Fa pid +argument nor the process group ID of an existing process group in +the same session as the calling process. +.It Bq Er ESRCH +The value of the +.Fa pid +argument does not match the process ID of the calling process or of a +descendant of the calling process. +.El +.Sh SEE ALSO +.Xr getpgrp 2 , +.Xr setsid 2 +.Sh STANDARDS +.Fn setpgrp +is identical to +.Fn setpgid , +and is retained for calling convention compatibility with historical +versions of +.Bx . +.Pp +The +.Fn setpgid +function conforms to +.St -p1003.1-2008 . diff --git a/static/openbsd/man2/setregid.2 b/static/openbsd/man2/setregid.2 new file mode 100644 index 00000000..602da875 --- /dev/null +++ b/static/openbsd/man2/setregid.2 @@ -0,0 +1,103 @@ +.\" $OpenBSD: setregid.2,v 1.11 2015/02/05 02:33:09 schwarze Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: February 5 2015 $ +.Dt SETREGID 2 +.Os +.Sh NAME +.Nm setregid +.Nd set real and effective group IDs +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn setregid "gid_t rgid" "gid_t egid" +.Sh DESCRIPTION +The real and effective group IDs of the current process +are set according to the arguments. +The saved group ID will be set to the new value of the real group +ID if a real group ID is specified and either +the new real group ID value is different from the current value +or the new value of the effective group ID differs from the +current saved group ID. +.Pp +Unprivileged users may change either group ID to the current value +of the real, effective, or saved group ID. +Only the superuser 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 purpose is now better served by the use of the +.Xr setegid 2 +function. +.Pp +When setting the real and effective group IDs to the same value, the +.Xr setgid 2 +function is preferred. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EPERM +The current process is not the superuser 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 setegid 2 , +.Xr setgid 2 , +.Xr setresgid 2 , +.Xr setreuid 2 +.Sh STANDARDS +The +.Fn setregid +function conforms to the +.St -p1003.1-2008 +specification, except that the conditions for changing the saved +group ID differ and that, if it is changed, the saved group ID +is set to the real group ID instead of the effective group ID. +.Sh HISTORY +The +.Fn setregid +system call first appeared in +.Bx 4.1c , +predating POSIX. +A semantically different version appeared in +.Bx 4.4 . +The current version, with the original semantics restored, appeared in +.Ox 3.3 . diff --git a/static/openbsd/man2/setresuid.2 b/static/openbsd/man2/setresuid.2 new file mode 100644 index 00000000..43e2dde1 --- /dev/null +++ b/static/openbsd/man2/setresuid.2 @@ -0,0 +1,100 @@ +.\" $OpenBSD: setresuid.2,v 1.10 2024/08/02 22:14:54 guenther Exp $ +.\" +.\" Copyright (c) 2000 +.\" Sheldon Hearn. 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 +.\" +.\" $FreeBSD: src/lib/libc/sys/setresuid.2,v 1.12 2001/10/01 16:09:02 ru Exp $ +.\" +.Dd $Mdocdate: August 2 2024 $ +.Dt SETRESUID 2 +.Os +.Sh NAME +.Nm getresgid , +.Nm getresuid , +.Nm setresgid , +.Nm setresuid +.Nd get or set real, effective and saved user or group ID +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn getresgid "gid_t *rgid" "gid_t *egid" "gid_t *sgid" +.Ft int +.Fn getresuid "uid_t *ruid" "uid_t *euid" "uid_t *suid" +.Ft int +.Fn setresgid "gid_t rgid" "gid_t egid" "gid_t sgid" +.Ft int +.Fn setresuid "uid_t ruid" "uid_t euid" "uid_t suid" +.Sh DESCRIPTION +The +.Fn setresuid +function sets the real, +effective and saved user IDs of the current process. +The analogous +.Fn setresgid +sets the real, effective and saved group IDs. +.Pp +Privileged processes may set these IDs to arbitrary values. +Unprivileged processes are restricted +in that each of the new IDs must match one of the current IDs. +.Pp +Passing \-1 as an argument causes the corresponding value +to remain unchanged. +.Pp +The +.Fn getresgid +and +.Fn getresuid +calls retrieve the real, effective, and saved group and user IDs of +the current process, respectively. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EPERM +The calling process was not privileged and tried to change one or +more IDs to a value which was not the current real ID, the current +effective ID nor the current saved ID. +.It Bq Er EFAULT +An address passed to +.Fn getresgid +or +.Fn getresuid +was invalid. +.El +.Sh SEE ALSO +.Xr getegid 2 , +.Xr geteuid 2 , +.Xr getgid 2 , +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr setgid 2 , +.Xr setregid 2 , +.Xr setreuid 2 , +.Xr setuid 2 +.Sh STANDARDS +The +.Fn getresgid , +.Fn getresuid , +.Fn setresgid , +and +.Fn setresuid +functions conform to the X/Open System Interfaces option of +.St -p1003.1-2024 . +.Sh HISTORY +These functions first appeared in HP-UX. diff --git a/static/openbsd/man2/setreuid.2 b/static/openbsd/man2/setreuid.2 new file mode 100644 index 00000000..29c11c2e --- /dev/null +++ b/static/openbsd/man2/setreuid.2 @@ -0,0 +1,103 @@ +.\" $OpenBSD: setreuid.2,v 1.12 2015/02/05 02:33:09 schwarze Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: February 5 2015 $ +.Dt SETREUID 2 +.Os +.Sh NAME +.Nm setreuid +.Nd set real and effective user IDs +.Sh SYNOPSIS +.In 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. +The saved user ID will be set to the new value of the real +user ID if a real user ID is specified and either +the new real user ID value is different from the current value +or the new value of the effective user ID differs from the +current saved user ID. +.Pp +Unprivileged users may change either user ID to the current value +of the real, effective, or saved user ID. +Only the superuser may make other changes. +.Pp +Supplying a value of -1 for either the real or effective +user ID forces the system to substitute the current +ID in place of the -1 parameter. +.Pp +The +.Fn setreuid +function was intended to allow swapping 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 +.Xr seteuid 2 +function. +.Pp +When setting the real and effective user IDs to the same value, the +.Xr setuid 2 +function is preferred. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EPERM +The current process is not the superuser 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 seteuid 2 , +.Xr setregid 2 , +.Xr setresuid 2 , +.Xr setuid 2 +.Sh STANDARDS +The +.Fn setreuid +function conforms to the +.St -p1003.1-2008 +specification, except that the conditions for changing the saved +user ID differ and that, if it is changed, the saved user ID +is set to the real user ID instead of the effective user ID. +.Sh HISTORY +The +.Fn setreuid +system call first appeared in +.Bx 4.1c , +predating POSIX. +A semantically different version appeared in +.Bx 4.4 . +The current version, with the original semantics restored, appeared in +.Ox 3.3 . diff --git a/static/openbsd/man2/setsid.2 b/static/openbsd/man2/setsid.2 new file mode 100644 index 00000000..3859e405 --- /dev/null +++ b/static/openbsd/man2/setsid.2 @@ -0,0 +1,79 @@ +.\" $OpenBSD: setsid.2,v 1.15 2023/01/12 12:56:07 jsg Exp $ +.\" $NetBSD: setsid.2,v 1.3 1995/10/12 15:41:13 jtc Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: January 12 2023 $ +.Dt SETSID 2 +.Os +.Sh NAME +.Nm setsid +.Nd create session and set process group ID +.Sh SYNOPSIS +.In 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. +.Pp +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. +.Sh ERRORS +If an error occurs, +.Fn setsid +returns \-1 and the global variable +.Va errno +is set to indicate the error, as follows: +.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 getsid 2 , +.Xr setpgid 2 , +.Xr tcgetpgrp 3 , +.Xr tcsetpgrp 3 +.Sh STANDARDS +The +.Fn setsid +function is compliant with the +.St -p1003.1-2008 +specification. diff --git a/static/openbsd/man2/setuid.2 b/static/openbsd/man2/setuid.2 new file mode 100644 index 00000000..2e5e41e5 --- /dev/null +++ b/static/openbsd/man2/setuid.2 @@ -0,0 +1,152 @@ +.\" $OpenBSD: setuid.2,v 1.23 2014/09/09 08:16:12 jmc Exp $ +.\" $NetBSD: setuid.2,v 1.3 1995/02/27 12:37:06 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: September 9 2014 $ +.Dt SETUID 2 +.Os +.Sh NAME +.Nm setuid , +.Nm seteuid , +.Nm setgid , +.Nm setegid +.Nd set user and group ID +.Sh SYNOPSIS +.In 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. +The +.Fn setuid +function is permitted if the effective user ID is that of the superuser, +or if the specified user ID is the same as the effective user ID. +If not, but the specified user ID is the same as the real user ID, +.Fn setuid +will set the effective user ID to the real user ID. +.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. +The +.Fn setgid +function is permitted if the effective user ID is that of the superuser, +or if the specified group ID is the same as the effective group ID. +If not, but the specified group ID is the same as the real group ID, +.Fn setgid +will set the effective group ID to the real group ID. +Supplementary group IDs remain unchanged. +.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-group-ID. +.Sh RETURN VALUES +.Rv -std setuid seteuid setgid setegid +.Sh ERRORS +.Fn setuid +and +.Fn seteuid +will succeed unless: +.Bl -tag -width Er +.It Bq Er EPERM +The user is not the superuser and the requested +.Fa uid +or +.Fa euid +is not the process's real, effective, or saved UID. +.El +.Pp +.Fn setgid +and +.Fn setegid +will succeed unless: +.Bl -tag -width Er +.It Bq Er EPERM +The user is not the superuser and the requested +.Fa gid +or +.Fa egid +is not the process's real, effective, or saved GID. +.El +.Sh SEE ALSO +.Xr getgid 2 , +.Xr getuid 2 , +.Xr issetugid 2 , +.Xr setgroups 2 , +.Xr setregid 2 , +.Xr setresgid 2 , +.Xr setresuid 2 , +.Xr setreuid 2 +.Sh STANDARDS +The +.Fn setuid , +.Fn seteuid , +.Fn setgid , +and +.Fn setegid +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn setuid +system call first appeared in +.At v1 ; +.Fn setgid +in +.At v4 ; +and +.Fn seteuid +and +.Fn setegid +in +.Bx 4.2 . diff --git a/static/openbsd/man2/shmat.2 b/static/openbsd/man2/shmat.2 new file mode 100644 index 00000000..b7f237e7 --- /dev/null +++ b/static/openbsd/man2/shmat.2 @@ -0,0 +1,129 @@ +.\" $OpenBSD: shmat.2,v 1.17 2022/06/16 13:54:39 deraadt Exp $ +.\" $NetBSD: shmat.2,v 1.2 1997/03/27 08:20:38 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: June 16 2022 $ +.Dt SHMAT 2 +.Os +.Sh NAME +.Nm shmat , +.Nm shmdt +.Nd map/unmap shared memory +.Sh SYNOPSIS +.In sys/shm.h +.Ft void * +.Fn shmat "int shmid" "const void *shmaddr" "int shmflg" +.Ft int +.Fn shmdt "const void *shmaddr" +.Sh DESCRIPTION +.Fn shmat +maps the shared memory segment associated with the shared memory identifier +.Fa shmid +into the address space of the calling process. +The address at which the segment is mapped is determined by the +.Fa shmaddr +parameter. +If it is equal to NULL, the system will pick an address itself. +Otherwise, an attempt is made to map the shared memory segment at the +address +.Fa shmaddr +specifies. +If +.Dv SHM_RND +is set in +.Fa shmflg , +the system will round the address down to a multiple of +.Dv SHMLBA +bytes +.Pf ( Dv SHMLBA +is defined in +.In sys/shm.h ) . +.Pp +A shared memory segment can be mapped read-only by specifying the +.Dv SHM_RDONLY +flag in +.Fa shmflg . +.Pp +.Fn shmdt +unmaps the shared memory segment that is currently mapped at +.Fa shmaddr +from the calling process' address space. +.Fa shmaddr +must be a value returned by a prior +.Fn shmat +call. +A shared memory segment will remain existent until it is removed by +a call to +.Xr shmctl 2 +with the +.Dv IPC_RMID +command. +.Sh RETURN VALUES +.Fn shmat +returns the address at which the shared memory segment has been mapped into +the calling process' address space when successful, +.Fn shmdt +returns 0 on successful completion. +Otherwise, a value of \-1 is returned, and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn shmat +will fail if: +.Bl -tag -width Er +.It Bq Er EACCES +The calling process has no permission to access this shared memory segment. +.It Bq Er ENOMEM +There is not enough available data space for the calling process to +map the shared memory segment. +.It Bq Er EINVAL +.Fa shmid +is not a valid shared memory identifier. +.Pp +.Fa shmaddr +specifies an illegal address. +.It Bq Er EMFILE +The number of shared memory segments has reached the system-wide limit. +.El +.Pp +.Fn shmdt +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa shmaddr +is not the start address of a mapped shared memory segment. +.El +.Sh SEE ALSO +.Xr ipcrm 1 , +.Xr ipcs 1 , +.Xr mmap 2 , +.Xr shmctl 2 , +.Xr shmget 2 diff --git a/static/openbsd/man2/shmctl.2 b/static/openbsd/man2/shmctl.2 new file mode 100644 index 00000000..8cd89414 --- /dev/null +++ b/static/openbsd/man2/shmctl.2 @@ -0,0 +1,198 @@ +.\" $OpenBSD: shmctl.2,v 1.19 2021/11/21 23:44:55 jan Exp $ +.\" $NetBSD: shmctl.2,v 1.3 1997/03/27 08:20:39 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: November 21 2021 $ +.Dt SHMCTL 2 +.Os +.Sh NAME +.Nm shmctl +.Nd shared memory control operations +.Sh SYNOPSIS +.In sys/shm.h +.Ft int +.Fn shmctl "int shmid" "int cmd" "struct shmid_ds *buf" +.Sh DESCRIPTION +The +.Fn shmctl +system call performs some control operations on the shared memory area +specified by +.Fa shmid . +.Pp +Each shared memory segment has a data structure associated with it, +parts of which may be altered by +.Fn shmctl +and parts of which determine the actions of +.Fn shmctl . +.Pp +This structure is defined as follows in +.In sys/shm.h : +.Bd -literal +struct shmid_ds { + struct ipc_perm shm_perm; /* operation permissions */ + int shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* pid of last shm op */ + pid_t shm_cpid; /* pid of creator */ + short shm_nattch; /* # of current attaches */ + time_t shm_atime; /* last shmat() time*/ + time_t shm_dtime; /* last shmdt() time */ + time_t shm_ctime; /* last change by shmctl() */ + void *shm_internal; /* sysv stupidity */ +}; +.Ed +.Pp +The +.Bf -literal +ipc_perm +.Ef +structure used inside the +.Bf -literal +shmid_ds +.Ef +structure is defined in +.In sys/ipc.h +and looks like this: +.Bd -literal +struct ipc_perm { + uid_t cuid; /* creator user id */ + gid_t cgid; /* creator group id */ + uid_t uid; /* user id */ + gid_t gid; /* group id */ + mode_t mode; /* r/w permission (see chmod(2)) */ + u_short seq; /* sequence # */ + /* (to generate unique msg/sem/shm id) */ + key_t key; /* user specified msg/sem/shm key */ +}; +.Ed +.Pp +The operation to be performed by +.Fn shmctl +is specified in +.Fa cmd +and is one of: +.Bl -tag -width IPC_RMIDX +.It Dv IPC_STAT +Gather information about the shared memory segment and place it in the +structure pointed to by +.Fa buf . +.It Dv IPC_SET +Set the value of the +.Va shm_perm.uid , +.Va shm_perm.gid +and +.Va shm_perm.mode +fields in the structure associated with +.Fa shmid . +The values are taken from the corresponding fields in the structure +pointed to by +.Fa buf . +This operation can only be executed by the superuser, or a process that +has an effective user ID equal to either +.Va shm_perm.cuid +or +.Va shm_perm.uid +in the data structure associated with the shared memory segment. +.It Dv IPC_RMID +Mark the shared memory segment specified by +.Fa shmid +for removal when it is no longer in use by any process. +When it is removed, all data associated with it will be destroyed too. +Only the superuser or a process with an effective UID equal to the +.Va shm_perm.cuid +or +.Va shm_perm.uid +values in the data structure associated with the queue can do this. +.El +.Pp +The read and write permissions on a shared memory identifier +are determined by the +.Va shm_perm.mode +field in the same way as is +done with files (see +.Xr chmod 2 ) , +but the effective UID can match either the +.Va shm_perm.cuid +field or the +.Va shm_perm.uid +field, and the +effective GID can match either +.Va shm_perm.cgid +or +.Va shm_perm.gid . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn shmctl +will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +.Fa cmd +is equal to +.Dv IPC_SET +or +.Dv IPC_RMID +and the caller is not the superuser, nor does +the effective UID match either the +.Va shm_perm.uid +or +.Va shm_perm.cuid +fields of the data structure associated with the shared memory segment. +.Pp +An attempt is made to increase the value of +.Va shm_qbytes +through +.Dv IPC_SET +but the caller is not the superuser. +.It Bq Er EACCES +The command is +.Dv IPC_STAT +and the caller has no read permission for this shared memory segment. +.It Bq Er EINVAL +.Fa shmid +is not a valid shared memory segment identifier. +.Pp +.Va cmd +is not a valid command. +.It Bq Er EFAULT +.Fa buf +specifies an invalid address. +.El +.Sh SEE ALSO +.Xr ipcrm 1 , +.Xr ipcs 1 , +.Xr shmat 2 , +.Xr shmget 2 +.Sh STANDARDS +Segments which are marked for removal (but not yet removed +since they are still in use) can be attached to by new callers +using +.Xr shmat 2 . +This is permitted as an extension beyond the standards. diff --git a/static/openbsd/man2/shmget.2 b/static/openbsd/man2/shmget.2 new file mode 100644 index 00000000..609105a8 --- /dev/null +++ b/static/openbsd/man2/shmget.2 @@ -0,0 +1,142 @@ +.\" $OpenBSD: shmget.2,v 1.17 2014/11/15 22:19:53 guenther Exp $ +.\" $NetBSD: shmget.2,v 1.2 1997/03/27 08:20:39 mikel Exp $ +.\" +.\" Copyright (c) 1995 Frank van der Linden +.\" 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 for the NetBSD Project +.\" by Frank van der Linden +.\" 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 $Mdocdate: November 15 2014 $ +.Dt SHMGET 2 +.Os +.Sh NAME +.Nm shmget +.Nd get shared memory area identifier +.Sh SYNOPSIS +.In sys/shm.h +.Ft int +.Fn shmget "key_t key" "size_t size" "int shmflg" +.Sh DESCRIPTION +.Fn shmget +returns the shared memory identifier associated with the key +.Fa key . +.Pp +A shared memory segment is created if either +.Fa key +is equal to +.Dv IPC_PRIVATE , +or +.Fa key +does not have a shared memory segment identifier associated with it, and the +.Dv IPC_CREAT +bit is set in +.Fa shmflg . +.Pp +If a new shared memory segment is created, the data structure associated with +it (the +.Va shmid_ds +structure, see +.Xr shmctl 2 ) +is initialized as follows: +.Bl -bullet +.It +.Va shm_perm.cuid +and +.Va shm_perm.uid +are set to the effective uid of the calling process. +.It +.Va shm_perm.gid +and +.Va shm_perm.cgid +are set to the effective gid of the calling process. +.It +.Va shm_perm.mode +is set to the lower 9 bits of +.Fa shmflg . +.It +.Va shm_lpid , +.Va shm_nattch , +.Va shm_atime , +and +.Va shm_dtime +are set to 0. +.It +.Va shm_ctime +is set to the current time. +.It +.Va shm_segsz +is set to the value of +.Fa size . +.El +.Sh RETURN VALUES +Upon successful completion a positive shared memory segment identifier is +returned. +Otherwise, \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EACCES +A shared memory segment is already associated with +.Fa key +and the caller has no permission to access it. +.It Bq Er EEXIST +Both +.Dv IPC_CREAT +and +.Dv IPC_EXCL +are set in +.Fa shmflg , +and a shared memory segment is already associated with +.Fa key . +.It Bq Er EINVAL +A shared memory segment is already associated with +.Fa key +and its +.Fa size +is less than the requested size. +.It Bq Er ENOSPC +A new shared memory identifier could not be created because the system limit +for the number of shared memory identifiers has been reached. +.It Bq Er ENOENT +.Dv IPC_CREAT +was not set in +.Fa shmflg +and no shared memory segment associated with +.Fa key +was found. +.It Bq Er ENOMEM +There is not enough memory left to create a shared memory segment of the +requested size. +.El +.Sh SEE ALSO +.Xr ipcrm 1 , +.Xr ipcs 1 , +.Xr mmap 2 , +.Xr shmat 2 , +.Xr shmctl 2 , +.Xr ftok 3 diff --git a/static/openbsd/man2/shutdown.2 b/static/openbsd/man2/shutdown.2 new file mode 100644 index 00000000..9f05eaae --- /dev/null +++ b/static/openbsd/man2/shutdown.2 @@ -0,0 +1,154 @@ +.\" $OpenBSD: shutdown.2,v 1.15 2014/09/09 09:00:17 guenther Exp $ +.\" $NetBSD: shutdown.2,v 1.5 1995/02/27 12:37:11 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: September 9 2014 $ +.Dt SHUTDOWN 2 +.Os +.Sh NAME +.Nm shutdown +.Nd disable sends or receives on a socket +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn shutdown "int s" "int how" +.Sh DESCRIPTION +The +.Fn shutdown +system call disables sends or receives on a socket. +.Pp +If the file descriptor +.Fa s +is associated with a +.Dv SOCK_STREAM +socket, all or part of the full-duplex connection will be shut down. +.Pp +The +.Fa how +argument specifies the type of shutdown. +Possible values are: +.Bl -tag -width "SHUT_RDWRXXX" -offset indent +.It Dv SHUT_RD +Further receives will be disallowed. +.It Dv SHUT_WR +Further sends will be disallowed. +This may cause actions specific to the protocol family of the socket +.Fa s +to happen. +.It Dv SHUT_RDWR +Further sends and receives will be disallowed. +.El +.Pp +The following protocol specific actions apply to the use of +.Dv SHUT_WR +based on the properties of the socket associated with the file descriptor +.Fa s : +.Bl -column "AF_INET6" "SOCK_STREAM" "IPPROTO_UDP" -offset indent +.It DOMAIN Ta TYPE Ta PROTOCOL Ta "RETURN VALUE AND ACTION" +.Pp +.It Dv AF_INET Ta Dv SOCK_DGRAM Ta Dv IPPROTO_UDP Ta +Return 0. +ICMP messages will +.Em not +be generated. +.It Dv AF_INET Ta Dv SOCK_STREAM Ta Dv IPPROTO_TCP Ta +Return 0. +Send queued data, wait for ACK, then send FIN. +.It Dv AF_INET6 Ta Dv SOCK_DGRAM Ta Dv IPPROTO_UDP Ta +Return 0. +ICMP messages will +.Em not +be generated. +.It Dv AF_INET6 Ta Dv SOCK_STREAM Ta Dv IPPROTO_TCP Ta +Return 0. +Send queued data, wait for ACK, then send FIN. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn shutdown +system call fails if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa s +argument is not a valid file descriptor. +.It Bq Er EINVAL +The +.Fa how +argument is invalid. +.It Bq Er ENOTCONN +The +.Fa s +argument specifies a +.Dv SOCK_STREAM +socket which is not connected. +.It Bq Er ENOTSOCK +The +.Fa s +argument does not refer to a socket. +.It Bq Er EOPNOTSUPP +The socket associated with the file descriptor +.Fa s +does not support this operation. +.El +.Sh SEE ALSO +.Xr connect 2 , +.Xr socket 2 , +.Xr inet 4 , +.Xr inet6 4 +.Sh STANDARDS +The +.Fn shutdown +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn shutdown +system call first appeared in +.Bx 4.1c . +The +.Dv SHUT_RD , SHUT_WR , +and +.Dv SHUT_RDWR +constants appeared in +.St -p1003.1g-2000 . +.Sh BUGS +The ICMP +.Dq port unreachable +message should be generated in response to +datagrams received on a local port to which +.Fa s +is bound +after +.Fn shutdown +is called. diff --git a/static/openbsd/man2/sigaction.2 b/static/openbsd/man2/sigaction.2 new file mode 100644 index 00000000..044d9574 --- /dev/null +++ b/static/openbsd/man2/sigaction.2 @@ -0,0 +1,698 @@ +.\" $OpenBSD: sigaction.2,v 1.79 2024/07/14 03:53:18 jsg Exp $ +.\" $NetBSD: sigaction.2,v 1.7 1995/10/12 15:41:16 jtc Exp $ +.\" +.\" 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. 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. +.\" +.\" @(#)sigaction.2 8.2 (Berkeley) 4/3/94 +.\" +.Dd $Mdocdate: July 14 2024 $ +.Dt SIGACTION 2 +.Os +.Sh NAME +.Nm sigaction +.Nd software signal facilities +.Sh SYNOPSIS +.In signal.h +.Bd -literal +struct sigaction { + union { /* signal handler */ + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, siginfo_t *, void *); + } __sigaction_u; + sigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ +}; +.Ed +.Pp +.Fd #define sa_handler __sigaction_u.__sa_handler +.Fd #define sa_sigaction __sigaction_u.__sa_sigaction +.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 2 +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 +.Fa sa_mask +associated with the handler to be invoked, but always excluding +.Dv SIGKILL +and +.Dv SIGSTOP . +.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. +The value of +.Fa sa_handler +(or, if the +.Dv SA_SIGINFO +flag is set, the value of +.Fa sa_sigaction +instead) indicates what action should be performed when a +signal arrives. +A signal-specific default action may be reset by +setting +.Fa sa_handler +to +.Dv SIG_DFL . +Alternately, if the +.Dv SA_RESETHAND +flag is set the default action will be reinstated when the signal +is first posted. +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. +If +.Fa sig +is +.Dv SIGCHLD +and +.Fa sa_handler +is set to +.Dv SIG_IGN , +the +.Dv SA_NOCLDWAIT +flag (described below) is implied. +.Pp +The signal mask +.Fa sa_mask +is typically manipulated using the +.Xr sigaddset 3 +family of functions. +.Pp +Options may be specified by setting +.Fa 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, +though existing zombies will remain. +If the calling process subsequently issues a +.Xr waitpid 2 +(or equivalent) and there are no previously existing zombie child +processes that match the +.Xr waitpid 2 +criteria, +it blocks until all of the calling process's child +processes that would match terminate, +and then returns a value of \-1 with +.Va errno +set to +.Er 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 2nd argument of the handler is set to +be a pointer to a +.Em siginfo_t +structure as described in +.In sys/siginfo.h . +It provides much more information about the causes and +attributes of the signal that is being delivered. +.It Dv SA_RESTART +If a signal is caught during the system calls listed below, +the call may be forced to terminate +with the error +.Er EINTR , +the call may return with a data transfer shorter than requested, +or the call may be restarted. +Restarting of pending calls is requested +by setting the +.Dv SA_RESTART +bit in +.Fa sa_flags . +The affected system calls include +.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). +.El +.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 +.Dv SIGCHLD +and all signals which were caught; all other signals remain ignored. +All signals are reset to be caught on the user stack and +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 +.In signal.h : +.Bl -column "SIGVTALARM" "create core image" "Description" +.It Sy "Name" Ta Sy "Default Action" Ta Sy "Description" +.It Dv SIGHUP Ta "terminate process" Ta "terminal line hangup" +.It Dv SIGINT Ta "terminate process" Ta "interrupt program" +.It Dv SIGQUIT Ta "create core image" Ta "quit program" +.It Dv SIGILL Ta "create core image" Ta "illegal instruction" +.It Dv SIGTRAP Ta "create core image" Ta "trace trap" +.It Dv SIGABRT Ta "create core image" Ta "abort(3) call (formerly SIGIOT)" +.It Dv SIGEMT Ta "create core image" Ta "emulate instruction executed" +.It Dv SIGFPE Ta "create core image" Ta "floating-point exception" +.It Dv SIGKILL Ta "terminate process" Ta "kill program (cannot be caught or ignored)" +.It Dv SIGBUS Ta "create core image" Ta "bus error" +.It Dv SIGSEGV Ta "create core image" Ta "segmentation violation" +.It Dv SIGSYS Ta "create core image" Ta "system call given invalid argument" +.It Dv SIGPIPE Ta "terminate process" Ta "write on a pipe with no reader" +.It Dv SIGALRM Ta "terminate process" Ta "real-time timer expired" +.It Dv SIGTERM Ta "terminate process" Ta "software termination signal" +.It Dv SIGURG Ta "discard signal" Ta "urgent condition present on socket" +.It Dv SIGSTOP Ta "stop process" Ta "stop (cannot be caught or ignored)" +.It Dv SIGTSTP Ta "stop process" Ta "stop signal generated from keyboard" +.It Dv SIGCONT Ta "discard signal" Ta "continue after stop" +.It Dv SIGCHLD Ta "discard signal" Ta "child status has changed" +.It Dv SIGTTIN Ta "stop process" Ta "background read attempted from controlling terminal" +.It Dv SIGTTOU Ta "stop process" Ta "background write attempted to controlling terminal" +.It Dv SIGIO Ta "discard signal" Ta "I/O is possible on a descriptor (see" +.Xr fcntl 2 ) +.It Dv SIGXCPU Ta "terminate process" Ta "CPU time limit exceeded (see" +.Xr setrlimit 2 ) +.It Dv SIGXFSZ Ta "terminate process" Ta "file size limit exceeded (see" +.Xr setrlimit 2 ) +.It Dv SIGVTALRM Ta "terminate process" Ta "virtual time alarm (see" +.Xr setitimer 2 ) +.It Dv SIGPROF Ta "terminate process" Ta "profiling timer alarm (see" +.Xr setitimer 2 ) +.It Dv SIGWINCH Ta "discard signal" Ta "window size change" +.It Dv SIGINFO Ta "discard signal" Ta "status request from keyboard" +.It Dv SIGUSR1 Ta "terminate process" Ta "user defined signal 1" +.It Dv SIGUSR2 Ta "terminate process" Ta "user defined signal 2" +.It Dv SIGTHR Ta "discard signal" Ta "thread AST" +.El +.Sh RETURN VALUES +.Rv -std +.Sh EXAMPLES +The handler routine can be declared: +.Bd -literal -offset indent +void +handler(int sig) +.Pp +.Ed +If the +.Dv SA_SIGINFO +option is enabled, the canonical way to declare it is: +.Bd -literal -offset indent +void +handler(int sig, siginfo_t *sip, void *ctx) +.Ed +.Pp +Here +.Fa sig +is the signal number, into which the hardware faults and traps are mapped. +If the +.Dv SA_SIGINFO +option is set, +.Fa sip +is a pointer to a +.Dv siginfo_t +as described in +.In sys/siginfo.h . +If +.Dv SA_SIGINFO +is not set, this pointer will be +.Dv NULL +instead. +The function specified in +.Fa sa_sigaction +will be called instead of the function specified by +.Fa sa_handler +(note that in some implementations these are in fact the same). +.Fa ctx +may be cast to a pointer to +.Fa ucontext_t +which can be used to restore the thread's context from before the signal. +On +.Ox , +.Fa ucontext_t +is an alias for the +.Fa sigcontext +structure defined in +.In signal.h . +The contents of this structure are machine-dependent. +.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 SEE ALSO +.Xr kill 1 , +.Xr kill 2 , +.Xr ptrace 2 , +.Xr sigaltstack 2 , +.Xr sigprocmask 2 , +.Xr sigsuspend 2 , +.Xr wait 2 , +.Xr setjmp 3 , +.Xr sigaddset 3 , +.Xr sigblock 3 , +.Xr sigpause 3 , +.Xr sigvec 3 , +.Xr tty 4 +.Sh STANDARDS +The +.Fn sigaction +function conforms to +.St -p1003.1-2008 . +.Pp +The +.Dv SA_ONSTACK +flag and the +.Dv SIGPROF , +.Dv SIGSYS , +.Dv SIGTRAP , +.Dv SIGVTALRM , +.Dv SIGXCPU , +and +.Dv SIGXFSZ +signals conform to the X/Open System Interfaces option of that standard. +The standard marks +.Dv SIGPROF +as obsolescent. +The signals +.Dv SIGEMT , +.Dv SIGINFO , +.Dv SIGIO , +and +.Dv SIGWINCH +are Berkeley extensions. +These signals are available on most +.Bx Ns -derived +systems. +The +.Dv SIGTHR +signal is specific to +.Ox +and is part of the +implementation of thread cancellation; +.Fa sigaction +and other signal interfaces may reject attempts to use or alter the +handling of +.Dv SIGTHR . +.Pp +Signal handlers should be as minimal as possible, and use only signal-safe +operations. +The safest handlers only change a single variable of type +.Va volatile sig_atomic_t , +which is inspected by an event loop. +Other variables accessed inside the handler must be either const, or +local to the handler. +More complicated global variables (such as strings, structs, or lists) +will require external methods to guarantee consistency, such as +signal-blocking with +.Xr sigprocmask 2 . +.Pp +More complicated handlers must restrict themselves to calling only the following +list of signal-safe functions directly. +Avoid abstracting the work to helper functions which are also called from +other contexts because future coders will forget the signal-safe requirement. +.Pp +Standard Interfaces: +.Pp +.Fn _exit , +.Fn _Exit , +.Fn abort , +.Fn accept , +.Fn access , +.Fn alarm , +.Fn bind , +.Fn cfgetispeed , +.Fn cfgetospeed , +.Fn cfsetispeed , +.Fn cfsetospeed , +.Fn chdir , +.Fn chmod , +.Fn chown , +.Fn clock_gettime , +.Fn close , +.Fn connect , +.Fn creat , +.Fn dup , +.Fn dup2 , +.Fn execl , +.Fn execle , +.Fn execv , +.Fn execve , +.Fn faccessat , +.Fn fchdir , +.Fn fchmod , +.Fn fchmodat , +.Fn fchown , +.Fn fchownat , +.Fn fcntl , +.Fn fdatasync , +.Fn fork , +.Fn fpathconf , +.Fn fstat , +.Fn fstatat , +.Fn fsync , +.Fn ftruncate , +.Fn futimens , +.Fn futimes , +.Fn getegid , +.Fn geteuid , +.Fn getgid , +.Fn getgroups , +.Fn getpeername , +.Fn getpgrp , +.Fn getpid , +.Fn getppid , +.Fn getsockname , +.Fn getsockopt , +.Fn getuid , +.Fn kill , +.Fn link , +.Fn linkat , +.Fn listen , +.Fn lseek , +.Fn lstat , +.Fn mkdir , +.Fn mkdirat , +.Fn mkfifo , +.Fn mkfifoat , +.Fn mknod , +.Fn mknodat , +.Fn open , +.Fn openat , +.Fn pathconf , +.Fn pause , +.Fn pipe , +.Fn poll , +.Fn pselect , +.Fn pthread_sigmask , +.Fn raise , +.Fn read , +.Fn readlink , +.Fn readlinkat , +.Fn recv , +.Fn recvfrom , +.Fn recvmsg , +.Fn rename , +.Fn renameat , +.Fn rmdir , +.Fn select , +.Fn send , +.Fn sendmsg , +.Fn sendto , +.Fn setgid , +.Fn setpgid , +.Fn setsid , +.Fn setsockopt , +.Fn setuid , +.Fn shutdown , +.Fn sigaction , +.Fn sigaddset , +.Fn sigdelset , +.Fn sigemptyset , +.Fn sigfillset , +.Fn sigismember , +.Fn signal , +.Fn sigpause , +.Fn sigpending , +.Fn sigprocmask , +.Fn sigsuspend , +.Fn sleep , +.Fn sockatmark , +.Fn socket , +.Fn socketpair , +.Fn stat , +.Fn strcat , +.Fn strcpy , +.Fn strncat , +.Fn strncpy , +.Fn symlink , +.Fn symlinkat , +.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 unlinkat , +.Fn utime , +.Fn utimensat , +.Fn utimes , +.Fn wait , +.Fn waitpid , +.Fn write , +and perhaps some others. +.\" unimplemented functions that should be async-sig-safe, if we had them +.\" POSIX Issue 7 additions +.\" .Pp +.\" .Fn fexecve . +.\" +.\" Realtime Interfaces: +.\" .Pp +.\" .Fn aio_error , +.\" .Fn aio_return , +.\" .Fn aio_suspend , +.\" .Fn sem_post , +.\" .Fn sigqueue , +.\" .Fn timer_getoverrun , +.\" .Fn timer_gettime , +.\" .Fn timer_settime . +.Pp +Extension Interfaces: +.Pp +.Fn accept4 , +.Fn chflags , +.Fn chflagsat , +.Fn dup3 , +.Fn fchflags , +.Fn getentropy , +.Fn getresgid , +.Fn getresuid , +.Fn pipe2 , +.Fn ppoll , +.Fn sendsyslog , +.Fn setresgid , +.Fn setresuid , +.Fn strlcat , +.Fn strlcpy , +.Fn wait3 , +.Fn wait4 . +.Pp +Since signal-safe functions can encounter system call errors, +.Va errno +should be protected inside the handler with the following pattern: +.Bd -literal -offset indent +void +handler(int sig) +{ + int save_errno = errno; + + ... + errno = save_errno; +} +.Ed +.Pp +On +.Ox , +a few more functions are signal-safe (except when the format string contains +floating-point arguments). +These functions are expected to be unsafe on other systems, so be very cautious of +the portability trap! +.Pp +.Bl -tag -offset indent -compact -width foofoofoofoo +.It Fn dprintf +Safe. +.It Fn vdprintf +Safe. +.It Fn snprintf +Safe. +.It Fn vsnprintf +Safe. +.It Fn syslog_r +Safe if the +.Va syslog_data +struct is initialized as a local variable. +.El diff --git a/static/openbsd/man2/sigaltstack.2 b/static/openbsd/man2/sigaltstack.2 new file mode 100644 index 00000000..e1fe4ab8 --- /dev/null +++ b/static/openbsd/man2/sigaltstack.2 @@ -0,0 +1,193 @@ +.\" $OpenBSD: sigaltstack.2,v 1.28 2024/06/22 17:19:05 deraadt Exp $ +.\" $NetBSD: sigaltstack.2,v 1.3 1995/02/27 10:41:52 cgd Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/4/93 +.\" +.Dd $Mdocdate: June 22 2024 $ +.Dt SIGALTSTACK 2 +.Os +.Sh NAME +.Nm sigaltstack +.Nd set and/or get signal stack context +.Sh SYNOPSIS +.In signal.h +.Bd -literal +typedef struct sigaltstack { + void *ss_sp; + size_t ss_size; + int ss_flags; +} stack_t; +.Ed +.Ft int +.Fn sigaltstack "const stack_t *ss" "stack_t *oss" +.Sh DESCRIPTION +.Fn sigaltstack +allows users to define an alternate stack on which signals +delivered to this thread +are to be processed. +If +.Fa ss +is non-zero and +.Dv SS_DISABLE +is set in +.Fa ss_flags , +the signal stack will be disabled. +A disabled stack will cause all signals to be +taken on the regular user stack. +Trying to disable an active stack will cause +.Fn sigaltstack +to return \-1 with +.Va errno +set to +.Er EPERM . +.Pp +Otherwise, +.Fa ss_sp +specifies a pointer to a space to be used as the signal stack and +.Fa ss_size +specifies the size of that space. +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 thread is currently executing on that stack. +If the thread 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 +.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 thread is currently on a signal stack and +.Dv SS_DISABLE +if the signal stack is currently disabled. +.Pp +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 = mmap(NULL, SIGSTKSZ, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) + /* error return */ +sigstk.ss_size = SIGSTKSZ; +sigstk.ss_flags = 0; +if (sigaltstack(&sigstk, NULL) == -1) + perror("sigaltstack"); +.Ed +.Pp +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 +.Dq grown +automatically as is done for the normal stack. +If the stack overflows and this space is not protected, +unpredictable results may occur. +.Pp +On +.Ox +some additional restrictions prevent dangerous address space modifications. +The proposed space at +.Fa ss_sp +is verified to be contiguously mapped for read-write permissions without +execute. +If those conditions are met, a page-aligned inner region will be freshly mapped +(all zero) with +.Dv MAP_STACK +(see +.Xr mmap 2 ) , +destroying the pre-existing data in the region. +Once the sigaltstack is disabled, the +.Dv MAP_STACK +attribute remains on the memory, so it is best to deallocate the memory +via a method that results in +.Xr munmap 2 . +.Sh RETURN VALUES +.Rv -std +.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 +The +.Fa ss_flags +member pointed to by the +.Fa ss +argument contains flags other than +.Dv SS_DISABLE . +.It Bq Er EINVAL +The memory region is not acceptable for use as a stack; +see above. +.It Bq Er ENOMEM +Size of alternate stack area is less than or equal to +.Dv MINSIGSTKSZ . +.It Bq Er EPERM +An attempt was made to disable an active stack. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr setjmp 3 +.Sh STANDARDS +The +.Fn sigaltstack +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The predecessor to +.Fn sigaltstack , +the +.Fn sigstack +system call, appeared in +.Bx 4.2 . diff --git a/static/openbsd/man2/sigpending.2 b/static/openbsd/man2/sigpending.2 new file mode 100644 index 00000000..02a06625 --- /dev/null +++ b/static/openbsd/man2/sigpending.2 @@ -0,0 +1,69 @@ +.\" $OpenBSD: sigpending.2,v 1.8 2017/05/29 09:40:02 deraadt Exp $ +.\" $NetBSD: sigpending.2,v 1.2 1995/02/27 12:37:26 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 29 2017 $ +.Dt SIGPENDING 2 +.Os +.Sh NAME +.Nm sigpending +.Nd get pending signals +.Sh SYNOPSIS +.In 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 +.Rv -std +.Sh ERRORS +The +.Fn sigpending +function does not currently detect any errors. +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigprocmask 2 , +.Xr sigaddset 3 +.Sh STANDARDS +The +.Fn sigpending +function is defined by +.St -p1003.1-2008 . diff --git a/static/openbsd/man2/sigprocmask.2 b/static/openbsd/man2/sigprocmask.2 new file mode 100644 index 00000000..0b57058f --- /dev/null +++ b/static/openbsd/man2/sigprocmask.2 @@ -0,0 +1,124 @@ +.\" $OpenBSD: sigprocmask.2,v 1.13 2017/05/29 09:40:02 deraadt Exp $ +.\" $NetBSD: sigprocmask.2,v 1.6 1995/02/27 12:37:33 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 29 2017 $ +.Dt SIGPROCMASK 2 +.Os +.Sh NAME +.Nm sigprocmask +.Nd manipulate current signal mask +.Sh SYNOPSIS +.In 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 , +which can be one of the following values: +.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 +.Fa how +is insignificant and the mask remains unchanged, +providing a way to examine the signal mask without modification. +.Pp +The system +quietly disallows +.Dv SIGKILL +or +.Dv SIGSTOP +to be blocked. +.Pp +Only signals which are in the pending state will be blocked. +Signals that are explicitly ignored or for which no handler has +been installed and where the default action is to discard the signal +are not held as pending and will be discarded regardless of the +signal mask. +.Pp +Blocked signals remain in the pending state until another call to +.Fn sigprocmask +removes the pending signal(s) from the mask. +If there are unblocked signals that are pending after the signal +mask is updated, at least one will be delivered before +.Fn sigprocmask +returns. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn sigprocmask +call will fail and the signal mask will be unchanged if one +of the following occurs: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa how +has a value other than those listed here. +.El +.Sh SEE ALSO +.Xr kill 2 , +.Xr sigaction 2 , +.Xr sigpending 2 , +.Xr sigsuspend 2 , +.Xr sigaddset 3 +.Sh STANDARDS +The +.Fn sigprocmask +function conforms to +.St -p1003.1-2008 . diff --git a/static/openbsd/man2/sigreturn.2 b/static/openbsd/man2/sigreturn.2 new file mode 100644 index 00000000..4ff03ca4 --- /dev/null +++ b/static/openbsd/man2/sigreturn.2 @@ -0,0 +1,86 @@ +.\" $OpenBSD: sigreturn.2,v 1.12 2016/05/09 23:57:10 guenther Exp $ +.\" $NetBSD: sigreturn.2,v 1.6 1995/02/27 12:37:40 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 9 2016 $ +.Dt SIGRETURN 2 +.Os +.Sh NAME +.Nm sigreturn +.Nd return from signal +.Sh SYNOPSIS +.Ft int +.Fn sigreturn "struct sigcontext *scp" +.Sh DESCRIPTION +The +.Fn sigreturn +syscall is used by the signal handling facility to +atomically switch stacks, restore registers and the thread's signal mask, +and return from a signal context +to resume the processing that was interrupted by the signal. +.Pp +Note that sigcontext contains machine dependent information. +.Pp +Direct use of +.Nm +is no longer supported and it is not provided as a function. +As used in the signal trampoline provided by the system, +if +.Nm +fails and returns then the process is terminated. +.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 Er +.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 sigcontext provided is invalid or would improperly +raise the privilege level of the process. +.El +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr setjmp 3 +.Sh HISTORY +The +.Fn sigreturn +function appeared in +.Bx 4.3 . +The function was removed from libc in +.Ox 6.0 . diff --git a/static/openbsd/man2/sigsuspend.2 b/static/openbsd/man2/sigsuspend.2 new file mode 100644 index 00000000..02ba8ad2 --- /dev/null +++ b/static/openbsd/man2/sigsuspend.2 @@ -0,0 +1,78 @@ +.\" $OpenBSD: sigsuspend.2,v 1.14 2017/05/29 09:40:02 deraadt Exp $ +.\" $NetBSD: sigsuspend.2,v 1.4 1995/02/27 12:37:46 cgd Exp $ +.\" +.\" 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. 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.1 (Berkeley) 6/4/93 +.\" +.Dd $Mdocdate: May 29 2017 $ +.Dt SIGSUSPEND 2 +.Os +.Sh NAME +.Nm sigsuspend +.Nd atomically change the signal mask and wait for interrupt +.Sh SYNOPSIS +.In 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 2 . +.Sh RETURN VALUES +The +.Fn sigsuspend +function always terminates by being interrupted, returning \-1 with +.Va errno +set to +.Er EINTR . +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr sigprocmask 2 , +.Xr sigaddset 3 +.Sh STANDARDS +The +.Fn sigsuspend +function call +conforms to +.St -p1003.1-2008 . diff --git a/static/openbsd/man2/socket.2 b/static/openbsd/man2/socket.2 new file mode 100644 index 00000000..ac17d321 --- /dev/null +++ b/static/openbsd/man2/socket.2 @@ -0,0 +1,308 @@ +.\" $OpenBSD: socket.2,v 1.46 2025/08/04 04:59:31 guenther Exp $ +.\" $NetBSD: socket.2,v 1.5 1995/02/27 12:37:53 cgd Exp $ +.\" +.\" 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. 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. +.\" +.\" @(#)socket.2 8.1 (Berkeley) 6/4/93 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt SOCKET 2 +.Os +.Sh NAME +.Nm socket +.Nd create an endpoint for communication +.Sh SYNOPSIS +.In 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 +.In sys/socket.h . +The currently understood formats are: +.Pp +.Bl -tag -width "AF_INET6XXX" -offset indent -compact +.It Dv AF_UNIX +UNIX internal protocols +.It Dv AF_INET +Internet Protocol version 4 (IPv4) protocol family +.It Dv AF_INET6 +Internet Protocol version 6 (IPv6) protocol family +.El +.Pp +The socket has the indicated +.Fa type , +which specifies the semantics of communication. +Currently defined types are: +.Pp +.Bl -tag -width "SOCK_SEQPACKETXXX" -offset indent -compact +.It Dv SOCK_STREAM +.It Dv SOCK_DGRAM +.It Dv SOCK_RAW +.It Dv SOCK_SEQPACKET +.El +.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 AF_UNIX . +.Dv SOCK_RAW +sockets provide access to internal network protocols and interfaces, +and are available only to the superuser. +.Pp +Any combination of the following flags may additionally be used in the +.Fa type +argument: +.Pp +.Bl -tag -width "SOCK_NONBLOCKX" -offset indent -compact +.It Dv SOCK_CLOEXEC +Set close-on-exec flag on the new descriptor. +.It Dv SOCK_CLOFORK +Set close-on-fork flag on the new descriptor. +.It Dv SOCK_NONBLOCK +Set non-blocking I/O mode on the new socket. +.It Dv SOCK_DNS +For domains +.Dv AF_INET +or +.Dv AF_INET6 , +only allow +.Xr connect 2 , +.Xr sendto 2 , +or +.Xr sendmsg 2 +to the DNS port (typically 53). +.El +.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 +.Dq communication domain +in which communication is to take place; see +.Xr protocols 5 . +A value of 0 for +.Fa protocol +will let the system select an appropriate protocol for the requested +socket type. +.Pp +Sockets of type +.Dv SOCK_STREAM +are full-duplex byte streams. +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. +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 +ensure 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 +.Er 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 an 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 +.In sys/socket.h . +.Xr setsockopt 2 +and +.Xr getsockopt 2 +are used to set and get options, respectively. +.Sh RETURN VALUES +If successful, +.Fn socket +returns a non-negative integer, the socket file descriptor. +Otherwise, a value of \-1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn socket +call fails if: +.Bl -tag -width Er +.It Bq Er EAFNOSUPPORT +The specified address family is not supported on this machine. +.It Bq Er EPROTONOSUPPORT +The protocol type or the specified protocol is not supported +within this domain. +.It Bq Er EPROTOTYPE +The combination of the specified protocol and type is not supported. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENOBUFS +Insufficient resources were available in the system +to perform the operation. +.It Bq Er EACCES +Permission to create a socket of the specified type and/or protocol +is denied. +.El +.Sh SEE ALSO +.Xr accept 2 , +.Xr bind 2 , +.Xr connect 2 , +.Xr getsockname 2 , +.Xr getsockopt 2 , +.Xr ioctl 2 , +.Xr listen 2 , +.Xr poll 2 , +.Xr read 2 , +.Xr recv 2 , +.Xr select 2 , +.Xr send 2 , +.Xr setsockopt 2 , +.Xr shutdown 2 , +.Xr socketpair 2 , +.Xr write 2 , +.Xr getprotoent 3 , +.Xr inet 4 , +.Xr inet6 4 , +.Xr netintro 4 , +.Xr unix 4 +.Rs +.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" +.%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1" +.Re +.Rs +.%T "BSD Interprocess Communication Tutorial" +.%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1" +.Re +.Sh STANDARDS +The +.Fn socket +function conforms to +.St -p1003.1-2024 . +.Pp +The +.Dv SOCK_DNS +flag is an +.Ox +extension. +.Sh HISTORY +The +.Fn socket +system call first appeared in +.Bx 4.1c . +Support for the +.Dv SOCK_CLOEXEC +and +.Dv SOCK_NONBLOCK +flags appeared in +.Ox 5.7 . +Support for the +.Dv SOCK_DNS +flag appeared in +.Ox 5.9 . diff --git a/static/openbsd/man2/socketpair.2 b/static/openbsd/man2/socketpair.2 new file mode 100644 index 00000000..7d03566e --- /dev/null +++ b/static/openbsd/man2/socketpair.2 @@ -0,0 +1,129 @@ +.\" $OpenBSD: socketpair.2,v 1.22 2025/08/04 04:59:31 guenther Exp $ +.\" $NetBSD: socketpair.2,v 1.5 1995/02/27 12:38:00 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: August 4 2025 $ +.Dt SOCKETPAIR 2 +.Os +.Sh NAME +.Nm socketpair +.Nd create a pair of connected sockets +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn socketpair "int domain" "int type" "int protocol" "int sv[2]" +.Sh DESCRIPTION +The +.Fn socketpair +call creates an unnamed pair of connected sockets. +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. +.Pp +The only supported +.Fa domain +is +.Dv AF_UNIX . +Possible values for the +.Fa type +and +.Fa protocol +arguments are explained in the +.Xr socket 2 +manual page. +The only useful value for +.Fa protocol +is 0, which will let the system select an appropriate protocol +for the requested socket +.Fa type . +.Pp +Any combination of the following flags may additionally be used in the +.Fa type +argument: +.Pp +.Bl -tag -width "SOCK_NONBLOCKX" -offset indent -compact +.It SOCK_CLOEXEC +Set close-on-exec flag on both the new descriptors. +.It SOCK_CLOFORK +Set close-on-fork flag on both the new descriptors. +.It SOCK_NONBLOCK +Set non-blocking I/O mode on both the new sockets. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The call succeeds unless: +.Bl -tag -width Er +.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 EOPNOTSUPP +The specified protocol does not support creation of socket pairs. +.It Bq Er EPROTOTYPE +The combination of the specified protocol and type is not supported. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENOBUFS +Insufficient resources were available in the system +to perform the operation. +.It Bq Er EFAULT +The address +.Fa sv +does not specify a valid part of the +process address space. +.El +.Sh SEE ALSO +.Xr pipe 2 , +.Xr read 2 , +.Xr socket 2 , +.Xr write 2 +.Sh STANDARDS +The +.Fn socketpair +function conforms to +.St -p1003.1-2024 . +.Sh HISTORY +The +.Fn socketpair +function call appeared in +.Bx 4.2 . +Support for the +.Dv SOCK_CLOEXEC +and +.Dv SOCK_NONBLOCK +flags appeared in +.Ox 5.7 . diff --git a/static/openbsd/man2/stat.2 b/static/openbsd/man2/stat.2 new file mode 100644 index 00000000..0d7d62a8 --- /dev/null +++ b/static/openbsd/man2/stat.2 @@ -0,0 +1,444 @@ +.\" $OpenBSD: stat.2,v 1.49 2021/11/21 23:44:55 jan Exp $ +.\" +.\" 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. 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.3 (Berkeley) 4/19/94 +.\" +.Dd $Mdocdate: November 21 2021 $ +.Dt STAT 2 +.Os +.Sh NAME +.Nm stat , +.Nm lstat , +.Nm fstatat , +.Nm fstat , +.Nm S_ISBLK , +.Nm S_ISCHR , +.Nm S_ISDIR , +.Nm S_ISFIFO , +.Nm S_ISLNK , +.Nm S_ISREG , +.Nm S_ISSOCK +.Nd get file status +.Sh SYNOPSIS +.In 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" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn fstatat "int fd" "const char *path" "struct stat *sb" "int flag" +.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 pathname leading to the file must be searchable. +.Pp +The +.Fn lstat +function is identical to +.Fn stat +except when the named file is a symbolic link, +in which case +.Fn lstat +returns information about the link itself, not the file the link references. +.Pp +The +.Fn fstatat +function is equivalent to either the +.Fn stat +or +.Fn lstat +function depending on the value of +.Fa flag +(see below), except that where +.Fa path +specifies a relative path, +the file whose information is returned is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn fstatat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn stat +or +.Fn lstat , +depending on whether or not the +.Dv AT_SYMLINK_NOFOLLOW +bit is set in +.Fa flag . +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the status of the symbolic link is returned. +.El +.Pp +The +.Fn fstat +function 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 +.Vt stat +structure +as defined by +.In 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 */ + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last data modification */ + struct timespec st_ctim; /* time of last file status change */ + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_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 +.Vt struct stat +are represented in +.Vt struct timespec +format, which has nanosecond precision. +However, the actual precision is generally limited by the file +system holding the file. +The fields are as follows: +.Bl -tag -width XXXst_mtim +.It Fa st_atim +Time when file data was last accessed. +Set when the file system object was created and updated by the +.Xr utimes 2 +and +.Xr read 2 +system calls. +.It Fa st_mtim +Time when file data was last modified. +Changed by the +.Xr truncate 2 , +.Xr utimes 2 , +and +.Xr write 2 +system calls. +For directories, changed by any system call that alters which files are +in the directory, such as the +.Xr unlink 2 , +.Xr rename 2 , +.Xr mkdir 2 , +and +.Xr symlink 2 +system calls. +.It Fa st_ctim +Time when file status was last changed (inode data modification). +Changed by the +.Xr chmod 2 , +.Xr chown 2 , +.Xr link 2 , +.Xr rename 2 , +.Xr unlink 2 , +.Xr utimes 2 , +and +.Xr write 2 +system calls. +.El +.Pp +In addition, all the time fields are set to the current time when +a file system object is first created by the +.Xr mkdir 2 , +.Xr mkfifo 2 , +.Xr mknod 2 , +.Xr open 2 , +and +.Xr symlink 2 +system calls. +.Pp +For compatibility with previous standards, +.Fa st_atime , +.Fa st_mtime , +and +.Fa st_ctime +macros are provided that expand to the +.Fa tv_secs +member of their respective +.Vt struct timespec +member. +Deprecated macros are also provided for some transitional names: +.Fa st_atimensec , +.Fa st_mtimensec , +.Fa st_ctimensec , +.Fa st_atimespec , +.Fa st_mtimespec , +and +.Fa st_ctimespec . +.Pp +The size-related fields of the +.Vt struct stat +are as follows: +.Bl -tag -width XXXst_blksize +.It Fa st_blksize +The optimal I/O block size for the file. +.It Fa 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 -offset indent +#define S_IFMT 0170000 /* type of file mask */ +#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_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_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 */ +.Ed +.Pp +The following macros test a file's type. +If the file is of that type, a non-zero value is returned; +otherwise, 0 is returned. +.Bd -literal -offset indent +S_ISBLK(st_mode m) /* block special */ +S_ISCHR(st_mode m) /* char special */ +S_ISDIR(st_mode m) /* directory */ +S_ISFIFO(st_mode m) /* fifo */ +S_ISLNK(st_mode m) /* symbolic link */ +S_ISREG(st_mode m) /* regular file */ +S_ISSOCK(st_mode m) /* socket */ +.Ed +.Pp +For a list of access modes, see +.In sys/stat.h , +.Xr access 2 , +and +.Xr chmod 2 . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn stat , +.Fn lstat , +and +.Fn fstatat +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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.It Bq Er ENOENT +A component of +.Fa path +does not exist or +.Fa path +is an empty string. +.It Bq Er EACCES +Search permission is denied for a component of the +.Fa path . +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the +.Fa path . +.It Bq Er EFAULT +.Fa sb +or +.Fa path +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 +Additionally, +.Fn fstatat +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_SYMLINK_NOFOLLOW . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Pp +.Fn fstat +will fail if: +.Bl -tag -width Er +.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 the file system. +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr chown 2 , +.Xr clock_gettime 2 , +.Xr utimes 2 , +.Xr symlink 7 +.Sh STANDARDS +Previous versions of the system used different types for the +.Fa st_dev , +.Fa st_uid , +.Fa st_gid , +.Fa st_rdev , +.Fa st_size , +.Fa st_blksize , +and +.Fa st_blocks +fields. +.Pp +The +.Fn fstat , +.Fn fstatat , +.Fn lstat , +and +.Fn stat +functions are intended to conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn stat +and +.Fn fstat +system calls first appeared in +.At v1 . +The +.In sys/stat.h +header file and the +.Vt "struct stat" +were introduced in +.At v7 . +.Pp +An +.Fn lstat +function call appeared in +.Bx 4.2 . +The +.Fn fstatat +function appeared in +.Ox 5.0 . +.Sh CAVEATS +The file generation number, +.Fa st_gen , +is only available to the superuser. +.Pp +Certain programs written when the timestamps were just of type +.Vt time_t +assumed that the members were consecutive (and could therefore +be treated as an array and have their address passed directly to +.Xr utime 3 ) . +The transition to timestamps of type +.Vt struct timespec +broke them irrevocably. +.Sh BUGS +Applying +.Fn fstat +to a pipe or socket +fails to fill in a unique device and inode number pair. +Applying +.Fn fstat +to a socket +also fails to fill in the time fields. diff --git a/static/openbsd/man2/statfs.2 b/static/openbsd/man2/statfs.2 new file mode 100644 index 00000000..9c371aba --- /dev/null +++ b/static/openbsd/man2/statfs.2 @@ -0,0 +1,158 @@ +.\" $OpenBSD: statfs.2,v 1.29 2022/07/30 07:19:30 jsg Exp $ +.\" $NetBSD: statfs.2,v 1.10 1995/06/29 11:40:48 cgd Exp $ +.\" +.\" 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. 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.3 (Berkeley) 2/11/94 +.\" +.Dd $Mdocdate: July 30 2022 $ +.Dt STATFS 2 +.Os +.Sh NAME +.Nm statfs , +.Nm fstatfs +.Nd get file system statistics +.Sh SYNOPSIS +.In sys/types.h +.In 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 pathname of any file within the mounted file system. +.Fa buf +is a pointer to a +.Nm statfs +structure defined as follows: +.Bd -literal +typedef struct { int32_t val[2]; } fsid_t; + +#define MFSNAMELEN 16 /* length of fs type name, including nul */ +#define MNAMELEN 90 /* length of buffer for returned name */ + +struct statfs { + u_int32_t f_flags; /* copy of mount flags */ + u_int32_t f_bsize; /* file system block size */ + u_int32_t f_iosize; /* optimal transfer block size */ + + /* unit is f_bsize */ + u_int64_t f_blocks; /* total data blocks in file system */ + u_int64_t f_bfree; /* free blocks in fs */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + + u_int64_t f_files; /* total file nodes in file system */ + u_int64_t f_ffree; /* free file nodes in fs */ + int64_t f_favail; /* free file nodes avail to non-root */ + + u_int64_t f_syncwrites; /* count of sync writes since mount */ + u_int64_t f_syncreads; /* count of sync reads since mount */ + u_int64_t f_asyncwrites; /* count of async writes since mount */ + u_int64_t f_asyncreads; /* count of async reads since mount */ + + fsid_t f_fsid; /* file system id */ + u_int32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the file system */ + u_int64_t f_ctime; /* last mount [-u] time */ + + char f_fstypename[MFSNAMELEN]; /* fs type name */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ + char f_mntfromname[MNAMELEN]; /* mounted file system */ + char f_mntfromspec[MNAMELEN]; /* special for mount request */ + union mount_info mount_info; /* per-filesystem mount options */ +}; +.Ed +.Pp +.Fn fstatfs +returns the same information about an open file referenced by descriptor +.Fa fd . +.Pp +Note that +.Fa f_fsid +will be empty unless the user is the superuser. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn statfs +fails if one or more of the following are true: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the path prefix of +.Fa path +is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 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 Er +.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 I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr df 1 , +.Xr getfsstat 2 , +.Xr mount 2 , +.Xr stat 2 +.Sh HISTORY +The +.Fn statfs +function first appeared in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/swapctl.2 b/static/openbsd/man2/swapctl.2 new file mode 100644 index 00000000..3540fd69 --- /dev/null +++ b/static/openbsd/man2/swapctl.2 @@ -0,0 +1,243 @@ +.\" $OpenBSD: swapctl.2,v 1.26 2024/06/24 14:39:28 deraadt Exp $ +.\" $NetBSD: swapctl.2,v 1.10 1998/08/29 17:11:09 mrg Exp $ +.\" +.\" Copyright (c) 1997 Matthew R. Green +.\" 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. 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 $Mdocdate: June 24 2024 $ +.Dt SWAPCTL 2 +.Os +.Sh NAME +.Nm swapctl +.Nd modify swap configuration +.Sh SYNOPSIS +.In sys/types.h +.In sys/swap.h +.In unistd.h +.Ft int +.Fn swapctl "int cmd" "const void *arg" "int misc" +.Sh DESCRIPTION +The +.Fn swapctl +function is used to add and delete swap devices, modify their configuration or +query their statistics. +.Pp +The +.Fa cmd +parameter specifies the operation to be performed. +The +.Fa arg +and +.Fa misc +parameters have different meanings, depending on the +.Fa cmd +parameter. +.Bl -item -offset indent +.It +If +.Fa cmd +is +.Dv SWAP_NSWAP , +the current number of swap devices in the system is returned. +The +.Fa arg +and +.Fa misc +parameters are ignored. +.It +If +.Fa cmd +is +.Dv SWAP_STATS , +the current statistics for swap devices are returned in the +.Fa arg +parameter. +No more than +.Fa misc +swap devices are returned. +The +.Fa arg +parameter should point to an array of at least +.Fa misc +struct swapent structures: +.Bd -literal +struct swapent { + dev_t se_dev; /* device id */ + int se_flags; /* entry flags */ + int se_nblks; /* total blocks */ + int se_inuse; /* blocks in use */ + int se_priority; /* priority */ + char se_path[PATH_MAX]; /* path to entry */ +}; +.Ed +.Pp +The flags are defined as +.Bd -literal + SWF_INUSE in use: we have swapped here + SWF_ENABLE enabled: we can swap here + SWF_BUSY busy: I/O happening here + SWF_FAKE fake: still being built +.Ed +.Pp +All but +.Dv SWAP_NSWAP +and +.Dv SWAP_STATS +require superuser privileges. +.It +If +.Fa cmd +is +.Dv SWAP_ON , +the +.Fa arg +parameter is used as a pathname of a file to enable swapping to. +The +.Fa misc +parameter is used to set the priority of this swap device. +.It +If +.Fa cmd +is +.Dv SWAP_OFF , +the +.Fa arg +parameter is used as the pathname of a file to disable swapping from. +The +.Fa misc +parameter is ignored. +.It +If +.Fa cmd +is +.Dv SWAP_CTL , +the +.Fa arg +and +.Fa misc +parameters have the same function as for the +.Dv SWAP_ON +case, except that they change the priority of a currently enabled swap device. +.El +.Pp +When swapping is enabled on a block device, the first portion of the disk is +left unused to prevent any disklabel present from being overwritten. +This space is allocated from the swap device when the +.Dv SWAP_ON +command is used. +.Sh RETURN VALUES +If the +.Fa cmd +parameter is +.Dv SWAP_NSWAP +or +.Dv SWAP_STATS , +.Fn swapctl +returns the number of swap devices, if successful. +The +.Dv SWAP_NSWAP +command is always successful. +Otherwise it returns 0 on success and \-1 on failure, +setting the global variable +.Va errno +to indicate the error. +.Sh ERRORS +.Fn swapctl +succeeds 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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.It Bq Er ENOENT +The named device does not exist. +For the +.Dv SWAP_CTL +command, the named device is not currently enabled for swapping. +.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 superuser. +.It Bq Er EBUSY +The device specified by +.Fa arg +has already been made available for swapping. +.It Bq Er EINVAL +The device configured by +.Fa arg +has insufficient size, or the +.Fa cmd +was unknown. +.It Bq Er ENXIO +The major device number of +.Fa arg +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 arg +points outside the process' allocated address space. +.It Bq Er ENOTSUP +The device specified by +.Fa arg +cannot be used for swapping. +.El +.Sh SEE ALSO +.Xr config 8 , +.Xr swapctl 8 +.Sh HISTORY +The +.Fn swapctl +function call appeared in +.Nx 1.3 . +The +.Fa se_path +member was added to +.Vt struct swapent +in +.Nx 1.4 , +when the header file was also moved from +.In vm/vm_swap.h . +.Sh AUTHORS +.An -nosplit +The current swap system was designed and implemented by +.An Matthew Green Aq Mt mrg@eterna.com.au , +with help from +.An Paul Kranenburg Aq Mt pk@NetBSD.ORG +and +.An Leo Weppelman Aq Mt leo@NetBSD.ORG , +and insights from +.An Jason R. Thorpe Aq Mt thorpej@NetBSD.ORG . diff --git a/static/openbsd/man2/symlink.2 b/static/openbsd/man2/symlink.2 new file mode 100644 index 00000000..829019f7 --- /dev/null +++ b/static/openbsd/man2/symlink.2 @@ -0,0 +1,204 @@ +.\" $OpenBSD: symlink.2,v 1.22 2021/01/03 18:10:27 rob Exp $ +.\" $NetBSD: symlink.2,v 1.7 1995/02/27 12:38:34 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: January 3 2021 $ +.Dt SYMLINK 2 +.Os +.Sh NAME +.Nm symlink , +.Nm symlinkat +.Nd make symbolic link to a file +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn symlink "const char *name1" "const char *name2" +.In fcntl.h +.In unistd.h +.Ft int +.Fn symlinkat "const char *name1" "int fd" "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 pathname; the files need not +be on the same file system, and the file specified by +.Fa name1 +need not exist at all. +.Pp +The +.Fn symlinkat +function is equivalent to +.Fn symlink +except that where +.Fa name2 +specifies a relative path, +the newly created symbolic link is created relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn symlinkat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn symlink . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The symbolic link will fail if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +A component of the +.Fa name2 +prefix is not a directory. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 +.Pp +Additionally, +.Fn symlinkat +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa name2 +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa name2 +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa name2 +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr ln 1 , +.Xr link 2 , +.Xr readlink 2 , +.Xr unlink 2 , +.Xr symlink 7 +.Sh STANDARDS +The +.Fn symlink +and +.Fn symlinkat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn symlink +system call first appeared in +.Bx 4.1c . +The +.Fn symlinkat +system call has been available since +.Ox 5.0 . diff --git a/static/openbsd/man2/sync.2 b/static/openbsd/man2/sync.2 new file mode 100644 index 00000000..91e6851b --- /dev/null +++ b/static/openbsd/man2/sync.2 @@ -0,0 +1,73 @@ +.\" $OpenBSD: sync.2,v 1.17 2022/03/31 17:27:16 naddy Exp $ +.\" $NetBSD: sync.2,v 1.4 1995/02/27 12:38:41 cgd 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. 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 +.\" +.Dd $Mdocdate: March 31 2022 $ +.Dt SYNC 2 +.Os +.Sh NAME +.Nm sync +.Nd synchronize disk block in-core status with that on disk +.Sh SYNOPSIS +.In 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 in-kernel process update +(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 sync 8 +.Sh STANDARDS +The +.Fn sync +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +A +.Fn sync +function appeared in +.At v2 . +.Sh BUGS +.Fn sync +may return before the buffers are completely flushed. diff --git a/static/openbsd/man2/sysarch.2 b/static/openbsd/man2/sysarch.2 new file mode 100644 index 00000000..c09d6d96 --- /dev/null +++ b/static/openbsd/man2/sysarch.2 @@ -0,0 +1,68 @@ +.\" $OpenBSD: sysarch.2,v 1.11 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: sysarch.2,v 1.4 1995/02/27 12:38:47 cgd Exp $ +.\" +.\" 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. 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 $Mdocdate: September 10 2015 $ +.Dt SYSARCH 2 +.Os +.Sh NAME +.Nm sysarch +.Nd architecture-dependent system call +.Sh SYNOPSIS +.In 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 +.In machine/sysarch.h . +.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. +.Sh RETURN VALUES +See the manual pages for specific architecture-dependent function calls +for information about their return values. +.Sh HISTORY +The +.Fn sysarch +function call appeared in +.Nx 0.9a . diff --git a/static/openbsd/man2/sysctl.2 b/static/openbsd/man2/sysctl.2 new file mode 100644 index 00000000..0f59ba60 --- /dev/null +++ b/static/openbsd/man2/sysctl.2 @@ -0,0 +1,2444 @@ +.\" $OpenBSD: sysctl.2,v 1.72 2026/04/04 19:26:32 jca Exp $ +.\" +.\" 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. 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 $Mdocdate: April 4 2026 $ +.Dt SYSCTL 2 +.Os +.Sh NAME +.Nm sysctl +.Nd get or set system information +.Sh SYNOPSIS +.In sys/types.h +.In sys/sysctl.h +.Ft int +.Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen" +.Sh DESCRIPTION +The +.Fn sysctl +function retrieves system information and allows processes with +appropriate privileges to set system information. +The information available from +.Fn sysctl +consists of integers, strings, and tables. +Information may be retrieved and set using the +.Xr sysctl 8 +utility; +the variable names used by this utility are given here in parentheses. +.Pp +Unless explicitly noted below, +.Fn sysctl +returns a consistent snapshot of the data requested. +Consistency is obtained by locking the destination +buffer into memory so that the data may be copied out without blocking. +Calls to +.Fn sysctl +are serialized to avoid deadlock. +.Pp +The state is described using a +.Dq Management Information Base (MIB) +style name, listed in +.Fa name , +which is a +.Fa namelen +length array of integers. +.Pp +The information is copied into the buffer specified by +.Fa oldp . +The size of the buffer is given by the location specified by +.Fa oldlenp +before the call, +and that location gives the amount of data copied after a successful call. +If the amount of data available is greater +than the size of the buffer supplied, +the call supplies as much data as fits in the buffer provided +and returns with the error code +.Er ENOMEM . +If the old value is not desired, +.Fa oldp +and +.Fa oldlenp +should be set to +.Dv NULL . +.Pp +The size of the available data can be determined by calling +.Fn sysctl +with a +.Dv NULL +parameter for +.Fa oldp . +The size of the available data will be returned in the location pointed to by +.Fa oldlenp . +For some operations, the amount of space may change often. +For these operations, +the system attempts to round up so that the returned size is +large enough for a call to return the data shortly thereafter. +.Pp +The terminating NUL character is included in the lengths of string values. +.Pp +To set a new value, +.Fa newp +is set to point to a buffer of length +.Fa newlen +from which the requested value is to be taken. +If a new value is not to be set, +.Fa newp +should be set to +.Dv NULL +and +.Fa newlen +set to 0. +.Pp +The top level names are defined with a +.Dv CTL_ +prefix in +.In sys/sysctl.h , +and are as follows. +The next and subsequent levels down are found in the include files +listed here, and described in separate sections below. +.Bl -column "CTL_MACHDEP" "ufs/ffs/ffs_extern.h" "Description" -offset indent +.It Sy "Name" Ta Sy "Next level names" Ta Sy "Description" +.It Dv CTL_DDB Ta "ddb/db_var.h" Ta "Kernel debugger" +.It Dv CTL_DEBUG Ta "sys/sysctl.h" Ta "Debugging" +.It Dv CTL_HW Ta "sys/sysctl.h" Ta "Generic CPU, I/O" +.It Dv CTL_KERN Ta "sys/sysctl.h" Ta "High kernel limits" +.It Dv CTL_MACHDEP Ta "sys/sysctl.h" Ta "Machine dependent" +.It Dv CTL_NET Ta "sys/socket.h" Ta "Networking" +.It Dv CTL_VFS Ta "ufs/ffs/ffs_extern.h" Ta "Virtual file system" +.It Dv CTL_VM Ta "uvm/uvmexp.h" Ta "Virtual memory" +.El +.Pp +For example, the following retrieves the maximum number of processes allowed +in the system: +.Bd -literal -offset indent +int mib[2], maxproc; +size_t len; + +mib[0] = CTL_KERN; +mib[1] = KERN_MAXPROC; +len = sizeof(maxproc); +if (sysctl(mib, 2, &maxproc, &len, NULL, 0) == -1) + err(1, "sysctl"); +.Ed +.Ss CTL_DDB +Integer information and settable variables are available for the +.Dv CTL_DDB level , +as described below. +More information is also available in +.Xr ddb 4 . +.Bl -column "Second level name" "integer" "Changeable" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv DBCTL_CONSOLE Ta "integer" Ta "yes" +.It Dv DBCTL_LOG Ta "integer" Ta "yes" +.It Dv DBCTL_MAXLINE Ta "integer" Ta "yes" +.It Dv DBCTL_MAXWIDTH Ta "integer" Ta "yes" +.It Dv DBCTL_PANIC Ta "integer" Ta "yes" +.It Dv DBCTL_RADIX Ta "integer" Ta "yes" +.It Dv DBCTL_TABSTOP Ta "integer" Ta "yes" +.It Dv DBCTL_TRIGGER Ta "integer" Ta "yes" +.El +.Bl -tag -width "123456" +.It Dv DBCTL_CONSOLE Pq Va ddb.console +When this variable is set, an architecture dependent magic key sequence +on the console or a debugger button will permit entry into the kernel debugger. +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be raised. +.It Dv DBCTL_LOG Pq Va ddb.log +When set, ddb output is also logged in the kernel message buffer. +.It Dv DBCTL_MAXLINE Pq Va ddb.max_line +Determines the number of lines to page in +.Xr ddb 4 . +This variable is also available as the ddb +.Dv $lines +variable. +.It Dv DBCTL_MAXWIDTH Pq Va ddb.max_width +Determines the maximum width of a line in +.Xr ddb 4 . +This variable is also available as the ddb +.Dv $maxwidth +variable. +.It Dv DBCTL_PANIC Pq Va ddb.panic +When this variable is set, system panics may drop into the kernel debugger. +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be raised. +.It Dv DBCTL_RADIX Pq Va ddb.radix +Determines the default radix or base for non-prefixed numbers +entered into +.Xr ddb 4 . +This variable is also available as the ddb +.Dv $radix +variable. +.It Dv DBCTL_TABSTOP Pq Va ddb.tab_stop_width +Width of a tab stop in +.Xr ddb 4 . +This variable is also available as the ddb +.Dv $tabstops +variable. +.It Dv DBCTL_TRIGGER Pq Va ddb.trigger +When +.Dv DBCTL_CONSOLE +is set, +writing to +.Dv DBCTL_TRIGGER +causes the system to enter +.Xr ddb 4 . +When running with a +.Xr securelevel 7 +greater than 0, +the process writing to this variable must be running +on the console in order to enter +.Xr ddb 4 . +.El +.Ss CTL_DEBUG +The debugging variables vary from system to system. +A debugging variable may be added or deleted without need to recompile +.Fn sysctl +to know about it. +Each time it runs, +.Fn sysctl +gets the list of debugging variables from the kernel and +displays their current values. +The system defines twenty +.Vt struct ctldebug +variables named +.Va debug0 +through +.Va debug19 . +They are declared as separate variables so that they can be +individually initialized at the location of their associated variable. +The loader prevents multiple use of the same variable by issuing errors +if a variable is initialized in more than one place. +For example, to export the variable +.Va dospecialcheck +as a debugging variable, the following declaration would be used: +.Bd -literal -offset indent +int dospecialcheck = 1; +struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck }; +.Ed +.Ss CTL_HW +The string and integer information available for the +.Dv CTL_HW +level is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "Second level name" "integer" "Changeable" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv HW_ALLOWPOWERDOWN Ta "integer" Ta "yes" +.It Dv HW_BATTERY Ta "node" Ta "not applicable" +.It Dv HW_BYTEORDER Ta "integer" Ta "no" +.It Dv HW_CPUSPEED Ta "integer" Ta "no" +.It Dv HW_DISKCOUNT Ta "integer" Ta "no" +.It Dv HW_DISKNAMES Ta "string" Ta "no" +.It Dv HW_DISKSTATS Ta "struct" Ta "no" +.It Dv HW_MACHINE Ta "string" Ta "no" +.It Dv HW_MODEL Ta "string" Ta "no" +.It Dv HW_NCPU Ta "integer" Ta "no" +.It Dv HW_NCPUFOUND Ta "integer" Ta "no" +.It Dv HW_NCPUONLINE Ta "integer" Ta "no" +.It Dv HW_PAGESIZE Ta "integer" Ta "no" +.It Dv HW_PERFPOLICY Ta "string" Ta "yes" +.It Dv HW_PHYSMEM Ta "integer" Ta "no" +.It Dv HW_PHYSMEM64 Ta "int64_t" Ta "no" +.It Dv HW_POWER Ta "integer" Ta "no" +.It Dv HW_PRODUCT Ta "string" Ta "no" +.It Dv HW_SENSORS Ta "node" Ta "not applicable" +.It Dv HW_SETPERF Ta "integer" Ta "yes" +.It Dv HW_SMT Ta "integer" Ta "yes" +.It Dv HW_UCOMNAMES Ta "string" Ta "no" +.It Dv HW_BLOCKCPU Ta "string" Ta "yes" +.It Dv HW_USERMEM Ta "integer" Ta "no" +.It Dv HW_USERMEM64 Ta "int64_t" Ta "no" +.It Dv HW_UUID Ta "string" Ta "no" +.It Dv HW_VENDOR Ta "string" Ta "no" +.It Dv HW_VERSION Ta "string" Ta "no" +.El +.Bl -tag -width "123456" +.It Dv HW_ALLOWPOWERDOWN Pq Va hw.allowpowerdown +Some machines generate an interrupt when the power button is pressed +and a driver can catch that interrupt. +When this variable is set, such an event will cause the system to +perform a regular shutdown and power off the machine. +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be changed. +.It Dv HW_BATTERY Pq Va hw.battery +Control battery charging. +These are only available on hardware that supports battery charging control. +There are three subnodes: +.Bl -column "HW_BATTERY_CHARGESTART" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv HW_BATTERY_CHARGEMODE Ta "integer" Ta "yes" +.It Dv HW_BATTERY_CHARGESTART Ta "integer" Ta "maybe" +.It Dv HW_BATTERY_CHARGESTOP Ta "integer" Ta "yes" +.El +.Pp +Their meanings are as follows: +.Bl -tag -width "123456" +.It Dv HW_BATTERY_CHARGEMODE Pq Va hw.battery.chargemode +Control if the battery is charged or discharged. +A value of -1 means to (forcibly) discharge the battery. +A value of 0 means to inhibit charging the battery. +A value of 1 means to charge the battery, subject to the configured limits. +.It Dv HW_BATTERY_CHARGESTART Pq Va hw.battery.chargestart +The percentage below which the battery will start charging. +Not all hardware allows setting this value. +On hardware that does not allow setting this value the battery will typically +start charging at a fixed percentage point below the value configured through +.Dv HW_BATTERY_CHARGESTOP . +.It Dv HW_BATTERY_CHARGESTOP Pq Va hw.battery.chargestop +The percentage above which the battery will stop charging. +Setting the value to 100 will fully charge the battery. +.El +.Pp +By setting +.Dv HW_BATTERY_CHARGEMODE +to 1, and setting both +.Dv HW_BATTERY_CHARGESTART +and +.Dv HW_BATTERY_CHARGESTOP , +the battery will be kept charged at a percentage between the configured limits. +.It Dv HW_BYTEORDER Pq Va hw.byteorder +The byteorder (4321 or 1234). +.It Dv HW_CPUSPEED Pq Va hw.cpuspeed +The current CPU frequency +.Pq in MHz . +.It Dv HW_DISKCOUNT Pq Va hw.diskcount +The number of disks currently attached to the system. +.It Dv HW_DISKNAMES Pq Va hw.disknames +A comma-separated list of disk names. +.It Dv HW_DISKSTATS Pq Va hw.diskstats +An array of +.Vt struct diskstats +structures containing disk statistics. +.It Dv HW_MACHINE Pq Va hw.machine +The kernel architecture as returned by +.Xr uname 1 +.Fl m +and by +.Xr machine 1 . +.It Dv HW_MODEL Pq Va hw.model +The machine model. +.It Dv HW_NCPU Pq Va hw.ncpu +The number of CPUs configured. +.It Dv HW_NCPUFOUND Pq Va hw.ncpufound +The number of CPUs found. +.It Dv HW_NCPUONLINE Pq Va hw.ncpuonline +The number of CPUs online. +.It Dv HW_PAGESIZE Pq Va hw.pagesize +The software page size. +.It Dv HW_PERFPOLICY Pq Va hw.perfpolicy +The performance policy for power management. +Can be one of +.Dq manual , +.Dq auto , +or +.Dq high . +If the policy contains a comma, the second part specifies an alternative +policy used while the system is running on battery. +The +.Nm +API only exports the currently applicable policy. +.\" XXX keep in sync with apmd(8) +The default setting is +.Dq high,auto . +.It Dv HW_PHYSMEM +The total physical memory, in bytes. +This variable is deprecated; use +.Dv HW_PHYSMEM64 +instead. +.It Dv HW_PHYSMEM64 Pq Va hw.physmem +The total physical memory, in bytes. +.It Dv HW_POWER Pq Va hw.power +Machine has wall-power. +.It Dv HW_PRODUCT Pq Va hw.product +The product name of the machine. +.It Dv HW_SENSORS Pq Va hw.sensors +Third level comprises an array of +.Vt struct sensordev +structures containing information about devices +that may attach hardware monitoring sensors. +.Pp +Third, fourth and fifth levels together comprise an array of +.Vt struct sensor +structures containing snapshot readings of hardware monitoring sensors. +In such usage, third level indicates the numerical representation +of the sensor device name to which the sensor is attached +(a device's xname and number are matched with the help of +.Vt struct sensordev +structure above), +fourth level indicates sensor type and +fifth level is an ordinal sensor number (unique to +the specified sensor type on the specified sensor device). +.Pp +The +.Sy sensordev +and +.Sy sensor +structures +and +.Sy sensor_type +enumeration +are defined in +.In sys/sensors.h . +.It Dv HW_SERIALNO Pq Va hw.serialno +The serial number of the machine. +.It Dv HW_SETPERF Pq Va hw.setperf +Current CPU performance +.Pq percentage . +It is only modifiable if +.Dv HW_PERFPOLICY +is set to +.Dq manual . +.It Dv HW_SMT Pq Va hw.smt +If set to 1, enable simultaneous multithreading (SMT) on CPUs that +support it. +Deprecated, use +.Va hw.blockcpu +instead. +.It Dv HW_BLOCKCPU Pq Va hw.blockcpu +A series of characters +.Ar ( S +(SMT), +.Ar P +(Performance core), +.Ar E +(Efficiency core), +and +.Ar L +(Lethargic, Low Power Efficiency core) +representing cpu types to avoid schedule tasks onto. +.It Dv HW_UCOMNAMES Pq Va hw.ucomnames +A comma-separated list of currently attached +.Xr ucom 4 +devices in the following format: +.Pp +.Sm off +.D1 Sy ucom Ar N : Sy usb Ar bus.rootport.route.interface +.Sm on +.Pp +The +.Ar route +consists of five hexadecimal digits identifying the path from +the root port to the port containing the +.Ar interface . +.It Dv HW_USERMEM +The amount of available non-kernel memory in bytes. +This variable is deprecated; use +.Dv HW_USERMEM64 +instead. +.It Dv HW_USERMEM64 Pq Va hw.usermem +The amount of available non-kernel memory in bytes. +.It Dv HW_UUID Pq Va hw.uuid +The universal unique identification number assigned to the machine. +.It Dv HW_VENDOR Pq Va hw.vendor +The vendor name for this machine. +.It Dv HW_VERSION Pq Va hw.version +The version or revision of this machine. +.El +.Ss CTL_KERN +The string and integer information available for the +.Dv CTL_KERN +level is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +The types of data currently available are process information, +system vnodes, the open file entries, routing table entries, +virtual memory statistics, load average history, and clock rate +information. +.Bl -column "KERN_PROC_NOBROADCASTKILL" "u_int64_t[CPUSTATES]" "no" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_ALLOWDT Ta "integer" Ta "yes" +.It Dv KERN_ALLOWKMEM Ta "integer" Ta "yes" +.It Dv KERN_ARGMAX Ta "integer" Ta "no" +.It Dv KERN_AUDIO Ta "node" Ta "yes" +.It Dv KERN_BOOTTIME Ta "struct timeval" Ta "no" +.It Dv KERN_CACHEPCT Ta "integer" Ta "yes" +.It Dv KERN_CCPU Ta "integer" Ta "no" +.It Dv KERN_CLOCKRATE Ta "struct clockinfo" Ta "no" +.It Dv KERN_CONSDEV Ta "dev_t" Ta "no" +.It Dv KERN_CPTIME Ta "long[CPUSTATES]" Ta "no" +.It Dv KERN_CPTIME2 Ta "u_int64_t[CPUSTATES]" Ta "no" +.It Dv KERN_CPUSTATS Ta "struct cpustats" Ta "no" +.It Dv KERN_DOMAINNAME Ta "string" Ta "yes" +.It Dv KERN_FILE Ta "struct kinfo_file" Ta "no" +.It Dv KERN_FORKSTAT Ta "struct forkstat" Ta "no" +.It Dv KERN_FSCALE Ta "integer" Ta "no" +.It Dv KERN_FSYNC Ta "integer" Ta "no" +.It Dv KERN_GLOBAL_PTRACE Ta "integer" Ta "yes" +.It Dv KERN_HOSTID Ta "integer" Ta "yes" +.It Dv KERN_HOSTNAME Ta "string" Ta "yes" +.It Dv KERN_INTRCNT Ta "node" Ta "not applicable" +.It Dv KERN_JOB_CONTROL Ta "integer" Ta "no" +.It Dv KERN_MALLOCSTATS Ta "node" Ta "no" +.It Dv KERN_MAXCLUSTERS Ta "integer" Ta "yes" +.It Dv KERN_MAXFILES Ta "integer" Ta "yes" +.It Dv KERN_MAXLOCKSPERUID Ta "integer" Ta "yes" +.It Dv KERN_MAXPARTITIONS Ta "integer" Ta "no" +.It Dv KERN_MAXPROC Ta "integer" Ta "yes" +.It Dv KERN_MAXTHREAD Ta "integer" Ta "yes" +.It Dv KERN_MAXVNODES Ta "integer" Ta "yes" +.It Dv KERN_MBSTAT Ta "struct mbstat" Ta "no" +.It Dv KERN_MSGBUF Ta "char[]" Ta "no" +.It Dv KERN_MSGBUFSIZE Ta "integer" Ta "no" +.It Dv KERN_NCHSTATS Ta "struct nchstats" Ta "no" +.It Dv KERN_NFILES Ta "integer" Ta "no" +.It Dv KERN_NGROUPS Ta "integer" Ta "no" +.It Dv KERN_NOSUIDCOREDUMP Ta "integer" Ta "yes" +.It Dv KERN_NPROCS Ta "integer" Ta "no" +.It Dv KERN_NTHREADS Ta "integer" Ta "no" +.It Dv KERN_NUMVNODES Ta "integer" Ta "no" +.It Dv KERN_OSRELEASE Ta "string" Ta "no" +.It Dv KERN_OSREV Ta "integer" Ta "no" +.It Dv KERN_OSTYPE Ta "string" Ta "no" +.It Dv KERN_OSVERSION Ta "string" Ta "no" +.It Dv KERN_PFSTATUS Ta "struct pf_status" Ta "no" +.It Dv KERN_POOL_DEBUG Ta "integer" Ta "yes" +.It Dv KERN_POSIX1 Ta "integer" Ta "no" +.It Dv KERN_PROC Ta "struct kinfo_proc" Ta "no" +.It Dv KERN_PROC_ARGS Ta "node" Ta "not applicable" +.It Dv KERN_PROC_CWD Ta "string" Ta "not applicable" +.It Dv KERN_PROC_NOBROADCASTKILL Ta "node" Ta "not applicable" +.It Dv KERN_PROC_VMMAP Ta "struct kinfo_vmentry" Ta "no" +.It Dv KERN_PROF Ta "node" Ta "not applicable" +.It Dv KERN_RAWPARTITION Ta "integer" Ta "no" +.It Dv KERN_SAVED_IDS Ta "integer" Ta "no" +.It Dv KERN_SECURELVL Ta "integer" Ta "raise only" +.It Dv KERN_SEMINFO Ta "node" Ta "not applicable" +.It Dv KERN_SHMINFO Ta "node" Ta "not applicable" +.It Dv KERN_SOMAXCONN Ta "integer" Ta "yes" +.It Dv KERN_SOMINCONN Ta "integer" Ta "yes" +.It Dv KERN_SPLASSERT Ta "int" Ta "yes" +.It Dv KERN_STACKGAPRANDOM Ta "integer" Ta "yes" +.It Dv KERN_SYSVIPC_INFO Ta "node" Ta "not applicable" +.It Dv KERN_SYSVMSG Ta "integer" Ta "no" +.It Dv KERN_SYSVSEM Ta "integer" Ta "no" +.It Dv KERN_SYSVSHM Ta "integer" Ta "no" +.It Dv KERN_TIMECOUNTER Ta "node" Ta "not applicable" +.It Dv KERN_TTY Ta "node" Ta "not applicable" +.It Dv KERN_TTYCOUNT Ta "integer" Ta "no" +.It Dv KERN_UTC_OFFSET Ta "integer" Ta "yes" +.It Dv KERN_VERSION Ta "string" Ta "no" +.It Dv KERN_VIDEO Ta "node" Ta "yes" +.It Dv KERN_WATCHDOG Ta "node" Ta "not applicable" +.It Dv KERN_WITNESS Ta "node" Ta "not applicable" +.It Dv KERN_WXABORT Ta "integer" Ta "yes" +.El +.Bl -tag -width "123456" +.It Dv KERN_ALLOWDT Pq Va kern.allowdt +Allow userland processes access to +.Pa /dev/dt . +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be changed. +.It Dv KERN_ALLOWKMEM Pq Va kern.allowkmem +Allow userland processes access to +.Pa /dev/mem +and +.Pa /dev/kmem . +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be changed. +.It Dv KERN_ARGMAX Pq Va kern.argmax +The maximum number of bytes allowed among the arguments to +.Xr execve 2 . +.It Dv KERN_AUDIO Pq Va kern.audio +Control device-independent aspects of the +.Xr audio 4 +subsystem. +.Bl -column "KERN_AUDIO_KBDCONTROL" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_AUDIO_RECORD Ta "integer" Ta "yes" +.It Dv KERN_AUDIO_KBDCONTROL Ta "integer" Ta "yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_AUDIO_RECORD Pq Va kern.audio.record +If set to the default value of 0, recording is muted by default +for all audio devices. +Otherwise, audio recording is enabled by default. +For individual devices, this setting can be overridden with the +.Xr mixerctl 8 +.Va record.enable +variable. +.It Dv KERN_AUDIO_KBDCONTROL Pq Va kern.audio.kbdcontrol +If set to the default value of 1, the +.Xr wskbd 4 +driver will attempt to adjust the level of the first +.Xr audio 4 +device when the volume keys of multimedia keyboards are pressed. +.El +.It Dv KERN_BOOTTIME Pq Va kern.boottime +A +.Vt struct timeval +structure is returned. +This structure contains the time that the system was booted. +.It Dv KERN_CACHEPCT Pq Va kern.bufcachepercent +The maximum percentage of DMA-reachable physical memory +the buffer cache may use. +.It Dv KERN_CCPU Pq Va kern.ccpu +The scheduler exponential decay value. +.It Dv KERN_CLOCKRATE Pq Va kern.clockrate +A +.Vt struct clockinfo +structure is returned. +This structure contains the hard clock, statistics clock and profiling clock +frequencies, and the number of microseconds per hard clock tick. +.It Dv KERN_CONSDEV Pq Va kern.consdev +The console device. +.It Dv KERN_CPTIME Pq Va kern.cp_time +An array of longs of size +.Dv CPUSTATES +is returned, containing statistics about the number of ticks spent by +the system in interrupt processing, user processes +.Po +.Xr nice 1 +or normal +.Pc , +system processing, lock spinning, or idling. +.It Dv KERN_CPTIME2 Pq Va kern.cp_time2 +Similar to +.Dv KERN_CPTIME , +but obtains information from only the single CPU specified by the +third level name given. +.It Dv KERN_CPUSTATS +A +.Vt struct cpustats +structure is returned. +This structure contains the array described in +.Dv KERN_CPTIME2 +and a bit mask indicating the status of the CPU specified by the +third level name. +.It Dv KERN_DOMAINNAME Pq Va kern.domainname +Get or set the YP domain name like with +.Xr getdomainname 3 , +.Xr setdomainname 3 , +and +.Xr domainname 1 . +.It Dv KERN_FILE Pq Va kern.file +Return the entire file table, or a subset of it. +An array of +.Vt struct kinfo_file +structures is returned, +whose size depends on the current number of selected files in the system. +The third and fourth level names are as follows: +.Bl -column "Third level name" "Fourth level is:" -offset indent +.It Sy "Third level name" Ta Sy "Fourth level is:" +.It Dv KERN_FILE_BYFILE Ta "A file type" +.It Dv KERN_FILE_BYPID Ta "A process ID" +.It Dv KERN_FILE_BYUID Ta "A user ID" +.El +.Pp +The fifth level name is the size of the +.Vt struct kinfo_file +and the sixth level name is the number of structures to return. +.It Dv KERN_FORKSTAT Pq Va kern.forkstat +A +.Vt struct forkstat +structure is returned. +This structure contains information about the number of +.Xr fork 2 , +.Xr vfork 2 , +and +.Xr __tfork 3 +system calls as well as kernel thread creations since system startup, +and the number of pages of virtual memory involved in each. +.It Dv KERN_FSCALE Pq Va kern.fscale +The kernel fixed-point scale factor. +.It Dv KERN_FSYNC Pq Va kern.fsync +Return 1 if the File Synchronisation Option is available on this system, +otherwise 0. +.It Dv KERN_GLOBAL_PTRACE Pq Va kern.global_ptrace +When set to 1, permit +.Xr ptrace 2 +to attach to any process with the appropriate privileges. +When set to 0, processes may only attach to their own descendants. +.It Dv KERN_HOSTID Pq Va kern.hostid +Get or set the host ID. +.It Dv KERN_HOSTNAME Pq Va kern.hostname +Get or set the hostname like with +.Xr gethostname 3 , +.Xr sethostname 3 , +and +.Xr hostname 1 . +.It Dv KERN_JOB_CONTROL Pq Va kern.job_control +Return 1 if job control is available on this system, otherwise 0. +.It Dv KERN_MALLOCSTATS Pq Va kern.malloc +Return kernel memory bucket statistics. +The third level names are detailed below. +There are no changeable values in this branch. +.Bl -column "KERN_MALLOC_KMEMNAMES" "string" -offset indent +.It Sy "Third level name" Ta Sy "Type" +.It Dv KERN_MALLOC_BUCKET Ta "node" +.It Dv KERN_MALLOC_BUCKETS Ta "string" +.It Dv KERN_MALLOC_KMEMNAMES Ta "string" +.It Dv KERN_MALLOC_KMEMSTATS Ta "node" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_MALLOC_BUCKET.<size> Pq Va kern.malloc.bucket +A node containing the statistics for the memory bucket of the +specified size (in decimal notation, the number of bytes per bucket +element, e.g., 16, 32, 128). +Each node returns a +.Vt struct kmembuckets . +.Pp +If a value is specified that does not correspond directly to a +bucket size, the statistics for the closest larger bucket size will be +returned instead. +.Pp +Note that bucket sizes are typically powers of 2. +.It Dv KERN_MALLOC_BUCKETS Pq Va kern.malloc.buckets +Return a comma-separated list of the bucket sizes used by the kernel. +.It Dv KERN_MALLOC_KMEMNAMES Pq Va kern.malloc.kmemnames +Return a comma-separated list of the names of the kernel +.Xr malloc 9 +types. +.It Dv KERN_MALLOC_KMEMSTATS Pq Va kern.malloc.kmemstat +A node containing the statistics for the memory types of the specified +name. +Each node returns a +.Vt struct kmemstats . +.El +.It Dv KERN_MAXCLUSTERS Pq Va kern.maxclusters +The maximum number of +.Xr mbuf 9 +clusters that may be allocated. +.It Dv KERN_MAXFILES Pq Va kern.maxfiles +The maximum number of open files that may be open in the system. +.It Dv KERN_MAXLOCKSPERUID Pq Va kern.maxlocksperuid +The maximum number of file locks per user; +the default is 1024. +.It Dv KERN_MAXPARTITIONS Pq Va kern.maxpartitions +The maximum number of partitions allowed per disk. +.It Dv KERN_MAXPROC Pq Va kern.maxproc +The maximum number of simultaneous processes the system will allow. +.It Dv KERN_MAXTHREAD Pq Va kern.maxthread +The maximum number of simultaneous threads the system will allow. +.It Dv KERN_MAXVNODES Pq Va kern.maxvnodes +The maximum number of vnodes available on the system. +.It Dv KERN_MBSTAT Pq Va kern.mbstat +A +.Vt struct mbstat +structure is returned, containing statistics on +.Xr mbuf 9 +usage. +.It Dv KERN_MSGBUF Pq Va kern.msgbuf +Returns a buffer containing kernel log messages; +see +.Xr dmesg 8 . +.It Dv KERN_MSGBUFSIZE Pq Va kern.msgbufsize +The size of the kernel message buffer. +.It Dv KERN_NCHSTATS Pq Va kern.nchstats +A +.Vt struct nchstats +structure is returned. +This structure contains information about the +filename to +.Xr inode 5 +mapping cache. +.It Dv KERN_NFILES Pq Va kern.nfiles +Number of open files. +.It Dv KERN_NGROUPS Pq Va kern.ngroups +The maximum number of supplemental groups. +.It Dv KERN_NOSUIDCOREDUMP Pq Va kern.nosuidcoredump +Whether a process may dump core after changing user or group ID: +.Bl -column "value" "condition" "current directory" +.It Sy "value" Ta Sy "condition" Ta Sy "dump core to" +.It 0 Ta "euid == 0" Ta "current directory" +.It 1 Ta "never" Ta "" +.It 2 Ta "always" Ta Pa "/var/crash" +.It 3 Ta "depends" Ta Pa "/var/crash/$programname/" +.El +.It Dv KERN_NPROCS Pq Va kern.nprocs +The number of entries in the kernel process table. +.It Dv KERN_NTHREADS Pq Va kern.nthreads +The number of entries in the kernel thread table. +.It Dv KERN_NUMVNODES Pq Va kern.numvnodes +Number of vnodes in use. +.It Dv KERN_OSRELEASE Pq Va kern.osrelease +The system release string as returned by +.Xr uname 1 +.Fl r . +.It Dv KERN_OSREV Pq Va kern.osrevision +The system revision number. +.It Dv KERN_OSTYPE Pq Va kern.ostype +The system type string as returned by +.Xr uname 1 +.Fl s ; +it is always +.Dq Ox . +.It Dv KERN_OSVERSION Pq Va kern.osversion +The kernel build version as returned by +.Xr uname 1 +.Fl v . +.It Dv KERN_PFSTATUS +The +.Vt struct pf_status +structure. +.It Dv KERN_POOL_DEBUG Pq Va kern.pool_debug +Modify the memory pool debug level. +Valid values are: +.Pp +.Bl -tag -width 3n -offset indent -compact +.It 0 +Disable pool debugging. +.It 1 +Enable use after free detection. +.It 2 +In addition to 1, when calling either +.Xr malloc 9 +or +.Xr pool_get 9 +with flags indicating that sleeping is allowed then always yield. +Useful to detect potential races. +.El +.It Dv KERN_POSIX1 Pq Va kern.posix1version +The version of ISO/IEC 9945 (POSIX 1003.1) with which the system +attempts to comply. +.It Dv KERN_PROC Pq Va kern.proc +Return the entire process table, or a subset of it. +An array of +.Vt struct kinfo_proc +structures is returned, +whose size depends on the current number of selected processes in the system. +The third and fourth level names are as follows: +.Bl -column "KERN_PROC_SESSION" "Fourth level is:" -offset indent +.It Sy "Third level name" Ta Sy "Fourth level is:" +.It Dv KERN_PROC_ALL Ta "None" +.It Dv KERN_PROC_KTHREAD Ta "A kernel thread" +.It Dv KERN_PROC_PID Ta "A process ID" +.It Dv KERN_PROC_PGRP Ta "A process group" +.It Dv KERN_PROC_RUID Ta "A real user ID" +.It Dv KERN_PROC_SESSION Ta "A session PID" +.It Dv KERN_PROC_TTY Ta "A tty device" +.It Dv KERN_PROC_UID Ta "A user ID" +.El +.Pp +The fifth level name is the size of the +.Vt struct kinfo_proc +and the sixth level name is the number of structures to return. +.It Dv KERN_PROC_ARGS Pq Va kern.procargs +Returns the arguments or environment of a process. +The third level name is the PID of the process. +The fourth level name is one of: +.Bl -column KERN_PROC_NARGV -offset indent +.It Dv KERN_PROC_ARGV +.It Dv KERN_PROC_ENV +.It Dv KERN_PROC_NARGV +.It Dv KERN_PROC_NENV +.El +.Pp +.Dv KERN_PROC_NARGV +and +.Dv KERN_PROC_NENV +return the number of elements as an +.Vt int +in the argv or env array. +.Dv KERN_PROC_ARGV +returns the argv array and +.Dv KERN_PROC_ENV +returns the environ array. +The buffer pointed to by +.Fa oldp +is filled with an array of char pointers +followed by the strings themselves. +The last char pointer is a +.Dv NULL +pointer. +.It Dv KERN_PROC_CWD Pq Va kern.proc_cwd +Return the current working directory of a process. +The third level name is the target process ID. +A NUL-terminated string is returned. +.It Dv KERN_PROC_NOBROADCASTKILL Pq Va kern.proc_nobroadcastkill +When set, a process will no longer be signaled when sending broadcast signals. +The third level name is the target process ID. +.It Dv KERN_PROC_VMMAP Pq Va kern.proc_vmmap +Return the entire process VM map entries. +An array of +.Vt struct kinfo_vmentry +structures is returned, +whose size depends on the current number of VM map entries +of the selected process. +Iteration is possible by setting the base address in the first element of +.Vt struct kinfo_vmentry . +.It Dv KERN_PROF Pq Va kern.profiling +Return profiling information about the kernel. +If the kernel is not compiled for profiling, +attempts to retrieve any of the +.Dv KERN_PROF +values will fail with +.Er EOPNOTSUPP . +The third level names for the string and integer profiling information +are detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "Third level name" "struct gmonparam" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv GPROF_COUNT Ta "u_short[]" Ta "yes" +.It Dv GPROF_FROMS Ta "u_short[]" Ta "yes" +.It Dv GPROF_GMONPARAM Ta "struct gmonparam" Ta "no" +.It Dv GPROF_STATE Ta "integer" Ta "yes" +.It Dv GPROF_TOS Ta "struct tostruct" Ta "yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv GPROF_COUNT +Array of statistical program counter counts. +.It Dv GPROF_FROMS +Array indexed by program counter of call-from points. +.It Dv GPROF_GMONPARAM +Structure giving the sizes of the above arrays. +.It Dv GPROF_STATE +Returns +.Dv GMON_PROF_ON +or +.Dv GMON_PROF_OFF +to show that profiling is running or stopped. +.It Dv GPROF_TOS +Array of +.Vt struct tostruct +describing destination of calls and their counts. +.El +.It Dv KERN_RAWPARTITION Pq Va kern.rawpartition +The raw partition of a disk (a == 0). +.It Dv KERN_SAVED_IDS Pq Va kern.saved_ids +Returns 1 if saved set-group-ID and saved set-user-ID are available. +.It Dv KERN_SECURELVL Pq Va kern.securelevel +The system security level. +This level may be raised by processes with appropriate privileges. +It may only be lowered by process 1. +.It Dv KERN_SEMINFO Pq Va kern.seminfo +Return the elements of +.Vt struct seminfo . +If the kernel is not compiled with System V style semaphore support, +attempts to retrieve any of the +.Dv KERN_SEMINFO +values will fail with +.Er EOPNOTSUPP . +The third level names for the elements of +.Vt struct seminfo +are detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "KERN_SEMINFO_SEMMNI" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_SEMINFO_SEMAEM Ta "integer" Ta "no" +.It Dv KERN_SEMINFO_SEMMNI Ta "integer" Ta "yes" +.It Dv KERN_SEMINFO_SEMMNS Ta "integer" Ta "yes" +.It Dv KERN_SEMINFO_SEMMNU Ta "integer" Ta "yes" +.It Dv KERN_SEMINFO_SEMMSL Ta "integer" Ta "yes" +.It Dv KERN_SEMINFO_SEMOPM Ta "integer" Ta "yes" +.It Dv KERN_SEMINFO_SEMUME Ta "integer" Ta "no" +.It Dv KERN_SEMINFO_SEMUSZ Ta "integer" Ta "no" +.It Dv KERN_SEMINFO_SEMVMX Ta "integer" Ta "no" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_SEMINFO_SEMAEM Pq Va kern.seminfo.semaem +The adjust on exit maximum value. +.It Dv KERN_SEMINFO_SEMMNI Pq Va kern.seminfo.semmni +The maximum number of semaphore identifiers allowed. +.It Dv KERN_SEMINFO_SEMMNS Pq Va kern.seminfo.semmns +The maximum number of semaphores allowed in the system. +.It Dv KERN_SEMINFO_SEMMNU Pq Va kern.seminfo.semmnu +The maximum number of semaphore undo structures allowed in the system. +.It Dv KERN_SEMINFO_SEMMSL Pq Va kern.seminfo.semmsl +The maximum number of semaphores allowed per ID. +.It Dv KERN_SEMINFO_SEMOPM Pq Va kern.seminfo.semopm +The maximum number of operations per +.Xr semop 2 +call. +.It Dv KERN_SEMINFO_SEMUME Pq Va kern.seminfo.semume +The maximum number of undo entries per process. +.It Dv KERN_SEMINFO_SEMUSZ Pq Va kern.seminfo.semusz +The size (in bytes) of the undo structure. +.It Dv KERN_SEMINFO_SEMVMX Pq Va kern.seminfo.semvmx +The semaphore maximum value. +.El +.It Dv KERN_SHMINFO Pq Va kern.shminfo +Return the elements of +.Vt struct shminfo . +If the kernel is not compiled with System V style shared memory support, +attempts to retrieve any of the +.Dv KERN_SHMINFO +values will fail with +.Er EOPNOTSUPP . +The third level names for the elements of +.Vt struct shminfo +are detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "KERN_SHMINFO_SHMMAX" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_SHMINFO_SHMALL Ta "integer" Ta "yes" +.It Dv KERN_SHMINFO_SHMMAX Ta "integer" Ta "yes" +.It Dv KERN_SHMINFO_SHMMIN Ta "integer" Ta "yes" +.It Dv KERN_SHMINFO_SHMMNI Ta "integer" Ta "yes" +.It Dv KERN_SHMINFO_SHMSEG Ta "integer" Ta "yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_SHMINFO_SHMALL Pq Va kern.shminfo.shmall +The maximum amount of total shared memory allowed in the system (in pages). +.It Dv KERN_SHMINFO_SHMMAX Pq Va kern.shminfo.shmmax +The maximum shared memory segment size (in bytes). +.It Dv KERN_SHMINFO_SHMMIN Pq Va kern.shminfo.shmmin +The minimum shared memory segment size (in bytes). +.It Dv KERN_SHMINFO_SHMMNI Pq Va kern.shminfo.shmmni +The maximum number of shared memory identifiers in the system. +.It Dv KERN_SHMINFO_SHMSEG Pq Va kern.shminfo.shmseg +The maximum number of shared memory segments per process. +.El +.It Dv KERN_SOMAXCONN Pq Va kern.somaxconn +Upper bound on the number of half-open connections a process can allow +to be associated with a socket, using +.Xr listen 2 . +The default value is 128. +.It Dv KERN_SOMINCONN Pq Va kern.sominconn +Lower bound on the number of half-open connections a process can allow +to be associated with a socket, using +.Xr listen 2 . +The default value is 80. +.It Dv KERN_SPLASSERT Pq Va kern.splassert +Modify the system interrupt priority level. +Valid values are: +.Pp +.Bl -tag -width 3n -offset indent -compact +.It 0 +Disable error checking. +.It 1 +Print a message if an error is detected. +.It 2 +Print a message if an error is detected, +and a stack trace if possible. +.It 3 +The same as 2, but also drop into the kernel debugger. +.El +.Pp +Any other value causes a system panic on errors. +See +.Xr splassert 9 +for more information. +.It Dv KERN_STACKGAPRANDOM Pq Va kern.stackgap_random +Sets the range of the random value added to the stack pointer on each +program execution. +The random value is added to make buffer overflow exploitation slightly +harder. +The bigger the number, the harder it is to brute force this added protection, +but it also means bigger waste of memory. +.It Dv KERN_SYSVIPC_INFO Pq Va kern.sysvipc_info +Return System V style IPC configuration and run-time information. +The third level name selects the System V style IPC facility. +.Bl -column "KERN_SYSVIPC_MSG_INFO" "struct shm_sysctl_info" -offset indent +.It Sy "Third level name" Ta Sy "Type" +.It Dv KERN_SYSVIPC_MSG_INFO Ta "struct msg_sysctl_info" +.It Dv KERN_SYSVIPC_SEM_INFO Ta "struct sem_sysctl_info" +.It Dv KERN_SYSVIPC_SHM_INFO Ta "struct shm_sysctl_info" +.El +.Bl -tag -width "123456" +.It Dv KERN_SYSVIPC_MSG_INFO +Return information on the System V style message facility. +The +.Sy msg_sysctl_info +structure is defined in +.In sys/msg.h . +.It Dv KERN_SYSVIPC_SEM_INFO +Return information on the System V style semaphore facility. +The +.Sy sem_sysctl_info +structure is defined in +.In sys/sem.h . +.It Dv KERN_SYSVIPC_SHM_INFO +Return information on the System V style shared memory facility. +The +.Sy shm_sysctl_info +structure is defined in +.In sys/shm.h . +.El +.It Dv KERN_SYSVMSG Pq Va kern.sysvmsg +Returns 1 if System V style message queue functionality is available on this +system, otherwise 0. +.It Dv KERN_SYSVSEM Pq Va kern.sysvem +Returns 1 if System V style semaphore functionality is available on this +system, otherwise 0. +.It Dv KERN_SYSVSHM Pq Va kern.sysvshm +Returns 1 if System V style shared memory functionality is available on this +system, otherwise 0. +.It Dv KERN_TIMECOUNTER Pq Va kern.timecounter +Return statistics information about the kernel time counter. +The third level names information is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "KERN_TIMECOUNTER_TIMESTEPWARNINGS" "integer" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_TIMECOUNTER_CHOICE Ta "string" Ta "no" +.It Dv KERN_TIMECOUNTER_HARDWARE Ta "string" Ta "yes" +.It Dv KERN_TIMECOUNTER_TICK Ta "integer" Ta "no" +.It Dv KERN_TIMECOUNTER_TIMESTEPWARNINGS Ta "integer" Ta "yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_TIMECOUNTER_CHOICE Pq Va kern.timecounter.choice +Get the list of kernel time counter sources and their claimed +quality (higher is better). +.It Dv KERN_TIMECOUNTER_HARDWARE Pq Va kern.timecounter.hardware +Get or set the kernel time counter source by name. +.It Dv KERN_TIMECOUNTER_TICK Pq Va kern.timecounter.tick +Get the number of times we have reset the kernel time counter +information. +.It Dv KERN_TIMECOUNTER_TIMESTEPWARNINGS Pq Va kern.timecounter.timestepwarnings +Get or set a flag to log a message when the kernel time is +stepped. +.El +.It Dv KERN_TTY Pq Va kern.tty +Return statistics information about tty input/output. +The third level names information is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "KERN_TTY_TKRAWCC" "struct itty" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_TTY_INFO Ta "struct itty" Ta "no" +.It Dv KERN_TTY_TKCANCC Ta "int64_t" Ta "no" +.It Dv KERN_TTY_TKNIN Ta "int64_t" Ta "no" +.It Dv KERN_TTY_TKNOUT Ta "int64_t" Ta "no" +.It Dv KERN_TTY_TKRAWCC Ta "int64_t" Ta "no" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_TTY_INFO Pq Va kern.tty.ttyinfo +Returns an array of +.Vt struct itty +structures containing tty statistics. +.It Dv KERN_TTY_TKCANCC Pq Va kern.tty.tk_cancc +Returns the number of input characters in canonical mode. +.It Dv KERN_TTY_TKNIN Pq Va kern.tty.tk_nin +Returns the number of input characters from a +.Xr tty 4 . +.It Dv KERN_TTY_TKNOUT Pq Va kern.tty.tk_nout +Returns the number of output characters on a +.Xr tty 4 . +.It Dv KERN_TTY_TKRAWCC Pq Va kern.tty.tk_rawcc +Returns the number of input characters in raw mode. +.El +.It Dv KERN_TTYCOUNT Pq Va kern.ttycount +Number of available +.Xr tty 4 +devices. +.It Dv KERN_UTC_OFFSET Pq Va kern.utc_offset +The real-time clock's +.Pq RTC +offset from +Coordinated Universal Time +.Pq UTC +expressed as minutes East of UTC+0. +When set, +time read from the RTC is adjusted to remove the offset +and time written to the RTC is adjusted to reapply it. +This may simplify multibooting with an operating system that +does not run the RTC in UTC mode. +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be changed. +.It Dv KERN_VERSION Pq Va kern.version +The system version string. +.It Dv KERN_VIDEO Pq Va kern.video +Control device-independent aspects of the +.Xr video 4 +subsystem. +Currently, there is one subnode: +.Bl -column "KERN_VIDEO_RECORD" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_VIDEO_RECORD Ta "integer" Ta "yes" +.El +.Pp +Its meaning is as follows: +.Bl -tag -width "123456" +.It Dv KERN_VIDEO_RECORD Pq Va kern.video.record +If set to the default value of 0, recording is blanked for all video devices. +If the value is non-zero, video recording is enabled. +.El +.It Dv KERN_WATCHDOG Pq Va kern.watchdog +Return information on hardware watchdog timers. +If the kernel does not support a hardware watchdog timer, +attempts to retrieve or set any of the +.Dv KERN_WATCHDOG +values will fail with +.Er EOPNOTSUPP . +.Bl -column "KERN_WATCHDOG_PERIOD" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_WATCHDOG_AUTO Ta "integer" Ta "yes" +.It Dv KERN_WATCHDOG_PERIOD Ta "integer" Ta "yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_WATCHDOG_AUTO Pq Va kern.watchdog.auto +If set to 1, the kernel refreshes the watchdog timer periodically. +If set to 0, a userland process must ensure that the watchdog timer +gets refreshed by setting the +.Dv KERN_WATCHDOG_PERIOD +variable. +.It Dv KERN_WATCHDOG_PERIOD Pq Va kern.watchdog.period +The period of the watchdog timer in seconds. +Set to 0 to disable the watchdog timer. +.El +.It Dv KERN_WITNESS Pq Va kern.witness +Control settings of +.Xr witness 4 . +.Bl -column "KERN_WITNESS_LOCKTRACE" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv KERN_WITNESS_LOCKTRACE Ta "integer" Ta "yes" +.It Dv KERN_WITNESS_WATCH Ta "integer" Ta "yes" +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Dv KERN_WITNESS_LOCKTRACE Pq Va kern.witness.locktrace +When set, +.Xr witness 4 +saves a stack trace on each lock acquisition. +The stack traces of acquired locks can be viewed using +.Xr ddb 4 . +.It Dv KERN_WITNESS_WATCH Pq Va kern.witness.watch +Control how +.Xr witness 4 +behaves on error. +Valid values are: +.Pp +.Bl -tag -width 3n -offset indent -compact +.It -1 +Disable +.Xr witness 4 +completely. +System reboot is needed to re-enable it. +.It 0 +Disable lock order checking. +.It 1 +Print a message if an error is detected. +.It 2 +Print a message if an error is detected, +and a stack trace if possible. +.It 3 +The same as 2, but also drop into the kernel debugger. +.El +.El +.It Dv KERN_WXABORT Pq Va kern.wxabort +Generate an abort, +rather than returning an error, +on W^X violation. +.El +.Ss CTL_MACHDEP +The set of variables defined is architecture dependent. +Most architectures define at least the following variables. +.Bl -column "Second level name" "dev_t" "Changeable" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv CPU_CONSDEV Ta "dev_t" Ta "no" +.El +.Pp +Consult the example file +.Pa /etc/examples/sysctl.conf +for a non-exhaustive list of +.Va machdep +variables. +.Ss CTL_NET +The string and integer information available for the +.Dv CTL_NET +level is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "Second level name" "routing messages" "Changeable" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv PF_ROUTE Ta "routing messages" Ta "no" +.It Dv PF_INET Ta "IPv4 values" Ta "yes" +.It Dv PF_INET6 Ta "IPv6 values" Ta "yes" +.It Dv PF_UNIX Ta "UNIX-domain values" Ta "yes" +.It Dv PF_KEY Ta "key management" Ta "no" +.It Dv PF_MPLS Ta "MPLS values" Ta "yes" +.It Dv PF_PIPEX Ta "PIPEX values" Ta "yes" +.El +.Bl -tag -width "123456" +.It Dv PF_ROUTE +Return the entire routing table or a subset of it. +The data is returned as a sequence of routing messages (see +.Xr route 4 +for the header file, format, and meaning). +The length of each message is contained in the message header. +.Pp +The third level name is a protocol number, which is currently always 0. +The fourth level name is an address family, which may be set to 0 to +select all address families. +The fifth and sixth level names are as follows: +.Bl -column "Fifth level name" "Sixth level is:" -offset indent +.It Sy "Fifth level name" Ta Sy "Sixth level is:" +.It Dv NET_RT_DUMP Ta "priority" +.It Dv NET_RT_FLAGS Ta "rtflags" +.It Dv NET_RT_IFLIST Ta "None" +.It Dv NET_RT_IFNAMES Ta "None" +.It Dv NET_RT_STATS Ta "None" +.It Dv NET_RT_TABLE Ta "rtableid" +.El +.Bl -tag -width "123456" +.It Dv NET_RT_DUMP +If set to 0, show all routes. +If set to any number, show all routes with that number priority. +If set to a negative number, show routes that do not have the positive +priority value. +.El +.Pp +An optional seventh level name can be provided to select the routing table +on which to run the operation. +If not provided, the current routing table is used. +.It Dv PF_INET +Get or set various global information about IPv4 +.Pq Internet Protocol version 4 . +The third level name is the protocol. +The fourth level name is the variable name. +The currently defined protocols and names are: +.Bl -column "Protocol name" "ipsec-expire-acquire" "structure" "Changeable" -offset 2n +.It Sy "Protocol name" Ta Sy "Variable name" Ta Sy "Type" Ta Sy "Changeable" +.It ah Ta enable Ta integer Ta yes +.It bpf Ta bufsize Ta integer Ta yes +.It bpf Ta maxbufsize Ta integer Ta yes +.It carp Ta allow Ta integer Ta yes +.It carp Ta log Ta integer Ta yes +.It carp Ta preempt Ta integer Ta yes +.It divert Ta recvspace Ta integer Ta yes +.It divert Ta sendspace Ta integer Ta yes +.It esp Ta enable Ta integer Ta yes +.It esp Ta udpencap Ta integer Ta yes +.It esp Ta udpencap_port Ta integer Ta yes +.It etherip Ta allow Ta integer Ta yes +.It gre Ta allow Ta integer Ta yes +.It gre Ta wccp Ta integer Ta yes +.It icmp Ta bmcastecho Ta integer Ta yes +.It icmp Ta errppslimit Ta integer Ta yes +.It icmp Ta maskrepl Ta integer Ta yes +.It icmp Ta rediraccept Ta integer Ta yes +.It icmp Ta redirtimeout Ta integer Ta yes +.It icmp Ta stats Ta structure Ta no +.It icmp Ta tstamprepl Ta integer Ta yes +.It ip Ta arpqueued Ta integer Ta no +.It ip Ta arpdown Ta integer Ta yes +.It ip Ta arptimeout Ta integer Ta yes +.It ip Ta arpq Ta node Ta "N/A" +.It ip Ta directed-broadcast Ta integer Ta yes +.It ip Ta encdebug Ta integer Ta yes +.It ip Ta forwarding Ta integer Ta yes +.It ip Ta ipsec-allocs Ta integer Ta yes +.It ip Ta ipsec-auth-alg Ta string Ta yes +.It ip Ta ipsec-bytes Ta integer Ta yes +.It ip Ta ipsec-comp-alg Ta string Ta yes +.It ip Ta ipsec-enc-alg Ta string Ta yes +.It ip Ta ipsec-expire-acquire Ta integer Ta yes +.It ip Ta ipsec-firstuse Ta integer Ta yes +.It ip Ta ipsec-invalid-life Ta integer Ta yes +.It ip Ta ipsec-pfs Ta integer Ta yes +.It ip Ta ipsec-soft-allocs Ta integer Ta yes +.It ip Ta ipsec-soft-bytes Ta integer Ta yes +.It ip Ta ipsec-soft-firstuse Ta integer Ta yes +.It ip Ta ipsec-soft-timeout Ta integer Ta yes +.It ip Ta ipsec-timeout Ta integer Ta yes +.It ip Ta maxqueue Ta integer Ta yes +.It ip Ta mforwarding Ta integer Ta yes +.It ip Ta mtudisc Ta integer Ta yes +.It ip Ta mtudisctimeout Ta integer Ta yes +.It ip Ta multipath Ta integer Ta yes +.It ip Ta portfirst Ta integer Ta yes +.It ip Ta porthifirst Ta integer Ta yes +.It ip Ta porthilast Ta integer Ta yes +.It ip Ta portlast Ta integer Ta yes +.It ip Ta redirect Ta integer Ta yes +.It ip Ta sourceroute Ta integer Ta yes +.It ip Ta stats Ta structure Ta no +.It ip Ta ttl Ta integer Ta yes +.It ipcomp Ta enable Ta integer Ta yes +.It ipip Ta allow Ta integer Ta yes +.It tcp Ta ackonpush Ta integer Ta yes +.It tcp Ta always_keepalive Ta integer Ta yes +.It tcp Ta baddynamic Ta array Ta yes +.It tcp Ta ecn Ta integer Ta yes +.It tcp Ta ident Ta structure Ta no +.It tcp Ta keepidle Ta integer Ta yes +.It tcp Ta keepinittime Ta integer Ta yes +.It tcp Ta keepintvl Ta integer Ta yes +.It tcp Ta mssdflt Ta integer Ta yes +.It tcp Ta reasslimit Ta integer Ta yes +.It tcp Ta rfc1323 Ta integer Ta yes +.It tcp Ta rfc3390 Ta integer Ta yes +.It tcp Ta rootonly Ta array Ta yes +.It tcp Ta rstppslimit Ta integer Ta yes +.It tcp Ta sack Ta integer Ta yes +.It tcp Ta stats Ta structure Ta no +.It tcp Ta synbucketlimit Ta integer Ta yes +.It tcp Ta syncachelimit Ta integer Ta yes +.It tcp Ta synhashsize Ta integer Ta yes +.It tcp Ta synuselimit Ta integer Ta yes +.It tcp Ta tso Ta integer Ta yes +.It udp Ta baddynamic Ta array Ta yes +.It udp Ta checksum Ta integer Ta yes +.It udp Ta recvspace Ta integer Ta yes +.It udp Ta rootonly Ta array Ta yes +.It udp Ta sendspace Ta integer Ta yes +.It udp Ta stats Ta structure Ta no +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Li ah.enable Pq Va net.inet.ah.enable +If set to 1, enable the Authentication Header +.Pq AH +IPsec protocol. +Enabled by default. +See +.Xr ipsec 4 +for more information. +.It Li bpf.bufsize Pq Va net.bpf.bufsize +The initial size of +.Xr bpf 4 +buffers. +.It Li bpf.maxbufsize Pq Va net.bpf.maxbufsize +The maximum size a user may request a +.Xr bpf 4 +buffer to be. +.It Li carp.allow Pq Va net.inet.carp.allow +If set to 0, incoming +.Xr carp 4 +packets will not be processed. +If set to any other value, processing will occur. +Enabled by default. +.It Li carp.log Pq Va net.inet.carp.log +Controls the verbosity of +.Xr carp 4 +logging. +May be a value between 0 and 7 corresponding with +.Xr syslog 3 +priorities. +The default value is 2. +.It Li carp.preempt Pq Va net.inet.carp.preempt +If set to 0, +.Xr carp 4 +will not attempt to become master if it is receiving advertisements from +another active master. +If set to any other value, carp will become master of the virtual host if it +believes it can send advertisements more frequently than the current master. +Disabled by default. +.It Li divert.recvspace Pq Va net.inet.divert.recvspace +Returns the default divert receive buffer size. +.It Li divert.sendspace Pq Va net.inet.divert.sendspace +Returns the default divert send buffer size. +.It Li esp.enable Pq Va net.inet.esp.enable +If set to 1, enable the Encapsulating Security Payload +.Pq ESP +IPsec protocol. +Enabled by default. +See +.Xr ipsec 4 +for more information. +.It Li esp.udpencap Pq Va net.inet.esp.udpencap +If set to 1, enable processing of UDP encapsulated ESP packets. +Enabled by default. +.It Li esp.udpencap_port Pq Va net.inet.udpencap_port +Contains the value of the UDP port that triggers +decapsulation for incoming UDP encapsulated ESP packets. +The default port is 4500. +.It Li etherip.allow Pq Va net.inet.etherip.allow +If set to 0, incoming Ethernet-in-IPv4 packets will not be processed. +If set to any other value, processing will occur. +.It Li gre.allow Pq Va net.inet.gre.allow +If set to 0, incoming GRE packets will not be processed. +If set to any other value, processing will occur. +.It Li gre.wccp Pq Va net.inet.gre.wccp +If set to 0, incoming WCCPv1-style GRE packets will not be processed. +If set to any other value, and gre.allow allows GRE packet processing, +WCCPv1-style GRE packets will be processed. +.It Li icmp.bmcastecho Pq Va net.inet.icmp.bmcastecho +If set to 1, respond to ICMP echo requests destined for +broadcast and multicast addresses. +Note, enabling this could open a system to a type of denial of service attack +called +.Qq smurfing , +and is thus not advised. +.It Li icmp.errppslimit Pq Va net.inet.icmp.errppslimit +This variable specifies the maximum number of outgoing ICMP error messages +per second. +ICMP error messages exceeding this value are subject to rate limitation +and will not go out from the node. +A negative value disables rate limitation. +.It Li icmp.maskrepl Pq Va kern.inet.icmp.maskrepl +Returns 1 if ICMP network mask requests are to be answered. +.It Li icmp.rediraccept Pq Va kern.inet.icmp.rediraccept +If set to non-zero, the host will accept ICMP redirect packets. +Note that routers will never accept ICMP redirect packets, +and the variable is meaningful on IP hosts only. +.It Li icmp.redirtimeout Pq Va net.inet.icmp.redrttimeout +This variable specifies the lifetime of routing entries generated by incoming +ICMP redirects. +The default timeout is 10 minutes. +.It Li icmp.stats Pq Va kern.inet.icmp.stats +Returns the ICMP statistics in a struct icmpstat. +.It Li icmp.tstamprepl Pq Va net.inet.icmp.tstamprepl +If set to 1, reply to ICMP timestamp requests. +If set to 0, ignore timestamp requests. +.It Li ip.arpqueued Pq Va net.inet.ip.arpqueued +Number of packets ARP resolution is holding onto until it gets a MAC +address for an IP. +.It Li ip.arpdown Pq Va net.inet.ip.arpdown +Lifetime of unresolved ARP entries, in seconds. +.It Li ip.arptimeout Pq Va net.inet.ip.arptimeout +Lifetime of resolved ARP entries, in seconds. +.It Li ip.arpq +Fifth level comprises an array of +.Vt struct ifqueue +structures containing information about ARP queue. +The fifth level names for the elements of +.Vt struct ifqueue +are detailed below. +.Bl -column "Fifth level name" "integer" "Changeable" -offset indent +.It Sy "Fifth level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv IFQCTL_DROPS Ta "integer" Ta "no" +.It Dv IFQCTL_LEN Ta "integer" Ta "no" +.It Dv IFQCTL_MAXLEN Ta "integer" Ta "yes" +.El +.Pp +The variables are as follows: +.Pp +.Bl -tag -width Ds -compact +.It Dv IFQCTL_DROPS Pq Va net.inet.ip.arpq.drops +Returns number of packet dropped. +.It Dv IFQCTL_LEN Pq Va net.inet.ip.arpq.len +Returns the current queue length. +.It Dv IFQCTL_MAXLEN Pq Va net.inet.ip.arpq.maxlen +Get or set the maximum number of queue length. +.El +.It Li ip.directed-broadcast Pq Va net.inet.ip.directed-broadcast +Returns 1 if directed broadcast behavior is enabled for the host. +.It Li ip.encdebug Pq Va net.inet.ip.encdebug +Returns 1 when error message reporting is enabled for the host. +If the kernel has been compiled with the +.Dv ENCDEBUG +option, +then debugging information will also be reported when this variable is set. +.It Li ip.forwarding Pq Va net.inet.ip.forwarding +If set to 0, IP forwarding is disabled. +The IP stack also requires the destination IP address of incoming packets +to match the IP address of the network interface the packet is bound to. +If set to 1, IP forwarding is enabled for the host, +indicating the host is acting as a router. +If set to 2, IP forwarding is restricted to traffic that has been +IPsec encapsulated or decapsulated by the host. +Enabling packet forwarding (values either 1 or 2) relaxes the requirements +on incoming packets, +so that its destination address must match just any IP address +bound to the host. +The default value is 0. +.It Li ip.ipsec-allocs Pq Va net.inet.ip.ipsec-allocs +The number of IPsec flows that can use a security association before +it expires. +If set to less than or equal to zero, the security association will not +expire because of this counter. +The default value is 0. +.It Li ip.ipsec-auth-alg Pq Va net.inet.ip.ipsec-auth-alg +This is the default authentication algorithm the kernel will instruct +key management daemons to negotiate when establishing security +associations on behalf of the kernel. +Such security associations can occur as a result of a process having +requested some security level through +.Xr setsockopt 2 , +or as a result of dynamic VPN entries. +Supported values are hmac-md5, hmac-sha1, and hmac-ripemd160. +If set to any other value, it is left to the key management daemons to +select an authentication algorithm for the security association. +The default value is hmac-sha1. +.It Li ip.ipsec-bytes Pq Va net.inet.ip.ipsec-bytes +The number of bytes that will be processed by a security association +before it expires. +If set to less than or equal to zero, the security association will not +expire because of this counter. +The default value is 0. +.It Li ip.ipsec-comp-alg Pq Va net.inet.ip.ipsec-comp-alg +The compression algorithm to use with an IP Compression Association +.Pq IPCA . +Currently the only possible value is +.Dq deflate . +.It Li ip.ipsec-enc-alg Pq Va net.inet.ip.ipsec-enc-alg +This is the default encryption algorithm the kernel will instruct key +management daemons to negotiate when establishing security +associations on behalf of the kernel. +Such security associations can occur as a result of a process having +requested some security level through +.Xr setsockopt 2 , +or as a result of dynamic VPN entries. +Supported values are aes, des, 3des, blowfish and cast128. +If set to any other value, it is left to the key management daemons to +select an encryption algorithm for the security association. +The default value is aes. +.It Li ip.ipsec-expire-acquire Pq Va net.inet.ip.ipsec-expire-acquire +How long the kernel should allow key management to dynamically acquire +security associations before re-sending a request. +The default value is 30 seconds. +.It Li ip.ipsec-firstuse Pq Va net.inet.ip.ipsec-firstuse +The number of seconds after a security association is first used before +it expires. +If set to less than or equal to zero, the security association will +not expire because of this timer. +The default value is 7200 seconds. +.It Li ip.ipsec-invalid-life Pq Va net.inet.ip.ipsec-invalid-life +The lifetime of embryonic Security Associations (SAs that key management +daemons have reserved but not fully established yet) in seconds. +If set to less than or equal to zero, embryonic SAs will not expire. +The default value is 60. +.It Li ip.ipsec-pfs Pq Va net.inet.ip.ipsec-pfs +If set to any non-zero value, the kernel will ask the key management +daemons to use Perfect Forward Secrecy when establishing IPsec +Security Associations. +Perfect Forward Secrecy makes IPsec Security Associations +cryptographically distinct from each other, such that breaking the key +for one such SA does not compromise any others. +Requiring PFS for every security association significantly increases the +computational load of +.Xr isakmpd 8 +exchanges. +The default value is 1. +.It Li ip.ipsec-soft-allocs Pq Va net.inet.ip.ipsec-soft-allocs +The number of IPsec flows that can use a security association before a +message is sent by the kernel to key management for renegotiation +of the security association. +If set to less than or equal to zero, no message is sent to key +management. +The default value is 0. +.It Li ip.ipsec-soft-bytes Pq Va net.inet.ip.ipsec-soft-bytes +The number of bytes that will be processed by a security association +before a message is sent by the kernel to key management for +renegotiation of the security association. +If set to less than or equal to zero, no message is sent to key +management. +The default value is 0. +.It Li ip.ipsec-soft-firstuse Pq Va net.inet.ip.ipsec-soft-firstuse +The number of seconds after a security association is first used +before a message is sent by the kernel to key management for +renegotiation of the security association. +If set to less than or equal to zero, no message is sent to key +management. +The default value is 3600 seconds. +.It Li ip.ipsec-soft-timeout Pq Va net.inet.ip.ipsec-soft-timeout +The number of seconds after a security association is established +before a message is sent by the kernel to key management for +renegotiation of the security association. +If set to less than or equal to zero, no message is sent to key +management. +The default value is 80000 seconds. +.It Li ip.ipsec-timeout Pq Va net.inet.ip.ipsec-timeout +The number of seconds after a security association is established +before it will expire. +If set to less than or equal to zero, the security association will +not expire because of this timer. +The default value is 86400 seconds. +.It Li ip.maxqueue Pq Va net.inet.ip.maxqueue +Fragment flood protection. +Sets the maximum number of unassembled IP fragments in the fragment queue. +.It Li ip.mforwarding Pq Va net.inet.ip.mforwarding +If set to 1, then multicast forwarding is enabled for the host. +The default is 0. +.It Li ip.mtudisc Pq Va net.inet.ip.mtudisc +Returns 1 if Path MTU Discovery is enabled. +.It Li ip.mtudisctimeout Pq Va net.inet.ip.mtudisctimeout +Number of seconds in which a route added by the Path MTU +Discovery engine will time out. +When the route times out, the Path MTU Discovery engine will attempt +to probe a larger path MTU. +.It Li ip.multipath Pq Va net.inet.ip.multipath +This variable enables multipath routing for IPv4 addresses. +If set to 0, only the first route selected will be used for a given +destination regardless of how many routes exist in the routing table. +.It Li ip.portfirst Pq Va net.inet.ip.portfirst +Minimum registered port number for TCP/UDP port allocation. +Registered ports can be used by ordinary user processes +or programs executed by ordinary users. +Cannot be less than 1024 or greater than 49151. +Must be less than ip.portlast. +.It Li ip.porthifirst Pq Va net.inet.ip.porthifirst +Minimum dynamic/private port number for TCP/UDP port allocation. +Dynamic/private ports can be used by ordinary user processes +or programs executed by ordinary users. +Cannot be less than 49152 or greater than 65535. +Must be less than ip.porthilast. +.It Li ip.porthilast Pq Va net.inet.ip.porthilast +Maximum dynamic/private port number for TCP/UDP port allocation. +Dynamic/private ports can be used by ordinary user processes +or programs executed by ordinary users. +Cannot be less than 49152 or greater than 65535. +Must be greater than ip.porthifirst. +.It Li ip.portlast Pq Va net.inet.ip.portlast +Maximum registered port number for TCP/UDP port allocation. +Registered ports can be used by ordinary user processes +or programs executed by ordinary users. +Cannot be less than 1024 or greater than 49151. +Must be greater than ip.portfirst. +.It Li ip.redirect Pq Va net.inet.ip.redirect +Returns 1 when ICMP redirects may be sent by the host. +This option is ignored unless the host is routing IP packets, +and should normally be enabled on all systems. +.It Li ip.sourceroute Pq Va net.inet.ip.sourceroute +Returns 1 when forwarding of source-routed packets is enabled for +the host. +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be changed. +.It Li ip.stats Pq Va net.inet.ip.stats +Returns the IP statistics in a struct ipstat. +.It Li ip.ttl Pq Va net.inet.ip.ttl +The maximum time-to-live (hop count) value for an IP packet +sourced by the system. +This value applies to normal transport protocols, not to ICMP. +.It Li ipcomp.enable Pq Va net.inet.ipcomp.enable +Enable the IPComp protocol. +See +.Xr ipcomp 4 +for more information. +.It Li ipip.allow Pq Va net.inet.ipip.allow +If set to 0, incoming IP-in-IP packets will not be processed. +If set to any other value, processing will occur; furthermore, if set +to 2, no checks for spoofing of loopback addresses will be done. +This is useful only for debugging purposes, and should never be used +in production systems. +.It Li tcp.ackonpush Pq Va net.inet.tcp.ackonpush +Returns 1 if TCP segments with the +.Dv TH_PUSH +flag set are being acknowledged immediately, otherwise 0. +.It Li tcp.baddynamic Pq Va net.inet.tcp.baddynamic +An array of +.Vt in_port_t +is returned specifying the bitmask of TCP ports between 512 +and 1023 inclusive that should not be allocated dynamically +by the kernel (i.e., they must be bound specifically by port number). +.It Li tcp.ecn Pq Va net.inet.tcp.ecn +Returns 1 if Explicit Congestion Notifications for TCP are enabled. +.It Li tcp.ident Pq Va net.inet.tcp.ident +A +.Vt struct tcp_ident_mapping +specifying a local and foreign endpoint of a TCP +socket is filled in with the effective and real UIDs of the process that +owns the socket. +If no such socket exists, then the effective and real UID values are +both set to \-1. +.It Li tcp.keepidle Pq Va net.inet.tcp.keepidle +If the socket option +.Dv SO_KEEPALIVE +has been set on a socket, then this value specifies how much time in seconds +a connection needs to be idle before keepalives are sent. +.It Li tcp.keepinittime Pq Va net.inet.tcp.keepinittime +Time in seconds to keep alive the initial SYN packet of a TCP handshake. +.It Li tcp.keepintvl Pq Va net.inet.tcp.keepintvl +Time in seconds after a keepalive probe is sent until, in the absence of any +response, another probe is sent. +.It Li tcp.always_keepalive Pq Va net.inet.tcp.always_keepalive +Act as if the option +.Dv SO_KEEPALIVE +was set on all TCP sockets. +.It Li tcp.mssdflt Pq Va net.inet.tcp.mssdflt +The maximum segment size that is used as default for non-local connections. +The default value is 512. +.It Li tcp.reasslimit Pq Va net.inet.tcp.reasslimit +The maximum number of out-of-order TCP +segments the system will store for reassembly. +.It Li tcp.rfc1323 Pq Va net.inet.tcp.rfc1323 +Returns 1 if RFC 1323 extensions to TCP are enabled. +.It Li tcp.rfc3390 Pq Va net.inet.tcp.rfc3390 +Returns 1 if the TCP Initial Window +is increased to 4 * MSS or 4380 bytes, as specified in RFC 3390. +Returns 2 if the TCP Initial Window +is increased to 10 * MSS or 14600 bytes, as specified in +RFC 6928. +.It Li tcp.rootonly Pq Va net.inet.tcp.rootonly +An array of +.Vt in_port_t +is returned specifying the bitmask of TCP ports +that can only be bound by processes with root euid. +When running with a +.Xr securelevel 7 +greater than 0, +this variable may not be changed. +.It Li tcp.rstppslimit Pq Va net.inet.tcp.rstppslimit +This variable specifies the maximum number of outgoing TCP RST packets +per second. +TCP RST packets exceeding this value are subject to rate limitation +and will not go out from the node. +A negative value disables rate limitation. +.It Li tcp.sack Pq Va net.inet.tcp.sack +Returns 1 if RFC 2018 Selective Acknowledgements are enabled. +.It Li tcp.stats Pq Va net.inet.tcp.stats +Returns the TCP statistics in a struct tcpstat. +.It Li tcp.synbucketlimit Pq Va net.inet.tcp.synbucketlimit +The maximum number of entries allowed per hash bucket in the TCP SYN cache. +.It Li tcp.syncachelimit Pq Va net.inet.tcp.syncachelimit +The maximum number of entries allowed in the TCP SYN cache. +.It Li tcp.synhashsize Pq Va net.inet.tcp.synhashsize +The number of buckets in the TCP SYN cache hash array. +After the value is set, the actual size changes when the alternative +SYN cache becomes empty and both SYN caches are swapped. +.It Li tcp.synuselimit Pq Va net.inet.tcp.synuselimit +The minimum number of times the hash function for the TCP SYN cache is used +before it is reseeded. +.It Li tcp.tso Pq Va net.inet.tcp.tso +If set to 0, disable TCP segmentation offload (TSO). +If set to 1, TSO is enabled (the default). +.It Li udp.baddynamic Pq Va net.inet.udp.baddynamic +Analogous to +.Li tcp.baddynamic +but for UDP sockets. +.It Li udp.checksum Pq Va net.inet.udp.checksum +Returns 1 when UDP checksums are being computed and checked. +Disabling UDP checksums is strongly discouraged. +.It Li udp.recvspace Pq Va net.inet.udp.recvspace +Returns the default UDP receive buffer size. +.It Li udp.rootonly Pq Va net.inet.udp.rootonly +Analogous to +.Li tcp.rootonly +but for UDP sockets. +.It Li udp.sendspace Pq Va net.inet.udp.sendspace +Returns the default UDP send buffer size. +.It Li udp.stats Pq Va net.inet.udp.stats +Returns the UDP statistics in a struct udpstat. +.El +.It Dv PF_INET6 +Get or set various global information about IPv6 +.Pq Internet Protocol version 6 . +The third level name is the protocol. +The fourth level name is the variable name. +The currently defined protocols and names are: +.Bl -column "Protocol name" "multicast_mtudisc" "integer" "yes" -offset indent +.It Sy "Protocol name" Ta Sy "Variable name" Ta Sy "Type" Ta Sy "Changeable" +.It icmp6 Ta errppslimit Ta integer Ta yes +.It icmp6 Ta mtudisc_hiwat Ta integer Ta yes +.It icmp6 Ta mtudisc_lowat Ta integer Ta yes +.It icmp6 Ta nd6_delay Ta integer Ta yes +.It icmp6 Ta nd6_mmaxtries Ta integer Ta yes +.It icmp6 Ta nd6_umaxtries Ta integer Ta yes +.It icmp6 Ta redirtimeout Ta integer Ta yes +.It ip6 Ta dad_count Ta integer Ta yes +.It ip6 Ta dad_pending Ta integer Ta yes +.It ip6 Ta defmcasthlim Ta integer Ta yes +.It ip6 Ta forwarding Ta integer Ta yes +.It ip6 Ta hdrnestlimit Ta integer Ta yes +.It ip6 Ta hlim Ta integer Ta yes +.It ip6 Ta maxdynroutes Ta integer Ta yes +.It ip6 Ta maxfragpackets Ta integer Ta yes +.It ip6 Ta maxfrags Ta integer Ta yes +.It ip6 Ta mforwarding Ta integer Ta yes +.It ip6 Ta mtudisctimeout Ta integer Ta yes +.It ip6 Ta multicast_mtudisc Ta integer Ta yes +.It ip6 Ta multipath Ta integer Ta yes +.It ip6 Ta neighborgcthresh Ta integer Ta yes +.It ip6 Ta redirect Ta integer Ta yes +.El +.Pp +The variables are as follows: +.Pp +.Bl -tag -width "123456" -compact +.It Li icmp6.errppslimit Pq Va net.inet6.icmp6.errppslimit +This variable specifies the maximum number of outgoing ICMPv6 error messages +per second. +ICMPv6 error messages exceeding this value are subject to rate limitation +and will not go out from the node. +A negative value will disable the rate limitation. +.Pp +.It Li icmp6.mtudisc_hiwat Pq Va net.inet6.icmp6.mtudisc_hiwat +.It Li icmp6.mtudisc_lowat Pq Va net.inet6.icmp6.mtudisc_lowat +These variables define the maximum number of routing table entries +created due to path MTU discovery +.Pq preventing denial-of-service attacks with ICMPv6 too big messages . +After IPv6 path MTU discovery happens, path MTU information is kept in +the routing table. +If the number of routing table entries exceeds this value, +the kernel will not attempt to keep the path MTU information. +.Li icmp6.mtudisc_hiwat +is used when we have verified ICMPv6 too big messages. +.Li icmp6.mtudisc_lowat +is used when we have unverified ICMPv6 too big messages. +Verification is performed by using address/port pairs kept in connected PCBs. +A negative value disables the upper limit. +.Pp +.It Li icmp6.nd6_delay Pq Va net.inet6.icmp6.nd6_delay +This variable specifies the +.Dv DELAY_FIRST_PROBE_TIME +timing constant in IPv6 neighbor discovery specification +.Pq RFC 4861 , +in seconds. +.Pp +.It Li icmp6.nd6_mmaxtries Pq Va net.inet6.icmp6.nd6_mmaxtries +This variable specifies the +.Dv MAX_MULTICAST_SOLICIT +constant in IPv6 neighbor discovery specification +.Pq RFC 4861 . +.Pp +.It Li icmp6.nd6_umaxtries Pq Va net.inet6.icmp6.nd6_umaxtries +This variable specifies the +.Dv MAX_UNICAST_SOLICIT +constant in IPv6 neighbor discovery specification +.Pq RFC 4861 . +.Pp +.It Li icmp6.redirtimeout Pq Va net.inet6.icmp6.redirtimeout +The variable specifies the lifetime of routing entries generated by +incoming ICMPv6 redirects. +.Pp +.It Li ip6.dad_count Pq Va net.inet6.ip6.dad_count +This variable configures the number of IPv6 DAD +.Pq duplicated address detection +probe packets. +These packets are generated when IPv6 interfaces are first brought up. +.Pp +.It Li ip6.dad_pending Pq Va net.inet6.ip6.dad_pending +This variable displays the number of pending IPv6 DAD +.Pq duplicated address detection +before completion. +It is used to make sure that DAD is completed before +.Xr netstart 8 +is executed. +.Pp +.It Li ip6.defmcasthlim Pq Va net.inet6.ip6.defmcasthlim +The default hop limit value for an IPv6 multicast packet sourced by the node. +This value applies to all the transport protocols on top of IPv6. +Methods for overriding this value are documented in +.Xr ip6 4 . +.Pp +.It Li ip6.forwarding Pq Va net.inet6.ip6.forwarding +Returns 1 when IPv6 forwarding is enabled for the node, +meaning that the node is acting as a router. +Returns 0 when IPv6 forwarding is disabled for the node, +meaning that the node is acting as a host. +Note that IPv6 defines node behavior for the +.Dq router +and +.Dq host +cases quite differently, and changing this variable during operation +may cause serious trouble. +Hence, this variable should only be set at bootstrap time. +As with IPv4, if forwarding is disabled then the destination address of +incoming packets must match the IP address bound to the interface. +If forwarding is enabled, the check is relaxed +so that the destination IP address of incoming packets must match +just any address bound to the host. +.Pp +.It Li ip6.hdrnestlimit Pq Va net.inet6.ip6.hdrnestlimit +The number of IPv6 extension headers permitted on incoming IPv6 packets. +If set to 0, the node will accept as many extension headers as possible. +.Pp +.It Li ip6.hlim Pq Va net.inet6.ip6.hlim +The default hop limit value for an IPv6 unicast packet sourced by the node. +This value applies to all the transport protocols on top of IPv6. +Methods for overriding this value are documented in +.Xr ip6 4 . +.Pp +.It Li ip6.maxdynroutes Pq Va net.inet6.ip6.maxdynroutes +Maximum number of routes created by redirect. +Set to negative to disable. +The default value is 4096. +.Pp +.It Li ip6.maxfragpackets Pq Va net.inet6.ip6.maxfragpackets +The maximum number of fragmented packets the node will accept. +0 means that the node will not accept any fragmented packets. +\-1 means that the node will accept as many fragmented packets as it receives. +The flag is provided basically for avoiding possible DoS attacks. +.Pp +.It Li ip6.maxfrags Pq Va net.inet6.ip6.maxfrags +The maximum number of fragments the node will accept. +0 means that the node will not accept any fragments. +\-1 means that the node will accept as many fragments as it receives. +The flag is provided basically for avoiding possible DoS attacks. +.Pp +.It Li ip6.mforwarding Pq Va net.inet6.ip6.mforwarding +If set to 1, then multicast forwarding is enabled for the host. +The default is 0. +.Pp +.It Li ip6.multicast_mtudisc Pq Va net.inet6.ip6.multicast_mtudisc +This variable controls generation of ICMPv6 Too Big messages +when the machine is performing as an IPv6 multicast router. +If set to 1, an ICMPv6 Too Big message will be generated for multicast packets +which were too big to be forwarded. +If set to 0, the ICMPv6 Too Big message will be suppressed. +.Pp +.It Li ip6.multipath Pq Va net.inet6.ip6.multipath +This variable enables multipath routing for IPv6 addresses. +If set to 0, only the first route selected will be used for a given +destination regardless of how many routes exist in the routing table. +.Pp +.It Li ip6.mtudisctimeout Pq Va net.inet6.ip6.mtudisctimeout +Number of seconds in which a route added by the Path MTU +Discovery engine will time out. +When the route times out, the Path MTU Discovery engine will attempt +to probe a larger path MTU. +.Pp +.It Li ip6.neighborgcthresh Pq Va net.inet6.ip6.neighborgcthresh +Maximum number of entries in neighbor cache. +Set to negative to disable. +The default value is 2048. +.Pp +.It Li ip6.redirect Pq Va net.inet6.ip6.redirect +Returns 1 when ICMPv6 redirects may be sent by the node. +This option is ignored unless the node is routing IP packets, +and should normally be enabled on all systems. +.El +.Pp +We reuse +.Li net.inet.tcp +and +.Li net.inet.udp +for TCP/UDP over IPv6. +.It Dv PF_UNIX +Get or set various global information about UNIX-domain protocol family. +The third level name is the socket type. +The fourth level name is the variable name. +The currently defined socket types and names are: +.Bl -column "Protocol name" "ipsec-expire-acquire" "structure" "Changeable" -offset 2n +.It Sy "Socket type" Ta Sy "Variable name" Ta Sy "Type" Ta Sy "Changeable" +.It stream Ta recvspace Ta integer Ta yes +.It stream Ta sendspace Ta integer Ta yes +.It dgram Ta recvspace Ta integer Ta yes +.It dgram Ta sendspace Ta integer Ta yes +.It seqpacket Ta recvspace Ta integer Ta yes +.It seqpacket Ta sendspace Ta integer Ta yes +.It inflight Ta Ta integer Ta no +.It deferred Ta Ta integer Ta no +.El +.Pp +The variables are as follows: +.Bl -tag -width "123456" +.It Li stream.recvspace Pq Va net.unix.stream.recvspace +Returns the default +.Dv SOCK_STREAM +receive buffer size. +.It Li stream.sendspace Pq Va net.unix.stream.sendspace +Returns the default +.Dv SOCK_STREAM +send buffer size. +.It Li dgram.recvspace Pq Va net.unix.dgram.recvspace +Returns the default +.Dv SOCK_DGRAM +receive buffer size. +.It Li dgram.sendspace Pq Va net.unix.dgram.sendspace +Returns the default +.Dv SOCK_DGRAM +send buffer size. +.It Li seqpacket.recvspace Pq Va net.unix.seqpacket.recvspace +Returns the default +.Dv SOCK_SEQPACKET +receive buffer size. +.It Li seqpacket.sendspace Pq Va net.unix.seqpacket.sendspace +Returns the default +.Dv SOCK_SEQPACKET +send buffer size. +.It Li inflight Pq Va net.unix.inflight +Returns the number of file descriptors inflight. +.It Li deferred Pq Va net.unix.deferred +Returns the number of file descriptors to be closed. +.El +.It Dv PF_KEY +Return +.Xr ipsec 4 +database dumps. +The second level name is +.Dv PF_KEY_V2 . +The third level name selects the database as follows: +.Pp +.Bl -tag -width "NET_KEY_SADB_DUMP" -offset indent -compact +.It Dv NET_KEY_SADB_DUMP +Security Association database (SADB). +.It Dv NET_KEY_SPD_DUMP +IPsec flow database (SPD). +.El +.It Dv PF_MPLS +Get or set global information about MPLS (Multiprotocol Label Switching). +.Bl -column "MPLSCTL_MAPTTL_IP6 " "integer" "not applicable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv MPLSCTL_DEFTTL Ta integer Ta yes +.It Dv MPLSCTL_MAPTTL_IP Ta integer Ta yes +.It Dv MPLSCTL_MAPTTL_IP6 Ta integer Ta yes +.El +.Bl -tag -width "123456" +.It Dv MPLSCTL_DEFTTL Pq Va net.mpls.ttl +Set or get the default TTL value which is used for MPLS (Shim) Header. +The default is 255. +.It Dv MPLSCTL_MAPTTL_IP Pq Va net.mpls.mapttl_ip +If set to 1, the TTL field is synchronized between the IP header and the +MPLS label stack. +If set to 0, the IP header TTL is not modified while passing through MPLS +and the MPLS label stack is initialized with the +.Dv MPLSCTL_DEFTTL . +The default is 1. +.It Dv MPLSCTL_MAPTTL_IP6 Pq Va net.mpls.mapttl_ip6 +If set to 1, the TTL field is synchronized between the IPv6 header and the +MPLS label stack. +If set to 0, the IPv6 header TTL is not modified while passing through MPLS +and the MPLS label stack is initialized with the +.Dv MPLSCTL_DEFTTL . +The default is 0. +.El +.It Dv PF_PIPEX Pq Va net.pipex +Get or set global information about PIPEX. +.Pp +The currently defined variable names are: +.Bl -column "Third level name" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv PIPEXCTL_ENABLE Ta integer Ta yes +.El +.Bl -tag -width "123456" +.It Dv PIPEXCTL_ENABLE +If set to 1, enable PIPEX processing. +The default is 0. +.El +.El +.Ss CTL_VFS +The string and integer information available for the +.Dv CTL_VFS +level is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "Second level name" "VFS generic info" "Changeable" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv VFS_GENERIC Ta "VFS generic info" Ta "no" +.It Dv "filesystem #" Ta "filesystem info" Ta "no" +.El +.Bl -tag -width "123456" +.It Dv VFS_GENERIC +This second level identifier requests generic information about the +VFS layer. +Within it, the following third level identifiers exist: +.Bl -column "Third level name" "struct vfsconf" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv VFS_CONF Ta "struct vfsconf" Ta "no" +.It Dv VFS_MAXTYPENUM Ta "int" Ta "no" +.El +.It filesystem # +After finding the filesystem dependent +.Va vfc_typenum +using +.Dv VFS_GENERIC +with +.Dv VFS_CONF , +it is possible to access filesystem dependent information. +.Pp +Some filesystems may contain settings. +.Bl -tag -width "123" +.It FFS +.Bl -column "FFS_SD_DIRECT_BLK_PTRS" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv FFS_DIRHASH_DIRSIZE Ta "integer" Ta "yes" +.It Dv FFS_DIRHASH_MAXMEM Ta "integer" Ta "yes" +.It Dv FFS_DIRHASH_MEM Ta "integer" Ta "no" +.It Dv FFS_MAX_SOFTDEPS Ta "integer" Ta "yes" +.It Dv FFS_SD_BLK_LIMIT_HIT Ta "integer" Ta "yes" +.It Dv FFS_SD_BLK_LIMIT_PUSH Ta "integer" Ta "yes" +.It Dv FFS_SD_DIR_ENTRY Ta "integer" Ta "yes" +.It Dv FFS_SD_DIRECT_BLK_PTRS Ta "integer" Ta "yes" +.It Dv FFS_SD_INDIR_BLK_PTRS Ta "integer" Ta "yes" +.It Dv FFS_SD_INO_LIMIT_HIT Ta "integer" Ta "yes" +.It Dv FFS_SD_INO_LIMIT_PUSH Ta "integer" Ta "yes" +.It Dv FFS_SD_INODE_BITMAP Ta "integer" Ta "yes" +.It Dv FFS_SD_SYNC_LIMIT_HIT Ta "integer" Ta "yes" +.It Dv FFS_SD_TICKDELAY Ta "integer" Ta "yes" +.It Dv FFS_SD_WORKLIST_PUSH Ta "integer" Ta "yes" +.El +.Bl -tag -width "123456" +.It Dv FFS_DIRHASH_DIRSIZE Pq Va vfs.ffs.dirhash_dirsize +The minimum size of a directory, in bytes, before it is considered for hashing. +.It Dv FFS_DIRHASH_MAXMEM Pq Va vfs.ffs.dirhash_maxmem +The maximum amount of memory, in bytes, to be used for storing directory +hashes. +.It Dv FFS_DIRHASH_MEM Pq Va vfs.ffs.dirhash_mem +The amount of memory currently used by all directory hashes. +.It Dv FFS_MAX_SOFTDEPS Pq Va vfs.ffs.max_softdeps +Maximum structures before slowdowns. +.It Dv FFS_SD_BLK_LIMIT_HIT Pq Va vfs.ffs.sd_blk_limit_hit +Number of times block slowdown imposed. +.It Dv FFS_SD_BLK_LIMIT_PUSH Pq Va vfs.ffs.sd_blk_limit_push +Number of times block limit neared. +.It Dv FFS_SD_DIR_ENTRY Pq Va vfs.ffs.sd_dir_entry +Bufs redirtied as dir entry cannot write. +.It Dv FFS_SD_DIRECT_BLK_PTRS Pq Va vfs.ffs.sd_direct_blk_ptrs +Bufs redirtied as direct ptrs not written. +.It Dv FFS_SD_INDIR_BLK_PTRS Pq Va vfs.ffs.sd_indir_blk_ptrs +Bufs redirtied as indirect ptrs not written. +.It Dv FFS_SD_INO_LIMIT_HIT Pq Va vfs.ffs.sd_ino_limit_hit +Number of times inode limit imposed. +.It Dv FFS_SD_INO_LIMIT_PUSH Pq Va vfs.ffs.sd_ino_limit_push +Number of times inode limit neared. +.It Dv FFS_SD_INODE_BITMAP Pq Va vfs.ffs.sd_inode_bitmap +Bufs redirtied as inode bitmap not written. +.It Dv FFS_SD_SYNC_LIMIT_HIT Pq Va vfs.ffs.sd_sync_limit_hit +Number of synchronous slowdowns imposed. +.It Dv FFS_SD_TICKDELAY Pq Va vfs.ffs.sd_tickdelay +Ticks to pause during slowdown. +.It Dv FFS_SD_WORKLIST_PUSH Pq Va vfs.ffs.sd_worklist_push +Number of worklist cleanups. +.El +.It NFS +.Bl -column "Third level name" "struct nfsstats" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv NFS_NFSSTATS Ta "struct nfsstats" Ta "yes" +.It Dv NFS_NIOTHREADS Ta "int" Ta "yes" +.El +.Bl -tag -width Ds +.It Dv NFS_NIOTHREADS Pq Va vfs.nfs.iothreads +The number of I/O kernel threads for NFS clients. +The default is 4; +the maximum is 20. +.El +.It FUSE +.Bl -column "FUSEFS_POOL_NBPAGES" "Type" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv FUSEFS_INFBUFS Ta "int" Ta "no" +.It Dv FUSEFS_OPENDEVS Ta "int" Ta "no" +.It Dv FUSEFS_POOL_NBPAGES Ta "int" Ta "no" +.It Dv FUSEFS_WAITFBUFS Ta "int" Ta "no" +.El +.Bl -tag -width Ds +.It Dv FUSEFS_INFBUFS Pq Va vfs.fuse.fusefs_fbufs_in +The number of inbound fusebufs. +.It Dv FUSEFS_OPENDEVS Pq Va vfs.fuse.fusefs_open_devices +The number of FUSE devices opened. +.It Dv FUSEFS_POOL_NBPAGES Pq Va vfs.fuse.fusefs_pool_pages +The number of pages used for fusebuf memory. +.It Dv FUSEFS_WAITFBUFS Pq Va vfs.fuse.fusefs_fbufs_wait +The number of fusebufs waiting for a response. +.El +.El +.El +.Ss CTL_VM +The string and integer information available for the +.Dv CTL_VM +level is detailed below. +The changeable column shows whether a process with appropriate +privileges may change the value. +.Bl -column "Second level name" "swap encrypt values" "yes" -offset indent +.It Sy "Second level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv VM_ANONMIN Ta "integer" Ta "yes" +.It Dv VM_LOADAVG Ta "struct loadavg" Ta "no" +.It Dv VM_MALLOC_CONF Ta "string" Ta "yes" +.It Dv VM_MAXSLP Ta "integer" Ta "no" +.It Dv VM_METER Ta "struct vmtotal" Ta "no" +.It Dv VM_NKMEMPAGES Ta "integer" Ta "no" +.It Dv VM_PSSTRINGS Ta "struct psstrings" Ta "no" +.It Dv VM_SWAPENCRYPT Ta "swap encrypt values" Ta "yes" +.It Dv VM_USPACE Ta "integer" Ta "no" +.It Dv VM_UVMEXP Ta "struct uvmexp" Ta "no" +.It Dv VM_VNODEMIN Ta "integer" Ta "yes" +.It Dv VM_VTEXTMIN Ta "integer" Ta "yes" +.El +.Bl -tag -width "123456" +.It Dv VM_ANONMIN Pq Va vm.anonmin +Percentage of physical memory available for +pages which contain anonymous mapping. +.It Dv VM_LOADAVG Pq Va vm.loadavg +Return the load average history. +The returned data consists of a +.Vt struct loadavg . +.It Dv VM_MALLOC_CONF Pq Va vm.malloc_conf +String of option flags for the +.Xr malloc 3 +family of functions +which will be applied to all programs starting in the future. +The string contains a maximum of 15 characters. +.It Dv VM_MAXSLP Pq Va vm.maxslp +The time for a process to be blocked before being swappable, +in seconds. +.It Dv VM_METER Pq Va vm.vmmeter +Return the system wide virtual memory statistics. +The returned data consists of a +.Vt struct vmtotal . +.It Dv VM_NKMEMPAGES Pq Va vm.nkmempages +Number of pages in kmem_map. +.It Dv VM_PSSTRINGS Pq Va vm.psstrings +Returns the address of the process +.Vt struct ps_strings . +The +.Xr ps 1 +program uses it to locate the argument and environment strings. +.It Dv VM_SWAPENCRYPT +Contains statistics about swap encryption. +The string and integer information available for the third level is +detailed below. +.Bl -column "Third level name" "integer" "Changeable" -offset indent +.It Sy "Third level name" Ta Sy "Type" Ta Sy "Changeable" +.It Dv SWPENC_CREATED Ta "integer" Ta "no" +.It Dv SWPENC_DELETED Ta "integer" Ta "no" +.It Dv SWPENC_ENABLE Ta "integer" Ta "yes" +.El +.Bl -tag -width "123456" +.It Dv SWPENC_CREATED Pq Va vm.swapencrypt.keyscreated +The number of encryption keys that have been randomly created. +The swap partition is divided into sections of normally 512KB. +Each section has its own encryption key. +.It Dv SWPENC_DELETED Pq Va vm.swapencrypt.keysdeleted +The number of encryption keys that have been deleted, thus effectively +erasing the data that has been encrypted with them. +Encryption keys are deleted when their reference counter reaches zero. +.It Dv SWPENC_ENABLE Pq Va vm.swapencrypt.enable +Set to 1 to enable swap encryption for all processes. +A 0 disables swap encryption. +Turning this option on does not affect swap data already on the disk, +but all newly written data will be encrypted. +When swap encryption is turned on, automatic +.Xr crash 8 +dumps are disabled. +.El +.It Dv VM_USPACE Pq Va vm.uspace +The number of bytes allocated for each kernel stack. +.It Dv VM_UVMEXP Pq Va vm.uvmexp +Contains statistics about the UVM memory management system. +.It Dv VM_VNODEMIN Pq Va vm.vnodemin +Percentage of physical memory available for +pages which contain cached file data. +.It Dv VM_VTEXTMIN Pq Va vm.vtextmin +Percentage of physical memory available for +pages which contain cached executable data. +.El +.Sh RETURN VALUES +If the call to +.Fn sysctl +is unsuccessful, \-1 is returned and +.Va errno +is set appropriately. +.Sh FILES +.Bl -tag -width "uvm/uvmXswapXencrypt.h " -compact +.It In sys/sysctl.h +top level identifiers and second level kernel and hardware +identifiers +.It In sys/socket.h +second level network identifiers +.It In sys/gmon.h +third level profiling identifiers +.It In uvm/uvmexp.h +second level virtual memory identifiers +.It In uvm/uvm_swap_encrypt.h +third level virtual memory identifiers +.It In net/if.h +packet input/output queue identifiers +.It In net/pipex.h +third level PIPEX identifiers +.It In netinet/in.h +third and fourth level IPv4/v6 identifiers +.It In netinet/ip_divert.h +fourth level divert identifiers +.It In netinet/icmp_var.h +fourth level ICMP identifiers +.It In netinet/icmp6.h +fourth level ICMPv6 identifiers +.It In netinet/tcp_var.h +fourth level TCP identifiers +.It In netinet/udp_var.h +fourth level UDP identifiers +.It In ddb/db_var.h +second level ddb identifiers +.It In sys/mount.h +second level vfs identifiers +.It In miscfs/fuse/fusefs.h +third level fusefs identifiers +.It In nfs/nfs.h +third level NFS identifiers +.It In ufs/ffs/ffs_extern.h +third level FFS identifiers +.It In machine/cpu.h +second level CPU identifiers +.El +.Sh ERRORS +The following errors may be reported: +.Bl -tag -width Er +.It Bq Er EFAULT +The buffer +.Fa name , +.Fa oldp , +.Fa newp , +or length pointer +.Fa oldlenp +contains an invalid address. +.It Bq Er EINVAL +The +.Fa name +array is less than two or greater than +.Dv CTL_MAXNAME . +.It Bq Er EINVAL +A non-null +.Fa newp +pointer is given and its specified length in +.Fa newlen +is too large or too small. +.It Bq Er ENOMEM +The length pointed to by +.Fa oldlenp +is too short to hold the requested value. +.It Bq Er ENOENT +The mib specified does not exist, or exceeds the range that is possible. +.It Bq Er ENXIO +If the mib is a sparsely populated array, this error may be returned +instead. +.It Bq Er ENOTDIR +The +.Fa name +array specifies an intermediate rather than terminal name. +.It Bq Er EOPNOTSUPP +The +.Fa name +array specifies a value that is unknown. +.It Bq Er EPERM +An attempt is made to set a read-only value. +.It Bq Er EPERM +A process without appropriate privileges attempts to set a value. +.It Bq Er EPERM +An attempt to change a value protected by the current kernel security +level is made. +.It Bq Er ESRCH +No process could be found which corresponds to the given process ID. +.El +.Sh SEE ALSO +.Xr pathconf 2 , +.Xr sysconf 3 , +.Xr ddb 4 , +.Xr sysctl.conf 5 , +.Xr securelevel 7 , +.Xr sysctl 8 +.Sh HISTORY +The +.Fn sysctl +function first appeared in +.Bx 4.4 . diff --git a/static/openbsd/man2/t1.2 b/static/openbsd/man2/t1.2 new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/static/openbsd/man2/t1.2 diff --git a/static/openbsd/man2/t10.2 b/static/openbsd/man2/t10.2 new file mode 100644 index 00000000..03f42c69 --- /dev/null +++ b/static/openbsd/man2/t10.2 @@ -0,0 +1 @@ +Another line of text
\ No newline at end of file diff --git a/static/openbsd/man2/t11.2 b/static/openbsd/man2/t11.2 new file mode 100644 index 00000000..b5579207 --- /dev/null +++ b/static/openbsd/man2/t11.2 @@ -0,0 +1,908 @@ +.\" $OpenBSD: t11.2,v 1.1 2003/07/21 20:16:21 otto Exp $ +.\" +.Dd May 2, 1993 +.Dt ED 1 +.Os +.Sh NAME +.Nm ed +.Nd text editor +.Sh SYNOPSIS +.Nm ed +.Op Fl +.Op Fl sx +.Op Fl p Ar string +.Op Ar file +.Sh DESCRIPTION +.Nm +is a line-oriented text editor. +It is used to create, display, modify, and otherwise manipulate text files. +If invoked with a +.Ar file +argument, then a copy of +.Ar file +is read into the editor's buffer. +Changes are made to this copy and not directly to +.Ar file +itself. +Upon quitting +.Nm ed , +any changes not explicitly saved with a +.Em w +command are lost. +.Pp +Editing is done in two distinct modes: +.Em command +and +.Em input . +When first invoked, +.Nm +is in command mode. +In this mode, commands are read from the standard input and +executed to manipulate the contents of the editor buffer. +.Pp +A typical command might look like: +.Bd -literal -offset indent +,s/old/new/g +.Ed +.Pp +which replaces all occurrences of the string +.Pa old +with +.Pa new . +.Pp +When an input command, such as +.Em a +(append), +.Em i +(insert), +or +.Em c +(change) is given, +.Nm +enters input mode. +This is the primary means of adding text to a file. +In this mode, no commands are available; +instead, the standard input is written directory to the editor buffer. +Lines consist of text up to and including a newline character. +Input mode is terminated by entering a single period +.Pq Ql \&. +on a line. +.Pp +All +.Nm +commands operate on whole lines or ranges of lines; e.g., +the +.Em d +command deletes lines; the +.Em m +command moves lines, and so on. +It is possible to modify only a portion of a line by means of replacement, +as in the example above. +However, even here, the +.Em s +command is applied to whole lines at a time. +.Pp +In general, +.Nm +commands consist of zero or more line addresses, followed by a single +character command and possibly additional parameters; i.e., +commands have the structure: +.Bd -literal -offset indent +[address [,address]]command[parameters] +.Ed +.Pp +The address(es) indicate the line or range of lines to be affected by the +command. +If fewer addresses are given than the command accepts, then +default addresses are supplied. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl +Same as the +.Fl s +option (deprecated). +.It Fl s +Suppress diagnostics. +This should be used if +.Nm +standard input is from a script. +.Fl s +flag. +.It Fl x +Prompt for an encryption key to be used in subsequent reads and writes +(see the +.Em x +command). +.It Fl p Ar string +Specifies a command prompt. +This may be toggled on and off with the +.Em P +command. +.It Ar file +Specifies the name of a file to read. +If +.Ar file +is prefixed with a +bang +.Pq Ql \&! , +then it is interpreted as a shell command. +In this case, what is read is the standard output of +.Ar file +executed via +.Xr sh 1 . +To read a file whose name begins with a bang, prefix the +name with a backslash +.Pq Ql \e . +The default filename is set to +.Ar file +only if it is not prefixed with a bang. +.El +.Ss LINE ADDRESSING +An address represents the number of a line in the buffer. +.Nm +maintains a +.Em current address +which is typically supplied to commands as the default address +when none is specified. +When a file is first read, the current address is set to the last line +of the file. +In general, the current address is set to the last line affected by a command. +.Pp +A line address is +constructed from one of the bases in the list below, optionally followed +by a numeric offset. +The offset may include any combination of digits, operators (i.e., +.Em + , +.Em - , +and +.Em ^ ) , +and whitespace. +Addresses are read from left to right, and their values are computed +relative to the current address. +.Pp +One exception to the rule that addresses represent line numbers is the +address +.Em 0 +(zero). +This means +.Dq before the first line , +and is legal wherever it makes sense. +.Pp +An address range is two addresses separated either by a comma or semi-colon. +The value of the first address in a range cannot exceed the +value of the second. +If only one address is given in a range, +then the second address is set to the given address. +If an +.Em n Ns No -tuple +of addresses is given where +.Em n > 2 , +then the corresponding range is determined by the last two addresses in the +.Em n Ns No -tuple. +If only one address is expected, then the last address is used. +.Pp +Each address in a comma-delimited range is interpreted relative to the +current address. +In a semi-colon-delimited range, the first address is +used to set the current address, and the second address is interpreted +relative to the first. +.Pp +The following address symbols are recognized: +.Bl -tag -width Ds +.It Em \&. +The current line (address) in the buffer. +.It Em $ +The last line in the buffer. +.It Em n +The +.Em n Ns No th +line in the buffer where +.Em n +is a number in the range +.Em [0,$] . +.It Em - No or Em ^ +The previous line. +This is equivalent to +.Em -1 +and may be repeated with cumulative effect. +.It Em -n No or Em ^n +The +.Em n Ns No th +previous line, where +.Em n +is a non-negative number. +.It Em + +The next line. +This is equivalent to +.Em +1 +and may be repeated with cumulative effect. +.It Em +n +The +.Em n Ns No th +next line, where +.Em n +is a non-negative number. +.It Em \&, No or Em % +The first through last lines in the buffer. +This is equivalent to the address range +.Em 1,$ . +.It Em \&; +The current through last lines in the buffer. +This is equivalent to the address range +.Em .,$ . +.It Em / Ns No re Ns Em / +The next line containing the regular expression +.Em re . +The search wraps to the beginning of the buffer and continues down to the +current line, if necessary. +.Em // +repeats the last search. +.It Em ? Ns No re Ns Em ? +The previous line containing the regular expression +.Em re . +The search wraps to the end of the buffer and continues up to the +current line, if necessary. +.Em ?? +repeats the last search. +.It Em \&\' Ns No lc +The line previously marked by a +.Em k +(mark) command, where +.Em lc +is a lower case letter. +.El +.Ss REGULAR EXPRESSIONS +Regular expressions are patterns used in selecting text. +For example, the +.Nm +command +.Bd -literal -offset indent +g/string/ +.Ed +.Pp +prints all lines containing +.Em string . +Regular expressions are also used by the +.Em s +command for selecting old text to be replaced with new. +.Pp +In addition to a specifying string literals, regular expressions can +represent classes of strings. +Strings thus represented are said to be matched by the +corresponding regular expression. +If it is possible for a regular expression to match several strings in +a line, then the leftmost longest match is the one selected. +.Pp +The following symbols are used in constructing regular expressions: +.Bl -tag -width Dsasdfsd +.It Em c +Any character +.Em c +not listed below, including +.Em { Ns No , +.Em } Ns No , +.Em \&( Ns No , +.Em \&) Ns No , +.Em < Ns No , +and +.Em > +matches itself. +.It Em \ec +Any backslash-escaped character +.Em c Ns No , +except for +.Em { Ns No , +.Em } Ns No , +.Em \&( Ns No , +.Em \&) Ns No , +.Em < Ns No , and +.Em > +matches itself. +.It Em \&. +Matches any single character. +.It Em [char-class] +Matches any single character in +.Em char-class . +To include a +.Ql \&] +in +.Em char-class Ns No , +it must be the first character. +A range of characters may be specified by separating the end characters +of the range with a +.Ql - ; +e.g., +.Em a-z +specifies the lower case characters. +The following literal expressions can also be used in +.Em char-class +to specify sets of characters: +.Pp +.Em \ \ [:alnum:]\ \ [:cntrl:]\ \ [:lower:]\ \ [:space:] +.Em \ \ [:alpha:]\ \ [:digit:]\ \ [:print:]\ \ [:upper:] +.Em \ \ [:blank:]\ \ [:graph:]\ \ [:punct:]\ \ [:xdigit:] +.Pp +If +.Ql - +appears as the first or last character of +.Em char-class Ns No , +then it matches itself. +All other characters in +.Em char-class +match themselves. +.Pp +Patterns in +.Em char-class +of the form +.Em [.col-elm.] No or Em [=col-elm=] +where +.Em col-elm +is a collating element are interpreted according to +.Xr locale 5 +(not currently supported). +See +.Xr regex 3 +for an explanation of these constructs. +.It Em [^char-class] +Matches any single character, other than newline, not in +.Em char-class Ns No . +.Em char-class +is defined as above. +.It Em ^ +If +.Em ^ +is the first character of a regular expression, then it +anchors the regular expression to the beginning of a line. +Otherwise, it matches itself. +.It Em $ +If +.Em $ +is the last character of a regular expression, +it anchors the regular expression to the end of a line. +Otherwise, it matches itself. +.It Em \e< +Anchors the single character regular expression or subexpression +immediately following it to the beginning of a word. +(This may not be available.) +.It Em \e> +Anchors the single character regular expression or subexpression +immediately following it to the end of a word. +(This may not be available.) +.It Em \e( Ns No re Ns Em \e) +Defines a subexpression +.Em re . +Subexpressions may be nested. +A subsequent backreference of the form +.Em \en Ns No , +where +.Em n +is a number in the range [1,9], expands to the text matched by the +.Em n Ns No th +subexpression. +For example, the regular expression +.Em \e(.*\e)\e1 +matches any string consisting of identical adjacent substrings. +Subexpressions are ordered relative to their left delimiter. +.It Em * +Matches the single character regular expression or subexpression +immediately preceding it zero or more times. +If +.Em * +is the first character of a regular expression or subexpression, +then it matches itself. +The +.Em * +operator sometimes yields unexpected results. +For example, the regular expression +.Em b* +matches the beginning of the string +.Em abbb +(as opposed to the substring +.Em bbb Ns No ), +since a null match is the only leftmost match. +.Sm off +.It Xo Em \e{ No n,m +.Em \e}\ \e{ No n, Em \e}\ +.Em \e{ No n Em \e} +.Xc +.Sm on +Matches the single character regular expression or subexpression +immediately preceding it at least +.Em n +and at most +.Em m +times. +If +.Em m +is omitted, then it matches at least +.Em n +times. +If the comma is also omitted, then it matches exactly +.Em n +times. +.El +.Pp +Additional regular expression operators may be defined depending on the +particular +.Xr regex 3 +implementation. +.Ss COMMANDS +All +.Nm +commands are single characters, though some require additional parameters. +If a command's parameters extend over several lines, then +each line except for the last must be terminated with a backslash +.Pq Ql \e . +.Pp +In general, at most one command is allowed per line. +However, most commands accept a print suffix, which is any of +.Em p No (print), +.Em l No (list), +or +.Em n No (enumerate), +to print the last line affected by the command. +.Pp +An interrupt (typically ^C) has the effect of aborting the current command +and returning the editor to command mode. +.Pp +.Nm +recognizes the following commands. +The commands are shown together with +the default address or address range supplied if none is +specified (in parentheses), and other possible arguments on the right. +.Bl -tag -width Dxxs +.It (.) Ns Em a +Appends text to the buffer after the addressed line. +Text is entered in input mode. +The current address is set to last line entered. +.It (.,.) Ns Em c +Changes lines in the buffer. +The addressed lines are deleted from the buffer, +and text is appended in their place. +Text is entered in input mode. +The current address is set to last line entered. +.It (.,.) Ns Em d +Deletes the addressed lines from the buffer. +If there is a line after the deleted range, then the current address is set +to this line. +Otherwise the current address is set to the line before the deleted range. +.It Em e No file +Edits +.Em file Ns No , +and sets the default filename. +If +.Em file +is not specified, then the default filename is used. +Any lines in the buffer are deleted before the new file is read. +The current address is set to the last line read. +.It Em e No !command +Edits the standard output of +.Em !command Ns No , +(see +.Em ! No command +below). +The default filename is unchanged. +Any lines in the buffer are deleted before the output of +.Em command +is read. +The current address is set to the last line read. +.It Em E No file +Edits +.Em file +unconditionally. +This is similar to the +.Em e +command, except that unwritten changes are discarded without warning. +The current address is set to the last line read. +.It Em f No file +Sets the default filename to +.Em file Ns No . +If +.Em file +is not specified, then the default unescaped filename is printed. +.It (1,$) Ns Em g Ns No /re/command-list +Applies +.Em command-list +to each of the addressed lines matching a regular expression +.Em re Ns No . +The current address is set to the line currently matched before +.Em command-list +is executed. +At the end of the +.Em g +command, the current address is set to the last line affected by +.Em command-list Ns No . +.Pp +Each command in +.Em command-list +must be on a separate line, +and every line except for the last must be terminated by +.Em \e No (backslash). +Any commands are allowed, except for +.Em g Ns No , +.Em G Ns No , +.Em v Ns No , +and +.Em V Ns No . +A newline alone in +.Em command-list +is equivalent to a +.Em p +command. +.It (1,$) Ns Em G Ns No /re/ +Interactively edits the addressed lines matching a regular expression +.Em re Ns No . +For each matching line, the line is printed, the current address is set, +and the user is prompted to enter a +.Em command-list Ns No . +At the end of the +.Em g +command, the current address is set to the last line affected by (the last) +.Em command-list Ns No . +.Pp +The format of +.Em command-list +is the same as that of the +.Em g +command. +A newline alone acts as a null command list. +A single +.Em & +repeats the last non-null command list. +.It Em H +Toggles the printing of error explanations. +By default, explanations are not printed. +It is recommended that +.Nm +scripts begin with this command to aid in debugging. +.It Em h +Prints an explanation of the last error. +.It (.) Ns Em i +Inserts text in the buffer before the current line. +Text is entered in input mode. +The current address is set to the last line entered. +.It (.,.+1) Ns Em j +Joins the addressed lines. +The addressed lines are deleted from the buffer and replaced by a single +line containing their joined text. +The current address is set to the resultant line. +.It (.) Ns Em klc +Marks a line with a lower case letter +.Em lc Ns No \&. +The line can then be addressed as +.Em \&'lc +(i.e., a single quote followed by +.Em lc Ns No ) +in subsequent commands. +The mark is not cleared until the line is deleted or otherwise modified. +.It (.,.) Ns Em l +Prints the addressed lines unambiguously. +If a single line fills more than one screen (as might be the case +when viewing a binary file, for instance), a +.Dq --More-- +prompt is printed on the last line. +.Nm +waits until the RETURN key is pressed before displaying the next screen. +The current address is set to the last line printed. +.It (.,.) Ns Em m Ns No (.) +Moves lines in the buffer. +The addressed lines are moved to after the +right-hand destination address, which may be the address +.Em 0 +(zero). +The current address is set to the last line moved. +.It (.,.) Ns Em n +Prints the addressed lines along with their line numbers. +The current address is set to the last line printed. +.It (.,.) Ns Em p +Prints the addressed lines. +The current address is set to the last line printed. +.It Em P +Toggles the command prompt on and off. +Unless a prompt was specified by with command-line option +.Fl p Ar string Ns No , +the command prompt is by default turned off. +.It Em q +Quits +.Nm ed . +.It Em Q +Quits +.Nm +unconditionally. +This is similar to the +.Em q +command, except that unwritten changes are discarded without warning. +.It ($) Ns Em r No file +Reads +.Em file +to after the addressed line. +If +.Em file +is not specified, then the default filename is used. +If there was no default filename prior to the command, +then the default filename is set to +.Em file Ns No . +Otherwise, the default filename is unchanged. +The current address is set to the last line read. +.It ($) Ns Em r No !command +Reads to after the addressed line the standard output of +.Em !command Ns No , +(see the +.Em ! +command below). +The default filename is unchanged. +The current address is set to the last line read. +.Sm off +.It Xo (.,.) Em s No /re/replacement/ , \ (.,.) +.Em s No /re/replacement/ Em g , No \ (.,.) +.Em s No /re/replacement/ Em n +.Xc +.Sm on +Replaces text in the addressed lines matching a regular expression +.Em re +with +.Em replacement Ns No . +By default, only the first match in each line is replaced. +If the +.Em g +(global) suffix is given, then every match to be replaced. +The +.Em n +suffix, where +.Em n +is a positive number, causes only the +.Em n Ns No th +match to be replaced. +It is an error if no substitutions are performed on any of the addressed +lines. +The current address is set the last line affected. +.Pp +.Em re +and +.Em replacement +may be delimited by any character other than space and newline +(see the +.Em s +command below). +If one or two of the last delimiters is omitted, then the last line +affected is printed as though the print suffix +.Em p +were specified. +.Pp +An unescaped +.Ql \e +in +.Em replacement +is replaced by the currently matched text. +The character sequence +.Em \em Ns No , +where +.Em m +is a number in the range [1,9], is replaced by the +.Em m Ns No th +backreference expression of the matched text. +If +.Em replacement +consists of a single +.Ql % , +then +.Em replacement +from the last substitution is used. +Newlines may be embedded in +.Em replacement +if they are escaped with a backslash +.Pq Ql \e . +.It (.,.) Ns Em s +Repeats the last substitution. +This form of the +.Em s +command accepts a count suffix +.Em n Ns No , +or any combination of the characters +.Em r Ns No , +.Em g Ns No , +and +.Em p Ns No . +If a count suffix +.Em n +is given, then only the +.Em n Ns No th +match is replaced. +The +.Em r +suffix causes +the regular expression of the last search to be used instead of the +that of the last substitution. +The +.Em g +suffix toggles the global suffix of the last substitution. +The +.Em p +suffix toggles the print suffix of the last substitution +The current address is set to the last line affected. +.It (.,.) Ns Em t Ns No (.) +Copies (i.e., transfers) the addressed lines to after the right-hand +destination address, which may be the address +.Em 0 +(zero). +The current address is set to the last line copied. +.It Em u +Undoes the last command and restores the current address +to what it was before the command. +The global commands +.Em g Ns No , +.Em G Ns No , +.Em v Ns No , +and +.Em V Ns No . +are treated as a single command by undo. +.Em u +is its own inverse. +.It (1,$) Ns Em v Ns No /re/command-list +Applies +.Em command-list +to each of the addressed lines not matching a regular expression +.Em re Ns No . +This is similar to the +.Em g +command. +.It (1,$) Ns Em V Ns No /re/ +Interactively edits the addressed lines not matching a regular expression +.Em re Ns No . +This is similar to the +.Em G +command. +.It (1,$) Ns Em w No file +Writes the addressed lines to +.Em file Ns No . +Any previous contents of +.Em file +is lost without warning. +If there is no default filename, then the default filename is set to +.Em file Ns No , +otherwise it is unchanged. +If no filename is specified, then the default filename is used. +The current address is unchanged. +.It (1,$) Ns Em wq No file +Writes the addressed lines to +.Em file Ns No , +and then executes a +.Em q +command. +.It (1,$) Ns Em w No !command +Writes the addressed lines to the standard input of +.Em !command Ns No , +(see the +.Em ! +command below). +The default filename and current address are unchanged. +.It (1,$) Ns Em W No file +Appends the addressed lines to the end of +.Em file Ns No . +This is similar to the +.Em w +command, expect that the previous contents of file is not clobbered. +The current address is unchanged. +.It Em x +Prompts for an encryption key which is used in subsequent reads and writes. +If a newline alone is entered as the key, then encryption is turned off. +Otherwise, echoing is disabled while a key is read. +Encryption/decryption is done using the +.Xr bdes 1 +algorithm. +.It (.+1) Ns Em z Ns No n +Scrolls +.Em n +lines at a time starting at addressed line. +If +.Em n +is not specified, then the current window size is used. +The current address is set to the last line printed. +.It ($) Ns Em = +Prints the line number of the addressed line. +.It (.+1) Ns Em newline +Prints the addressed line, and sets the current address to that line. +.It Em ! Ns No command +Executes +.Em command +via +.Xr sh 1 . +If the first character of +.Em command +is +.Em ! Ns No , +then it is replaced by text of the previous +.Em !command Ns No . +.Nm +does not process +.Em command +for +.Em \e +(backslash) escapes. +However, an unescaped +.Em % +is replaced by the default filename. +When the shell returns from execution, a +.Em ! +is printed to the standard output. +The current line is unchanged. +.El +.Sh LIMITATIONS +.Nm +processes +.Em file +arguments for backslash escapes, i.e., in a filename, +any characters preceded by a backslash +.Pq Ql \e +are interpreted literally. +.Pp +If a text (non-binary) file is not terminated by a newline character, +then +.Nm +appends one on reading/writing it. +In the case of a binary file, +.Nm +does not append a newline on reading/writing. +.Sh DIAGNOSTICS +When an error occurs, +.Nm +prints a +.Dq ? +and either returns to command mode or exits if its input is from a script. +An explanation of the last error can be printed with the +.Em h +(help) command. +.Pp +Since the +.Em g +(global) command masks any errors from failed searches and substitutions, +it can be used to perform conditional operations in scripts; e.g., +.Bd -literal -offset indent +g/old/s//new/ +.Ed +.Pp +replaces any occurrences of +.Em old +with +.Em new Ns No . +.Pp +If the +.Em u +(undo) command occurs in a global command list, then +the command list is executed only once. +.Pp +If diagnostics are not disabled, attempting to quit +.Nm +or edit another file before writing a modified buffer results in an error. +If the command is entered a second time, it succeeds, +but any changes to the buffer are lost. +.Sh FILES +.Bl -tag -width /tmp/ed.* -compact +.It Pa /tmp/ed.* +buffer file +.It Pa ed.hup +where +.Nm +attempts to write the buffer if the terminal hangs up +.El +.Sh SEE ALSO +.Xr bdes 1 , +.Xr sed 1 , +.Xr sh 1 , +.Xr vi 1 , +.Xr regex 3 +.Pp +USD:12-13 +.Rs +.%A B. W. Kernighan +.%A P. J. Plauger +.%B Software Tools in Pascal +.%O Addison-Wesley +.%D 1981 +.Re +.Sh HISTORY +An +.Nm +command appeared in +.At v1 . diff --git a/static/openbsd/man2/t12.2 b/static/openbsd/man2/t12.2 new file mode 100644 index 00000000..93a7a2f8 --- /dev/null +++ b/static/openbsd/man2/t12.2 @@ -0,0 +1,12 @@ +# $OpenBSD: t12.2,v 1.1 2003/07/21 20:16:21 otto Exp $ + +# Test HMAC: + +PROG= hmactest +SRCS= hash.c hmactest.c +.PATH: ${.CURDIR}/../../ +NOMAN= +CFLAGS+= -I${.CURDIR}/../../ -Wall +DEBUG= -g + +.include <bsd.prog.mk>
\ No newline at end of file diff --git a/static/openbsd/man2/t13.2 b/static/openbsd/man2/t13.2 new file mode 100644 index 00000000..3e00acf6 --- /dev/null +++ b/static/openbsd/man2/t13.2 @@ -0,0 +1,9 @@ +A line of text +Another line of text +.. +. +A third line +... +.. +We keep counting +. diff --git a/static/openbsd/man2/t14.2 b/static/openbsd/man2/t14.2 new file mode 100644 index 00000000..01e79c32 --- /dev/null +++ b/static/openbsd/man2/t14.2 @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/static/openbsd/man2/t15.2 b/static/openbsd/man2/t15.2 new file mode 100644 index 00000000..1191247b --- /dev/null +++ b/static/openbsd/man2/t15.2 @@ -0,0 +1,2 @@ +1 +2 diff --git a/static/openbsd/man2/t2.2 b/static/openbsd/man2/t2.2 new file mode 100644 index 00000000..40a0f253 --- /dev/null +++ b/static/openbsd/man2/t2.2 @@ -0,0 +1,25 @@ +Below is an example license to be used for new code in OpenBSD, +modeled after the ISC license. + +It is important to specify the year of the copyright. Additional years +should be separated by a comma, e.g. + Copyright (c) 2003, 2004, 2005 + +If you add extra text to the body of the license, be careful not to +add further restrictions. + +/* + * Copyright (c) CCYY YOUR NAME HERE <user@your.dom.ain> + * + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +An extra line diff --git a/static/openbsd/man2/t3.2 b/static/openbsd/man2/t3.2 new file mode 100644 index 00000000..e01fce04 --- /dev/null +++ b/static/openbsd/man2/t3.2 @@ -0,0 +1,25 @@ +Below is an example license to be used for new code in OpenBSD, +modeled after the ISC license. + +It is important to specify the year of the copyright. Additional years +should be separated by a comma, e.g. + Copyright (c) 2003, 2004 + +If you add extra text to the body of the license, be careful not to +add further restrictions. + +/* + * Copyright (c) CCYY YOUR NAME HERE <user@your.dom.ain> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/static/openbsd/man2/t4.2 b/static/openbsd/man2/t4.2 new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/static/openbsd/man2/t4.2 diff --git a/static/openbsd/man2/t5.2 b/static/openbsd/man2/t5.2 new file mode 100644 index 00000000..44312fc9 --- /dev/null +++ b/static/openbsd/man2/t5.2 @@ -0,0 +1,10 @@ +OpenBSD 3.3-current (GENERIC) #47: Mon Jun 30 11:19:56 CEST 2003 + +Welcome to OpenBSD: The proactively secure Unix-like operating system. + +Please use the sendbug(1) utility to report bugs in the system. +Before reporting a bug, please try to reproduce it with the latest +version of the code. With bug reports, please try to ensure that +enough information to reproduce the problem is enclosed, and if a +known fix for it exists, include that as well. + diff --git a/static/openbsd/man2/t6.2 b/static/openbsd/man2/t6.2 new file mode 100644 index 00000000..54d08bd6 --- /dev/null +++ b/static/openbsd/man2/t6.2 @@ -0,0 +1,9 @@ +OpenBSD 3.3-current (GENERIC) #47: Mon Jun 30 11:19:56 CEST 2003 + +Welcome to OpenBSD: The proactively secure Unix-like operating system. + +Please use the sendbug(1) utility to report bugs in the system. +Before reporting a bug, please try to reproduce it with the latest +version of the code. With bug reports, please try to ensure that +enough information to reproduce the problem is enclosed, and if a +known fix for it exists, include that as well. diff --git a/static/openbsd/man2/t7.2 b/static/openbsd/man2/t7.2 new file mode 100644 index 00000000..0e009186 --- /dev/null +++ b/static/openbsd/man2/t7.2 @@ -0,0 +1,9 @@ +OpenBSD 3.3-current (GENERIC) #47: Mon Jun 30 11:19:56 CEST 2003 + +Welcome to OpenBSD: The proactively secure Unix-like operating system. + +Please use the sendbug(1) utility to report bugs in the system. +Before reporting a bug, please try to reproduce it with the latest +version of the code. With bug reports, please try to ensure that +enough information to reproduce the problem is enclosed, and if a +known fix for it exists, include that as well.
\ No newline at end of file diff --git a/static/openbsd/man2/t8.2 b/static/openbsd/man2/t8.2 new file mode 100644 index 00000000..f060fd1a --- /dev/null +++ b/static/openbsd/man2/t8.2 @@ -0,0 +1,616 @@ +/* $OpenBSD: t8.2,v 1.2 2024/07/10 09:20:33 krw Exp $ */ +/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ + +/* + * Copyright (c) 1987, 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. 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. + * + * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/systm.h> +#include <sys/sysctl.h> + +#include <uvm/uvm_extern.h> + +static struct vm_map_intrsafe kmem_map_store; +struct vm_map *kmem_map = NULL; + +#ifdef NKMEMCLUSTERS +#error NKMEMCLUSTERS is obsolete; remove it from your kernel config file and use NKMEMPAGES instead or let the kernel auto-size +#endif + +/* + * Default number of pages in kmem_map. We attempt to calculate this + * at run-time, but allow it to be either patched or set in the kernel + * config file. + */ +#ifndef NKMEMPAGES +#define NKMEMPAGES 0 +#endif +int nkmempages = NKMEMPAGES; + +/* + * Defaults for lower- and upper-bounds for the kmem_map page count. + * Can be overridden by kernel config options. + */ +#ifndef NKMEMPAGES_MIN +#define NKMEMPAGES_MIN NKMEMPAGES_MIN_DEFAULT +#endif + +#ifndef NKMEMPAGES_MAX +#define NKMEMPAGES_MAX NKMEMPAGES_MAX_DEFAULT +#endif + +struct kmembuckets bucket[MINBUCKET + 16]; +struct kmemstats kmemstats[M_LAST]; +struct kmemusage *kmemusage; +char *kmembase, *kmemlimit; +char buckstring[16 * sizeof("123456,")]; +int buckstring_init = 0; +#if defined(KMEMSTATS) || defined(DIAGNOSTIC) +char *memname[] = INITKMEMNAMES; +char *memall = NULL; +extern struct lock sysctl_kmemlock; +#endif + +#ifdef DIAGNOSTIC +/* + * This structure provides a set of masks to catch unaligned frees. + */ +const long addrmask[] = { 0, + 0x00000001, 0x00000003, 0x00000007, 0x0000000f, + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, + 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, + 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff, +}; + +/* + * The WEIRD_ADDR is used as known text to copy into free objects so + * that modifications after frees can be detected. + */ +#define WEIRD_ADDR ((unsigned) 0xdeadbeef) +#define MAX_COPY 32 + +/* + * Normally the freelist structure is used only to hold the list pointer + * for free objects. However, when running with diagnostics, the first + * 8 bytes of the structure is unused except for diagnostic information, + * and the free list pointer is at offset 8 in the structure. Since the + * first 8 bytes is the portion of the structure most often modified, this + * helps to detect memory reuse problems and avoid free list corruption. + */ +struct freelist { + int32_t spare0; + int16_t type; + int16_t spare1; + caddr_t next; +}; +#else /* !DIAGNOSTIC */ +struct freelist { + caddr_t next; +}; +#endif /* DIAGNOSTIC */ + +/* + * Allocate a block of memory + */ +void * +malloc(size, type, flags) + unsigned long size; + int type, flags; +{ + register struct kmembuckets *kbp; + register struct kmemusage *kup; + register struct freelist *freep; + long indx, npg, allocsize; + int s; + caddr_t va, cp, savedlist; +#ifdef DIAGNOSTIC + int32_t *end, *lp; + int copysize; + char *savedtype; +#endif +#ifdef KMEMSTATS + register struct kmemstats *ksp = &kmemstats[type]; + + if (((unsigned long)type) >= M_LAST) + panic("malloc - bogus type"); +#endif + +#ifdef MALLOC_DEBUG + if (debug_malloc(size, type, flags, (void **)&va)) + return ((void *) va); +#endif + + indx = BUCKETINDX(size); + kbp = &bucket[indx]; + s = splvm(); +#ifdef KMEMSTATS + while (ksp->ks_memuse >= ksp->ks_limit) { + if (flags & M_NOWAIT) { + splx(s); + return ((void *) NULL); + } + if (ksp->ks_limblocks < 65535) + ksp->ks_limblocks++; + tsleep((caddr_t)ksp, PSWP+2, memname[type], 0); + } + ksp->ks_size |= 1 << indx; +#endif +#ifdef DIAGNOSTIC + copysize = 1 << indx < MAX_COPY ? 1 << indx : MAX_COPY; +#endif + if (kbp->kb_next == NULL) { + kbp->kb_last = NULL; + if (size > MAXALLOCSAVE) + allocsize = round_page(size); + else + allocsize = 1 << indx; + npg = btoc(allocsize); + va = (caddr_t) uvm_km_kmemalloc(kmem_map, uvmexp.kmem_object, + (vsize_t)ctob(npg), + (flags & M_NOWAIT) ? UVM_KMF_NOWAIT : 0); + if (va == NULL) { + /* + * Kmem_malloc() can return NULL, even if it can + * wait, if there is no map space available, because + * it can't fix that problem. Neither can we, + * right now. (We should release pages which + * are completely free and which are in buckets + * with too many free elements.) + */ + if ((flags & M_NOWAIT) == 0) + panic("malloc: out of space in kmem_map"); + splx(s); + return ((void *) NULL); + } +#ifdef KMEMSTATS + kbp->kb_total += kbp->kb_elmpercl; +#endif + kup = btokup(va); + kup->ku_indx = indx; + if (allocsize > MAXALLOCSAVE) { + if (npg > 65535) + panic("malloc: allocation too large"); + kup->ku_pagecnt = npg; +#ifdef KMEMSTATS + ksp->ks_memuse += allocsize; +#endif + goto out; + } +#ifdef KMEMSTATS + kup->ku_freecnt = kbp->kb_elmpercl; + kbp->kb_totalfree += kbp->kb_elmpercl; +#endif + /* + * Just in case we blocked while allocating memory, + * and someone else also allocated memory for this + * bucket, don't assume the list is still empty. + */ + savedlist = kbp->kb_next; + kbp->kb_next = cp = va + (npg * PAGE_SIZE) - allocsize; + for (;;) { + freep = (struct freelist *)cp; +#ifdef DIAGNOSTIC + /* + * Copy in known text to detect modification + * after freeing. + */ + end = (int32_t *)&cp[copysize]; + for (lp = (int32_t *)cp; lp < end; lp++) + *lp = WEIRD_ADDR; + freep->type = M_FREE; +#endif /* DIAGNOSTIC */ + if (cp <= va) + break; + cp -= allocsize; + freep->next = cp; + } + freep->next = savedlist; + if (kbp->kb_last == NULL) + kbp->kb_last = (caddr_t)freep; + } + va = kbp->kb_next; + kbp->kb_next = ((struct freelist *)va)->next; +#ifdef DIAGNOSTIC + freep = (struct freelist *)va; + savedtype = (unsigned)freep->type < M_LAST ? + memname[freep->type] : "???"; + if (kbp->kb_next) { + int rv; + vaddr_t addr = (vaddr_t)kbp->kb_next; + + vm_map_lock(kmem_map); + rv = uvm_map_checkprot(kmem_map, addr, + addr + sizeof(struct freelist), VM_PROT_WRITE); + vm_map_unlock(kmem_map); + + if (!rv) { + printf("%s %d of object %p size 0x%lx %s %s (invalid addr %p)\n", + "Data modified on freelist: word", + (int32_t *)&kbp->kb_next - (int32_t *)kbp, va, size, + "previous type", savedtype, kbp->kb_next); + kbp->kb_next = NULL; + } + } + + /* Fill the fields that we've used with WEIRD_ADDR */ +#if BYTE_ORDER == BIG_ENDIAN + freep->type = WEIRD_ADDR >> 16; +#endif +#if BYTE_ORDER == LITTLE_ENDIAN + freep->type = (short)WEIRD_ADDR; +#endif + end = (int32_t *)&freep->next + + (sizeof(freep->next) / sizeof(int32_t)); + for (lp = (int32_t *)&freep->next; lp < end; lp++) + *lp = WEIRD_ADDR; + + /* and check that the data hasn't been modified. */ + end = (int32_t *)&va[copysize]; + for (lp = (int32_t *)va; lp < end; lp++) { + if (*lp == WEIRD_ADDR) + continue; + printf("%s %d of object %p size 0x%lx %s %s (0x%x != 0x%x)\n", + "Data modified on freelist: word", lp - (int32_t *)va, + va, size, "previous type", savedtype, *lp, WEIRD_ADDR); + break; + } + + freep->spare0 = 0; +#endif /* DIAGNOSTIC */ +#ifdef KMEMSTATS + kup = btokup(va); + if (kup->ku_indx != indx) + panic("malloc: wrong bucket"); + if (kup->ku_freecnt == 0) + panic("malloc: lost data"); + kup->ku_freecnt--; + kbp->kb_totalfree--; + ksp->ks_memuse += 1 << indx; +out: + kbp->kb_calls++; + ksp->ks_inuse++; + ksp->ks_calls++; + if (ksp->ks_memuse > ksp->ks_maxused) + ksp->ks_maxused = ksp->ks_memuse; +#else +out: +#endif + splx(s); + return ((void *) va); +} + +/* + * Free a block of memory allocated by malloc. + */ +void +free(addr, type) + void *addr; + int type; +{ + register struct kmembuckets *kbp; + register struct kmemusage *kup; + register struct freelist *freep; + long size; + int s; +#ifdef DIAGNOSTIC + caddr_t cp; + int32_t *end, *lp; + long alloc, copysize; +#endif +#ifdef KMEMSTATS + register struct kmemstats *ksp = &kmemstats[type]; +#endif + +#ifdef MALLOC_DEBUG + if (debug_free(addr, type)) + return; +#endif + +#ifdef DIAGNOSTIC + if (addr < (void *)kmembase || addr >= (void *)kmemlimit) + panic("free: non-malloced addr %p type %s", addr, + memname[type]); +#endif + + kup = btokup(addr); + size = 1 << kup->ku_indx; + kbp = &bucket[kup->ku_indx]; + s = splvm(); +#ifdef DIAGNOSTIC + /* + * Check for returns of data that do not point to the + * beginning of the allocation. + */ + if (size > PAGE_SIZE) + alloc = addrmask[BUCKETINDX(PAGE_SIZE)]; + else + alloc = addrmask[kup->ku_indx]; + if (((u_long)addr & alloc) != 0) + panic("free: unaligned addr %p, size %ld, type %s, mask %ld", + addr, size, memname[type], alloc); +#endif /* DIAGNOSTIC */ + if (size > MAXALLOCSAVE) { + uvm_km_free(kmem_map, (vaddr_t)addr, ctob(kup->ku_pagecnt)); +#ifdef KMEMSTATS + size = kup->ku_pagecnt << PGSHIFT; + ksp->ks_memuse -= size; + kup->ku_indx = 0; + kup->ku_pagecnt = 0; + if (ksp->ks_memuse + size >= ksp->ks_limit && + ksp->ks_memuse < ksp->ks_limit) + wakeup((caddr_t)ksp); + ksp->ks_inuse--; + kbp->kb_total -= 1; +#endif + splx(s); + return; + } + freep = (struct freelist *)addr; +#ifdef DIAGNOSTIC + /* + * Check for multiple frees. Use a quick check to see if + * it looks free before laboriously searching the freelist. + */ + if (freep->spare0 == WEIRD_ADDR) { + for (cp = kbp->kb_next; cp; + cp = ((struct freelist *)cp)->next) { + if (addr != cp) + continue; + printf("multiply freed item %p\n", addr); + panic("free: duplicated free"); + } + } + /* + * Copy in known text to detect modification after freeing + * and to make it look free. Also, save the type being freed + * so we can list likely culprit if modification is detected + * when the object is reallocated. + */ + copysize = size < MAX_COPY ? size : MAX_COPY; + end = (int32_t *)&((caddr_t)addr)[copysize]; + for (lp = (int32_t *)addr; lp < end; lp++) + *lp = WEIRD_ADDR; + freep->type = type; +#endif /* DIAGNOSTIC */ +#ifdef KMEMSTATS + kup->ku_freecnt++; + if (kup->ku_freecnt >= kbp->kb_elmpercl) { + if (kup->ku_freecnt > kbp->kb_elmpercl) + panic("free: multiple frees"); + else if (kbp->kb_totalfree > kbp->kb_highwat) + kbp->kb_couldfree++; + } + kbp->kb_totalfree++; + ksp->ks_memuse -= size; + if (ksp->ks_memuse + size >= ksp->ks_limit && + ksp->ks_memuse < ksp->ks_limit) + wakeup((caddr_t)ksp); + ksp->ks_inuse--; +#endif + if (kbp->kb_next == NULL) + kbp->kb_next = addr; + else + ((struct freelist *)kbp->kb_last)->next = addr; + freep->next = NULL; + kbp->kb_last = addr; + splx(s); +} + +/* + * Compute the number of pages that kmem_map will map, that is, + * the size of the kernel malloc arena. + */ +void +kmeminit_nkmempages() +{ + int npages; + + if (nkmempages != 0) { + /* + * It's already been set (by us being here before, or + * by patching or kernel config options), bail out now. + */ + return; + } + + /* + * We use the following (simple) formula: + * + * - Starting point is physical memory / 4. + * + * - Clamp it down to NKMEMPAGES_MAX. + * + * - Round it up to NKMEMPAGES_MIN. + */ + npages = physmem / 4; + + if (npages > NKMEMPAGES_MAX) + npages = NKMEMPAGES_MAX; + + if (npages < NKMEMPAGES_MIN) + npages = NKMEMPAGES_MIN; + + nkmempages = npages; +} + +/* + * Initialize the kernel memory allocator + */ +void +kmeminit() +{ + vaddr_t base, limit; +#ifdef KMEMSTATS + long indx; +#endif + +#ifdef DIAGNOSTIC + if (sizeof(struct freelist) > (1 << MINBUCKET)) + panic("kmeminit: minbucket too small/struct freelist too big"); +#endif + + /* + * Compute the number of kmem_map pages, if we have not + * done so already. + */ + kmeminit_nkmempages(); + base = vm_map_min(kernel_map); + kmem_map = uvm_km_suballoc(kernel_map, &base, &limit, + (vsize_t)(nkmempages * PAGE_SIZE), VM_MAP_INTRSAFE, FALSE, + &kmem_map_store.vmi_map); + kmembase = (char *)base; + kmemlimit = (char *)limit; + kmemusage = (struct kmemusage *) uvm_km_zalloc(kernel_map, + (vsize_t)(nkmempages * sizeof(struct kmemusage))); +#ifdef KMEMSTATS + for (indx = 0; indx < MINBUCKET + 16; indx++) { + if (1 << indx >= PAGE_SIZE) + bucket[indx].kb_elmpercl = 1; + else + bucket[indx].kb_elmpercl = PAGE_SIZE / (1 << indx); + bucket[indx].kb_highwat = 5 * bucket[indx].kb_elmpercl; + } + for (indx = 0; indx < M_LAST; indx++) + kmemstats[indx].ks_limit = nkmempages * PAGE_SIZE * 6 / 10; +#endif +#ifdef MALLOC_DEBUG + debug_malloc_init(); +#endif +} + +/* + * Return kernel malloc statistics information. + */ +int +sysctl_malloc(name, namelen, oldp, oldlenp, newp, newlen, p) + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + struct proc *p; +{ + struct kmembuckets kb; + int i, siz; + + if (namelen != 2 && name[0] != KERN_MALLOC_BUCKETS && + name[0] != KERN_MALLOC_KMEMNAMES) + return (ENOTDIR); /* overloaded */ + + switch (name[0]) { + case KERN_MALLOC_BUCKETS: + /* Initialize the first time */ + if (buckstring_init == 0) { + buckstring_init = 1; + bzero(buckstring, sizeof(buckstring)); + for (siz = 0, i = MINBUCKET; i < MINBUCKET + 16; i++) { + snprintf(buckstring + siz, + sizeof buckstring - siz, + "%d,", (u_int)(1<<i)); + siz += strlen(buckstring + siz); + } + /* Remove trailing comma */ + if (siz) + buckstring[siz - 1] = '\0'; + } + return (sysctl_rdstring(oldp, oldlenp, newp, buckstring)); + + case KERN_MALLOC_BUCKET: + bcopy(&bucket[BUCKETINDX(name[1])], &kb, sizeof(kb)); + kb.kb_next = kb.kb_last = 0; + return (sysctl_rdstruct(oldp, oldlenp, newp, &kb, sizeof(kb))); + case KERN_MALLOC_KMEMSTATS: +#ifdef KMEMSTATS + if ((name[1] < 0) || (name[1] >= M_LAST)) + return (EINVAL); + return (sysctl_rdstruct(oldp, oldlenp, newp, + &kmemstats[name[1]], sizeof(struct kmemstats))); +#else + return (EOPNOTSUPP); +#endif + case KERN_MALLOC_KMEMNAMES: +#if defined(KMEMSTATS) || defined(DIAGNOSTIC) + if (memall == NULL) { + int totlen; + + i = lockmgr(&sysctl_kmemlock, LK_EXCLUSIVE, NULL, p); + if (i) + return (i); + + /* Figure out how large a buffer we need */ + for (totlen = 0, i = 0; i < M_LAST; i++) { + if (memname[i]) + totlen += strlen(memname[i]); + totlen++; + } + memall = malloc(totlen + M_LAST, M_SYSCTL, M_WAITOK); + bzero(memall, totlen + M_LAST); + for (siz = 0, i = 0; i < M_LAST; i++) { + snprintf(memall + siz, + totlen + M_LAST - siz, + "%s,", memname[i] ? memname[i] : ""); + siz += strlen(memall + siz); + } + /* Remove trailing comma */ + if (siz) + memall[siz - 1] = '\0'; + + /* Now, convert all spaces to underscores */ + for (i = 0; i < totlen; i++) + if (memall[i] == ' ') + memall[i] = '_'; + lockmgr(&sysctl_kmemlock, LK_RELEASE, NULL, p); + } + return (sysctl_rdstring(oldp, oldlenp, newp, memall)); +#else + return (EOPNOTSUPP); +#endif + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ +} + +/* + * Round up a size to how much malloc would actually allocate. + */ +size_t +malloc_roundup(size_t sz) +{ + if (sz > MAXALLOCSAVE) + return round_page(sz); + + return (1 << BUCKETINDX(sz)); +} diff --git a/static/openbsd/man2/t9.2 b/static/openbsd/man2/t9.2 new file mode 100644 index 00000000..7ef3b3aa --- /dev/null +++ b/static/openbsd/man2/t9.2 @@ -0,0 +1,3200 @@ +/* $OpenBSD: t9.2,v 1.4 2024/07/10 09:24:03 krw Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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 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. + * + * @(#)vfs_syscalls.c 8.28 (Berkeley) 12/10/94 + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/namei.h> +#include <sys/filedesc.h> +#include <sys/kernel.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/vnode.h> +#include <sys/mount.h> +#include <sys/proc.h> +#include <sys/uio.h> +#include <sys/malloc.h> +#include <sys/dirent.h> +#include <sys/extattr.h> + +#include <sys/syscallargs.h> + +#include <uvm/uvm_extern.h> +#include <sys/sysctl.h> + +extern int suid_clear; +int usermount = 0; /* sysctl: by default, users may not mount */ + +static int change_dir(struct nameidata *, struct proc *); + +void checkdirs(struct vnode *); + +/* + * Redirection info so we don't have to include the union fs routines in + * the kernel directly. This way, we can build unionfs as an LKM. The + * pointer gets filled in later, when we modload the LKM, or when the + * compiled-in unionfs code gets initialized. For now, we just set + * it to a stub routine. + */ + +int (*union_check_p)(struct proc *, struct vnode **, + struct file *, struct uio, int *) = NULL; + +/* + * Virtual File System System Calls + */ + +/* + * Mount a file system. + */ +/* ARGSUSED */ +int +sys_mount(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_mount_args /* { + syscallarg(char *) type; + syscallarg(char *) path; + syscallarg(int) flags; + syscallarg(void *) data; + } */ *uap = v; + register struct vnode *vp; + register struct mount *mp; + int error, flag = 0; +#ifdef COMPAT_43 + u_long fstypenum = 0; +#endif + char fstypename[MFSNAMELEN]; + char fspath[MNAMELEN]; + struct vattr va; + struct nameidata nd; + struct vfsconf *vfsp; + struct timeval tv; + + if (usermount == 0 && (error = suser(p->p_ucred, &p->p_acflag))) + return (error); + + /* + * Mount points must fit in MNAMELEN, not MAXPATHLEN. + */ + error = copyinstr(SCARG(uap, path), fspath, MNAMELEN, NULL); + if (error) + return(error); + + /* + * Get vnode to be covered + */ + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspath, p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + if (SCARG(uap, flags) & MNT_UPDATE) { + if ((vp->v_flag & VROOT) == 0) { + vput(vp); + return (EINVAL); + } + mp = vp->v_mount; + flag = mp->mnt_flag; + /* + * We only allow the filesystem to be reloaded if it + * is currently mounted read-only. + */ + if ((SCARG(uap, flags) & MNT_RELOAD) && + ((mp->mnt_flag & MNT_RDONLY) == 0)) { + vput(vp); + return (EOPNOTSUPP); /* Needs translation */ + } + mp->mnt_flag |= + SCARG(uap, flags) & (MNT_RELOAD | MNT_UPDATE); + /* + * Only root, or the user that did the original mount is + * permitted to update it. + */ + if (mp->mnt_stat.f_owner != p->p_ucred->cr_uid && + (error = suser(p->p_ucred, &p->p_acflag))) { + vput(vp); + return (error); + } + /* + * Do not allow NFS export by non-root users. Silently + * enforce MNT_NOSUID and MNT_NODEV for non-root users. + */ + if (p->p_ucred->cr_uid != 0) { + if (SCARG(uap, flags) & MNT_EXPORTED) { + vput(vp); + return (EPERM); + } + SCARG(uap, flags) |= MNT_NOSUID | MNT_NODEV; + } + if ((error = vfs_busy(mp, LK_NOWAIT, 0, p)) != 0) { + vput(vp); + return (error); + } + VOP_UNLOCK(vp, 0, p); + goto update; + } + /* + * If the user is not root, ensure that they own the directory + * onto which we are attempting to mount. + */ + if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)) || + (va.va_uid != p->p_ucred->cr_uid && + (error = suser(p->p_ucred, &p->p_acflag)))) { + vput(vp); + return (error); + } + /* + * Do not allow NFS export by non-root users. Silently + * enforce MNT_NOSUID and MNT_NODEV for non-root users. + */ + if (p->p_ucred->cr_uid != 0) { + if (SCARG(uap, flags) & MNT_EXPORTED) { + vput(vp); + return (EPERM); + } + SCARG(uap, flags) |= MNT_NOSUID | MNT_NODEV; + } + if ((error = vinvalbuf(vp, V_SAVE, p->p_ucred, p, 0, 0)) != 0) + return (error); + if (vp->v_type != VDIR) { + vput(vp); + return (ENOTDIR); + } + error = copyinstr(SCARG(uap, type), fstypename, MFSNAMELEN, NULL); + if (error) { +#ifdef COMPAT_43 + /* + * Historically filesystem types were identified by number. + * If we get an integer for the filesystem type instead of a + * string, we check to see if it matches one of the historic + * filesystem types. + */ + fstypenum = (u_long)SCARG(uap, type); + + for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) + if (vfsp->vfc_typenum == fstypenum) + break; + if (vfsp == NULL) { + vput(vp); + return (ENODEV); + } + strncpy(fstypename, vfsp->vfc_name, MFSNAMELEN); + +#else + vput(vp); + return (error); +#endif + } + for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) { + if (!strcmp(vfsp->vfc_name, fstypename)) + break; + } + + if (vfsp == NULL) { + vput(vp); + return (EOPNOTSUPP); + } + + if (vp->v_mountedhere != NULL) { + vput(vp); + return (EBUSY); + } + + /* + * Allocate and initialize the file system. + */ + mp = (struct mount *)malloc((u_long)sizeof(struct mount), + M_MOUNT, M_WAITOK); + bzero((char *)mp, (u_long)sizeof(struct mount)); + lockinit(&mp->mnt_lock, PVFS, "vfslock", 0, 0); + /* This error never happens, but it makes auditing easier */ + if ((error = vfs_busy(mp, LK_NOWAIT, 0, p))) + return (error); + mp->mnt_op = vfsp->vfc_vfsops; + mp->mnt_vfc = vfsp; + mp->mnt_flag |= (vfsp->vfc_flags & MNT_VISFLAGMASK); + strncpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN); + mp->mnt_vnodecovered = vp; + mp->mnt_stat.f_owner = p->p_ucred->cr_uid; +update: + /* + * Set the mount level flags. + */ + if (SCARG(uap, flags) & MNT_RDONLY) + mp->mnt_flag |= MNT_RDONLY; + else if (mp->mnt_flag & MNT_RDONLY) + mp->mnt_flag |= MNT_WANTRDWR; + mp->mnt_flag &=~ (MNT_NOSUID | MNT_NOEXEC | MNT_NODEV | + MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | MNT_SOFTDEP | + MNT_NOATIME | MNT_FORCE); + mp->mnt_flag |= SCARG(uap, flags) & (MNT_NOSUID | MNT_NOEXEC | + MNT_NODEV | MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | + MNT_SOFTDEP | MNT_NOATIME | MNT_FORCE); + /* + * Mount the filesystem. + */ + error = VFS_MOUNT(mp, SCARG(uap, path), SCARG(uap, data), &nd, p); + if (!error) { + microtime(&tv); + mp->mnt_stat.f_ctime = tv.tv_sec; + } + if (mp->mnt_flag & MNT_UPDATE) { + vrele(vp); + if (mp->mnt_flag & MNT_WANTRDWR) + mp->mnt_flag &= ~MNT_RDONLY; + mp->mnt_flag &=~ + (MNT_UPDATE | MNT_RELOAD | MNT_FORCE | MNT_WANTRDWR); + if (error) + mp->mnt_flag = flag; + + if ((mp->mnt_flag & MNT_RDONLY) == 0) { + if (mp->mnt_syncer == NULL) + error = vfs_allocate_syncvnode(mp); + } else { + if (mp->mnt_syncer != NULL) + vgone(mp->mnt_syncer); + mp->mnt_syncer = NULL; + } + + vfs_unbusy(mp, p); + return (error); + } + + vp->v_mountedhere = mp; + + /* + * Put the new filesystem on the mount list after root. + */ + cache_purge(vp); + if (!error) { + vfsp->vfc_refcount++; + simple_lock(&mountlist_slock); + TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list); + simple_unlock(&mountlist_slock); + checkdirs(vp); + VOP_UNLOCK(vp, 0, p); + if ((mp->mnt_flag & MNT_RDONLY) == 0) + error = vfs_allocate_syncvnode(mp); + vfs_unbusy(mp, p); + (void) VFS_STATFS(mp, &mp->mnt_stat, p); + if ((error = VFS_START(mp, 0, p)) != 0) + vrele(vp); + } else { + mp->mnt_vnodecovered->v_mountedhere = (struct mount *)0; + vfs_unbusy(mp, p); + free((caddr_t)mp, M_MOUNT); + vput(vp); + } + return (error); +} + +/* + * Scan all active processes to see if any of them have a current + * or root directory onto which the new filesystem has just been + * mounted. If so, replace them with the new mount point. + */ +void +checkdirs(olddp) + struct vnode *olddp; +{ + struct filedesc *fdp; + struct vnode *newdp; + struct proc *p; + + if (olddp->v_usecount == 1) + return; + if (VFS_ROOT(olddp->v_mountedhere, &newdp)) + panic("mount: lost mount"); + for (p = LIST_FIRST(&allproc); p != 0; p = LIST_NEXT(p, p_list)) { + fdp = p->p_fd; + if (fdp->fd_cdir == olddp) { + vrele(fdp->fd_cdir); + VREF(newdp); + fdp->fd_cdir = newdp; + } + if (fdp->fd_rdir == olddp) { + vrele(fdp->fd_rdir); + VREF(newdp); + fdp->fd_rdir = newdp; + } + } + if (rootvnode == olddp) { + vrele(rootvnode); + VREF(newdp); + rootvnode = newdp; + } + vput(newdp); +} + +/* + * Unmount a file system. + * + * Note: unmount takes a path to the vnode mounted on as argument, + * not special file (as before). + */ +/* ARGSUSED */ +int +sys_unmount(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_unmount_args /* { + syscallarg(char *) path; + syscallarg(int) flags; + } */ *uap = v; + register struct vnode *vp; + struct mount *mp; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + mp = vp->v_mount; + + /* + * Only root, or the user that did the original mount is + * permitted to unmount this filesystem. + */ + if ((mp->mnt_stat.f_owner != p->p_ucred->cr_uid) && + (error = suser(p->p_ucred, &p->p_acflag))) { + vput(vp); + return (error); + } + + /* + * Don't allow unmounting the root file system. + */ + if (mp->mnt_flag & MNT_ROOTFS) { + vput(vp); + return (EINVAL); + } + + /* + * Must be the root of the filesystem + */ + if ((vp->v_flag & VROOT) == 0) { + vput(vp); + return (EINVAL); + } + vput(vp); + + if (vfs_busy(mp, LK_EXCLUSIVE, NULL, p)) + return (EBUSY); + + return (dounmount(mp, SCARG(uap, flags), p, vp)); +} + +/* + * Do the actual file system unmount. + */ +int +dounmount(struct mount *mp, int flags, struct proc *p, struct vnode *olddp) +{ + struct vnode *coveredvp; + struct proc *p2; + int error; + int hadsyncer = 0; + + mp->mnt_flag &=~ MNT_ASYNC; + cache_purgevfs(mp); /* remove cache entries for this file sys */ + if (mp->mnt_syncer != NULL) { + hadsyncer = 1; + vgone(mp->mnt_syncer); + mp->mnt_syncer = NULL; + } + if (((mp->mnt_flag & MNT_RDONLY) || + (error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p)) == 0) || + (flags & MNT_FORCE)) + error = VFS_UNMOUNT(mp, flags, p); + simple_lock(&mountlist_slock); + if (error) { + if ((mp->mnt_flag & MNT_RDONLY) == 0 && hadsyncer) + (void) vfs_allocate_syncvnode(mp); + lockmgr(&mp->mnt_lock, LK_RELEASE | LK_INTERLOCK, + &mountlist_slock, p); + return (error); + } + TAILQ_REMOVE(&mountlist, mp, mnt_list); + if ((coveredvp = mp->mnt_vnodecovered) != NULLVP) { + if (olddp) { + /* + * Try to put processes back in a real directory + * after a forced unmount. + * XXX We're not holding a ref on olddp, which may + * change, so compare id numbers. + */ + LIST_FOREACH(p2, &allproc, p_list) { + struct filedesc *fdp = p2->p_fd; + if (fdp->fd_cdir && + fdp->fd_cdir->v_id == olddp->v_id) { + vrele(fdp->fd_cdir); + vref(coveredvp); + fdp->fd_cdir = coveredvp; + } + if (fdp->fd_rdir && + fdp->fd_rdir->v_id == olddp->v_id) { + vrele(fdp->fd_rdir); + vref(coveredvp); + fdp->fd_rdir = coveredvp; + } + } + } + coveredvp->v_mountedhere = NULL; + vrele(coveredvp); + } + mp->mnt_vfc->vfc_refcount--; + if (mp->mnt_vnodelist.lh_first != NULL) + panic("unmount: dangling vnode"); + lockmgr(&mp->mnt_lock, LK_RELEASE | LK_INTERLOCK, &mountlist_slock, p); + free((caddr_t)mp, M_MOUNT); + return (0); +} + +/* + * Sync each mounted filesystem. + */ +#ifdef DEBUG +int syncprt = 0; +struct ctldebug debug0 = { "syncprt", &syncprt }; +#endif + +/* ARGSUSED */ +int +sys_sync(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct mount *mp, *nmp; + int asyncflag; + + simple_lock(&mountlist_slock); + TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mnt_list, nmp) { + if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock, p)) + continue; + if ((mp->mnt_flag & MNT_RDONLY) == 0) { + asyncflag = mp->mnt_flag & MNT_ASYNC; + mp->mnt_flag &= ~MNT_ASYNC; + uvm_vnp_sync(mp); + VFS_SYNC(mp, MNT_NOWAIT, p->p_ucred, p); + if (asyncflag) + mp->mnt_flag |= MNT_ASYNC; + } + simple_lock(&mountlist_slock); + vfs_unbusy(mp, p); + } + simple_unlock(&mountlist_slock); + +#ifdef DEBUG + if (syncprt) + vfs_bufstats(); +#endif /* DEBUG */ + return (0); +} + +/* + * Change filesystem quotas. + */ +/* ARGSUSED */ +int +sys_quotactl(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_quotactl_args /* { + syscallarg(char *) path; + syscallarg(int) cmd; + syscallarg(int) uid; + syscallarg(caddr_t) arg; + } */ *uap = v; + register struct mount *mp; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + mp = nd.ni_vp->v_mount; + vrele(nd.ni_vp); + return (VFS_QUOTACTL(mp, SCARG(uap, cmd), SCARG(uap, uid), + SCARG(uap, arg), p)); +} + +/* + * Get filesystem statistics. + */ +/* ARGSUSED */ +int +sys_statfs(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_statfs_args /* { + syscallarg(char *) path; + syscallarg(struct statfs *) buf; + } */ *uap = v; + register struct mount *mp; + register struct statfs *sp; + int error; + struct nameidata nd; + struct statfs sb; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + mp = nd.ni_vp->v_mount; + sp = &mp->mnt_stat; + vrele(nd.ni_vp); + if ((error = VFS_STATFS(mp, sp, p)) != 0) + return (error); + sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + /* Don't let non-root see filesystem id (for NFS security) */ + if (suser(p->p_ucred, &p->p_acflag)) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } + return (copyout((caddr_t)sp, (caddr_t)SCARG(uap, buf), sizeof(*sp))); +} + +/* + * Get filesystem statistics. + */ +/* ARGSUSED */ +int +sys_fstatfs(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_fstatfs_args /* { + syscallarg(int) fd; + syscallarg(struct statfs *) buf; + } */ *uap = v; + struct file *fp; + struct mount *mp; + struct statfs *sp; + int error; + struct statfs sb; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + mp = ((struct vnode *)fp->f_data)->v_mount; + sp = &mp->mnt_stat; + error = VFS_STATFS(mp, sp, p); + FRELE(fp); + if (error) + return (error); + sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + /* Don't let non-root see filesystem id (for NFS security) */ + if (suser(p->p_ucred, &p->p_acflag)) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } + return (copyout((caddr_t)sp, (caddr_t)SCARG(uap, buf), sizeof(*sp))); +} + +/* + * Get statistics on all filesystems. + */ +int +sys_getfsstat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_getfsstat_args /* { + syscallarg(struct statfs *) buf; + syscallarg(size_t) bufsize; + syscallarg(int) flags; + } */ *uap = v; + register struct mount *mp *nmp; + register struct statfs *sp; + struct statfs sb; + caddr_t sfsp; + size_t count, maxcount; + int error, flags = SCARG(uap, flags); + + maxcount = SCARG(uap, bufsize) / sizeof(struct statfs); + sfsp = (caddr_t)SCARG(uap, buf); + count = 0; + simple_lock(&mountlist_slock); + TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mnt_list, nmp) { + if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock, p)) + continue; + if (sfsp && count < maxcount) { + sp = &mp->mnt_stat; + + /* Refresh stats unless MNT_NOWAIT is specified */ + if (flags != MNT_NOWAIT && + flags != MNT_LAZY && + (flags == MNT_WAIT || + flags == 0) && + (error = VFS_STATFS(mp, sp, p))) { + simple_lock(&mountlist_slock); + vfs_unbusy(mp, p); + continue; + } + + sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + if (suser(p->p_ucred, &p->p_acflag)) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } + error = copyout((caddr_t)sp, sfsp, sizeof(*sp)); + if (error) { + vfs_unbusy(mp, p); + return (error); + } + sfsp += sizeof(*sp); + } + count++; + simple_lock(&mountlist_slock); + vfs_unbusy(mp, p); + } + simple_unlock(&mountlist_slock); + if (sfsp && count > maxcount) + *retval = maxcount; + else + *retval = count; + return (0); +} + +/* + * Change current working directory to a given file descriptor. + */ +/* ARGSUSED */ +int +sys_fchdir(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_fchdir_args /* { + syscallarg(int) fd; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct vnode *vp, *tdp; + struct mount *mp; + struct file *fp; + int error; + + if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + VREF(vp); + FRELE(fp); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_type != VDIR) + error = ENOTDIR; + else + error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); + + while (!error && (mp = vp->v_mountedhere) != NULL) { + if (vfs_busy(mp, 0, 0, p)) + continue; + error = VFS_ROOT(mp, &tdp); + vfs_unbusy(mp, p); + if (error) + break; + vput(vp); + vp = tdp; + } + if (error) { + vput(vp); + return (error); + } + VOP_UNLOCK(vp, 0, p); + vrele(fdp->fd_cdir); + fdp->fd_cdir = vp; + return (0); +} + +/* + * Change current working directory (``.''). + */ +/* ARGSUSED */ +int +sys_chdir(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_chdir_args /* { + syscallarg(char *) path; + } */ *uap = v; + register struct filedesc *fdp = p->p_fd; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = change_dir(&nd, p)) != 0) + return (error); + vrele(fdp->fd_cdir); + fdp->fd_cdir = nd.ni_vp; + return (0); +} + +/* + * Change notion of root (``/'') directory. + */ +/* ARGSUSED */ +int +sys_chroot(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_chroot_args /* { + syscallarg(char *) path; + } */ *uap = v; + register struct filedesc *fdp = p->p_fd; + int error; + struct nameidata nd; + + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return (error); + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = change_dir(&nd, p)) != 0) + return (error); + if (fdp->fd_rdir != NULL) { + /* + * A chroot() done inside a changed root environment does + * an automatic chdir to avoid the out-of-tree experience. + */ + vrele(fdp->fd_rdir); + vrele(fdp->fd_cdir); + VREF(nd.ni_vp); + fdp->fd_cdir = nd.ni_vp; + } + fdp->fd_rdir = nd.ni_vp; + return (0); +} + +/* + * Common routine for chroot and chdir. + */ +static int +change_dir(ndp, p) + register struct nameidata *ndp; + struct proc *p; +{ + struct vnode *vp; + int error; + + if ((error = namei(ndp)) != 0) + return (error); + vp = ndp->ni_vp; + if (vp->v_type != VDIR) + error = ENOTDIR; + else + error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); + if (error) + vput(vp); + else + VOP_UNLOCK(vp, 0, p); + return (error); +} + +/* + * Check permissions, allocate an open file structure, + * and call the device open routine if any. + */ +int +sys_open(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_open_args /* { + syscallarg(char *) path; + syscallarg(int) flags; + syscallarg(int) mode; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + struct vattr vattr; + int flags, cmode; + int type, indx, error, localtrunc = 0; + struct flock lf; + struct nameidata nd; + + if ((error = falloc(p, &fp, &indx)) != 0) + return (error); + + flags = FFLAGS(SCARG(uap, flags)); + cmode = ((SCARG(uap, mode) &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT; + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + p->p_dupfd = -indx - 1; /* XXX check for fdopen */ + if ((flags & O_TRUNC) && (flags & (O_EXLOCK | O_SHLOCK))) { + localtrunc = 1; + flags &= ~O_TRUNC; /* Must do truncate ourselves */ + } + if ((error = vn_open(&nd, flags, cmode)) != 0) { + if ((error == ENODEV || error == ENXIO) && + p->p_dupfd >= 0 && /* XXX from fdopen */ + (error = + dupfdopen(fdp, indx, p->p_dupfd, flags, error)) == 0) { + closef(fp, p); + *retval = indx; + return (0); + } + if (error == ERESTART) + error = EINTR; + fdremove(fdp, indx); + closef(fp, p); + return (error); + } + p->p_dupfd = 0; + vp = nd.ni_vp; + fp->f_flag = flags & FMASK; + fp->f_type = DTYPE_VNODE; + fp->f_ops = &vnops; + fp->f_data = (caddr_t)vp; + if (flags & (O_EXLOCK | O_SHLOCK)) { + lf.l_whence = SEEK_SET; + lf.l_start = 0; + lf.l_len = 0; + if (flags & O_EXLOCK) + lf.l_type = F_WRLCK; + else + lf.l_type = F_RDLCK; + type = F_FLOCK; + if ((flags & FNONBLOCK) == 0) + type |= F_WAIT; + VOP_UNLOCK(vp, 0, p); + error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type); + if (error) { + /* closef will vn_close the file for us. */ + fdremove(fdp, indx); + closef(fp, p); + return (error); + } + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + fp->f_flag |= FHASLOCK; + } + if (localtrunc) { + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + if ((fp->f_flag & FWRITE) == 0) + error = EACCES; + else if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else if (vp->v_type == VDIR) + error = EISDIR; + else if ((error = vn_writechk(vp)) == 0) { + VATTR_NULL(&vattr); + vattr.va_size = 0; + error = VOP_SETATTR(vp, &vattr, fp->f_cred, p); + } + if (error) { + VOP_UNLOCK(vp, 0, p); + /* closef will close the file for us. */ + fdremove(fdp, indx); + closef(fp, p); + return (error); + } + } + VOP_UNLOCK(vp, 0, p); + *retval = indx; + FILE_SET_MATURE(fp); + return (0); +} + +/* + * Get file handle system call + */ +int +sys_getfh(p, v, retval) + struct proc *p; + register void *v; + register_t *retval; +{ + register struct sys_getfh_args /* { + syscallarg(char *) fname; + syscallarg(fhandle_t *) fhp; + } */ *uap = v; + register struct vnode *vp; + fhandle_t fh; + int error; + struct nameidata nd; + + /* + * Must be super user + */ + error = suser(p->p_ucred, &p->p_acflag); + if (error) + return (error); + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, fname), p); + error = namei(&nd); + if (error) + return (error); + vp = nd.ni_vp; + bzero((caddr_t)&fh, sizeof(fh)); + fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid; + error = VFS_VPTOFH(vp, &fh.fh_fid); + vput(vp); + if (error) + return (error); + error = copyout((caddr_t)&fh, (caddr_t)SCARG(uap, fhp), sizeof (fh)); + return (error); +} + +/* + * Open a file given a file handle. + * + * Check permissions, allocate an open file structure, + * and call the device open routine if any. + */ +int +sys_fhopen(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_fhopen_args /* { + syscallarg(const fhandle_t *) fhp; + syscallarg(int) flags; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp = NULL; + struct mount *mp; + struct ucred *cred = p->p_ucred; + int flags; + int type, indx, error=0; + struct flock lf; + struct vattr va; + fhandle_t fh; + + /* + * Must be super user + */ + if ((error = suser(p->p_ucred, &p->p_acflag))) + return (error); + + flags = FFLAGS(SCARG(uap, flags)); + if ((flags & (FREAD | FWRITE)) == 0) + return (EINVAL); + if ((flags & O_CREAT)) + return (EINVAL); + + if ((error = falloc(p, &fp, &indx)) != 0) + return (error); + + if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0) + goto bad; + + if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL) { + error = ESTALE; + goto bad; + } + + if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)) != 0) { + vp = NULL; /* most likely unnecessary sanity for bad: */ + goto bad; + } + + /* Now do an effective vn_open */ + + if (vp->v_type == VSOCK) { + error = EOPNOTSUPP; + goto bad; + } + if (flags & FREAD) { + if ((error = VOP_ACCESS(vp, VREAD, cred, p)) != 0) + goto bad; + } + if (flags & (FWRITE | O_TRUNC)) { + if (vp->v_type == VDIR) { + error = EISDIR; + goto bad; + } + if ((error = vn_writechk(vp)) != 0 || + (error = VOP_ACCESS(vp, VWRITE, cred, p)) != 0) + goto bad; + } + if (flags & O_TRUNC) { + VOP_UNLOCK(vp, 0, p); /* XXX */ + VOP_LEASE(vp, p, cred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); /* XXX */ + VATTR_NULL(&va); + va.va_size = 0; + if ((error = VOP_SETATTR(vp, &va, cred, p)) != 0) + goto bad; + } + if ((error = VOP_OPEN(vp, flags, cred, p)) != 0) + goto bad; + if (flags & FWRITE) + vp->v_writecount++; + + /* done with modified vn_open, now finish what sys_open does. */ + + fp->f_flag = flags & FMASK; + fp->f_type = DTYPE_VNODE; + fp->f_ops = &vnops; + fp->f_data = (caddr_t)vp; + if (flags & (O_EXLOCK | O_SHLOCK)) { + lf.l_whence = SEEK_SET; + lf.l_start = 0; + lf.l_len = 0; + if (flags & O_EXLOCK) + lf.l_type = F_WRLCK; + else + lf.l_type = F_RDLCK; + type = F_FLOCK; + if ((flags & FNONBLOCK) == 0) + type |= F_WAIT; + VOP_UNLOCK(vp, 0, p); + error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type); + if (error) { + /* closef will vn_close the file for us. */ + fdremove(fdp, indx); + closef(fp, p); + return (error); + } + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + fp->f_flag |= FHASLOCK; + } + VOP_UNLOCK(vp, 0, p); + *retval = indx; + FILE_SET_MATURE(fp); + return (0); + +bad: + fdremove(fdp, indx); + closef(fp, p); + if (vp != NULL) + vput(vp); + return (error); +} + +/* ARGSUSED */ +int +sys_fhstat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_fhstat_args /* { + syscallarg(const fhandle_t *) fhp; + syscallarg(struct stat *) sb; + } */ *uap = v; + struct stat sb; + int error; + fhandle_t fh; + struct mount *mp; + struct vnode *vp; + + /* + * Must be super user + */ + if ((error = suser(p->p_ucred, &p->p_acflag))) + return (error); + + if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0) + return (error); + + if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL) + return (ESTALE); + if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp))) + return (error); + error = vn_stat(vp, &sb, p); + vput(vp); + if (error) + return (error); + error = copyout(&sb, SCARG(uap, sb), sizeof(sb)); + return (error); +} + +/* ARGSUSED */ +int +sys_fhstatfs(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_fhstatfs_args /* + syscallarg(const fhandle_t *) fhp; + syscallarg(struct statfs *) buf; + } */ *uap = v; + struct statfs sp; + fhandle_t fh; + struct mount *mp; + struct vnode *vp; + int error; + + /* + * Must be super user + */ + if ((error = suser(p->p_ucred, &p->p_acflag))) + return (error); + + if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0) + return (error); + + if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL) + return (ESTALE); + if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp))) + return (error); + mp = vp->v_mount; + vput(vp); + if ((error = VFS_STATFS(mp, &sp, p)) != 0) + return (error); + sp.f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + return (copyout(&sp, SCARG(uap, buf), sizeof(sp))); +} + +/* + * Create a special file. + */ +/* ARGSUSED */ +int +sys_mknod(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_mknod_args /* { + syscallarg(char *) path; + syscallarg(int) mode; + syscallarg(int) dev; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + int whiteout = 0; + struct nameidata nd; + + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return (error); + if (p->p_fd->fd_rdir) + return (EINVAL); + NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + if (vp != NULL) + error = EEXIST; + else { + VATTR_NULL(&vattr); + vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ p->p_fd->fd_cmask; + vattr.va_rdev = SCARG(uap, dev); + whiteout = 0; + + switch (SCARG(uap, mode) & S_IFMT) { + case S_IFMT: /* used by badsect to flag bad sectors */ + vattr.va_type = VBAD; + break; + case S_IFCHR: + vattr.va_type = VCHR; + break; + case S_IFBLK: + vattr.va_type = VBLK; + break; + case S_IFWHT: + whiteout = 1; + break; + default: + error = EINVAL; + break; + } + } + if (!error) { + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + if (whiteout) { + error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, CREATE); + if (error) + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + vput(nd.ni_dvp); + } else { + error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, + &nd.ni_cnd, &vattr); + } + } else { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + if (vp) + vrele(vp); + } + return (error); +} + +/* + * Create a named pipe. + */ +/* ARGSUSED */ +int +sys_mkfifo(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ +#ifndef FIFO + return (EOPNOTSUPP); +#else + register struct sys_mkfifo_args /* { + syscallarg(char *) path; + syscallarg(int) mode; + } */ *uap = v; + struct vattr vattr; + int error; + struct nameidata nd; + + NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + if (nd.ni_vp != NULL) { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == nd.ni_vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + vrele(nd.ni_vp); + return (EEXIST); + } + VATTR_NULL(&vattr); + vattr.va_type = VFIFO; + vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ p->p_fd->fd_cmask; + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + return (VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr)); +#endif /* FIFO */ +} + +/* + * Make a hard file link. + */ +/* ARGSUSED */ +int +sys_link(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_link_args /* { + syscallarg(char *) path; + syscallarg(char *) link; + } */ *uap = v; + register struct vnode *vp; + struct nameidata nd; + int error; + int flags; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + + flags = LOCKPARENT; + if (vp->v_type == VDIR) { + flags |= STRIPSLASHES; + } + + NDINIT(&nd, CREATE, flags, UIO_USERSPACE, SCARG(uap, link), p); + if ((error = namei(&nd)) != 0) + goto out; + if (nd.ni_vp) { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == nd.ni_vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + vrele(nd.ni_vp); + error = EEXIST; + goto out; + } + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd); +out: + vrele(vp); + return (error); +} + +/* + * Make a symbolic link. + */ +/* ARGSUSED */ +int +sys_symlink(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_symlink_args /* { + syscallarg(char *) path; + syscallarg(char *) link; + } */ *uap = v; + struct vattr vattr; + char *path; + int error; + struct nameidata nd; + + MALLOC(path, char *, MAXPATHLEN, M_NAMEI, M_WAITOK); + error = copyinstr(SCARG(uap, path), path, MAXPATHLEN, NULL); + if (error) + goto out; + NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, link), p); + if ((error = namei(&nd)) != 0) + goto out; + if (nd.ni_vp) { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == nd.ni_vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + vrele(nd.ni_vp); + error = EEXIST; + goto out; + } + VATTR_NULL(&vattr); + vattr.va_mode = ACCESSPERMS &~ p->p_fd->fd_cmask; + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, path); +out: + FREE(path, M_NAMEI); + return (error); +} + +/* + * Delete a whiteout from the filesystem. + */ +/* ARGSUSED */ +int +sys_undelete(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_undelete_args /* { + syscallarg(char *) path; + } */ *uap = v; + int error; + struct nameidata nd; + + NDINIT(&nd, DELETE, LOCKPARENT|DOWHITEOUT, UIO_USERSPACE, + SCARG(uap, path), p); + error = namei(&nd); + if (error) + return (error); + + if (nd.ni_vp != NULLVP || !(nd.ni_cnd.cn_flags & ISWHITEOUT)) { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == nd.ni_vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + if (nd.ni_vp) + vrele(nd.ni_vp); + return (EEXIST); + } + + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + if ((error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, DELETE)) != 0) + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + vput(nd.ni_dvp); + return (error); +} + +/* + * Delete a name from the filesystem. + */ +/* ARGSUSED */ +int +sys_unlink(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_unlink_args /* { + syscallarg(char *) path; + } */ *uap = v; + register struct vnode *vp; + int error; + struct nameidata nd; + + NDINIT(&nd, DELETE, LOCKPARENT | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + + /* + * The root of a mounted filesystem cannot be deleted. + */ + if (vp->v_flag & VROOT) { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + vput(vp); + error = EBUSY; + goto out; + } + + (void)uvm_vnp_uncache(vp); + + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd); +out: + return (error); +} + +/* + * Reposition read/write file offset. + */ +int +sys_lseek(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_lseek_args /* { + syscallarg(int) fd; + syscallarg(int) pad; + syscallarg(off_t) offset; + syscallarg(int) whence; + } */ *uap = v; + struct ucred *cred = p->p_ucred; + register struct filedesc *fdp = p->p_fd; + register struct file *fp; + struct vattr vattr; + struct vnode *vp; + int error, special; + + if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL) + return (EBADF); + if (fp->f_type != DTYPE_VNODE) + return (ESPIPE); + vp = (struct vnode *)fp->f_data; + if (vp->v_type == VFIFO) + return (ESPIPE); + if (vp->v_type == VCHR) + special = 1; + else + special = 0; + switch (SCARG(uap, whence)) { + case SEEK_CUR: + if (!special && fp->f_offset + SCARG(uap, offset) < 0) + return (EINVAL); + fp->f_offset += SCARG(uap, offset); + break; + case SEEK_END: + error = VOP_GETATTR((struct vnode *)fp->f_data, &vattr, + cred, p); + if (error) + return (error); + if (!special && (off_t)vattr.va_size + SCARG(uap, offset) < 0) + return (EINVAL); + fp->f_offset = SCARG(uap, offset) + vattr.va_size; + break; + case SEEK_SET: + if (!special && SCARG(uap, offset) < 0) + return (EINVAL); + fp->f_offset = SCARG(uap, offset); + break; + default: + return (EINVAL); + } + *(off_t *)retval = fp->f_offset; + return (0); +} + +/* + * Check access permissions. + */ +int +sys_access(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_access_args /* { + syscallarg(char *) path; + syscallarg(int) flags; + } */ *uap = v; + register struct ucred *cred = p->p_ucred; + register struct vnode *vp; + int error, flags, t_gid, t_uid; + struct nameidata nd; + + if (SCARG(uap, flags) & ~(R_OK | W_OK | X_OK)) + return (EINVAL); + t_uid = cred->cr_uid; + t_gid = cred->cr_gid; + cred->cr_uid = p->p_cred->p_ruid; + cred->cr_gid = p->p_cred->p_rgid; + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + goto out1; + vp = nd.ni_vp; + + /* Flags == 0 means only check for existence. */ + if (SCARG(uap, flags)) { + flags = 0; + if (SCARG(uap, flags) & R_OK) + flags |= VREAD; + if (SCARG(uap, flags) & W_OK) + flags |= VWRITE; + if (SCARG(uap, flags) & X_OK) + flags |= VEXEC; + if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0) + error = VOP_ACCESS(vp, flags, cred, p); + } + vput(vp); +out1: + cred->cr_uid = t_uid; + cred->cr_gid = t_gid; + return (error); +} + +/* + * Get file status; this version follows links. + */ +/* ARGSUSED */ +int +sys_stat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_stat_args /* { + syscallarg(char *) path; + syscallarg(struct stat *) ub; + } */ *uap = v; + struct stat sb; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + error = vn_stat(nd.ni_vp, &sb, p); + vput(nd.ni_vp); + if (error) + return (error); + /* Don't let non-root see generation numbers (for NFS security) */ + if (suser(p->p_ucred, &p->p_acflag)) + sb.st_gen = 0; + error = copyout((caddr_t)&sb, (caddr_t)SCARG(uap, ub), sizeof (sb)); + return (error); +} + +/* + * Get file status; this version does not follow links. + */ +/* ARGSUSED */ +int +sys_lstat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_lstat_args /* { + syscallarg(char *) path; + syscallarg(struct stat *) ub; + } */ *uap = v; + struct stat sb; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + error = vn_stat(nd.ni_vp, &sb, p); + vput(nd.ni_vp); + if (error) + return (error); + /* Don't let non-root see generation numbers (for NFS security) */ + if (suser(p->p_ucred, &p->p_acflag)) + sb.st_gen = 0; + error = copyout((caddr_t)&sb, (caddr_t)SCARG(uap, ub), sizeof (sb)); + return (error); +} + +/* + * Get configurable pathname variables. + */ +/* ARGSUSED */ +int +sys_pathconf(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_pathconf_args /* { + syscallarg(char *) path; + syscallarg(int) name; + } */ *uap = v; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + error = VOP_PATHCONF(nd.ni_vp, SCARG(uap, name), retval); + vput(nd.ni_vp); + return (error); +} + +/* + * Return target name of a symbolic link. + */ +/* ARGSUSED */ +int +sys_readlink(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_readlink_args /* { + syscallarg(char *) path; + syscallarg(char *) buf; + syscallarg(size_t) count; + } */ *uap = v; + register struct vnode *vp; + struct iovec aiov; + struct uio auio; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + if (vp->v_type != VLNK) + error = EINVAL; + else { + aiov.iov_base = SCARG(uap, buf); + aiov.iov_len = SCARG(uap, count); + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_offset = 0; + auio.uio_rw = UIO_READ; + auio.uio_segflg = UIO_USERSPACE; + auio.uio_procp = p; + auio.uio_resid = SCARG(uap, count); + error = VOP_READLINK(vp, &auio, p->p_ucred); + } + vput(vp); + *retval = SCARG(uap, count) - auio.uio_resid; + return (error); +} + +/* + * Change flags of a file given a path name. + */ +/* ARGSUSED */ +int +sys_chflags(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_chflags_args /* { + syscallarg(char *) path; + syscallarg(unsigned int) flags; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else if (SCARG(uap, flags) == VNOVAL) + error = EINVAL; + else { + if (suser(p->p_ucred, &p->p_acflag)) { + if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0) + goto out; + if (vattr.va_type == VCHR || vattr.va_type == VBLK) { + error = EINVAL; + goto out; + } + } + VATTR_NULL(&vattr); + vattr.va_flags = SCARG(uap, flags); + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } +out: + vput(vp); + return (error); +} + +/* + * Change flags of a file given a file descriptor. + */ +/* ARGSUSED */ +int +sys_fchflags(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_fchflags_args /* { + syscallarg(int) fd; + syscallarg(unsigned int) flags; + } */ *uap = v; + struct vattr vattr; + struct vnode *vp; + struct file *fp; + int error; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else if (SCARG(uap, flags) == VNOVAL) + error = EINVAL; + else { + if (suser(p->p_ucred, &p->p_acflag)) { + if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) + != 0) + goto out; + if (vattr.va_type == VCHR || vattr.va_type == VBLK) { + error = EINVAL; + goto out; + } + } + VATTR_NULL(&vattr); + vattr.va_flags = SCARG(uap, flags); + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } +out: + VOP_UNLOCK(vp, 0, p); + FRELE(fp); + return (error); +} + +/* + * Change mode of a file given path name. + */ +/* ARGSUSED */ +int +sys_chmod(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_chmod_args /* { + syscallarg(char *) path; + syscallarg(int) mode; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + + if (SCARG(uap, mode) & ~(S_IFMT | ALLPERMS)) + return (EINVAL); + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + VATTR_NULL(&vattr); + vattr.va_mode = SCARG(uap, mode) & ALLPERMS; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } + vput(vp); + return (error); +} + +/* + * Change mode of a file given a file descriptor. + */ +/* ARGSUSED */ +int +sys_fchmod(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_fchmod_args /* { + syscallarg(int) fd; + syscallarg(int) mode; + } */ *uap = v; + struct vattr vattr; + struct vnode *vp; + struct file *fp; + int error; + + if (SCARG(uap, mode) & ~(S_IFMT | ALLPERMS)) + return (EINVAL); + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + VATTR_NULL(&vattr); + vattr.va_mode = SCARG(uap, mode) & ALLPERMS; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } + VOP_UNLOCK(vp, 0, p); + FRELE(fp); + return (error); +} + +/* + * Set ownership given a path name. + */ +/* ARGSUSED */ +int +sys_chown(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_chown_args /* { + syscallarg(char *) path; + syscallarg(int) uid; + syscallarg(int) gid; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + u_short mode; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + if ((SCARG(uap, uid) != -1 || SCARG(uap, gid) != -1) && + (suser(p->p_ucred, &p->p_acflag) || suid_clear)) { + error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); + if (error) + goto out; + mode = vattr.va_mode & ~(VSUID | VSGID); + if (mode == vattr.va_mode) + mode = VNOVAL; + } + else + mode = VNOVAL; + VATTR_NULL(&vattr); + vattr.va_uid = SCARG(uap, uid); + vattr.va_gid = SCARG(uap, gid); + vattr.va_mode = mode; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } +out: + vput(vp); + return (error); +} + +/* + * Set ownership given a path name, without following links. + */ +/* ARGSUSED */ +int +sys_lchown(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_lchown_args /* { + syscallarg(char *) path; + syscallarg(int) uid; + syscallarg(int) gid; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + u_short mode; + + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + if ((SCARG(uap, uid) != -1 || SCARG(uap, gid) != -1) && + (suser(p->p_ucred, &p->p_acflag) || suid_clear)) { + error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); + if (error) + goto out; + mode = vattr.va_mode & ~(VSUID | VSGID); + if (mode == vattr.va_mode) + mode = VNOVAL; + } + else + mode = VNOVAL; + VATTR_NULL(&vattr); + vattr.va_uid = SCARG(uap, uid); + vattr.va_gid = SCARG(uap, gid); + vattr.va_mode = mode; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } +out: + vput(vp); + return (error); +} + +/* + * Set ownership given a file descriptor. + */ +/* ARGSUSED */ +int +sys_fchown(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_fchown_args /* { + syscallarg(int) fd; + syscallarg(int) uid; + syscallarg(int) gid; + } */ *uap = v; + struct vnode *vp; + struct vattr vattr; + int error; + struct file *fp; + u_short mode; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + if ((SCARG(uap, uid) != -1 || SCARG(uap, gid) != -1) && + (suser(p->p_ucred, &p->p_acflag) || suid_clear)) { + error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); + if (error) + goto out; + mode = vattr.va_mode & ~(VSUID | VSGID); + if (mode == vattr.va_mode) + mode = VNOVAL; + } else + mode = VNOVAL; + VATTR_NULL(&vattr); + vattr.va_uid = SCARG(uap, uid); + vattr.va_gid = SCARG(uap, gid); + vattr.va_mode = mode; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } +out: + VOP_UNLOCK(vp, 0, p); + FRELE(fp); + return (error); +} + +/* + * Set the access and modification times given a path name. + */ +/* ARGSUSED */ +int +sys_utimes(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_utimes_args /* { + syscallarg(char *) path; + syscallarg(struct timeval *) tptr; + } */ *uap = v; + register struct vnode *vp; + struct timeval tv[2]; + struct vattr vattr; + int error; + struct nameidata nd; + + VATTR_NULL(&vattr); + if (SCARG(uap, tptr) == NULL) { + microtime(&tv[0]); + tv[1] = tv[0]; + vattr.va_vaflags |= VA_UTIMES_NULL; + } else { + error = copyin((caddr_t)SCARG(uap, tptr), (caddr_t)tv, + sizeof (tv)); + if (error) + return (error); + /* XXX workaround timeval matching the VFS constant VNOVAL */ + if (tv[0].tv_sec == VNOVAL) + tv[0].tv_sec = VNOVAL - 1; + if (tv[1].tv_sec == VNOVAL) + tv[1].tv_sec = VNOVAL - 1; + } + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + vattr.va_atime.tv_sec = tv[0].tv_sec; + vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000; + vattr.va_mtime.tv_sec = tv[1].tv_sec; + vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } + vput(vp); + return (error); +} + + +/* + * Set the access and modification times given a file descriptor. + */ +/* ARGSUSED */ +int +sys_futimes(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_futimes_args /* { + syscallarg(int) fd; + syscallarg(struct timeval *) tptr; + } */ *uap = v; + struct vnode *vp; + struct timeval tv[2]; + struct vattr vattr; + int error; + struct file *fp; + + VATTR_NULL(&vattr); + if (SCARG(uap, tptr) == NULL) { + microtime(&tv[0]); + tv[1] = tv[0]; + vattr.va_vaflags |= VA_UTIMES_NULL; + } else { + error = copyin((caddr_t)SCARG(uap, tptr), (caddr_t)tv, + sizeof (tv)); + if (error) + return (error); + /* XXX workaround timeval matching the VFS constant VNOVAL */ + if (tv[0].tv_sec == VNOVAL) + tv[0].tv_sec = VNOVAL - 1; + if (tv[1].tv_sec == VNOVAL) + tv[1].tv_sec = VNOVAL - 1; + } + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + vattr.va_atime.tv_sec = tv[0].tv_sec; + vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000; + vattr.va_mtime.tv_sec = tv[1].tv_sec; + vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } + VOP_UNLOCK(vp, 0, p); + FRELE(fp); + return (error); +} + +/* + * Truncate a file given its path name. + */ +/* ARGSUSED */ +int +sys_truncate(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_truncate_args /* { + syscallarg(char *) path; + syscallarg(int) pad; + syscallarg(off_t) length; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_type == VDIR) + error = EISDIR; + else if ((error = vn_writechk(vp)) == 0 && + (error = VOP_ACCESS(vp, VWRITE, p->p_ucred, p)) == 0) { + VATTR_NULL(&vattr); + vattr.va_size = SCARG(uap, length); + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } + vput(vp); + return (error); +} + +/* + * Truncate a file given a file descriptor. + */ +/* ARGSUSED */ +int +sys_ftruncate(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_ftruncate_args /* { + syscallarg(int) fd; + syscallarg(int) pad; + syscallarg(off_t) length; + } */ *uap = v; + struct vattr vattr; + struct vnode *vp; + struct file *fp; + int error; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + if ((fp->f_flag & FWRITE) == 0) { + error = EINVAL; + goto bad; + } + vp = (struct vnode *)fp->f_data; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + if (vp->v_type == VDIR) + error = EISDIR; + else if ((error = vn_writechk(vp)) == 0) { + VATTR_NULL(&vattr); + vattr.va_size = SCARG(uap, length); + error = VOP_SETATTR(vp, &vattr, fp->f_cred, p); + } + VOP_UNLOCK(vp, 0, p); +bad: + FRELE(fp); + return (error); +} + +/* + * Sync an open file. + */ +/* ARGSUSED */ +int +sys_fsync(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_fsync_args /* { + syscallarg(int) fd; + } */ *uap = v; + struct vnode *vp; + struct file *fp; + int error; + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p); + + VOP_UNLOCK(vp, 0, p); + FRELE(fp); + return (error); +} + +/* + * Rename files. Source and destination must either both be directories, + * or both not be directories. If target is a directory, it must be empty. + */ +/* ARGSUSED */ +int +sys_rename(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_rename_args /* { + syscallarg(char *) from; + syscallarg(char *) to; + } */ *uap = v; + register struct vnode *tvp, *fvp, *tdvp; + struct nameidata fromnd, tond; + int error; + int flags; + + NDINIT(&fromnd, DELETE, WANTPARENT | SAVESTART, UIO_USERSPACE, + SCARG(uap, from), p); + if ((error = namei(&fromnd)) != 0) + return (error); + fvp = fromnd.ni_vp; + + flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART; + /* + * rename("foo/", "bar/"); is OK + */ + if (fvp->v_type == VDIR) + flags |= STRIPSLASHES; + + NDINIT(&tond, RENAME, flags, + UIO_USERSPACE, SCARG(uap, to), p); + if ((error = namei(&tond)) != 0) { + VOP_ABORTOP(fromnd.ni_dvp, &fromnd.ni_cnd); + vrele(fromnd.ni_dvp); + vrele(fvp); + goto out1; + } + tdvp = tond.ni_dvp; + tvp = tond.ni_vp; + if (tvp != NULL) { + if (fvp->v_type == VDIR && tvp->v_type != VDIR) { + error = ENOTDIR; + goto out; + } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) { + error = EISDIR; + goto out; + } + } + if (fvp == tdvp) + error = EINVAL; + /* + * If source is the same as the destination (that is the + * same inode number) + */ + if (fvp == tvp) + error = -1; +out: + if (!error) { + VOP_LEASE(tdvp, p, p->p_ucred, LEASE_WRITE); + if (fromnd.ni_dvp != tdvp) + VOP_LEASE(fromnd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + if (tvp) { + (void)uvm_vnp_uncache(tvp); + VOP_LEASE(tvp, p, p->p_ucred, LEASE_WRITE); + } + error = VOP_RENAME(fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd, + tond.ni_dvp, tond.ni_vp, &tond.ni_cnd); + } else { + VOP_ABORTOP(tond.ni_dvp, &tond.ni_cnd); + if (tdvp == tvp) + vrele(tdvp); + else + vput(tdvp); + if (tvp) + vput(tvp); + VOP_ABORTOP(fromnd.ni_dvp, &fromnd.ni_cnd); + vrele(fromnd.ni_dvp); + vrele(fvp); + } + vrele(tond.ni_startdir); + FREE(tond.ni_cnd.cn_pnbuf, M_NAMEI); +out1: + if (fromnd.ni_startdir) + vrele(fromnd.ni_startdir); + FREE(fromnd.ni_cnd.cn_pnbuf, M_NAMEI); + if (error == -1) + return (0); + return (error); +} + +/* + * Make a directory file. + */ +/* ARGSUSED */ +int +sys_mkdir(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_mkdir_args /* { + syscallarg(char *) path; + syscallarg(int) mode; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + + NDINIT(&nd, CREATE, LOCKPARENT | STRIPSLASHES, + UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + if (vp != NULL) { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + vrele(vp); + return (EEXIST); + } + VATTR_NULL(&vattr); + vattr.va_type = VDIR; + vattr.va_mode = (SCARG(uap, mode) & ACCESSPERMS) &~ p->p_fd->fd_cmask; + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); + if (!error) + vput(nd.ni_vp); + return (error); +} + +/* + * Remove a directory file. + */ +/* ARGSUSED */ +int +sys_rmdir(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_rmdir_args /* { + syscallarg(char *) path; + } */ *uap = v; + register struct vnode *vp; + int error; + struct nameidata nd; + + NDINIT(&nd, DELETE, LOCKPARENT | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + if (vp->v_type != VDIR) { + error = ENOTDIR; + goto out; + } + /* + * No rmdir "." please. + */ + if (nd.ni_dvp == vp) { + error = EBUSY; + goto out; + } + /* + * The root of a mounted filesystem cannot be deleted. + */ + if (vp->v_flag & VROOT) + error = EBUSY; +out: + if (!error) { + VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + error = VOP_RMDIR(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd); + } else { + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + vput(vp); + } + return (error); +} + +/* + * Read a block of directory entries in a file system independent format. + */ +int +sys_getdirentries(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_getdirentries_args /* { + syscallarg(int) fd; + syscallarg(char *) buf; + syscallarg(int) count; + syscallarg(long *) basep; + } */ *uap = v; + struct vnode *vp; + struct file *fp; + struct uio auio; + struct iovec aiov; + long loff; + int error, eofflag; + + if (SCARG(uap, count) < 0) + return EINVAL; + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + if ((fp->f_flag & FREAD) == 0) { + error = EBADF; + goto bad; + } + vp = (struct vnode *)fp->f_data; +unionread: + if (vp->v_type != VDIR) { + error = EINVAL; + goto bad; + } + aiov.iov_base = SCARG(uap, buf); + aiov.iov_len = SCARG(uap, count); + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_rw = UIO_READ; + auio.uio_segflg = UIO_USERSPACE; + auio.uio_procp = p; + auio.uio_resid = SCARG(uap, count); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + loff = auio.uio_offset = fp->f_offset; + error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, 0, 0); + fp->f_offset = auio.uio_offset; + VOP_UNLOCK(vp, 0, p); + if (error) + goto bad; + if ((SCARG(uap, count) == auio.uio_resid) && + union_check_p && + (union_check_p(p, &vp, fp, auio, &error) != 0)) + goto unionread; + if (error) + goto bad; + + if ((SCARG(uap, count) == auio.uio_resid) && + (vp->v_flag & VROOT) && + (vp->v_mount->mnt_flag & MNT_UNION)) { + struct vnode *tvp = vp; + vp = vp->v_mount->mnt_vnodecovered; + VREF(vp); + fp->f_data = (caddr_t) vp; + fp->f_offset = 0; + vrele(tvp); + goto unionread; + } + error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep), + sizeof(long)); + *retval = SCARG(uap, count) - auio.uio_resid; +bad: + FRELE(fp); + return (error); +} + +/* + * Set the mode mask for creation of filesystem nodes. + */ +int +sys_umask(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_umask_args /* { + syscallarg(int) newmask; + } */ *uap = v; + register struct filedesc *fdp; + + fdp = p->p_fd; + *retval = fdp->fd_cmask; + fdp->fd_cmask = SCARG(uap, newmask) & ACCESSPERMS; + return (0); +} + +/* + * Void all references to file by ripping underlying filesystem + * away from vnode. + */ +/* ARGSUSED */ +int +sys_revoke(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_revoke_args /* { + syscallarg(char *) path; + } */ *uap = v; + register struct vnode *vp; + struct vattr vattr; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0) + goto out; + if (p->p_ucred->cr_uid != vattr.va_uid && + (error = suser(p->p_ucred, &p->p_acflag))) + goto out; + if (vp->v_usecount > 1 || (vp->v_flag & (VALIASED | VLAYER))) + VOP_REVOKE(vp, REVOKEALL); +out: + vrele(vp); + return (error); +} + +/* + * Convert a user file descriptor to a kernel file entry. + * + * On return *fpp is FREF:ed. + */ +int +getvnode(fdp, fd, fpp) + struct filedesc *fdp; + struct file **fpp; + int fd; +{ + struct file *fp; + + if ((fp = fd_getfile(fdp, fd)) == NULL) + return (EBADF); + if (fp->f_type != DTYPE_VNODE) + return (EINVAL); + FREF(fp); + *fpp = fp; + + return (0); +} + +/* + * Positional read system call. + */ +int +sys_pread(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_pread_args /* { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int fd = SCARG(uap, fd); + + if ((fp = fd_getfile(fdp, fd)) == NULL) + return (EBADF); + if ((fp->f_flag & FREAD) == 0) + return (EBADF); + + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + return (ESPIPE); + } + + offset = SCARG(uap, offset); + + FREF(fp); + + /* dofileread() will FRELE the descriptor for us */ + return (dofileread(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), + &offset, retval)); +} + +/* + * Positional scatter read system call. + */ +int +sys_preadv(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_preadv_args /* { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int fd = SCARG(uap, fd); + + if ((fp = fd_getfile(fdp, fd)) == NULL) + return (EBADF); + if ((fp->f_flag & FREAD) == 0) + return (EBADF); + + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + return (ESPIPE); + } + + FREF(fp); + + offset = SCARG(uap, offset); + + /* dofilereadv() will FRELE the descriptor for us */ + return (dofilereadv(p, fd, fp, SCARG(uap, iovp), SCARG(uap, iovcnt), + &offset, retval)); +} + +/* + * Positional write system call. + */ +int +sys_pwrite(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_pwrite_args /* { + syscallarg(int) fd; + syscallarg(const void *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int fd = SCARG(uap, fd); + + if ((fp = fd_getfile(fdp, fd)) == NULL) + return (EBADF); + if ((fp->f_flag & FWRITE) == 0) + return (EBADF); + + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + return (ESPIPE); + } + + FREF(fp); + + offset = SCARG(uap, offset); + + /* dofilewrite() will FRELE the descriptor for us */ + return (dofilewrite(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), + &offset, retval)); +} + + +/* + * Positional gather write system call. + */ +int +sys_pwritev(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_pwritev_args /* { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int fd = SCARG(uap, fd); + + if ((fp = fd_getfile(fdp, fd)) == NULL) + return (EBADF); + if ((fp->f_flag & FWRITE) == 0) + return (EBADF); + + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + return (ESPIPE); + } + + FREF(fp); + + offset = SCARG(uap, offset); + + /* dofilewritev() will FRELE the descriptor for us */ + return (dofilewritev(p, fd, fp, SCARG(uap, iovp), SCARG(uap, iovcnt), + &offset, retval)); +} + +#ifdef UFS_EXTATTR +/* + * Syscall to push extended attribute configuration information into the + * VFS. Accepts a path, which it converts to a mountpoint, as well as + * a command (int cmd), and attribute name and misc data. For now, the + * attribute name is left in userspace for consumption by the VFS_op. + * It will probably be changed to be copied into sysspace by the + * syscall in the future, once issues with various consumers of the + * attribute code have raised their hands. + * + * Currently this is used only by UFS Extended Attributes. + */ +int +sys_extattrctl(struct proc *p, void *v, register_t *reval) +{ + struct sys_extattrctl_args /* { + syscallarg(const char *) path; + syscallarg(int) cmd; + syscallarg(const char *) filename; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + } */ *uap = v; + struct vnode *filename_vp; + struct nameidata nd; + struct mount *mp; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + /* + * SCARG(uap, attrname) not always defined. We check again later + * when we invoke the VFS call so as to pass in NULL there if needed. + */ + if (SCARG(uap, attrname) != NULL) { + error = copyinstr(SCARG(uap, attrname), attrname, + EXTATTR_MAXNAMELEN, NULL); + if (error) + return (error); + } + + /* + * SCARG(uap, filename) not always defined. If it is, grab + * a vnode lock, which VFS_EXTATTRCTL() will later release. + */ + filename_vp = NULL; + if (SCARG(uap, filename) != NULL) { + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, filename), p); + if ((error = namei(&nd)) != 0) + return (error); + filename_vp = nd.ni_vp; + } + + /* SCARG(uap, path) always defined. */ + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) { + if (filename_vp != NULL) + vput(filename_vp); + return (error); + } + + mp = nd.ni_vp->v_mount; + if (error) { + if (filename_vp != NULL) + vput(filename_vp); + return (error); + } + + if (SCARG(uap, attrname) != NULL) { + error = VFS_EXTATTRCTL(mp, SCARG(uap, cmd), filename_vp, + SCARG(uap, attrnamespace), attrname, p); + } else { + error = VFS_EXTATTRCTL(mp, SCARG(uap, cmd), filename_vp, + SCARG(uap, attrnamespace), NULL, p); + } + + /* + * VFS_EXTATTRCTL will have unlocked, but not de-ref'd, + * filename_vp, so vrele it if it is defined. + */ + if (filename_vp != NULL) + vrele(filename_vp); + + return (error); +} + +/*- + * Set a named extended attribute on a file or directory + * + * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace", + * kernelspace string pointer "attrname", userspace buffer + * pointer "data", buffer length "nbytes", thread "td". + * Returns: 0 on success, an error number otherwise + * Locks: none + * References: vp must be a valid reference for the duration of the call + */ +static int +extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname, + void *data, size_t nbytes, struct proc *p, register_t *retval) +{ + struct uio auio; + struct iovec aiov; + ssize_t cnt; + int error; + + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + + aiov.iov_base = data; + aiov.iov_len = nbytes; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_offset = 0; + if (nbytes > INT_MAX) { + error = EINVAL; + goto done; + } + auio.uio_resid = nbytes; + auio.uio_rw = UIO_WRITE; + auio.uio_segflg = UIO_USERSPACE; + auio.uio_procp = p; + cnt = nbytes; + + error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio, + p->p_ucred, p); + cnt -= auio.uio_resid; + retval[0] = cnt; + +done: + VOP_UNLOCK(vp, 0, p); + return (error); +} + +int +sys_extattr_set_file(struct proc *p, void *v, register_t *retval) +{ + struct sys_extattr_set_file_args /* { + syscallarg(const char *) path; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + syscallarg(void *) data; + syscallarg(size_t) nbytes; + } */ *uap = v; + struct nameidata nd; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN, + NULL); + if (error) + return (error); + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + + error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname, + SCARG(uap, data), SCARG(uap, nbytes), p, retval); + + vrele(nd.ni_vp); + return (error); +} + +int +sys_extattr_set_fd(struct proc *p, void *v, register_t *retval) +{ + struct sys_extattr_set_fd_args /* { + syscallarg(int) fd; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + syscallarg(struct iovec *) iovp; + syscallarg(int) iovcnt; + } */ *uap = v; + struct file *fp; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN, + NULL); + if (error) + return (error); + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + + error = extattr_set_vp((struct vnode *)fp->f_data, + SCARG(uap, attrnamespace), attrname, SCARG(uap, data), + SCARG(uap, nbytes), p, retval); + FRELE(fp); + + return (error); +} + +/*- + * Get a named extended attribute on a file or directory + * + * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace", + * kernelspace string pointer "attrname", userspace buffer + * pointer "data", buffer length "nbytes", thread "td". + * Returns: 0 on success, an error number otherwise + * Locks: none + * References: vp must be a valid reference for the duration of the call + */ +static int +extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname, + void *data, size_t nbytes, struct proc *p, register_t *retval) +{ + struct uio auio; + struct iovec aiov; + ssize_t cnt; + size_t size; + int error; + + VOP_LEASE(vp, p, p->p_ucred, LEASE_READ); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + + /* + * Slightly unusual semantics: if the user provides a NULL data + * pointer, they don't want to receive the data, just the + * maximum read length. + */ + if (data != NULL) { + aiov.iov_base = data; + aiov.iov_len = nbytes; + auio.uio_iov = &aiov; + auio.uio_offset = 0; + if (nbytes > INT_MAX) { + error = EINVAL; + goto done; + } + auio.uio_resid = nbytes; + auio.uio_rw = UIO_READ; + auio.uio_segflg = UIO_USERSPACE; + auio.uio_procp = p; + cnt = nbytes; + error = VOP_GETEXTATTR(vp, attrnamespace, attrname, &auio, + NULL, p->p_ucred, p); + cnt -= auio.uio_resid; + retval[0] = cnt; + } else { + error = VOP_GETEXTATTR(vp, attrnamespace, attrname, NULL, + &size, p->p_ucred, p); + retval[0] = size; + } +done: + VOP_UNLOCK(vp, 0, p); + return (error); +} + +int +sys_extattr_get_file(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_extattr_get_file_args /* { + syscallarg(const char *) path; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + syscallarg(void *) data; + syscallarg(size_t) nbytes; + } */ *uap = v; + struct nameidata nd; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN, + NULL); + if (error) + return (error); + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + + error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname, + SCARG(uap, data), SCARG(uap, nbytes), p, retval); + + vrele(nd.ni_vp); + return (error); +} + +int +sys_extattr_get_fd(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_extattr_get_fd_args /* { + syscallarg(int) fd; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + syscallarg(void *) data; + syscallarg(size_t) nbytes; + } */ *uap = v; + struct file *fp; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN, + NULL); + if (error) + return (error); + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + + error = extattr_get_vp((struct vnode *)fp->f_data, + SCARG(uap, attrnamespace), attrname, SCARG(uap, data), + SCARG(uap, nbytes), p, retval); + FRELE(fp); + + return (error); +} + +/* + * extattr_delete_vp(): Delete a named extended attribute on a file or + * directory + * + * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace", + * kernelspace string pointer "attrname", proc "p" + * Returns: 0 on success, an error number otherwise + * Locks: none + * References: vp must be a valid reference for the duration of the call + */ +static int +extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname, + struct proc *p) +{ + int error; + + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + + error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL, + p->p_ucred, p); + + VOP_UNLOCK(vp, 0, p); + return (error); +} + +int +sys_extattr_delete_file(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_extattr_delete_file_args /* { + syscallarg(int) fd; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + } */ *uap = v; + struct nameidata nd; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN, + NULL); + if (error) + return(error); + + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return(error); + + error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), + attrname, p); + + vrele(nd.ni_vp); + return(error); +} + +int +sys_extattr_delete_fd(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct sys_extattr_delete_fd_args /* { + syscallarg(int) fd; + syscallarg(int) attrnamespace; + syscallarg(const char *) attrname; + } */ *uap = v; + struct file *fp; + char attrname[EXTATTR_MAXNAMELEN]; + int error; + + error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN, + NULL); + if (error) + return (error); + + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + + error = extattr_delete_vp((struct vnode *)fp->f_data, + SCARG(uap, attrnamespace), attrname, p); + FRELE(fp); + + return (error); +} +#endif diff --git a/static/openbsd/man2/thrkill.2 b/static/openbsd/man2/thrkill.2 new file mode 100644 index 00000000..30b7bf6f --- /dev/null +++ b/static/openbsd/man2/thrkill.2 @@ -0,0 +1,105 @@ +.\" $OpenBSD: thrkill.2,v 1.2 2016/03/19 21:56:12 guenther Exp $ +.\" $NetBSD: kill.2,v 1.7 1995/02/27 12:33:53 cgd 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. 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 +.\" +.Dd $Mdocdate: March 19 2016 $ +.Dt THRKILL 2 +.Os +.Sh NAME +.Nm thrkill +.Nd send signal to a thread in the same process +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn thrkill "pid_t tid" "int sig" "void *tcb" +.Sh DESCRIPTION +The +.Fn thrkill +function sends the signal given by +.Fa sig +to +.Fa tid , +a thread in the same process as the caller. +.Fn thrkill +will only succeed if +.Fa tcb +is either +.Dv NULL +or the address of the thread control block (TCB) of the target thread. +.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. +.Pp +If +.Fa tid +is zero then the current thread is targeted. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn thrkill +will fail and no signal will be sent if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa sig +is not a valid signal number. +.It Bq Er ESRCH +The process doesn't have a thread with thread ID +.Fa tid . +.It Bq Er ESRCH +.Fa tcb +is not +.Dv NULL +and not the TCB address of the thread with thread ID +.Fa tid . +.El +.Sh SEE ALSO +.Xr __get_tcb 2 , +.Xr kill 2 , +.Xr sigaction 2 , +.Xr pthread_kill 3 , +.Xr raise 3 +.Sh STANDARDS +The +.Fn thrkill +function is specific to +.Ox +and should not be used in portable applications. +Use +.Xr pthread_kill 3 +instead. +.Sh HISTORY +The +.Fn thrkill +system call appeared in +.Ox 5.9 . diff --git a/static/openbsd/man2/truncate.2 b/static/openbsd/man2/truncate.2 new file mode 100644 index 00000000..63568410 --- /dev/null +++ b/static/openbsd/man2/truncate.2 @@ -0,0 +1,152 @@ +.\" $OpenBSD: truncate.2,v 1.21 2022/05/23 15:17:11 millert Exp $ +.\" $NetBSD: truncate.2,v 1.7 1995/02/27 12:39:00 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: May 23 2022 $ +.Dt TRUNCATE 2 +.Os +.Sh NAME +.Nm truncate , +.Nm ftruncate +.Nd truncate or extend a file to a specified length +.Sh SYNOPSIS +.In 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 +.Rv -std +.Sh ERRORS +.Fn truncate +and +.Fn ftruncate +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa length +is a negative value. +.It Bq Er EFBIG +The +.Fa length +exceeds the process's file size limit or the maximum file size +of the underlying filesystem. +.It Bq Er EIO +An I/O error occurred updating the inode. +.El +.Pp +In addition, +.Fn truncate +may return the following errors: +.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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 EFAULT +.Fa path +points outside the process's allocated address space. +.El +.Pp +.Fn ftruncate +may return the following errors: +.Bl -tag -width Er +.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 STANDARDS +The +.Fn truncate +and +.Fn ftruncate +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn truncate +and +.Fn ftruncate +system calls first appeared in +.Bx 4.1c . +.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. diff --git a/static/openbsd/man2/umask.2 b/static/openbsd/man2/umask.2 new file mode 100644 index 00000000..61d77997 --- /dev/null +++ b/static/openbsd/man2/umask.2 @@ -0,0 +1,94 @@ +.\" $OpenBSD: umask.2,v 1.13 2022/02/18 23:17:14 jsg Exp $ +.\" $NetBSD: umask.2,v 1.6 1995/02/27 12:39:06 cgd 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. 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 +.\" +.Dd $Mdocdate: February 18 2022 $ +.Dt UMASK 2 +.Os +.Sh NAME +.Nm umask +.Nd set file creation mode mask +.Sh SYNOPSIS +.In sys/types.h +.In 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. +Only the read, write, and execute file permission bits of +.Fa numask +are honored, all others are ignored. +.Pp +The file mode creation mask is used by the +.Xr bind 2 , +.Xr mkdir 2 , +.Xr mkdirat 2 , +.Xr mkfifo 2 , +.Xr mkfifoat 2 , +.Xr mknod 2 , +.Xr mknodat 2 , +.Xr open 2 +and +.Xr openat 2 +system calls to turn off corresponding bits requested in the file mode +(see +.Xr chmod 2 ) . +This clearing allows users to restrict the default access to their 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 mkdir 2 , +.Xr mkfifo 2 , +.Xr mknod 2 , +.Xr open 2 +.Sh STANDARDS +The +.Fn umask +function conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn umask +system call first appeared in +.At v7 . diff --git a/static/openbsd/man2/unlink.2 b/static/openbsd/man2/unlink.2 new file mode 100644 index 00000000..c1683a2a --- /dev/null +++ b/static/openbsd/man2/unlink.2 @@ -0,0 +1,237 @@ +.\" $OpenBSD: unlink.2,v 1.28 2021/06/30 18:46:49 schwarze Exp $ +.\" $NetBSD: unlink.2,v 1.7 1995/02/27 12:39:13 cgd 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. 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 +.\" +.Dd $Mdocdate: June 30 2021 $ +.Dt UNLINK 2 +.Os +.Sh NAME +.Nm unlink , +.Nm unlinkat +.Nd remove directory entry +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn unlink "const char *path" +.In fcntl.h +.In unistd.h +.Ft int +.Fn unlinkat "int fd" "const char *path" "int flag" +.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 processes 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. +.Pp +The +.Fn unlinkat +function is equivalent to either the +.Fn unlink +or +.Xr rmdir 2 +function depending on the value of +.Fa flag +(see below), except that where +.Fa path +specifies a relative path, +the directory entry to be removed is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn unlinkat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used +and the behavior is identical to a call to +.Fn unlink +or +.Xr rmdir 2 , +depending on whether or not the +.Dv AT_REMOVEDIR +bit is set in +.Fa flag . +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_REMOVEDIR -offset indent -compact +.It Dv AT_REMOVEDIR +Remove the directory entry specified by +.Fa path +as a directory, not a normal file. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn unlink +and +.Fn unlinkat +functions 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 +.Dv NAME_MAX +characters, or an entire pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 and the effective user ID +of the process is not the superuser, or the file system +containing the file does not permit the use of +.Fn unlink +on 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 EPERM +The named file or the directory containing it has its immutable or +append-only flag set (see +.Xr chflags 2 ) . +.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 +.Pp +Additionally, +.Fn unlinkat +will fail if: +.Bl -tag -width Er +.It Bq Er ENOTDIR +The +.Dv AT_REMOVEDIR +flag bit is set and +.Fa path +does not name a directory. +.It Bq Er ENOTEMPTY +The +.Dv AT_REMOVEDIR +flag bit is set and the named directory contains files other than +.Ql \&. +and +.Ql \&.. +in it. +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_REMOVEDIR . +.It Bq Er EINVAL +The value of the +.Fa flag +argument was +.Dv AT_REMOVEDIR +and the last element of +.Fa path +consists of +.Ql \&. . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Sh SEE ALSO +.Xr rm 1 , +.Xr chflags 2 , +.Xr close 2 , +.Xr link 2 , +.Xr rmdir 2 , +.Xr symlink 7 +.Sh STANDARDS +The +.Fn unlink +and +.Fn unlinkat +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn unlink +system call first appeared in +.At v1 . +The +.Fn unlinkat +function appeared in +.Ox 5.0 . diff --git a/static/openbsd/man2/unveil.2 b/static/openbsd/man2/unveil.2 new file mode 100644 index 00000000..880f1ca7 --- /dev/null +++ b/static/openbsd/man2/unveil.2 @@ -0,0 +1,176 @@ +.\" $OpenBSD: unveil.2,v 1.24 2026/04/11 17:04:55 deraadt Exp $ +.\" +.\" Copyright (c) 2018 Bob Beck <beck@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: April 11 2026 $ +.Dt UNVEIL 2 +.Os +.Sh NAME +.Nm unveil +.Nd unveil parts of a restricted filesystem view +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn unveil "const char *path" "const char *permissions" +.Sh DESCRIPTION +The first call to +.Fn unveil +removes visibility of the entire filesystem from all other +filesystem-related system calls (such as +.Xr open 2 , +.Xr chmod 2 +and +.Xr rename 2 ) , +except for the specified +.Fa path +and +.Fa permissions . +.Pp +The +.Fn unveil +system call remains capable of traversing to any +.Fa path +in the filesystem, so additional calls can set permissions at any +point in the filesystem hierarchy. +.Pp +After establishing a collection of +.Fa path +and +.Fa permissions +rules, future calls to +.Fn unveil +can be disabled by passing two +.Dv NULL +arguments, or with a +.Xr pledge 2 +call which lacks the +.Qq unveil +promise. +It is strongly recommended to lock +.Fn unveil +after configuration. +.Pp +The +.Fa permissions +argument points to a string consisting of zero or more of the following +characters: +.Pp +.Bl -tag -width "XXXX" -offset indent -compact +.It Cm r +Make +.Fa path +available for read operations, corresponding to the +.Xr pledge 2 +promise +.Qq rpath . +.It Cm w +Make +.Fa path +available for write operations, corresponding to the +.Xr pledge 2 +promise +.Qq wpath . +.It Cm x +Make +.Fa path +available for execute operations, corresponding to the +.Xr pledge 2 +promise +.Qq exec . +.It Cm c +Allow +.Fa path +to be created and removed, corresponding to the +.Xr pledge 2 +promise +.Qq cpath . +.El +.Pp +A +.Fa path +that is a directory will enable all filesystem access underneath +.Fa path +using +.Fa permissions +if and only if no more specific matching +.Fn unveil +exists at a lower level. +Directories are remembered at the time of a call to +.Fn unveil . +This means that a directory that is removed and recreated after a call to +.Fn unveil +will appear to not exist. +.Pp +Non-directory paths are remembered by name within their containing +directory, and so may be created, removed, or re-created after a call to +.Fn unveil +and still appear to exist. +.Pp +Attempts to access paths not allowed by +.Fn unveil +will result in an error of +.Er EACCES +when the +.Fa permissions +argument does not match the attempted operation. +.Er ENOENT +is returned for paths for which no +.Fn unveil +permissions qualify. +After a process has terminated, +.Xr lastcomm 1 +will mark it with the +.Sq U +flag if file access was prevented by +.Fn unveil . +.Pp +.Fn unveil +use can be tricky because programs misbehave badly when their files +unexpectedly disappear. +In many cases it is easier to unveil the directories in which an +application makes use of files. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er E2BIG +The addition of +.Fa path +would exceed the per-process limit for unveiled paths. +.It Bq Er EFAULT +.Fa path +or +.Fa permissions +points outside the process's allocated address space. +.It Bq Er ENOENT +A directory in +.Fa path +did not exist. +.It Bq Er EINVAL +An invalid value of +.Fa permissions +was used. +.It Bq Er EPERM +An attempt to increase permissions was made, or the +.Fa path +was not accessible, or +.Fn unveil +was called after locking. +.El +.Sh HISTORY +The +.Fn unveil +system call first appeared in +.Ox 6.4 . diff --git a/static/openbsd/man2/utimes.2 b/static/openbsd/man2/utimes.2 new file mode 100644 index 00000000..b58032c5 --- /dev/null +++ b/static/openbsd/man2/utimes.2 @@ -0,0 +1,329 @@ +.\" $OpenBSD: utimes.2,v 1.28 2020/09/30 16:27:16 deraadt Exp $ +.\" $NetBSD: utimes.2,v 1.9 1996/04/23 10:34:16 mycroft 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. 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 +.\" +.Dd $Mdocdate: September 30 2020 $ +.Dt UTIMES 2 +.Os +.Sh NAME +.Nm utimes , +.Nm futimes , +.Nm utimensat , +.Nm futimens +.Nd set file access and modification times +.Sh SYNOPSIS +.In sys/time.h +.Ft int +.Fn utimes "const char *path" "const struct timeval times[2]" +.Ft int +.Fn futimes "int fd" "const struct timeval times[2]" +.In sys/stat.h +.In fcntl.h +.Ft int +.Fn utimensat "int fd" "const char *path" "const struct timespec times[2]" "int flag" +.Ft int +.Fn futimens "int fd" "const struct timespec times[2]" +.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 superuser. +.Pp +If +.Fa times +is non-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 superuser. +.Pp +In either case, the file status change time is set to the current time. +.Pp +The +.Fn utimensat +and +.Fn futimens +are equivalent to +.Fn utimes +and +.Fn futimes , +respectively, with the following differences. +.Pp +Both +.Fn utimensat +and +.Fn futimens +take two timespec values instead of two timeval values. +Further, either of the +.Fa tv_nsec +fields can be set to one of the following special values defined in +.In sys/stat.h , +in which case the value of +.Fa tv_sec +is ignored: +.Pp +.Bl -tag -width UTIME_OMIT -offset indent -compact +.It Dv UTIME_NOW +Set the respective timestamp to the greatest value supported +that is not greater than the current time. +.It Dv UTIME_OMIT +Do not change the respective timestamp. +.El +.Pp +Additionally, if the +.Fa path +argument to +.Fn utimensat +specifies a relative path, +the file whose timestamps are changed is determined relative to +the directory associated with file descriptor +.Fa fd +instead of the current working directory. +.Pp +If +.Fn utimensat +is passed the special value +.Dv AT_FDCWD +(defined in +.In fcntl.h ) +in the +.Fa fd +parameter, the current working directory is used. +.Pp +The +.Fa flag +argument is the bitwise OR of zero or more of the following values: +.Pp +.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the timestamps of the symbolic link are changed. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn utimes +and +.Fn utimensat +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 superuser, 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 pathname (including the terminating NUL) +exceeded +.Dv PATH_MAX +bytes. +.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 superuser. +.It Bq Er EROFS +The file system containing the file is mounted read-only. +.El +.Pp +Additionally, +.Fn utimensat +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value of the +.Fa flag +argument was neither zero nor +.Dv AT_SYMLINK_NOFOLLOW . +.It Bq Er EBADF +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa path +argument specifies a relative path and the +.Fa fd +argument is a valid file descriptor but it does not reference a directory. +.It Bq Er EACCES +The +.Fa path +argument specifies a relative path but search permission is denied +for the directory which the +.Fa fd +file descriptor references. +.El +.Pp +.Fn futimes +and +.Fn futimens +will fail if: +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +does not refer to a valid descriptor. +.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 superuser, 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 superuser. +.It Bq Er EROFS +The file system containing the file is mounted read-only. +.El +.Pp +.Fn utimes +and +.Fn futimes +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Either of the +.Fa times +arguments specified a microsecond value less than zero or greater +than or equal to 1 million, or a second value less than zero. +.El +.Pp +.Fn utimesat +and +.Fn futimens +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Either of the +.Fa times +argument specified a nanosecond value less than zero or greater +than or equal to 1000 million, or a second value less than zero. +.El +.Sh SEE ALSO +.Xr clock_gettime 2 , +.Xr stat 2 , +.Xr utime 3 +.Sh STANDARDS +The +.Fn utimes , +.Fn utimensat , +and +.Fn futimens +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The predecessors of +.Fn utimes +were +.Fn smdate +in +.At v1 , +.Fn mdate +in +.At v3 , +and +.Fn utime +in +.At v7 ; +the latter first supported the concept of an access time +in addition to the modification time. +.Pp +The +.Fn utimes +function call appeared in +.Bx 4.2 . +The +.Fn futimes +function call appeared in +.Nx 1.2 . +The +.Fn utimensat +and +.Fn futimens +function calls appeared in +.Ox 5.0 . +.Sh CAVEATS +Some filesystems, such as FAT, use the same timestamp for both +modification and file status change; +on those filesystems, the file status change timestamp will not be +updated if +.Dv UTIME_OMIT +is specified for the modification timestamp argument. +Similarly, on NFS the file status change timestamp will not be +updated if +.Dv UTIME_OMIT +is specified for both the access and the modification timestamp arguments. diff --git a/static/openbsd/man2/utrace.2 b/static/openbsd/man2/utrace.2 new file mode 100644 index 00000000..e412ce5b --- /dev/null +++ b/static/openbsd/man2/utrace.2 @@ -0,0 +1,86 @@ +.\" $OpenBSD: utrace.2,v 1.4 2023/02/23 01:34:27 deraadt Exp $ +.\" $NetBSD: utrace.2,v 1.13 2008/05/02 18:38:32 martin Exp $ +.\" +.\" Copyright (c) 2000 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Gregory McGarry <g.mcgarry@ieee.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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 $Mdocdate: February 23 2023 $ +.Dt UTRACE 2 +.Os +.Sh NAME +.Nm utrace +.Nd insert user record in ktrace log +.Sh SYNOPSIS +.In sys/types.h +.In sys/ktrace.h +.Ft int +.Fn utrace "const char *label" "void *addr" "size_t len" +.Sh DESCRIPTION +Adds a record to the process trace with information supplied by the user. +The record is identified by +.Fa label +and contains +.Fa len +bytes from memory pointed to by +.Fa addr . +This call only has an effect if the calling process is being traced. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ENOSYS +The currently running kernel was compiled without +.Xr ktrace 2 +support (option KTRACE). +.It Bq Er ENAMETOOLONG +The length of the +.Fa label +string was longer than +.Dv KTR_USER_MAXIDLEN\-1 . +.It Bq Er EINVAL +The specified data length +.Fa len +was bigger than +.Dv KTR_USER_MAXLEN . +.El +.Sh SEE ALSO +.Xr kdump 1 , +.Xr ktrace 1 , +.Xr ktrace 2 , +.Xr options 4 +.Sh HISTORY +The +.Fn utrace +system call first appeared in +.Fx 2.2 . +It was added to +.Ox +in +.Ox 5.4 . +The +.Fa label +argument is an extension. diff --git a/static/openbsd/man2/vfork.2 b/static/openbsd/man2/vfork.2 new file mode 100644 index 00000000..a9e819ac --- /dev/null +++ b/static/openbsd/man2/vfork.2 @@ -0,0 +1,107 @@ +.\" $OpenBSD: vfork.2,v 1.20 2015/09/10 17:55:21 schwarze Exp $ +.\" $NetBSD: vfork.2,v 1.8 1997/07/10 07:54:13 mikel 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. 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 +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt VFORK 2 +.Os +.Sh NAME +.Nm vfork +.Nd spawn new process and block parent +.Sh SYNOPSIS +.In unistd.h +.Ft pid_t +.Fn vfork void +.Sh DESCRIPTION +.Fn vfork +was originally used to create new processes without fully copying the address +space of the old process, which is horrendously inefficient in a paged +environment. +It was useful when the purpose of +.Xr fork 2 +would have been to create a new system context for an +.Xr execve 2 . +Since +.Xr fork 2 +is now efficient, even in the above case, the need for +.Fn vfork +has diminished. +.Fn vfork +differs from +.Xr fork 2 +in that the parent is suspended until the child makes a call to +.Xr execve 2 +or an exit (either by a call to +.Xr _exit 2 +or abnormally). +In addition, fork handlers established using +.Xr pthread_atfork 3 +are not called when a multithreaded program calls +.Fn vfork . +.Pp +.Fn vfork +returns 0 in the child's context and (later) the PID of the child in +the parent's context. +.Sh RETURN VALUES +Same as for +.Xr fork 2 . +.Sh SEE ALSO +.Xr execve 2 , +.Xr fork 2 , +.Xr sigaction 2 , +.Xr wait 2 +.Sh HISTORY +The +.Fn vfork +function call appeared in +.Bx 3.0 +with the additional semantics that the child process ran in the +memory of the parent until it called +.Xr execve 2 +or exited. +That sharing of memory was removed in +.Bx 4.4 , +leaving just the semantics of blocking the parent until the child calls +.Xr execve 2 +or exits. +On many other systems the original behavior has been restored, +making this interface particularly unportable. +.Sh BUGS +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. diff --git a/static/openbsd/man2/wait.2 b/static/openbsd/man2/wait.2 new file mode 100644 index 00000000..70e0fcb2 --- /dev/null +++ b/static/openbsd/man2/wait.2 @@ -0,0 +1,350 @@ +.\" $OpenBSD: wait.2,v 1.33 2022/12/19 18:13:50 guenther Exp $ +.\" $NetBSD: wait.2,v 1.6 1995/02/27 12:39:37 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: December 19 2022 $ +.Dt WAIT 2 +.Os +.Sh NAME +.Nm wait , +.Nm waitpid , +.Nm wait4 , +.Nm wait3 , +.Nm WCOREDUMP , +.Nm WEXITSTATUS , +.Nm WIFCONTINUED , +.Nm WIFEXITED , +.Nm WIFSIGNALED , +.Nm WIFSTOPPED , +.Nm WSTOPSIG , +.Nm WTERMSIG +.Nd wait for process termination +.Sh SYNOPSIS +.In sys/wait.h +.Ft pid_t +.Fn wait "int *status" +.Ft pid_t +.Fn waitpid "pid_t wpid" "int *status" "int options" +.In sys/resource.h +.In sys/wait.h +.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, if non-zero, is filled in with termination information about the +process that exited (see 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. +The following symbolic constants are currently defined in +.In sys/wait.h : +.Bd -unfilled -offset indent +#define WAIT_ANY (-1) /* any process */ +#define WAIT_MYPGRP 0 /* any process in my process group */ +.Ed +.Pp +If +.Fa wpid +is set to +.Dv WAIT_ANY , +the call waits for any child process. +If +.Fa wpid +is set to +.Dv WAIT_MYPGRP , +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 +argument is the bitwise OR of zero or more of the following values: +.Bl -tag -width "WCONTINUED" +.It Dv WCONTINUED +Causes status to be reported for stopped child processes that have been +continued by receipt of a +.Dv SIGCONT +signal. +.It Dv WNOHANG +Indicates that the call should not block if there are no processes that wish +to report status. +.It Dv WUNTRACED +If 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. +.El +.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 WIFCONTINUED status +True if the process has not terminated, and has continued after a job +control stop. +This macro can be true only if the wait call specified the +.Dv WCONTINUED +option. +.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; for further information, see +.Xr siginterrupt 3 . +.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 , +.Fn waitpid , +.Fn wait3 , +and +.Fn wait4 +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 ECHILD +No status from the terminated child process is available +because the calling process has asked the system to discard +such status by ignoring the signal +.Dv SIGCHLD +or setting the flag +.Dv SA_NOCLDWAIT +for that signal. +.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 +.Pp +.Fn waitpid +and +.Fn wait4 +will fail and return immediately if: +.Bl -tag -width Er +.It Bq Er ECHILD +The process specified by the +.Fa wpid +argument does not exist or is not a child of the calling process. +.It Bq Er EINVAL +Invalid or undefined flags were passed in the +.Fa options +argument. +.El +.Sh SEE ALSO +.Xr _exit 2 , +.Xr sigaction 2 , +.Xr waitid 2 , +.Xr exit 3 +.Sh STANDARDS +The +.Fn wait +and +.Fn waitpid +functions conform to +.St -p1003.1-2008 . +.Pp +.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 that specification. +.Sh HISTORY +A +.Fn wait +system call first appeared in +.At v1 . +The +.Fa status +argument is accepted since +.At v2 . +A +.Fn wait3 +system call first appeared in +.Bx 4.0 , +but the final calling convention was only established in +.Bx 4.2 . +The +.Fn wait4 +and +.Fn waitpid +function calls first appeared in +.Bx 4.3 Reno . diff --git a/static/openbsd/man2/waitid.2 b/static/openbsd/man2/waitid.2 new file mode 100644 index 00000000..4e884f85 --- /dev/null +++ b/static/openbsd/man2/waitid.2 @@ -0,0 +1,261 @@ +.\" $OpenBSD: waitid.2,v 1.2 2022/12/20 09:01:05 jmc Exp $ +.\" $NetBSD: wait.2,v 1.6 1995/02/27 12:39:37 cgd Exp $ +.\" +.\" 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. 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 +.\" +.Dd $Mdocdate: December 20 2022 $ +.Dt WAITID 2 +.Os +.Sh NAME +.Nm waitid +.Nd wait for process state change +.Sh SYNOPSIS +.In sys/wait.h +.Ft int +.Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *infop" "int options" +.Sh DESCRIPTION +The +.Fn waitid +function suspends execution of its calling process until +a selected state change occurs for a matching child process, +or a signal is received. +.Pp +The set of child processes to be queried is specified by the arguments +.Fa idtype +and +.Fa id . +.Bl -dash -offset indent +.It +If +.Fa idtype +is +.Dv P_PID , +.Fn waitid +waits for the child process with a process ID equal to +.Dv (pid_t)id . +.It +If +.Fa idtype +is +.Dv P_PGID , +.Fn waitid +waits for the child process with a process group ID equal to +.Dv (pid_t)id . +.It +If +.Fa idtype +is +.Dv P_ALL , +.Fn waitid +waits for any child process and the +.Dv id +is ignored. +.El +.Pp +The +.Fa options +argument is the bitwise OR of zero or more of the following values: +.Bl -tag -width "WCONTINUED" +.It Dv WCONTINUED +Causes status to be reported for selected child processes that were +previously stopped and which have been continued by receipt of a +.Dv SIGCONT +signal. +.It Dv WEXITED +Reports the status of selected processes which have terminated. +.It Dv WNOHANG +Indicates that the call should not block if there are no selected processes +that have a status change to report. +.It Dv WNOWAIT +Keeps the process whose status is returned in a waitable state. +The process may be waited for again after this call completes. +.It Dv WSTOPPED +Reports the status of selected processes which are stopped due to a +.Dv SIGTTIN , SIGTTOU , SIGTSTP , +or +.Dv SIGSTOP +signal. +.It Dv WTRAPPED +Reports the status of selected processes which are stopped due to a +process tracing event +.Xr ( ptrace 2 ) . +.El +.Pp +At least one of +.Dv WCONTINUED , WEXITED , WSTOPPED , +or +.Dv WTRAPPED +must be specified. +.Pp +If +.Fn waitid +found a matching process, the structure referenced by +.Fa infop +is filled with the status of the process: +.Fa si_signo +is set to +.Dv SIGCHLD , +and +.Fa si_pid +and +.Fa si_uid +are set to the process ID and effective user ID of the matched process. +.Fa si_code +will be set to one of the following values: +.Bl -tag -width "CLD_CONTINUED" +.It Dv CLD_CONTINUED +The process was previously stopped and was continued. +.Fa si_status +will be set to +.Dv SIGCONT . +Only returned if +.Fa options +includes +.Dv WCONTINUED . +.It Dv CLD_DUMPED +The process was killed by a signal and a core file was generated. +.Fa si_status +will be set to the signal that killed the process. +Only returned if +.Fa options +includes +.Dv WEXITED . +.It Dv CLD_EXITED +The process exited normally. +.Fa si_status +will be set to the full +.Ft int +value that was passed to +.Xr _exit 2 . +Only returned if +.Fa options +includes +.Dv WEXITED . +.It Dv CLD_KILLED +The process was killed by a signal with generation of a core file. +.Fa si_status +will be set to the signal that killed the process. +Only returned if +.Fa options +includes +.Dv WEXITED . +.It Dv CLD_STOPPED +The process was stopped due to a signal. +.Fa si_status +will be set to the signal that stopped the process. +Only returned if +.Fa options +includes +.Dv WSTOPPED . +.It Dv CLD_TRAPPED +The process was stopped due to process tracing +.Xr ( ptrace 2 ) . +.Fa si_status +will be set to the signal that caused the trap. +Only returned if +.Fa options +includes +.Dv WTRAPPED . +.El +.Pp +If +.Dv WNOHANG +was specified and +.Fn waitid +didn't find a matching process, +.Fa si_signo +and +.Fa si_pid +will be set to zero. +.Sh RETURN VALUES +If +.Fn waitid +returns because one or more processes have a state change to report, +0 is returned. +If an error is detected, +a value of -1 +is returned and +.Va errno +is set to indicate the error. +If +.Dv WNOHANG +is specified and there are +no stopped, continued or exited children, +0 is returned. +.Sh ERRORS +.Fn waitid +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 ECHILD +No status from the terminated child process is available +because the calling process has asked the system to discard +such status by ignoring the signal +.Dv SIGCHLD +or setting the flag +.Dv SA_NOCLDWAIT +for that signal. +.It Bq Er EFAULT +The +.Fa infop +argument points 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. +.It Bq Er EINVAL +Invalid or undefined flags were passed in the +.Fa options +argument, or +.Fa idtype +and +.Fa id +specified an invalid set of processes. +.El +.Sh SEE ALSO +.Xr _exit 2 , +.Xr ptrace 2 , +.Xr sigaction 2 , +.Xr wait 2 , +.Xr exit 3 +.Sh STANDARDS +The +.Fn waitid +function conforms to +.St -p1003.1-2008 . +The +.Dv WTRAPPED +macro is an extension to that specification. +.\" .Sh HISTORY +.\" A +.\" .Fn waitid +.\" system call first appeared in diff --git a/static/openbsd/man2/write.2 b/static/openbsd/man2/write.2 new file mode 100644 index 00000000..cf7a6fba --- /dev/null +++ b/static/openbsd/man2/write.2 @@ -0,0 +1,329 @@ +.\" $OpenBSD: write.2,v 1.45 2023/02/05 12:33:17 jsg Exp $ +.\" $NetBSD: write.2,v 1.6 1995/02/27 12:39:43 cgd 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. 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 +.\" +.Dd $Mdocdate: February 5 2023 $ +.Dt WRITE 2 +.Os +.Sh NAME +.Nm write , +.Nm writev , +.Nm pwrite , +.Nm pwritev +.Nd write output +.Sh SYNOPSIS +.In unistd.h +.Ft ssize_t +.Fn write "int d" "const void *buf" "size_t nbytes" +.Ft ssize_t +.Fn pwrite "int d" "const void *buf" "size_t nbytes" "off_t offset" +.Pp +.In sys/uio.h +.Ft ssize_t +.Fn writev "int d" "const struct iovec *iov" "int iovcnt" +.In sys/types.h +.In sys/uio.h +.Ft ssize_t +.Fn pwritev "int d" "const struct iovec *iov" "int iovcnt" "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 +and +.Fn pwritev +perform the same functions, but write to the specified position +.Fa offset +in the file without modifying the file pointer. +.Pp +For +.Fn writev +and +.Fn pwritev , +the +.Vt iovec +structure is defined as: +.Bd -literal -offset indent +struct iovec { + void *iov_base; + size_t iov_len; +}; +.Ed +.Pp +Each +.Vt iovec +entry specifies the base address and length of an area +in memory from which data should be written. +.Fn writev +and +.Fn pwritev +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. +If a file was opened with the +.Dv O_APPEND +flag (see +.Xr open 2 ) , +calls to +.Fn write +or +.Fn writev +will automatically set the pointer to the end of the file before writing. +.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 superuser, 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 superuser. +.Pp +If +.Fn write +succeeds, it will update the st_ctime and st_mtime fields of the file's +meta-data (see +.Xr stat 2 ) . +.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. +.Pp +Note that +.Fn writev +and +.Fn pwritev +will fail if the value of +.Fa iovcnt +exceeds the constant +.Dv IOV_MAX . +.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 EXAMPLES +A typical loop allowing partial writes looks like this: +.Bd -literal +const char *buf; +size_t bsz, off; +ssize_t nw; +int d; + +for (off = 0; off < bsz; off += nw) + if ((nw = write(d, buf + off, bsz - off)) == 0 || nw == -1) + err(1, "write"); +.Ed +.Sh ERRORS +.Fn write , +.Fn pwrite , +.Fn writev , +and +.Fn pwritev +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 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 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 EINTR +A write to a slow device +(i.e. one that might block for an arbitrary amount of time) +was interrupted by the delivery of a signal +before any data could be written. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er EFAULT +Part of +.Fa buf +points outside the process's allocated address space. +.El +.Pp +In addition, +.Fn write +and +.Fn writev +may return the following errors: +.Bl -tag -width Er +.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 EAGAIN +The file was marked for non-blocking I/O, and no data could be +written immediately. +.It Bq Er ENETDOWN +The destination address specified a network that is down. +.It Bq Er EDESTADDRREQ +The destination is no longer available when writing to a +.Ux Ns -domain +datagram socket on which +.Xr connect 2 +had been used to set a destination address. +.It Bq Er EIO +The process is a member of a background process attempting to write +to its controlling terminal, +.Dv TOSTOP +is set on the terminal, +the process isn't ignoring the +.Dv SIGTTOUT +signal and the thread isn't blocking the +.Dv SIGTTOUT +signal, +and either the process was created with +.Xr vfork 2 +and hasn't successfully executed one of the exec functions or +the process group is orphaned. +.El +.Pp +.Fn write +and +.Fn pwrite +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa nbytes +was larger than +.Dv SSIZE_MAX . +.El +.Pp +.Fn pwrite +and +.Fn pwritev +may return the following error: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa offset +was negative. +.It Bq Er ESPIPE +.Fa d +is associated with a pipe, socket, FIFO, or tty. +.El +.Pp +.Fn writev +and +.Fn pwritev +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 +.Dv IOV_MAX . +.It Bq Er EINVAL +The sum of the +.Fa iov_len +values in the +.Fa iov +array overflowed an +.Vt ssize_t . +.It Bq Er EFAULT +Part of +.Fa iov +points outside the process's allocated address space. +.It Bq Er ENOBUFS +The system lacked sufficient buffer space or a queue was full. +.El +.Sh SEE ALSO +.Xr fcntl 2 , +.Xr lseek 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr termios 4 +.Sh STANDARDS +The +.Fn write , +.Fn writev , +and +.Fn pwrite +functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn write +function call appeared in +.At v1 , +.Fn pwrite +in +.At V.4 , +.Fn writev +in +.Bx 4.1c , +and +.Fn pwritev +in +.Ox 2.7 . +.Sh CAVEATS +Error checks should explicitly test for \-1. +On some platforms, if +.Fa nbytes +is larger than +.Dv SSIZE_MAX +but smaller than +.Dv SIZE_MAX +\- 2, the return value of an error-free call +may appear as a negative number distinct from \-1. diff --git a/static/openbsd/man2/ypconnect.2 b/static/openbsd/man2/ypconnect.2 new file mode 100644 index 00000000..8ca33ace --- /dev/null +++ b/static/openbsd/man2/ypconnect.2 @@ -0,0 +1,80 @@ +.\" $OpenBSD: ypconnect.2,v 1.3 2022/07/21 22:45:06 deraadt Exp $ +.\" +.\" Copyright (c) 2022 Theo de Raadt <deraadt@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: July 21 2022 $ +.Dt YPCONNECT 2 +.Os +.Sh NAME +.Nm ypconnect +.Nd create connected socket to a YP server +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn ypconnect "int type" +.Sh DESCRIPTION +The +.Fn ypconnect +system call creates a pre-connected +.Va SOCK_STREAM +or +.Va SOCK_DGRAM +socket to a YP server (either the original +.Xr ypserv 8 +or +.Xr ypldap 8 ) +for use by internal library routines. +It verifies that the domainname is set, that +.Xr ypbind 8 +has found a server and created an advisory locked binding file, +and then creates the connected socket based upon the binding file. +This type of socket is restricted in various ways and is not +general purpose. +.Nm +is only intended for use by internal libc YP functions. +.Sh RETURN VALUES +If successful, +.Fn ypconnect +returns a non-negative integer, the socket file descriptor. +Otherwise, a value of \-1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn ypconnect +will fail if: +.Bl -tag -width Er +.It Bq Er EAFNOSUPPORT +The YP subsystem is not active. +.It Bq Er EFTYPE +The YP binding file is strange. +.It Bq Er EOWNERDEAD +The YP binding file is not locked. +YP subsystem is not active. +.It Bq Er EMFILE +The per-process descriptor table is full. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENOBUFS +Insufficient resources were available in the system to perform the operation. +.El +.Sh SEE ALSO +.Xr connect 2 , +.Xr socket 2 , +.Xr ypbind 8 +.Sh HISTORY +The +.Fn ypconnect +function first appeared in +.Ox 7.2 . |
