diff options
author | Dave Brolley <brolley@redhat.com> | 2009-11-27 14:15:58 -0500 |
---|---|---|
committer | Dave Brolley <brolley@redhat.com> | 2009-11-27 14:15:58 -0500 |
commit | 1d4a927582c68e4278a1e44619e0cc310a83addf (patch) | |
tree | c029ffa738e221ffb89aecd51c8d1dfad792e63a | |
parent | cf4ed91947a0716e25053eb5332761b6ae4f33a2 (diff) | |
parent | f429df668ac09575b0db710aa54cb2117dc542c3 (diff) | |
download | systemtap-steved-1d4a927582c68e4278a1e44619e0cc310a83addf.tar.gz systemtap-steved-1d4a927582c68e4278a1e44619e0cc310a83addf.tar.xz systemtap-steved-1d4a927582c68e4278a1e44619e0cc310a83addf.zip |
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap
-rw-r--r-- | util.cxx | 31 |
1 files changed, 15 insertions, 16 deletions
@@ -194,28 +194,27 @@ remove_file_or_dir (const char *name) bool in_group_id (gid_t target_gid) { - gid_t gid, gidlist[NGROUPS_MAX]; - int i, ngids; - // According to the getgroups() man page, getgroups() may not // return the effective gid, so try to match it first. */ - gid = getegid(); - if (gid == target_gid) + if (target_gid == getegid()) return true; // Get the list of the user's groups. - ngids = getgroups(NGROUPS_MAX, gidlist); + int ngids = getgroups(0, 0); // Returns the number to allocate. + if (ngids > 0) { + gid_t gidlist[ngids]; + ngids = getgroups(ngids, gidlist); + for (int i = 0; i < ngids; i++) { + // If the user is a member of the target group, then we're done. + if (gidlist[i] == target_gid) + return true; + } + } if (ngids < 0) { cerr << "Unable to retrieve group list" << endl; return false; } - for (i = 0; i < ngids; i++) { - // If the user is a member of the target group, then we're done. - if (gidlist[i] == target_gid) - return true; - } - // The user is not a member of the target group return false; } @@ -375,7 +374,7 @@ stap_system(int verbose, const std::string& command) spawned_pid = 0; - if (verbose > 1) + if (verbose > 1) clog << "Running " << command << endl; ret = posix_spawn(&spawned_pid, "/bin/sh", NULL, NULL, const_cast<char * const *>(argv), environ); @@ -386,19 +385,19 @@ stap_system(int verbose, const std::string& command) if (ret == spawned_pid) { ret = WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status); - if (verbose > 2) + if (verbose > 2) clog << "Spawn waitpid result (0x" << ios::hex << status << ios::dec << "): " << ret << endl; } else { - if (verbose > 1) + if (verbose > 1) clog << "Spawn waitpid error (" << ret << "): " << strerror(errno) << endl; ret = -1; } } else { - if (verbose > 1) + if (verbose > 1) clog << "Spawn error (" << ret << "): " << strerror(ret) << endl; ret = -1; } |