diff options
author | Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> | 2009-06-08 17:18:43 +0900 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-06-08 14:33:25 +0530 |
commit | 5620d31b78fda7d5db0b85fcceca9c2cabe8f155 (patch) | |
tree | e603474e7427afabd610f07ac5c8e4512e6732f4 /src/daemon/cgrulesengd.c | |
parent | 340feae163c4797a6cb1247b3812c1ccdc52fa41 (diff) | |
download | libcg-5620d31b78fda7d5db0b85fcceca9c2cabe8f155.tar.gz libcg-5620d31b78fda7d5db0b85fcceca9c2cabe8f155.tar.xz libcg-5620d31b78fda7d5db0b85fcceca9c2cabe8f155.zip |
Cleanup: Integrate similar code to cgroup_get_uid_gid_from_procfs().
CHANGELOG of v2.1:
================
* Rebase the patch for commit '340feae163c4797a6cb1247b3812c1ccdc52fa41'.
There are some similar functions for getting process's data (uid, gid) from
/proc/<pid>/status file, so this patch integrates these functions into one
cgroup_get_uid_gid_from_procfs().
Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Reviewed-By: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Diffstat (limited to 'src/daemon/cgrulesengd.c')
-rw-r--r-- | src/daemon/cgrulesengd.c | 56 |
1 files changed, 7 insertions, 49 deletions
diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index 1a7b321..4c71283 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -33,6 +33,7 @@ #include "libcgroup.h" #include "cgrulesengd.h" +#include "../libcgroup-internal.h" #include <errno.h> #include <stdarg.h> @@ -140,52 +141,6 @@ void flog(int level, const char *format, ...) } } -static int cgre_get_euid_egid_from_status(pid_t pid, uid_t *euid, gid_t *egid) -{ - /* Handle for the /proc/PID/status file */ - FILE *f; - - /* Path for /proc/PID/status file */ - char path[FILENAME_MAX]; - - /* Temporary buffer */ - char buf[4092]; - - /* UID data */ - uid_t ruid, suid, fsuid; - - /* GID data */ - gid_t rgid, sgid, fsgid; - - /* - * First, we need to open the /proc/PID/status file so that we can - * get the effective UID and GID for the process that we're working - * on. This process is probably not us, so we can't just call - * geteuid() or getegid(). - */ - sprintf(path, "/proc/%d/status", pid); - f = fopen(path, "r"); - if (!f) { - flog(LOG_WARNING, "Failed to open %s", path); - return 1; - } - - /* Have the eUID, need to find the eGID. */ - memset(buf, '\0', sizeof(buf)); - while (fgets(buf, sizeof(buf), f)) { - if (!strncmp(buf, "Uid:", 4)) { - sscanf((buf + 5), "%d%d%d%d", &ruid, euid, - &suid, &fsuid); - } else if (!strncmp(buf, "Gid:", 4)) { - sscanf((buf + 5), "%d%d%d%d", &rgid, egid, - &sgid, &fsgid); - } - memset(buf, '\0', sizeof(buf)); - } - fclose(f); - return 0; -} - struct parent_info { __u64 timestamp; pid_t pid; @@ -325,10 +280,13 @@ int cgre_process_event(const struct proc_event *ev, const int type) default: break; } - if (cgre_get_euid_egid_from_status(pid, &euid, &egid)) - /* cgre_get_euid_egid_from_status() returns 1 if it fails to - * open /proc/<pid>/status file and that is not a problem. */ + ret = cgroup_get_uid_gid_from_procfs(pid, &euid, &egid); + if (ret == ECGROUPNOTEXIST) + /* cgroup_get_uid_gid_from_procfs() returns ECGROUPNOTEXIST + * if a process finished and that is not a problem. */ return 0; + else if (ret) + return ret; /* * Now that we have the UID, the GID, and the PID, we can make a call |