xref: /csrg-svn/lib/libc/gen/sysctl.3 (revision 58462)
158401Smckusick.\" Copyright (c) 1993 The Regents of the University of California.
258401Smckusick.\" All rights reserved.
358401Smckusick.\"
458401Smckusick.\" %sccs.include.redist.roff%
558401Smckusick.\"
6*58462Sbostic.\"	@(#)sysctl.3	6.2 (Berkeley) 03/04/93
758401Smckusick.\"
858401Smckusick.Dd ""
958401Smckusick.Dt SYSCTL 2
1058401Smckusick.Os
1158401Smckusick.Sh NAME
1258401Smckusick.Nm sysctl
1358401Smckusick.Nd get or set kernel state
1458401Smckusick.Sh SYNOPSIS
1558401Smckusick.Fd #include <sys/sysctl.h>
1658401Smckusick.Ft int
17*58462Sbostic.Fn sysctl "int *name" "u_int namelen" "void *old" "size_t *oldlenp" "void *new" "size_t newlen"
1858401Smckusick.Sh DESCRIPTION
1958401SmckusickThe
2058401Smckusick.Fn sysctl
2158401Smckusickfunction retrieves kernel state and allows processes with
2258401Smckusickappropriate privilege to set kernel state.
2358401SmckusickThe state to be set is described using a ``MIB'' style name,
2458401Smckusickdescribed in a
2558401Smckusick.Fa namelen
2658401Smckusicklength array of integers pointed to by
2758401Smckusick.Fa name .
2858401SmckusickThe top level names are defined with a CTL_ prefix in
2958401Smckusick.Pa <sys/sysctl.h> .
3058401SmckusickThe next levels down are found in the files given in the ``FILES''
3158401Smckusicksection of this manual page.
3258401Smckusick.Pp
3358401SmckusickTo retrieve a value,
3458401Smckusick.Fa old
3558401Smckusickis set to point to a buffer
3658401Smckusickinto which the requested value is to be placed.
3758401SmckusickThe length of the buffer is given in the location pointed to by
3858401Smckusick.Fa oldlenp .
3958401SmckusickThe size of the returned value is put in the location pointed to by
4058401Smckusick.Fa oldlenp .
4158401SmckusickThe size of the requested value can be determined by calling
4258401Smckusick.Fn sysctl
4358401Smckusickwith a NULL parameter for
4458401Smckusick.Fa old ;
4558401Smckusickthe size of the value will be returned in the location pointed to by
4658401Smckusick.Fa oldlenp .
4758401SmckusickIf the old value is not desired,
4858401Smckusick.Fa old
4958401Smckusickand
5058401Smckusick.Fa oldlenp
5158401Smckusickcan be set to NULL.
5258401Smckusick.Pp
5358401SmckusickTo set a new value,
5458401Smckusick.Fa new
5558401Smckusickis set to point to a buffer of length
5658401Smckusick.Fa newlen
5758401Smckusickfrom which the requested value is to be taken.
5858401SmckusickIf the setting of a new value is not desired,
5958401Smckusick.Fa new
6058401Smckusickshould be set to NULL and
6158401Smckusick.Fa newlen
6258401Smckusickset to 0.
6358401Smckusick.Pp
6458401SmckusickFor example, to retrieve the maximum number of processes allowed
6558401Smckusickin the system, one would use the follow request:
6658401Smckusick.sp
6758401Smckusick.Bd -literal -offset indent -compact
68*58462Sbosticint name[2], maxproc;
69*58462Sbosticsize_t len;
7058401Smckusick
7158401Smckusickname[0] = CTL_KERN;
7258401Smckusickname[1] = KERN_MAXPROC;
73*58462Sbosticlen = sizeof(maxproc);
7458401Smckusicksysctl(name, 2, &maxproc, &len, NULL, 0);
7558401Smckusick.Ed
7658401Smckusick.Sh RETURN VALUES
7758401SmckusickIf the call to
7858401Smckusick.Fn sysctl
7958401Smckusickis successful, the length of the old value is returned.
8058401SmckusickOtherwise \-1 is returned and
8158401Smckusick.Va errno
8258401Smckusickis set appropriately.
8358401Smckusick.Sh ERRORS
8458401SmckusickThe following error may be reported:
8558401Smckusick.Bl -tag -width Er
8658401Smckusick.It Bq Er EFAULT
8758401SmckusickThe buffer
8858401Smckusick.Fa name ,
8958401Smckusick.Fa old ,
9058401Smckusick.Fa new ,
9158401Smckusickor length pointer
9258401Smckusick.Fa oldlenp
9358401Smckusickcontains an invalid address.
9458401Smckusick.It Bq Er EINVAL
9558401SmckusickThe
9658401Smckusick.Fa name
9758401Smckusickarray is less than two or greater than CTL_MAXNAME.
9858401Smckusick.It Bq Er EINVAL
9958401SmckusickA non-null
10058401Smckusick.Fa new
10158401Smckusickis given and its specified length in
10258401Smckusick.Fa newlen
10358401Smckusickis too large or too small.
10458401Smckusick.It Bq Er ENOMEM
10558401SmckusickThe length pointed to by
10658401Smckusick.Fa oldlenp
10758401Smckusickis too short to hold the requested value.
10858401Smckusick.It Bq Er ENOTDIR
10958401SmckusickThe
11058401Smckusick.Fa name
11158401Smckusickarray specifies an intermediate rather than terminal name.
11258401Smckusick.It Bq Er EOPNOTSUPP
11358401SmckusickThe
11458401Smckusick.Fa name
11558401Smckusickarray specifies a value that is unknown.
11658401Smckusick.It Bq Er EPERM
11758401SmckusickAn attempt is made to set a read-only value.
11858401Smckusick.It Bq Er EPERM
11958401SmckusickA process without appropriate privilege attempts to set a value.
12058401Smckusick.El
12158401Smckusick.Sh FILES
12258401Smckusick.Bl -tag -width <vm/vm_param.h> -compact
12358401Smckusick.It Pa <sys/sysctl.h>
12458401Smckusickdefinitions for top level identifiers and second level kernel
12558401Smckusickand hardware identifiers
12658401Smckusick.It Pa <sys/socket.h>
12758401Smckusickdefinitions for second level network identifiers
12858401Smckusick.It Pa <vm/vm_param.h>
12958401Smckusickdefinitions for second level virtual memory identifiers
13058401Smckusick.El
13158401Smckusick.Sh SEE ALSO
13258401Smckusick.Xr sysctl 8
13358401Smckusick.Sh HISTORY
13458401Smckusick.Fn sysctl
13558401Smckusickfirst appeared in 4.4BSD.
136