Skip to content

Commit b552563

Browse files
committed
ancillary fix dragonfly build
1 parent d594910 commit b552563

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

library/std/src/os/unix/net/ancillary.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,46 +249,53 @@ impl SocketCred {
249249
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
250250
#[must_use]
251251
pub fn new() -> SocketCred {
252-
SocketCred(libc::cmsgcred { cmsgcred_pid: 0, cmsgcred_uid: 0, cmsgcred_gid: 0 })
252+
SocketCred(libc::cmsgcred {
253+
cmcred_pid: 0,
254+
cmcred_uid: 0,
255+
cmcred_euid: 0,
256+
cmcred_gid: 0,
257+
cmcred_ngroups: 0,
258+
cmcred_groups: [0; libc::CMGROUP_MAX],
259+
})
253260
}
254261

255262
/// Set the PID.
256263
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
257264
pub fn set_pid(&mut self, pid: libc::pid_t) {
258-
self.0.cmsgcred_pid = pid;
265+
self.0.cmcred_pid = pid;
259266
}
260267

261268
/// Get the current PID.
262269
#[must_use]
263270
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
264271
pub fn get_pid(&self) -> libc::pid_t {
265-
self.0.cmsgcred_pid
272+
self.0.cmcred_pid
266273
}
267274

268275
/// Set the UID.
269276
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
270277
pub fn set_uid(&mut self, uid: libc::uid_t) {
271-
self.0.cmsgcred_uid = uid;
278+
self.0.cmcred_uid = uid;
272279
}
273280

274281
/// Get the current UID.
275282
#[must_use]
276283
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
277284
pub fn get_uid(&self) -> libc::uid_t {
278-
self.0.cmsgcred_uid
285+
self.0.cmcred_uid
279286
}
280287

281288
/// Set the GID.
282289
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
283290
pub fn set_gid(&mut self, gid: libc::gid_t) {
284-
self.0.cmsgcred_gid = gid;
291+
self.0.cmcred_gid = gid;
285292
}
286293

287294
/// Get the current GID.
288295
#[must_use]
289296
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
290297
pub fn get_gid(&self) -> libc::gid_t {
291-
self.0.cmsgcred_gid
298+
self.0.cmcred_gid
292299
}
293300
}
294301

@@ -340,7 +347,7 @@ pub enum AncillaryError {
340347
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
341348
pub enum AncillaryData<'a> {
342349
ScmRights(ScmRights<'a>),
343-
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
350+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly"))]
344351
ScmCredentials(ScmCredentials<'a>),
345352
}
346353

@@ -363,7 +370,7 @@ impl<'a> AncillaryData<'a> {
363370
///
364371
/// `data` must contain a valid control message and the control message must be type of
365372
/// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDS`.
366-
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
373+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly"))]
367374
unsafe fn as_credentials(data: &'a [u8]) -> Self {
368375
let ancillary_data_iter = AncillaryDataIter::new(data);
369376
let scm_credentials = ScmCredentials(ancillary_data_iter);

library/std/src/os/unix/net/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl UnixStream {
415415
/// Ok(())
416416
/// }
417417
/// ```
418-
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
418+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly"))]
419419
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
420420
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
421421
self.0.set_passcred(passcred)
@@ -427,7 +427,7 @@ impl UnixStream {
427427
/// Get the socket option `SO_PASSCRED`.
428428
///
429429
/// [`set_passcred`]: UnixStream::set_passcred
430-
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
430+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly"))]
431431
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
432432
pub fn passcred(&self) -> io::Result<bool> {
433433
self.0.passcred()

library/std/src/sys/unix/net.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,30 @@ impl Socket {
408408
Ok(raw != 0)
409409
}
410410

411-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "dragonfly",))]
411+
#[cfg(any(target_os = "android", target_os = "linux"))]
412412
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
413413
setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int)
414414
}
415415

416-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "dragonfly",))]
416+
#[cfg(target_os = "dragonfly")]
417+
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
418+
const SO_PASSCRED: libc::c_int = 0x4000;
419+
setsockopt(self, libc::SOL_SOCKET, SO_PASSCRED, passcred as libc::c_int)
420+
}
421+
422+
#[cfg(any(target_os = "android", target_os = "linux"))]
417423
pub fn passcred(&self) -> io::Result<bool> {
418424
let passcred: libc::c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED)?;
419425
Ok(passcred != 0)
420426
}
421427

428+
#[cfg(target_os = "dragonfly")]
429+
pub fn passcred(&self) -> io::Result<bool> {
430+
const SO_PASSCRED: libc::c_int = 0x4000;
431+
let passcred: libc::c_int = getsockopt(self, libc::SOL_SOCKET, SO_PASSCRED)?;
432+
Ok(passcred != 0)
433+
}
434+
422435
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
423436
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
424437
let mut nonblocking = nonblocking as libc::c_int;

0 commit comments

Comments
 (0)