Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

       sysctl - システムパラメーターを読み書きする

書式

        #include <unistd.h>
       #include <linux/sysctl.h>

       int _sysctl(struct __sysctl_args *args);

説明

       This system call no longer exists on current kernels! See NOTES.

       _sysctl()   コールはカーネルパラメーターを読み書きする。例えば、 ホストネームや同時にオープンできるファイ
       ルの最大数など。 引数は以下の形式である。

           struct __sysctl_args {
               int    *name;    /* integer vector describing variable */
               int     nlen;    /* length of this vector */
               void   *oldval;  /* 0 or address where to store old value */
               size_t *oldlenp; /* available room for old value,
                                   overwritten by actual size of old value */
               void   *newval;  /* 0 or address of new value */
               size_t  newlen;  /* size of new value */
           };

       このコールは /proc/sys の下のディレクトリツリーに似た木構造(tree structure)を検索する。  そして、要求され
       た項目が見つかった場合は適切なルーチンを呼び出して 値を読んだり修正したりする。

返り値

       成功した場合は  _sysctl()   は 0 を返す。失敗した場合、-1 が返され、 errno がそのエラーを示す値に設定され
       る。

エラー

       EACCESEPERM
              「ディレクトリ」のどれかに検索許可がなかったか、 oldval が 0  でないのに読み込み許可がなかったか、
              newval が 0 でないのに書き込み許可がなかった。

       EFAULT oldval に NULL でない値を設定して、以前の値を要求しているのに、 oldlenp に空きがない。

       ENOTDIR
              name が見つからなかった。

バージョン

       This  system call first appeared in Linux 1.3.57.  It was removed in Linux 5.5; glibc support was removed
       in version 2.32.

準拠

       このコールは Linux 特有であり、移植を意図したプログラムで使用しては いけない。これは 4.4BSD  に由来してい
       る。Linux  は  /proc/sys  に写し(mirror)をもっており、項目の名前の付け方が  Linux と 4.4BSD では 異ってい
       る。しかし sysctl()  関数の宣言は両方で同じである。

注意

       Use of this system call was long discouraged: since Linux 2.6.24, uses of  this  system  call  result  in
       warnings  in  the  kernel  log, and in Linux 5.5, the system call was finally removed.  Use the /proc/sys
       interface instead.

       Note that on older kernels where this system call still exists, it is available only if  the  kernel  was
       configured with the CONFIG_SYSCTL_SYSCALL option.  Furthermore, glibc does not provide a wrapper for this
       system call, necessitating the use of syscall(2).

バグ

       オブジェクトの名前は、カーネルのバージョンごとに異なっている。   このため、このシステムコールはアプリケー
       ションにとって 無価値なものとなっている。

       全ての可能な項目が正確に記述されているわけではない。

       今のところ /proc/sys/kernel/ostype に書き込むことでオペーレーティングシステムを変えることはできない。

       #define _GNU_SOURCE
       #include <unistd.h>
       #include <sys/syscall.h>
       #include <string.h>
       #include <stdio.h>
       #include <stdlib.h>
       #include <linux/sysctl.h>

       int _sysctl(struct __sysctl_args *args );

       #define OSNAMESZ 100

       int
       main(void)
       {
           struct __sysctl_args args;
           char osname[OSNAMESZ];
           size_t osnamelth;
           int name[] = { CTL_KERN, KERN_OSTYPE };

            memset(&args, 0, sizeof(args));
           args.name = name;
           args.nlen = sizeof(name)/sizeof(name[0]);
           args.oldval = osname;
           args.oldlenp = &osnamelth;

           osnamelth = sizeof(osname);

           if (syscall(SYS__sysctl, &args) == -1) {
               perror("_sysctl");
               exit(EXIT_FAILURE);
           }
           printf("This machine is running %*s\n", osnamelth, osname);
           exit(EXIT_SUCCESS);
       }

関連項目

       proc(5)

この文書について

       この  man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告
       に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。