Skip to content

Commit a9c8fc9

Browse files
committed
NetBSD: Introduce utmpx_.rs, correct utmpx definitions
Create a new module for `utmpx` and move definitions there, then correct `_UTX_PADSIZE`. We can also just use `s!`, there is no need to manually implement the traits. NetBSD defines `_UTX_PADSIZE` manually but includes this comment in their source: /* * This should be: * 40 - (sizeof(struct timeval) - sizeof(struct { long s; long u; }))) * but g++ does not like it, to retain size compatibility with v1.00, * so we do it manually. */ #ifdef _LP64 #define _UTX_PADSIZE 36 #else #define _UTX_PADSIZE 40 #endif I tried using the expression here: 40 - (size_of::<crate::timeval>() - size_of::<(c_long, c_long)>()); But this returns a value of 8 which doesn't match the expected 36. So, keep with their source and hardcode the values. Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/include/utmpx.h#L91-L101 (backport <#4782>) (cherry picked from commit 4055637)
1 parent e8ba00e commit a9c8fc9

File tree

4 files changed

+85
-64
lines changed

4 files changed

+85
-64
lines changed

src/new/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ cfg_if! {
186186
pub use sys::ipc::*;
187187
pub use sys::statvfs::*;
188188
pub use utmp_::*;
189+
pub use utmpx_::*;
189190
} else if #[cfg(target_os = "openbsd")] {
190191
pub use sys::ipc::*;
191192
}

src/new/netbsd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
pub(crate) mod sys;
88
pub(crate) mod unistd;
99
pub(crate) mod utmp_;
10+
pub(crate) mod utmpx_;

src/new/netbsd/utmpx_.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//! Header: `utmpx.h`
2+
//!
3+
//! <https://github.com/NetBSD/src/blob/master/include/utmp.h>
4+
5+
use crate::prelude::*;
6+
7+
// pub const _PATH_UTMPX: &[c_char; 14] = b"/var/run/utmpx";
8+
// pub const _PATH_WTMPX: &[c_char; 14] = b"/var/log/wtmpx";
9+
// pub const _PATH_LASTLOGX: &[c_char; 17] = b"/var/log/lastlogx";
10+
// pub const _PATH_UTMP_UPDATE: &[c_char; 24] = b"/usr/libexec/utmp_update";
11+
12+
pub const _UTX_USERSIZE: usize = 32;
13+
pub const _UTX_LINESIZE: usize = 32;
14+
pub const _UTX_IDSIZE: usize = 4;
15+
pub const _UTX_HOSTSIZE: usize = 256;
16+
17+
pub const EMPTY: u16 = 0;
18+
pub const RUN_LVL: u16 = 1;
19+
pub const BOOT_TIME: u16 = 2;
20+
pub const OLD_TIME: u16 = 3;
21+
pub const NEW_TIME: u16 = 4;
22+
pub const INIT_PROCESS: u16 = 5;
23+
pub const LOGIN_PROCESS: u16 = 6;
24+
pub const USER_PROCESS: u16 = 7;
25+
pub const DEAD_PROCESS: u16 = 8;
26+
pub const ACCOUNTING: u16 = 9;
27+
pub const SIGNATURE: u16 = 10;
28+
pub const DOWN_TIME: u16 = 11;
29+
30+
// Expression based on the comment in NetBSD source.
31+
pub const _UTX_PADSIZE: usize = if cfg!(target_pointer_width = "64") {
32+
36
33+
} else {
34+
40
35+
};
36+
37+
s! {
38+
pub struct utmpx {
39+
pub ut_name: [c_char; _UTX_USERSIZE],
40+
pub ut_id: [c_char; _UTX_IDSIZE],
41+
pub ut_line: [c_char; _UTX_LINESIZE],
42+
pub ut_host: [c_char; _UTX_HOSTSIZE],
43+
pub ut_session: u16,
44+
pub ut_type: u16,
45+
pub ut_pid: crate::pid_t,
46+
pub ut_exit: __exit_status, // FIXME(netbsd): when anonymous struct are supported
47+
pub ut_ss: crate::sockaddr_storage,
48+
pub ut_tv: crate::timeval,
49+
ut_pad: [u8; _UTX_PADSIZE],
50+
}
51+
52+
pub struct __exit_status {
53+
pub e_termination: u16,
54+
pub e_exit: u16,
55+
}
56+
57+
pub struct lastlogx {
58+
pub ll_tv: crate::timeval,
59+
pub ll_line: [c_char; _UTX_LINESIZE],
60+
pub ll_host: [c_char; _UTX_HOSTSIZE],
61+
pub ll_ss: crate::sockaddr_storage,
62+
}
63+
}
64+
65+
#[link(name = "util")]
66+
extern "C" {
67+
pub fn setutxent();
68+
pub fn endutxent();
69+
70+
pub fn getutxent() -> *mut utmpx;
71+
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
72+
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
73+
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
74+
75+
pub fn updwtmpx(file: *const c_char, ut: *const utmpx) -> c_int;
76+
pub fn getlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx)
77+
-> *mut lastlogx;
78+
pub fn updlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) -> c_int;
79+
pub fn getutmp(ux: *const utmpx, u: *mut crate::utmp);
80+
pub fn getutmpx(u: *const crate::utmp, ux: *mut utmpx);
81+
pub fn utmpxname(file: *const c_char) -> c_int;
82+
}

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,6 @@ s! {
419419
pub sdl_data: [c_char; 24],
420420
}
421421

