From a98c983cf019a070e62c939e8c1e2dada63ac84f Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 13:22:51 +0300 Subject: [PATCH 1/7] Linux: add reboot() and constants --- libc-test/build.rs | 2 ++ src/unix/notbsd/linux/mod.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 260772c89cf07..b55ad73de7354 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -165,9 +165,11 @@ fn main() { cfg.header("sys/vfs.h"); cfg.header("sys/syscall.h"); cfg.header("sys/sysinfo.h"); + cfg.header("sys/reboot.h"); if !musl { cfg.header("linux/netlink.h"); cfg.header("linux/magic.h"); + cfg.header("linux/reboot.h"); if !mips { cfg.header("linux/quota.h"); diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 4b46caf7fe4be..722bd4eba7f99 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -462,6 +462,29 @@ pub const LOG_NFACILITIES: ::c_int = 24; pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; +pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; +pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; +pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; +pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; +pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; + +pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; +pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; +pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; +pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; +pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; +pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; +pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; +pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; + +pub const RB_AUTOBOOT: ::c_int = 0x01234567; +pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123; +pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef; +pub const RB_DISABLE_CAD: ::c_int = 0; +pub const RB_POWER_OFF: ::c_int = 0x4321fedc; +pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2; +pub const RB_KEXEC: ::c_int = 0x45584543; + f! { pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.bits.iter_mut() { @@ -633,6 +656,7 @@ extern { remote_iov: *const ::iovec, riovcnt: ::c_ulong, flags: ::c_ulong) -> isize; + pub fn reboot(how_to: ::c_int) -> ::c_int; // Not available now on Android pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, From f4c3fc541780c73bcc0115877cb5ddfe21995102 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 14:35:45 +0300 Subject: [PATCH 2/7] Move LINUX_REBOOT_* constants out of common Linux code Copy them into individual platform files instead. Fixes musl build. --- src/unix/notbsd/android/mod.rs | 15 +++++++++++++++ src/unix/notbsd/linux/mips.rs | 15 +++++++++++++++ src/unix/notbsd/linux/mod.rs | 15 --------------- src/unix/notbsd/linux/other/mod.rs | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 6ddcfafc5d8bf..8bdcd167d221f 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -486,6 +486,21 @@ pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void; pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t; +pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; +pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; +pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; +pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; +pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; + +pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; +pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; +pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; +pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; +pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; +pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; +pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; +pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; + f! { pub fn sigemptyset(set: *mut sigset_t) -> ::c_int { *set = 0; diff --git a/src/unix/notbsd/linux/mips.rs b/src/unix/notbsd/linux/mips.rs index fa5a2a36694b1..62b43f49ca947 100644 --- a/src/unix/notbsd/linux/mips.rs +++ b/src/unix/notbsd/linux/mips.rs @@ -527,6 +527,21 @@ pub const RTLD_DEEPBIND: ::c_int = 0x10; pub const RTLD_GLOBAL: ::c_int = 0x4; pub const RTLD_NOLOAD: ::c_int = 0x8; +pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; +pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; +pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; +pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; +pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; + +pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; +pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; +pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; +pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; +pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; +pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; +pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; +pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; + pub const SYS_gettid: ::c_long = 4222; // Valid for O32 #[link(name = "util")] diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 722bd4eba7f99..9141ff4160fce 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -462,21 +462,6 @@ pub const LOG_NFACILITIES: ::c_int = 24; pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; -pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; -pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; -pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; -pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; -pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; - -pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; -pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; -pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; -pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; -pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; -pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; -pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; -pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; - pub const RB_AUTOBOOT: ::c_int = 0x01234567; pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123; pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef; diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs index 2998fbc21e2ed..2449c6878af65 100644 --- a/src/unix/notbsd/linux/other/mod.rs +++ b/src/unix/notbsd/linux/other/mod.rs @@ -474,6 +474,21 @@ pub const RTLD_DEEPBIND: ::c_int = 0x8; pub const RTLD_GLOBAL: ::c_int = 0x100; pub const RTLD_NOLOAD: ::c_int = 0x4; +pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; +pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; +pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; +pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; +pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; + +pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; +pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; +pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; +pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; +pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; +pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; +pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; +pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; + cfg_if! { if #[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64"))] { From 4624510ae323806cda738bdf37e09173f149ee7e Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 20:20:57 +0300 Subject: [PATCH 3/7] Cosmetic: fix the indentation --- src/unix/notbsd/mod.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 6f1bf379fd9fa..f1add7f6eaeab 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -847,19 +847,19 @@ extern { pub fn linkat(olddirfd: ::c_int, oldpath: *const ::c_char, newdirfd: ::c_int, newpath: *const ::c_char, flags: ::c_int) -> ::c_int; - pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char, - mode: ::mode_t) -> ::c_int; - pub fn mknodat(dirfd: ::c_int, pathname: *const ::c_char, - mode: ::mode_t, dev: dev_t) -> ::c_int; - pub fn readlinkat(dirfd: ::c_int, pathname: *const ::c_char, - buf: *mut ::c_char, bufsiz: ::size_t) -> ::ssize_t; - pub fn renameat(olddirfd: ::c_int, oldpath: *const ::c_char, - newdirfd: ::c_int, newpath: *const ::c_char) - -> ::c_int; - pub fn symlinkat(target: *const ::c_char, newdirfd: ::c_int, - linkpath: *const ::c_char) -> ::c_int; - pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char, - flags: ::c_int) -> ::c_int; + pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char, + mode: ::mode_t) -> ::c_int; + pub fn mknodat(dirfd: ::c_int, pathname: *const ::c_char, + mode: ::mode_t, dev: dev_t) -> ::c_int; + pub fn readlinkat(dirfd: ::c_int, pathname: *const ::c_char, + buf: *mut ::c_char, bufsiz: ::size_t) -> ::ssize_t; + pub fn renameat(olddirfd: ::c_int, oldpath: *const ::c_char, + newdirfd: ::c_int, newpath: *const ::c_char) + -> ::c_int; + pub fn symlinkat(target: *const ::c_char, newdirfd: ::c_int, + linkpath: *const ::c_char) -> ::c_int; + pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char, + flags: ::c_int) -> ::c_int; } cfg_if! { From ea0a870b4f3c3b1726be6bc6c18006555b1ae253 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 20:22:26 +0300 Subject: [PATCH 4/7] Share reboot code between Linux & Android --- src/unix/notbsd/linux/mod.rs | 8 -------- src/unix/notbsd/mod.rs | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 9141ff4160fce..3ead50d894c38 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -462,13 +462,6 @@ pub const LOG_NFACILITIES: ::c_int = 24; pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; -pub const RB_AUTOBOOT: ::c_int = 0x01234567; -pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123; -pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef; -pub const RB_DISABLE_CAD: ::c_int = 0; -pub const RB_POWER_OFF: ::c_int = 0x4321fedc; -pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2; -pub const RB_KEXEC: ::c_int = 0x45584543; f! { pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { @@ -641,7 +634,6 @@ extern { remote_iov: *const ::iovec, riovcnt: ::c_ulong, flags: ::c_ulong) -> isize; - pub fn reboot(how_to: ::c_int) -> ::c_int; // Not available now on Android pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index f1add7f6eaeab..e9a93141468e7 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -666,6 +666,14 @@ pub const PIPE_BUF: usize = 4096; pub const SI_LOAD_SHIFT: ::c_uint = 16; +pub const RB_AUTOBOOT: ::c_int = 0x01234567; +pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123; +pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef; +pub const RB_DISABLE_CAD: ::c_int = 0; +pub const RB_POWER_OFF: ::c_int = 0x4321fedc; +pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2; +pub const RB_KEXEC: ::c_int = 0x45584543; + f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; @@ -860,6 +868,7 @@ extern { linkpath: *const ::c_char) -> ::c_int; pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char, flags: ::c_int) -> ::c_int; + pub fn reboot(how_to: ::c_int) -> ::c_int; } cfg_if! { From 43ab51cba47511bfc2e382a30d84eb3d5e129d42 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 20:26:49 +0300 Subject: [PATCH 5/7] Fix accidental two blank lines --- src/unix/notbsd/linux/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 3ead50d894c38..4b46caf7fe4be 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -462,7 +462,6 @@ pub const LOG_NFACILITIES: ::c_int = 24; pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; - f! { pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.bits.iter_mut() { From 5d65c3f2463ecad20eb02d383729b9c408ecacad Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 20:55:08 +0300 Subject: [PATCH 6/7] Revert "Fix accidental two blank lines" This reverts commit 43ab51cba47511bfc2e382a30d84eb3d5e129d42. --- src/unix/notbsd/linux/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 4b46caf7fe4be..3ead50d894c38 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -462,6 +462,7 @@ pub const LOG_NFACILITIES: ::c_int = 24; pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; + f! { pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.bits.iter_mut() { From 8b76797d8f05bc5e52b7eb366d718cc2e446799f Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 12 Jul 2016 20:56:43 +0300 Subject: [PATCH 7/7] Revert "Share reboot code between Linux & Android" This reverts commit ea0a870b4f3c3b1726be6bc6c18006555b1ae253. --- src/unix/notbsd/linux/mod.rs | 8 ++++++++ src/unix/notbsd/mod.rs | 9 --------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 3ead50d894c38..9141ff4160fce 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -462,6 +462,13 @@ pub const LOG_NFACILITIES: ::c_int = 24; pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; +pub const RB_AUTOBOOT: ::c_int = 0x01234567; +pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123; +pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef; +pub const RB_DISABLE_CAD: ::c_int = 0; +pub const RB_POWER_OFF: ::c_int = 0x4321fedc; +pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2; +pub const RB_KEXEC: ::c_int = 0x45584543; f! { pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { @@ -634,6 +641,7 @@ extern { remote_iov: *const ::iovec, riovcnt: ::c_ulong, flags: ::c_ulong) -> isize; + pub fn reboot(how_to: ::c_int) -> ::c_int; // Not available now on Android pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index e9a93141468e7..f1add7f6eaeab 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -666,14 +666,6 @@ pub const PIPE_BUF: usize = 4096; pub const SI_LOAD_SHIFT: ::c_uint = 16; -pub const RB_AUTOBOOT: ::c_int = 0x01234567; -pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123; -pub const RB_ENABLE_CAD: ::c_int = 0x89abcdef; -pub const RB_DISABLE_CAD: ::c_int = 0; -pub const RB_POWER_OFF: ::c_int = 0x4321fedc; -pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2; -pub const RB_KEXEC: ::c_int = 0x45584543; - f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; @@ -868,7 +860,6 @@ extern { linkpath: *const ::c_char) -> ::c_int; pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char, flags: ::c_int) -> ::c_int; - pub fn reboot(how_to: ::c_int) -> ::c_int; } cfg_if! {