Skip to content

Commit 65be52f

Browse files
authored
Merge pull request #1830 from JohnTitor/utmpx
Declare `utmpx` on musl
2 parents dce0ec0 + 05c4574 commit 65be52f

File tree

3 files changed

+107
-3
lines changed

3 files changed

+107
-3
lines changed

libc-test/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,11 @@ fn test_linux(target: &str) {
25512551
"statx" => true,
25522552
"statx_timestamp" => true,
25532553

2554+
// On Linux, the type of `ut_exit` field of struct `utmpx`
2555+
// can be an anonymous struct, so an extra struct,
2556+
// which is absent in musl, has to be defined.
2557+
"__exit_status" if musl => true,
2558+
25542559
_ => false,
25552560
}
25562561
});
@@ -2678,7 +2683,9 @@ fn test_linux(target: &str) {
26782683
// sigval is actually a union, but we pretend it's a struct
26792684
(struct_ == "sigevent" && field == "sigev_value") ||
26802685
// this one is an anonymous union
2681-
(struct_ == "ff_effect" && field == "u")
2686+
(struct_ == "ff_effect" && field == "u") ||
2687+
// `__exit_status` type is a patch which is absent in musl
2688+
(struct_ == "utmpx" && field == "ut_exit" && musl)
26822689
});
26832690

26842691
cfg.volatile_item(|i| {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ s! {
9292
pub st_spare: [u32; 2],
9393
}
9494

95-
pub struct addrinfo {
95+
pub struct addrinfo {
9696
pub ai_flags: ::c_int,
9797
pub ai_family: ::c_int,
9898
pub ai_socktype: ::c_int,
@@ -286,7 +286,7 @@ s! {
286286
pub struct __exit_status {
287287
pub e_termination: u16,
288288
pub e_exit: u16,
289-
}
289+
}
290290

291291
pub struct shmid_ds {
292292
pub shm_perm: ::ipc_perm,

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ s! {
144144
pub imr_address: ::in_addr,
145145
pub imr_ifindex: ::c_int,
146146
}
147+
148+
pub struct __exit_status {
149+
pub e_termination: ::c_short,
150+
pub e_exit: ::c_short,
151+
}
147152
}
148153

149154
s_no_extra_traits! {
@@ -163,6 +168,36 @@ s_no_extra_traits! {
163168
pub mem_unit: ::c_uint,
164169
pub __reserved: [::c_char; 256],
165170
}
171+
172+
// FIXME: musl added paddings and adjusted
173+
// layout in 1.2.0 but our CI is still 1.1.24.
174+
// So, I'm leaving some fields as comments for now.
175+
// ref. https://github.com/bminor/musl/commit/
176+
// 1e7f0fcd7ff2096904fd93a2ee6d12a2392be392
177+
pub struct utmpx {
178+
pub ut_type: ::c_short,
179+
//__ut_pad1: ::c_short,
180+
pub ut_pid: ::pid_t,
181+
pub ut_line: [::c_char; 32],
182+
pub ut_id: [::c_char; 4],
183+
pub ut_user: [::c_char; 32],
184+
pub ut_host: [::c_char; 256],
185+
pub ut_exit: __exit_status,
186+
187+
//#[cfg(target_endian = "little")]
188+
pub ut_session: ::c_long,
189+
//#[cfg(target_endian = "little")]
190+
//__ut_pad2: ::c_long,
191+
192+
//#[cfg(not(target_endian = "little"))]
193+
//__ut_pad2: ::c_int,
194+
//#[cfg(not(target_endian = "little"))]
195+
//pub ut_session: ::c_int,
196+
197+
pub ut_tv: ::timeval,
198+
pub ut_addr_v6: [::c_uint; 4],
199+
__unused: [::c_char; 20],
200+
}
166201
}
167202

168203
cfg_if! {
@@ -231,6 +266,68 @@ cfg_if! {
231266
self.__reserved.hash(state);
232267
}
233268
}
269+
270+
impl PartialEq for utmpx {
271+
fn eq(&self, other: &utmpx) -> bool {
272+
self.ut_type == other.ut_type
273+
//&& self.__ut_pad1 == other.__ut_pad1
274+
&& self.ut_pid == other.ut_pid
275+
&& self.ut_line == other.ut_line
276+
&& self.ut_id == other.ut_id
277+
&& self.ut_user == other.ut_user
278+
&& self
279+
.ut_host
280+
.iter()
281+
.zip(other.ut_host.iter())
282+
.all(|(a,b)| a == b)
283+
&& self.ut_exit == other.ut_exit
284+
&& self.ut_session == other.ut_session
285+
//&& self.__ut_pad2 == other.__ut_pad2
286+
&& self.ut_tv == other.ut_tv
287+
&& self.ut_addr_v6 == other.ut_addr_v6
288+
&& self.__unused == other.__unused
289+
}
290+
}
291+
292+
impl Eq for utmpx {}
293+
294+
impl ::fmt::Debug for utmpx {
295+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
296+
f.debug_struct("utmpx")
297+
.field("ut_type", &self.ut_type)
298+
//.field("__ut_pad1", &self.__ut_pad1)
299+
.field("ut_pid", &self.ut_pid)
300+
.field("ut_line", &self.ut_line)
301+
.field("ut_id", &self.ut_id)
302+
.field("ut_user", &self.ut_user)
303+
//FIXME: .field("ut_host", &self.ut_host)
304+
.field("ut_exit", &self.ut_exit)
305+
.field("ut_session", &self.ut_session)
306+
//.field("__ut_pad2", &self.__ut_pad2)
307+
.field("ut_tv", &self.ut_tv)
308+
.field("ut_addr_v6", &self.ut_addr_v6)
309+
.field("__unused", &self.__unused)
310+
.finish()
311+
}
312+
}
313+
314+
impl ::hash::Hash for utmpx {
315+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
316+
self.ut_type.hash(state);
317+
//self.__ut_pad1.hash(state);
318+
self.ut_pid.hash(state);
319+
self.ut_line.hash(state);
320+
self.ut_id.hash(state);
321+
self.ut_user.hash(state);
322+
self.ut_host.hash(state);
323+
self.ut_exit.hash(state);
324+
self.ut_session.hash(state);
325+
//self.__ut_pad2.hash(state);
326+
self.ut_tv.hash(state);
327+
self.ut_addr_v6.hash(state);
328+
self.__unused.hash(state);
329+
}
330+
}
234331
}
235332
}
236333

0 commit comments

Comments
 (0)