422-
pub struct __exit_status {
423-
pub e_termination: u16,
424-
pub e_exit: u16,
425-
}
426-
427422
pub struct shmid_ds {
428423
pub shm_perm: crate::ipc_perm,
429424
pub shm_segsz: size_t,
@@ -780,27 +775,6 @@ s! {
780775
pub __tcpi_pad: [u32; 26],
781776
}
782777

783-
pub struct utmpx {
784-
pub ut_name: [c_char; _UTX_USERSIZE],
785-
pub ut_id: [c_char; _UTX_IDSIZE],
786-
pub ut_line: [c_char; _UTX_LINESIZE],
787-
pub ut_host: [c_char; _UTX_HOSTSIZE],
788-
pub ut_session: u16,
789-
pub ut_type: u16,
790-
pub ut_pid: crate::pid_t,
791-
pub ut_exit: __exit_status, // FIXME(netbsd): when anonymous struct are supported
792-
pub ut_ss: sockaddr_storage,
793-
pub ut_tv: crate::timeval,
794-
pub ut_pad: [u8; _UTX_PADSIZE],
795-
}
796-
797-
pub struct lastlogx {
798-
pub ll_tv: crate::timeval,
799-
pub ll_line: [c_char; _UTX_LINESIZE],
800-
pub ll_host: [c_char; _UTX_HOSTSIZE],
801-
pub ll_ss: sockaddr_storage,
802-
}
803-
804778
pub struct in_pktinfo {
805779
pub ipi_addr: crate::in_addr,
806780
pub ipi_ifindex: c_uint,
@@ -1799,28 +1773,6 @@ pub const ONLRET: crate::tcflag_t = 0x40;
17991773
pub const CDTRCTS: crate::tcflag_t = 0x00020000;
18001774
pub const CHWFLOW: crate::tcflag_t = crate::MDMBUF | crate::CRTSCTS | crate::CDTRCTS;
18011775

1802-
// pub const _PATH_UTMPX: &[c_char; 14] = b"/var/run/utmpx";
1803-
// pub const _PATH_WTMPX: &[c_char; 14] = b"/var/log/wtmpx";
1804-
// pub const _PATH_LASTLOGX: &[c_char; 17] = b"/var/log/lastlogx";
1805-
// pub const _PATH_UTMP_UPDATE: &[c_char; 24] = b"/usr/libexec/utmp_update";
1806-
pub const _UTX_USERSIZE: usize = 32;
1807-
pub const _UTX_LINESIZE: usize = 32;
1808-
pub const _UTX_PADSIZE: usize = 40;
1809-
pub const _UTX_IDSIZE: usize = 4;
1810-
pub const _UTX_HOSTSIZE: usize = 256;
1811-
pub const EMPTY: u16 = 0;
1812-
pub const RUN_LVL: u16 = 1;
1813-
pub const BOOT_TIME: u16 = 2;
1814-
pub const OLD_TIME: u16 = 3;
1815-
pub const NEW_TIME: u16 = 4;
1816-
pub const INIT_PROCESS: u16 = 5;
1817-
pub const LOGIN_PROCESS: u16 = 6;
1818-
pub const USER_PROCESS: u16 = 7;
1819-
pub const DEAD_PROCESS: u16 = 8;
1820-
pub const ACCOUNTING: u16 = 9;
1821-
pub const SIGNATURE: u16 = 10;
1822-
pub const DOWN_TIME: u16 = 11;
1823-
18241776
pub const SOCK_CLOEXEC: c_int = 0x10000000;
18251777
pub const SOCK_NONBLOCK: c_int = 0x20000000;
18261778

@@ -2469,21 +2421,6 @@ extern "C" {
24692421
result: *mut *mut crate::group,
24702422
) -> c_int;
24712423

2472-
pub fn updwtmpx(file: *const c_char, ut: *const utmpx) -> c_int;
2473-
pub fn getlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx)
2474-
-> *mut lastlogx;
2475-
pub fn updlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) -> c_int;
2476-
pub fn utmpxname(file: *const c_char) -> c_int;
2477-
pub fn getutxent() -> *mut utmpx;
2478-
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
2479-
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
2480-
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
2481-
pub fn setutxent();
2482-
pub fn endutxent();
2483-
2484-
pub fn getutmp(ux: *const utmpx, u: *mut crate::utmp);
2485-
pub fn getutmpx(u: *const crate::utmp, ux: *mut utmpx);
2486-
24872424
pub fn efopen(p: *const c_char, m: *const c_char) -> crate::FILE;
24882425
pub fn emalloc(n: size_t) -> *mut c_void;
24892426
pub fn ecalloc(n: size_t, c: size_t) -> *mut c_void;
@@ -2547,7 +2484,7 @@ extern "C" {
25472484
#[link_name = "__login50"]
25482485
pub fn login(ut: *const crate::utmp);
25492486
#[link_name = "__loginx50"]
2550-
pub fn loginx(ut: *const utmpx);
2487+
pub fn loginx(ut: *const crate::utmpx);
25512488
pub fn logout(line: *const c_char);
25522489
pub fn logoutx(line: *const c_char, status: c_int, tpe: c_int);
25532490
pub fn logwtmp(line: *const c_char, name: *const c_char, host: *const c_char);

0 commit comments

Comments
 (0)