Skip to content

Commit 3630c46

Browse files
authored
Merge pull request rust-lang#353 from knight42/utmp
Make utmp(x) support more platforms
2 parents 2022265 + ee0a812 commit 3630c46

File tree

7 files changed

+139
-46
lines changed

7 files changed

+139
-46
lines changed

libc-test/build-generated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010
.flag("-Wall")
1111
.flag("-Wextra")
1212
.flag("-Werror")
13+
.flag("-Wno-deprecated-declarations")
1314
.flag("-Wno-type-limits")
1415
.compile("liball.a");
1516
}

libc-test/build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ fn main() {
6464
cfg.header("ws2tcpip.h");
6565
}
6666
} else {
67+
cfg.flag("-Wno-deprecated-declarations");
68+
6769
cfg.header("ctype.h");
6870
cfg.header("dirent.h");
6971
if openbsd {
@@ -281,6 +283,11 @@ fn main() {
281283
match ty {
282284
"sockaddr_nl" => musl,
283285

286+
// On Linux, the type of `ut_tv` field of `struct utmpx`
287+
// can be an anonymous struct, so an extra struct,
288+
// which is absent in glibc, has to be defined.
289+
"__timeval" if linux => true,
290+
284291
// The alignment of this is 4 on 64-bit OSX...
285292
"kevent" if apple && x86_64 => true,
286293

@@ -429,7 +436,9 @@ fn main() {
429436
// This is a weird union, don't check the type.
430437
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
431438
// sighandler_t type is super weird
432-
(struct_ == "sigaction" && field == "sa_sigaction")
439+
(struct_ == "sigaction" && field == "sa_sigaction") ||
440+
// __timeval type is a patch which doesn't exist in glibc
441+
(linux && struct_ == "utmpx" && field == "ut_tv")
433442
});
434443

435444
cfg.skip_field(move |struct_, field| {

libc-test/generate-files/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/unix/bsd/apple/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ pub type sem_t = ::c_int;
2525
pub enum timezone {}
2626

2727
s! {
28+
pub struct utmpx {
29+
pub ut_user: [::c_char; _UTX_USERSIZE],
30+
pub ut_id: [::c_char; _UTX_IDSIZE],
31+
pub ut_line: [::c_char; _UTX_LINESIZE],
32+
pub ut_pid: ::pid_t,
33+
pub ut_type: ::c_short,
34+
pub ut_tv: ::timeval,
35+
pub ut_host: [::c_char; _UTX_HOSTSIZE],
36+
ut_pad: [::uint32_t; 16],
37+
}
38+
2839
pub struct glob_t {
2940
pub gl_pathc: ::size_t,
3041
__unused1: ::c_int,
@@ -294,6 +305,24 @@ s! {
294305
}
295306
}
296307

308+
pub const _UTX_USERSIZE: usize = 256;
309+
pub const _UTX_LINESIZE: usize = 32;
310+
pub const _UTX_IDSIZE: usize = 4;
311+
pub const _UTX_HOSTSIZE: usize = 256;
312+
313+
pub const EMPTY: ::c_short = 0;
314+
pub const RUN_LVL: ::c_short = 1;
315+
pub const BOOT_TIME: ::c_short = 2;
316+
pub const OLD_TIME: ::c_short = 3;
317+
pub const NEW_TIME: ::c_short = 4;
318+
pub const INIT_PROCESS: ::c_short = 5;
319+
pub const LOGIN_PROCESS: ::c_short = 6;
320+
pub const USER_PROCESS: ::c_short = 7;
321+
pub const DEAD_PROCESS: ::c_short = 8;
322+
pub const ACCOUNTING: ::c_short = 9;
323+
pub const SIGNATURE: ::c_short = 10;
324+
pub const SHUTDOWN_TIME: ::c_short = 11;
325+
297326
pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
298327
pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
299328
pub const LC_MESSAGES_MASK: ::c_int = (1 << 2);
@@ -1286,6 +1315,14 @@ f! {
12861315
}
12871316

12881317
extern {
1318+
pub fn getutxent() -> *mut utmpx;
1319+
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
1320+
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
1321+
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
1322+
pub fn setutxent();
1323+
pub fn endutxent();
1324+
pub fn utmpxname(file: *const ::c_char) -> ::c_int;
1325+
12891326
pub fn getnameinfo(sa: *const ::sockaddr,
12901327
salen: ::socklen_t,
12911328
host: *mut ::c_char,

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ pub type sem_t = _sem;
1717
pub enum timezone {}
1818

1919
s! {
20+
pub struct utmpx {
21+
pub ut_type: ::c_short,
22+
pub ut_tv: ::timeval,
23+
pub ut_id: [::c_char; 8],
24+
pub ut_pid: ::pid_t,
25+
pub ut_user: [::c_char; 32],
26+
pub ut_line: [::c_char; 16],
27+
pub ut_host: [::c_char; 128],
28+
pub __ut_spare: [::c_char; 64],
29+
}
30+
2031
pub struct glob_t {
2132
pub gl_pathc: ::size_t,
2233
__unused1: ::size_t,
@@ -158,6 +169,16 @@ s! {
158169
}
159170
}
160171

172+
pub const EMPTY: ::c_short = 0;
173+
pub const BOOT_TIME: ::c_short = 1;
174+
pub const OLD_TIME: ::c_short = 2;
175+
pub const NEW_TIME: ::c_short = 3;
176+
pub const USER_PROCESS: ::c_short = 4;
177+
pub const INIT_PROCESS: ::c_short = 5;
178+
pub const LOGIN_PROCESS: ::c_short = 6;
179+
pub const DEAD_PROCESS: ::c_short = 7;
180+
pub const SHUTDOWN_TIME: ::c_short = 8;
181+
161182
pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
162183
pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
163184
pub const LC_MESSAGES_MASK: ::c_int = (1 << 2);
@@ -701,6 +722,17 @@ f! {
701722
}
702723
}
703724

725+
extern {
726+
pub fn endutxent();
727+
pub fn getutxent() -> *mut utmpx;
728+
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
729+
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
730+
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
731+
pub fn setutxent();
732+
pub fn getutxuser(user: *const ::c_char) -> *mut utmpx;
733+
pub fn setutxdb(_type: ::c_int, file: *const ::c_char) -> ::c_int;
734+
}
735+
704736
#[link(name = "util")]
705737
extern {
706738
pub fn getnameinfo(sa: *const ::sockaddr,

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,6 @@ s! {
8383
pub mem_unit: ::c_uint,
8484
pub _f: [::c_char; 8],
8585
}
86-
87-
pub struct __exit_status {
88-
pub e_termination: ::c_short,
89-
pub e_exit: ::c_short,
90-
}
91-
92-
pub struct utmpx {
93-
pub ut_type: ::c_short,
94-
pub ut_pid: ::pid_t,
95-
pub ut_line: [::c_char; __UT_LINESIZE],
96-
pub ut_id: [::c_char; 4],
97-
98-
pub ut_user: [::c_char; __UT_NAMESIZE],
99-
pub ut_host: [::c_char; __UT_HOSTSIZE],
100-
pub ut_exit: __exit_status,
101-
pub ut_session: ::c_long,
102-
pub ut_tv: ::timeval,
103-
104-
pub ut_addr_v6: [::int32_t; 4],
105-
__glibc_reserved: [::c_char; 20],
106-
}
10786
}
10887

10988
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
@@ -118,29 +97,6 @@ pub const PTRACE_SETFPXREGS: ::c_uint = 19;
11897
pub const PTRACE_GETREGS: ::c_uint = 12;
11998
pub const PTRACE_SETREGS: ::c_uint = 13;
12099

121-
pub const __UT_LINESIZE: usize = 32;
122-
pub const __UT_NAMESIZE: usize = 32;
123-
pub const __UT_HOSTSIZE: usize = 256;
124-
pub const EMPTY: ::c_short = 0;
125-
pub const RUN_LVL: ::c_short = 1;
126-
pub const BOOT_TIME: ::c_short = 2;
127-
pub const NEW_TIME: ::c_short = 3;
128-
pub const OLD_TIME: ::c_short = 4;
129-
pub const INIT_PROCESS: ::c_short = 5;
130-
pub const LOGIN_PROCESS: ::c_short = 6;
131-
pub const USER_PROCESS: ::c_short = 7;
132-
pub const DEAD_PROCESS: ::c_short = 8;
133-
pub const ACCOUNTING: ::c_short = 9;
134-
135-
extern {
136-
pub fn getutxent() -> *mut utmpx;
137-
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
138-
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
139-
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
140-
pub fn setutxent();
141-
pub fn endutxent();
142-
}
143-
144100
cfg_if! {
145101
if #[cfg(target_arch = "x86")] {
146102
mod x86;

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@ pub type rlim_t = c_ulong;
44
pub type __priority_which_t = ::c_uint;
55

66
s! {
7+
pub struct __exit_status {
8+
pub e_termination: ::c_short,
9+
pub e_exit: ::c_short,
10+
}
11+
12+
pub struct __timeval {
13+
pub tv_sec: ::int32_t,
14+
pub tv_usec: ::int32_t,
15+
}
16+
17+
pub struct utmpx {
18+
pub ut_type: ::c_short,
19+
pub ut_pid: ::pid_t,
20+
pub ut_line: [::c_char; __UT_LINESIZE],
21+
pub ut_id: [::c_char; 4],
22+
23+
pub ut_user: [::c_char; __UT_NAMESIZE],
24+
pub ut_host: [::c_char; __UT_HOSTSIZE],
25+
pub ut_exit: __exit_status,
26+
27+
#[cfg(any(target_arch = "aarch64", target_pointer_width = "32"))]
28+
pub ut_session: ::c_long,
29+
#[cfg(any(target_arch = "aarch64", target_pointer_width = "32"))]
30+
pub ut_tv: ::timeval,
31+
32+
#[cfg(not(any(target_arch = "aarch64", target_pointer_width = "32")))]
33+
pub ut_session: ::int32_t,
34+
#[cfg(not(any(target_arch = "aarch64", target_pointer_width = "32")))]
35+
pub ut_tv: __timeval,
36+
37+
pub ut_addr_v6: [::int32_t; 4],
38+
__glibc_reserved: [::c_char; 20],
39+
}
40+
741
pub struct sigaction {
842
pub sa_sigaction: ::sighandler_t,
943
pub sa_mask: ::sigset_t,
@@ -132,6 +166,20 @@ s! {
132166
}
133167
}
134168

169+
pub const __UT_LINESIZE: usize = 32;
170+
pub const __UT_NAMESIZE: usize = 32;
171+
pub const __UT_HOSTSIZE: usize = 256;
172+
pub const EMPTY: ::c_short = 0;
173+
pub const RUN_LVL: ::c_short = 1;
174+
pub const BOOT_TIME: ::c_short = 2;
175+
pub const NEW_TIME: ::c_short = 3;
176+
pub const OLD_TIME: ::c_short = 4;
177+
pub const INIT_PROCESS: ::c_short = 5;
178+
pub const LOGIN_PROCESS: ::c_short = 6;
179+
pub const USER_PROCESS: ::c_short = 7;
180+
pub const DEAD_PROCESS: ::c_short = 8;
181+
pub const ACCOUNTING: ::c_short = 9;
182+
135183
pub const RLIMIT_RSS: ::c_int = 5;
136184
pub const RLIMIT_NOFILE: ::c_int = 7;
137185
pub const RLIMIT_AS: ::c_int = 9;
@@ -498,6 +546,16 @@ cfg_if! {
498546
}
499547
}
500548

549+
extern {
550+
pub fn utmpxname(file: *const ::c_char) -> ::c_int;
551+
pub fn getutxent() -> *mut utmpx;
552+
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
553+
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
554+
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
555+
pub fn setutxent();
556+
pub fn endutxent();
557+
}
558+
501559
#[link(name = "util")]
502560
extern {
503561
pub fn sysctl(name: *mut ::c_int,

0 commit comments

Comments
 (0)