Blame man2/reboot.2

Packit 7cfc04
.\" Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl), 24 September 1998
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"     Added notes on capability requirements
Packit 7cfc04
.\"
Packit 7cfc04
.TH REBOOT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
reboot \- reboot or enable/disable Ctrl-Alt-Del
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
/* Since kernel version 2.1.30 there are symbolic names LINUX_REBOOT_*
Packit 7cfc04
   for the constants and a fourth argument to the call: */
Packit 7cfc04
.PP
Packit 7cfc04
.B #include <unistd.h>
Packit 7cfc04
.br
Packit 7cfc04
.B #include <linux/reboot.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int reboot(int " magic ", int " magic2 ", int " cmd ", void *" arg );
Packit 7cfc04
Packit 7cfc04
/* Under glibc and most alternative libc's (including uclibc, dietlibc,
Packit 7cfc04
   musl and a few others), some of the constants involved have gotten
Packit 7cfc04
   symbolic names RB_*, and the library call is a 1-argument
Packit 7cfc04
   wrapper around the system call: */
Packit 7cfc04
.PP
Packit 7cfc04
.B #include <unistd.h>
Packit 7cfc04
.br
Packit 7cfc04
.B #include <sys/reboot.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int reboot(int " cmd );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR reboot ()
Packit 7cfc04
call reboots the system, or enables/disables the reboot keystroke
Packit 7cfc04
(abbreviated CAD, since the default is Ctrl-Alt-Delete;
Packit 7cfc04
it can be changed using
Packit 7cfc04
.BR loadkeys (1)).
Packit 7cfc04
.PP
Packit 7cfc04
This system call fail (with the error
Packit 7cfc04
.BR EINVAL )
Packit 7cfc04
unless
Packit 7cfc04
.I magic
Packit 7cfc04
equals
Packit 7cfc04
.B LINUX_REBOOT_MAGIC1
Packit 7cfc04
(that is, 0xfee1dead) and
Packit 7cfc04
.I magic2
Packit 7cfc04
equals
Packit 7cfc04
.B LINUX_REBOOT_MAGIC2
Packit 7cfc04
(that is, 672274793).
Packit 7cfc04
However, since 2.1.17 also
Packit 7cfc04
.B LINUX_REBOOT_MAGIC2A
Packit 7cfc04
(that is, 85072278)
Packit 7cfc04
and since 2.1.97 also
Packit 7cfc04
.B LINUX_REBOOT_MAGIC2B
Packit 7cfc04
(that is, 369367448)
Packit 7cfc04
and since 2.5.71 also
Packit 7cfc04
.B LINUX_REBOOT_MAGIC2C
Packit 7cfc04
(that is, 537993216)
Packit 7cfc04
are permitted as values for
Packit 7cfc04
.IR magic2 .
Packit 7cfc04
(The hexadecimal values of these constants are meaningful.)
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I cmd
Packit 7cfc04
argument can have the following values:
Packit 7cfc04
.TP
Packit 7cfc04
.B LINUX_REBOOT_CMD_CAD_OFF
Packit 7cfc04
.RB ( RB_DISABLE_CAD ,
Packit 7cfc04
0).
Packit 7cfc04
CAD is disabled.
Packit 7cfc04
This means that the CAD keystroke will cause a
Packit 7cfc04
.B SIGINT
Packit 7cfc04
signal to be
Packit 7cfc04
sent to init (process 1), whereupon this process may decide upon a
Packit 7cfc04
proper action (maybe: kill all processes, sync, reboot).
Packit 7cfc04
.TP
Packit 7cfc04
.B LINUX_REBOOT_CMD_CAD_ON
Packit 7cfc04
.RB ( RB_ENABLE_CAD ,
Packit 7cfc04
0x89abcdef).
Packit 7cfc04
CAD is enabled.
Packit 7cfc04
This means that the CAD keystroke will immediately cause
Packit 7cfc04
the action associated with
Packit 7cfc04
.BR LINUX_REBOOT_CMD_RESTART .
Packit 7cfc04
.TP
Packit 7cfc04
.B LINUX_REBOOT_CMD_HALT
Packit 7cfc04
.RB ( RB_HALT_SYSTEM ,
Packit 7cfc04
0xcdef0123; since Linux 1.1.76).
Packit 7cfc04
The message "System halted." is printed, and the system is halted.
Packit 7cfc04
Control is given to the ROM monitor, if there is one.
Packit 7cfc04
If not preceded by a
Packit 7cfc04
.BR sync (2),
Packit 7cfc04
data will be lost.
Packit 7cfc04
.TP
Packit 7cfc04
.BR LINUX_REBOOT_CMD_KEXEC
Packit 7cfc04
.RB ( RB_KEXEC ,
Packit 7cfc04
0x45584543, since Linux 2.6.13).
Packit 7cfc04
Execute a kernel that has been loaded earlier with
Packit 7cfc04
.BR kexec_load (2).
Packit 7cfc04
This option is available only if the kernel was configured with
Packit 7cfc04
.BR CONFIG_KEXEC .
Packit 7cfc04
.TP
Packit 7cfc04
.B LINUX_REBOOT_CMD_POWER_OFF
Packit 7cfc04
.RB ( RB_POWER_OFF ,
Packit 7cfc04
0x4321fedc; since Linux 2.1.30).
Packit 7cfc04
The message "Power down." is printed, the system is stopped,
Packit 7cfc04
and all power is removed from the system, if possible.
Packit 7cfc04
If not preceded by a
Packit 7cfc04
.BR sync (2),
Packit 7cfc04
data will be lost.
Packit 7cfc04
.TP
Packit 7cfc04
.B LINUX_REBOOT_CMD_RESTART
Packit 7cfc04
.RB ( RB_AUTOBOOT ,
Packit 7cfc04
0x1234567).
Packit 7cfc04
The message "Restarting system." is printed, and a default
Packit 7cfc04
restart is performed immediately.
Packit 7cfc04
If not preceded by a
Packit 7cfc04
.BR sync (2),
Packit 7cfc04
data will be lost.
Packit 7cfc04
.TP
Packit 7cfc04
.B LINUX_REBOOT_CMD_RESTART2
Packit 7cfc04
(0xa1b2c3d4; since Linux 2.1.30).
Packit 7cfc04
The message "Restarting system with command \(aq%s\(aq" is printed,
Packit 7cfc04
and a restart (using the command string given in
Packit 7cfc04
.IR arg )
Packit 7cfc04
is performed immediately.
Packit 7cfc04
If not preceded by a
Packit 7cfc04
.BR sync (2),
Packit 7cfc04
data will be lost.
Packit 7cfc04
.TP
Packit 7cfc04
.BR LINUX_REBOOT_CMD_SW_SUSPEND
Packit 7cfc04
.RB ( RB_SW_SUSPEND ,
Packit 7cfc04
0xd000fce1; since Linux 2.5.18).
Packit 7cfc04
The system is suspended (hibernated) to disk.
Packit 7cfc04
This option is available only if the kernel was configured with
Packit 7cfc04
.BR CONFIG_HIBERNATION .
Packit 7cfc04
.PP
Packit 7cfc04
Only the superuser may call
Packit 7cfc04
.BR reboot ().
Packit 7cfc04
.PP
Packit 7cfc04
The precise effect of the above actions depends on the architecture.
Packit 7cfc04
For the i386 architecture, the additional argument does not do
Packit 7cfc04
anything at present (2.1.122), but the type of reboot can be
Packit 7cfc04
determined by kernel command-line arguments ("reboot=...") to be
Packit 7cfc04
either warm or cold, and either hard or through the BIOS.
Packit 7cfc04
.\"
Packit 7cfc04
.SS Behavior inside PID namespaces
Packit 7cfc04
.\" commit cf3f89214ef6a33fad60856bc5ffd7bb2fc4709b
Packit 7cfc04
.\" see also commit 923c7538236564c46ee80c253a416705321f13e3
Packit 7cfc04
Since Linux 3.4,
Packit 7cfc04
if
Packit 7cfc04
.BR reboot ()
Packit 7cfc04
is called
Packit 7cfc04
from a PID namespace other than the initial PID namespace
Packit 7cfc04
with one of the
Packit 7cfc04
.I cmd
Packit 7cfc04
values listed below,
Packit 7cfc04
it performs a "reboot" of that namespace:
Packit 7cfc04
the "init" process of the PID namespace is immediately terminated,
Packit 7cfc04
with the effects described in
Packit 7cfc04
.BR pid_namespaces (7).
Packit 7cfc04
.PP
Packit 7cfc04
The values that can be supplied in
Packit 7cfc04
.I cmd
Packit 7cfc04
when calling
Packit 7cfc04
.BR reboot ()
Packit 7cfc04
in this case are as follows:
Packit 7cfc04
.TP
Packit 7cfc04
.BR LINUX_REBOOT_CMD_RESTART ", " LINUX_REBOOT_CMD_RESTART2
Packit 7cfc04
The "init" process is terminated,
Packit 7cfc04
and
Packit 7cfc04
.BR wait (2)
Packit 7cfc04
in the parent process reports that the child was killed with a
Packit 7cfc04
.B SIGHUP
Packit 7cfc04
signal.
Packit 7cfc04
.TP
Packit 7cfc04
.BR LINUX_REBOOT_CMD_POWER_OFF ", " LINUX_REBOOT_CMD_HALT
Packit 7cfc04
The "init" process is terminated,
Packit 7cfc04
and
Packit 7cfc04
.BR wait (2)
Packit 7cfc04
in the parent process reports that the child was killed with a
Packit 7cfc04
.B SIGINT
Packit 7cfc04
signal.
Packit 7cfc04
.PP
Packit 7cfc04
For the other
Packit 7cfc04
.I cmd
Packit 7cfc04
values,
Packit 7cfc04
.BR reboot ()
Packit 7cfc04
returns \-1 and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to
Packit 7cfc04
.BR EINVAL .
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
For the values of
Packit 7cfc04
.I cmd
Packit 7cfc04
that stop or restart the system,
Packit 7cfc04
a successful call to
Packit 7cfc04
.BR reboot ()
Packit 7cfc04
does not return.
Packit 7cfc04
For the other
Packit 7cfc04
.I cmd
Packit 7cfc04
values, zero is returned on success.
Packit 7cfc04
In all cases, \-1 is returned on failure, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
Problem with getting user-space data under
Packit 7cfc04
.BR LINUX_REBOOT_CMD_RESTART2 .
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
Bad magic numbers or \fIcmd\fP.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The calling process has insufficient privilege to call
Packit 7cfc04
.BR reboot ();
Packit 7cfc04
the caller must have the
Packit 7cfc04
.B CAP_SYS_BOOT
Packit 7cfc04
inside its user namespace.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR reboot ()
Packit 7cfc04
is Linux-specific,
Packit 7cfc04
and should not be used in programs intended to be portable.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR systemctl (1),
Packit 7cfc04
.BR systemd (1),
Packit 7cfc04
.BR kexec_load (2),
Packit 7cfc04
.BR sync (2),
Packit 7cfc04
.BR bootparam (7),
Packit 7cfc04
.BR capabilities (7),
Packit 7cfc04
.BR ctrlaltdel (8),
Packit 7cfc04
.BR halt (8),
Packit 7cfc04
.BR shutdown (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.