Skip to content

Commit 16f3a8e

Browse files
authored
Merge pull request rust-lang#333 from bugaevc/reboot
Linux: add reboot() and constants
2 parents baf71f8 + 8b76797 commit 16f3a8e

File tree

6 files changed

+69
-13
lines changed

6 files changed

+69
-13
lines changed

libc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ fn main() {
165165
cfg.header("sys/vfs.h");
166166
cfg.header("sys/syscall.h");
167167
cfg.header("sys/sysinfo.h");
168+
cfg.header("sys/reboot.h");
168169
if !musl {
169170
cfg.header("linux/netlink.h");
170171
cfg.header("linux/magic.h");
172+
cfg.header("linux/reboot.h");
171173

172174
if !mips {
173175
cfg.header("linux/quota.h");

src/unix/notbsd/android/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,21 @@ pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void;
486486

487487
pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;
488488

489+
pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
490+
pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
491+
pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;
492+
pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448;
493+
pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216;
494+
495+
pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567;
496+
pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123;
497+
pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF;
498+
pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000;
499+
pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC;
500+
pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4;
501+
pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2;
502+
pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543;
503+
489504
f! {
490505
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int {
491506
*set = 0;

src/unix/notbsd/linux/mips.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,21 @@ pub const RTLD_DEEPBIND: ::c_int = 0x10;
527527
pub const RTLD_GLOBAL: ::c_int = 0x4;
528528
pub const RTLD_NOLOAD: ::c_int = 0x8;
529529

530+
pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
531+
pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
532+
pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;
533+
pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448;
534+
pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216;
535+
536+
pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567;
537+
pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123;
538+
pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF;
539+
pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000;
540+
pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC;
541+
pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4;
542+
pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2;
543+
pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543;
544+
530545
pub const SYS_gettid: ::c_long = 4222; // Valid for O32
531546

532547
#[link(name = "util")]

src/unix/notbsd/linux/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ pub const LOG_NFACILITIES: ::c_int = 24;
468468

469469
pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t;
470470

471+
pub const RB_AUTOBOOT: ::c_int = 0x01234567;
472+
pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123;
473+
pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef;
474+
pub const RB_DISABLE_CAD: ::c_int = 0;
475+
pub const RB_POWER_OFF: ::c_int = 0x4321fedc;
476+
pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2;
477+
pub const RB_KEXEC: ::c_int = 0x45584543;
478+
471479
f! {
472480
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
473481
for slot in cpuset.bits.iter_mut() {
@@ -639,6 +647,7 @@ extern {
639647
remote_iov: *const ::iovec,
640648
riovcnt: ::c_ulong,
641649
flags: ::c_ulong) -> isize;
650+
pub fn reboot(how_to: ::c_int) -> ::c_int;
642651

643652
// Not available now on Android
644653
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char,

src/unix/notbsd/linux/other/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,21 @@ pub const RTLD_DEEPBIND: ::c_int = 0x8;
474474
pub const RTLD_GLOBAL: ::c_int = 0x100;
475475
pub const RTLD_NOLOAD: ::c_int = 0x4;
476476

477+
pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
478+
pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
479+
pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;
480+
pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448;
481+
pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216;
482+
483+
pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567;
484+
pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123;
485+
pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF;
486+
pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000;
487+
pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC;
488+
pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4;
489+
pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2;
490+
pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543;
491+
477492
cfg_if! {
478493
if #[cfg(any(target_arch = "arm", target_arch = "x86",
479494
target_arch = "x86_64"))] {

src/unix/notbsd/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,19 +847,19 @@ extern {
847847
pub fn linkat(olddirfd: ::c_int, oldpath: *const ::c_char,
848848
newdirfd: ::c_int, newpath: *const ::c_char,
849849
flags: ::c_int) -> ::c_int;
850-
pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char,
851-
mode: ::mode_t) -> ::c_int;
852-
pub fn mknodat(dirfd: ::c_int, pathname: *const ::c_char,
853-
mode: ::mode_t, dev: dev_t) -> ::c_int;
854-
pub fn readlinkat(dirfd: ::c_int, pathname: *const ::c_char,
855-
buf: *mut ::c_char, bufsiz: ::size_t) -> ::ssize_t;
856-
pub fn renameat(olddirfd: ::c_int, oldpath: *const ::c_char,
857-
newdirfd: ::c_int, newpath: *const ::c_char)
858-
-> ::c_int;
859-
pub fn symlinkat(target: *const ::c_char, newdirfd: ::c_int,
860-
linkpath: *const ::c_char) -> ::c_int;
861-
pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char,
862-
flags: ::c_int) -> ::c_int;
850+
pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char,
851+
mode: ::mode_t) -> ::c_int;
852+
pub fn mknodat(dirfd: ::c_int, pathname: *const ::c_char,
853+
mode: ::mode_t, dev: dev_t) -> ::c_int;
854+
pub fn readlinkat(dirfd: ::c_int, pathname: *const ::c_char,
855+
buf: *mut ::c_char, bufsiz: ::size_t) -> ::ssize_t;
856+
pub fn renameat(olddirfd: ::c_int, oldpath: *const ::c_char,
857+
newdirfd: ::c_int, newpath: *const ::c_char)
858+
-> ::c_int;
859+
pub fn symlinkat(target: *const ::c_char, newdirfd: ::c_int,
860+
linkpath: *const ::c_char) -> ::c_int;
861+
pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char,
862+
flags: ::c_int) -> ::c_int;
863863
}
864864

865865
cfg_if! {

0 commit comments

Comments
 (0)