From 49ef90f5dc85e00b4021b2ce5b3dd27920bb6a91 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 7 Nov 2023 21:26:49 +0000 Subject: [PATCH] adding reboot to netbsd/openbsd. close #3403 --- libc-test/build.rs | 2 ++ libc-test/semver/netbsd.txt | 14 ++++++++++++++ libc-test/semver/openbsd.txt | 15 +++++++++++++++ src/unix/bsd/netbsdlike/mod.rs | 4 ++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 18 ++++++++++++++++++ src/unix/bsd/netbsdlike/openbsd/mod.rs | 21 +++++++++++++++++++++ 6 files changed, 74 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 05ec059bc94c4..32867523aa883 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -518,6 +518,7 @@ fn test_openbsd(target: &str) { "util.h", "ufs/ufs/quota.h", "pthread_np.h", + "sys/reboot.h", "sys/syscall.h", "sys/shm.h", "sys/param.h", @@ -1110,6 +1111,7 @@ fn test_netbsd(target: &str) { "netinet/dccp.h", "sys/event.h", "sys/quota.h", + "sys/reboot.h", "sys/shm.h", "iconv.h", } diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index a548a2d77d057..495b56cc3611a 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -863,6 +863,19 @@ Q_SETQUOTA Q_SYNC RADIXCHAR RAND_MAX +RB_ASKNAME +RB_AUTOBOOT +RB_DUMP +RB_HALT +RB_INITNAME +RB_KDB +RB_MINIROOT +RB_NOSYNC +RB_POWERDOWN +RB_RDONLY +RB_SINGLE +RB_STRING +RB_USERCONF REG_ASSERT REG_ATOI REG_BACKR @@ -1466,6 +1479,7 @@ readdir_r readlinkat reallocarr reallocarray +reboot recvmmsg recvmsg regcomp diff --git a/libc-test/semver/openbsd.txt b/libc-test/semver/openbsd.txt index 0b11c5fdbbc7e..7843f6af10c87 100644 --- a/libc-test/semver/openbsd.txt +++ b/libc-test/semver/openbsd.txt @@ -704,6 +704,20 @@ Q_SETQUOTA Q_SYNC RADIXCHAR RAND_MAX +RB_ASKNAME +RB_AUTOBOOT +RB_CONFIG +RB_DUMP +RB_GOODRANDOM +RB_HALT +RB_KDB +RB_INITNAME +RB_POWERDOWN +RB_RESET +RB_SERCONS +RB_TIMEBAD +RB_UNHIBERNATE +RB_USERREQ REG_ASSERT REG_ATOI REG_BACKR @@ -1174,6 +1188,7 @@ rand readdir_r readlinkat reallocarray +reboot recvmsg regcomp regerror diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index a787ac6db8553..07dc39be54e36 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -646,6 +646,10 @@ pub const TIOCM_RI: ::c_int = TIOCM_RNG; pub const TIMER_ABSTIME: ::c_int = 1; +// sys/reboot.h + +pub const RB_AUTOBOOT: ::c_int = 0; + #[link(name = "util")] extern "C" { pub fn setgrent(); diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index c612689a53f06..3473c7a4c4e25 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1949,6 +1949,8 @@ pub const PL_EVENT_NONE: ::c_int = 0; pub const PL_EVENT_SIGNAL: ::c_int = 1; pub const PL_EVENT_SUSPENDED: ::c_int = 2; +// sys/reboot.h + cfg_if! { if #[cfg(any(target_arch = "sparc", target_arch = "sparc64", target_arch = "x86", target_arch = "x86_64"))] { @@ -2434,6 +2436,20 @@ pub const GRND_NONBLOCK: ::c_uint = 0x1; pub const GRND_RANDOM: ::c_uint = 0x2; pub const GRND_INSECURE: ::c_uint = 0x4; +// sys/reboot.h +pub const RB_ASKNAME: ::c_int = 0x000000001; +pub const RB_SINGLE: ::c_int = 0x000000002; +pub const RB_NOSYNC: ::c_int = 0x000000004; +pub const RB_HALT: ::c_int = 0x000000008; +pub const RB_INITNAME: ::c_int = 0x000000010; +pub const RB_KDB: ::c_int = 0x000000040; +pub const RB_RDONLY: ::c_int = 0x000000080; +pub const RB_DUMP: ::c_int = 0x000000100; +pub const RB_MINIROOT: ::c_int = 0x000000200; +pub const RB_STRING: ::c_int = 0x000000400; +pub const RB_POWERDOWN: ::c_int = RB_HALT | 0x000000800; +pub const RB_USERCONF: ::c_int = 0x000001000; + cfg_if! { if #[cfg(libc_const_extern_fn)] { @@ -2984,6 +3000,8 @@ extern "C" { newfd: ::c_int, ) -> ::c_int; pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; + + pub fn reboot(mode: ::c_int, bootstr: *mut ::c_char) -> ::c_int; } #[link(name = "rt")] diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index ab2968091d936..17dfa6571568f 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1830,6 +1830,25 @@ pub const LC_ALL_MASK: ::c_int = (1 << _LC_LAST) - 2; pub const LC_GLOBAL_LOCALE: ::locale_t = -1isize as ::locale_t; +// sys/reboot.h +pub const RB_ASKNAME: ::c_int = 0x00001; +pub const RB_SINGLE: ::c_int = 0x00002; +pub const RB_NOSYNC: ::c_int = 0x00004; +pub const RB_HALT: ::c_int = 0x00008; +pub const RB_INITNAME: ::c_int = 0x00010; +pub const RB_KDB: ::c_int = 0x00040; +pub const RB_RDONLY: ::c_int = 0x00080; +pub const RB_DUMP: ::c_int = 0x00100; +pub const RB_MINIROOT: ::c_int = 0x00200; +pub const RB_CONFIG: ::c_int = 0x00400; +pub const RB_TIMEBAD: ::c_int = 0x00800; +pub const RB_POWERDOWN: ::c_int = 0x01000; +pub const RB_SERCONS: ::c_int = 0x02000; +pub const RB_USERREQ: ::c_int = 0x04000; +pub const RB_RESET: ::c_int = 0x08000; +pub const RB_GOODRANDOM: ::c_int = 0x10000; +pub const RB_UNHIBERNATE: ::c_int = 0x20000; + const_fn! { {const} fn _ALIGN(p: usize) -> usize { (p + _ALIGNBYTES) & !_ALIGNBYTES @@ -2057,6 +2076,8 @@ extern "C" { ) -> ::c_int; pub fn mimmutable(addr: *mut ::c_void, len: ::size_t) -> ::c_int; + + pub fn reboot(mode: ::c_int) -> ::c_int; } #[link(name = "execinfo")]