Chromium Code Reviews| Index: chromeos/process.cc |
| diff --git a/chromeos/process.cc b/chromeos/process.cc |
| index 54d9a9ff8462ba80b843ee8c9e1f449489f289d6..32e53032180d396f3eff0be85c76a105ceb103bc 100644 |
| --- a/chromeos/process.cc |
| +++ b/chromeos/process.cc |
| @@ -8,6 +8,7 @@ |
| #include <sys/types.h> |
| #include <sys/wait.h> |
| #include <fcntl.h> |
| +#include <unistd.h> |
| #include <map> |
| @@ -30,7 +31,7 @@ bool Process::ProcessExists(pid_t pid) { |
| return file_util::DirectoryExists(FilePath(StringPrintf("/proc/%d", pid))); |
| } |
| -ProcessImpl::ProcessImpl() : pid_(0) { |
| +ProcessImpl::ProcessImpl() : pid_(0), uid_(-1), gid_(-1) { |
|
sosa
2011/04/17 05:12:46
seems like the default pid should also be -1 since
kmixter1
2011/04/17 06:54:30
I didn't realize that. However, I guess they are
|
| } |
| ProcessImpl::~ProcessImpl() { |
| @@ -51,6 +52,14 @@ void ProcessImpl::RedirectUsingPipe(int child_fd, bool is_input) { |
| pipe_map_[child_fd] = info; |
| } |
| +void ProcessImpl::SetUid(uid_t uid) { |
| + uid_ = uid; |
| +} |
| + |
| +void ProcessImpl::SetGid(gid_t gid) { |
| + gid_ = gid; |
| +} |
| + |
| int ProcessImpl::GetPipe(int child_fd) { |
| PipeMap::iterator i = pipe_map_.find(child_fd); |
| if (i == pipe_map_.end()) |
| @@ -154,6 +163,16 @@ bool ProcessImpl::Start() { |
| HANDLE_EINTR(close(output_handle)); |
| } |
| } |
| + if (uid_ >= 0 && setresuid(uid_, uid_, uid_) < 0) { |
| + int saved_errno = errno; |
| + LOG(ERROR) << "Unable to set UID to " << uid_ << ": " << saved_errno; |
| + _exit(127); |
|
sosa
2011/04/17 05:12:46
Was looking at docs for exit codes, is 127 appropr
kmixter1
2011/04/17 06:54:30
Not sure if you mean the man page for exit statuse
|
| + } |
| + if (gid_ >= 0 && setresgid(gid_, gid_, gid_) < 0) { |
| + int saved_errno = errno; |
| + LOG(ERROR) << "Unable to set GID to " << gid_ << ": " << saved_errno; |
| + _exit(127); |
| + } |
| execv(argv[0], &argv[0]); |
| saved_errno = errno; |
| LOG(ERROR) << "Exec of " << argv[0] << " failed: " << saved_errno; |