summaryrefslogtreecommitdiffstats
path: root/src/daemon
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2009-05-26 15:08:43 +0200
committerJan Safranek <jsafrane@redhat.com>2009-05-26 15:08:43 +0200
commit14a7cff3d55ee45762b7911fb0266e63ab99bc69 (patch)
treef506486ecb790117b9a1f31587574697e2c35bf8 /src/daemon
parentfa3fa8fdb076b5f1f315e38fd3e2656f32669a3f (diff)
downloadlibcg-14a7cff3d55ee45762b7911fb0266e63ab99bc69.tar.gz
libcg-14a7cff3d55ee45762b7911fb0266e63ab99bc69.tar.xz
libcg-14a7cff3d55ee45762b7911fb0266e63ab99bc69.zip
Hi,
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_procdata_from_status(). In addition, cgroup_get_procdata_from_status() can get also a process name from /proc/<pid>/status file. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/cgrulesengd.c50
1 files changed, 2 insertions, 48 deletions
diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c
index fb757c1..ea093ad 100644
--- a/src/daemon/cgrulesengd.c
+++ b/src/daemon/cgrulesengd.c
@@ -140,52 +140,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,8 +279,8 @@ 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
+ if (cgroup_get_procdata_from_status(pid, &euid, &egid, NULL, 0))
+ /* cgroup_get_procdata_from_status() returns 1 if it fails to
* open /proc/<pid>/status file and that is not a problem. */
return 0;