1SYSCTL(2) Linux Programmer's Manual SYSCTL(2)
2
3
4
6 sysctl - read/write system parameters
7
9 #include <unistd.h>
10 #include <linux/unistd.h>
11 #include <linux/sysctl.h>
12 #include <errno.h>
13
14 _syscall1(int, _sysctl, struct __sysctl_args *, args)
15 /* Using syscall(2) may be preferable; see intro(2) */
16
17 int _sysctl(struct __sysctl_args *args);
18
20 The _sysctl() call reads and/or writes kernel parameters. For example,
21 the hostname, or the maximum number of open files. The argument has the
22 form
23
24 struct __sysctl_args {
25 int *name; /* integer vector describing variable */
26 int nlen; /* length of this vector */
27 void *oldval; /* 0 or address where to store old value */
28 size_t *oldlenp; /* available room for old value,
29 overwritten by actual size of old value */
30 void *newval; /* 0 or address of new value */
31 size_t newlen; /* size of new value */
32 };
33
34 This call does a search in a tree structure, possibly resembling a
35 directory tree under /proc/sys, and if the requested item is found
36 calls some appropriate routine to read or modify the value.
37
38
40 #include <linux/unistd.h>
41 #include <linux/types.h>
42 #include <linux/sysctl.h>
43
44 _syscall1(int, _sysctl, struct __sysctl_args *, args);
45 int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
46 void *newval, size_t newlen)
47 {
48 struct __sysctl_args args={name,nlen,oldval,oldlenp,newval,newlen};
49 return _sysctl(&args);
50 }
51
52 #define SIZE(x) sizeof(x)/sizeof(x[0])
53 #define OSNAMESZ 100
54
55 char osname[OSNAMESZ];
56 int osnamelth;
57 int name[] = { CTL_KERN, KERN_OSTYPE };
58
59 main(){
60 osnamelth = sizeof(osname);
61 if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
62 perror("sysctl");
63 else
64 printf("This machine is running %*s\n", osnamelth, osname);
65 return 0;
66 }
67
68
70 Upon successful completion, _sysctl() returns 0. Otherwise, a value of
71 -1 is returned and errno is set to indicate the error.
72
74 EFAULT The invocation asked for the previous value by setting oldval
75 non-NULL, but allowed zero room in oldlenp.
76
77 ENOTDIR
78 name was not found.
79
80 EPERM No search permission for one of the encountered `directories',
81 or no read permission where oldval was non-zero, or no write
82 permission where newval was non-zero.
83
85 This call is Linux specific, and should not be used in programs
86 intended to be portable. A sysctl() call has been present in Linux
87 since version 1.3.57. It originated in 4.4BSD. Only Linux has the
88 /proc/sys mirror, and the object naming schemes differ between Linux
89 and 4.4BSD, but the declaration of the sysctl(2) function is the same
90 in both.
91
93 The object names vary between kernel versions. THIS MAKES THIS SYSTEM
94 CALL WORTHLESS FOR APPLICATIONS. Use the /proc/sys interface instead.
95 Not all available objects are properly documented.
96 It is not yet possible to change operating system by writing to
97 /proc/sys/kernel/ostype.
98
100 proc(5)
101
102
103
104Linux 1.3.85 1996-04-11 SYSCTL(2)