Skip to content

Commit

Permalink
Match c_char definitions and enable signal reset for L4Re
Browse files Browse the repository at this point in the history
*   Match definition of c_char in os/raw.rs with the libc definition

    Due to historic reasons, os/raw.rs redefines types for c_char from
    libc, but these didn't match. Now they do :).

*   Enable signal reset on exec for L4Re

    L4Re has full signal emulation and hence it needs to reset the
    signal set of the child with sigemptyset. However, gid and uid
    should *not* be set.
  • Loading branch information
humenda authored and Tobias Schaffner committed Sep 8, 2017
1 parent d6ad402 commit 2cf0a4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/libstd/os/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use fmt;
target_arch = "s390x")),
all(target_os = "android", any(target_arch = "aarch64",
target_arch = "arm")),
all(target_os = "l4re", target_arch = "x86_64"),
all(target_os = "fuchsia", target_arch = "aarch64")))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
Expand All @@ -30,6 +31,7 @@ use fmt;
target_arch = "s390x")),
all(target_os = "android", any(target_arch = "aarch64",
target_arch = "arm")),
all(target_os = "l4re", target_arch = "x86_64"),
all(target_os = "fuchsia", target_arch = "aarch64"))))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod fs;
pub mod process;
pub mod raw;
pub mod thread;
#[cfg(not(target_os = "l4re"))]
pub mod net;

/// A prelude for conveniently writing platform-specific code.
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod fd;
pub mod fs;
pub mod memchr;
pub mod mutex;
#[cfg(not(target_os = "l4re"))]
pub mod net;
pub mod os;
pub mod os_str;
Expand Down
28 changes: 15 additions & 13 deletions src/libstd/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,22 @@ impl Command {
t!(cvt_r(|| libc::dup2(fd, libc::STDERR_FILENO)));
}

if let Some(u) = self.get_gid() {
t!(cvt(libc::setgid(u as gid_t)));
}
if let Some(u) = self.get_uid() {
// When dropping privileges from root, the `setgroups` call
// will remove any extraneous groups. If we don't call this,
// then even though our uid has dropped, we may still have
// groups that enable us to do super-user things. This will
// fail if we aren't root, so don't bother checking the
// return value, this is just done as an optimistic
// privilege dropping function.
let _ = libc::setgroups(0, ptr::null());
if cfg!(not(any(target_os = "l4re"))) {
if let Some(u) = self.get_gid() {
t!(cvt(libc::setgid(u as gid_t)));
}
if let Some(u) = self.get_uid() {
// When dropping privileges from root, the `setgroups` call
// will remove any extraneous groups. If we don't call this,
// then even though our uid has dropped, we may still have
// groups that enable us to do super-user things. This will
// fail if we aren't root, so don't bother checking the
// return value, this is just done as an optimistic
// privilege dropping function.
let _ = libc::setgroups(0, ptr::null());

t!(cvt(libc::setuid(u as uid_t)));
t!(cvt(libc::setuid(u as uid_t)));
}
}
if let Some(ref cwd) = *self.get_cwd() {
t!(cvt(libc::chdir(cwd.as_ptr())));
Expand Down

0 comments on commit 2cf0a4a

Please sign in to comment.