Hi, From: Dhaval Giani <[email protected]> Subject: Re: [Libcg-devel] [PATCH] cgrulesengd cannot get Gid from/proc/PID/status. Date: Thu, 14 May 2009 23:19:16 +0530 > On Thu, May 14, 2009 at 01:34:26PM -0400, Steve Olivieri wrote: >> Hi, >> >> It's not a magic number. Four is the length of the string "Uid:". You >> could replace it with strlen("Uid:"), but would that really be better? >> > > I would say so. It would make it obviously clear that it is for Uid:. > Also, if you notice, the sscanf is doing a buf+5, why is 5 the correct > place, and it just makes it much clearer.
How about this patch? Thanks. Masayuki Igawa Signed-off-by: Masayuki Igawa <[email protected]> --- src/daemon/cgrulesengd.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index 595c321..8feb165 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -165,11 +165,11 @@ static int cgre_get_euid_egid_from_status(pid_t pid, uid_t *euid, gid_t *egid) /* 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, + if (!strncmp(buf, "Uid:", strlen("Uid:"))) { + sscanf((buf + strlen("Uid:") + 1), "%d%d%d%d", &ruid, euid, &suid, &fsuid); - } else if (!strncmp(buf, "Gid:", 4)) { - sscanf((buf + 5), "%d%d%d%d", &rgid, egid, + } else if (!strncmp(buf, "Gid:", strlen("Gid:"))) { + sscanf((buf + strlen("Gid:") + 1), "%d%d%d%d", &rgid, egid, &sgid, &fsgid); } memset(buf, '\0', sizeof(buf)); === > >> - Steve >> >> > On Wed, May 13, 2009 at 01:12:39PM +0900, Masayuki Igawa wrote: >> >> Hi, >> >> >> >> There is the problem that cgrulesengd cannot get Gid from >> >> /proc/PID/status, >> >> because the function breaks just after getting Uid data: >> >> >> >> $ cat /proc/$$/status >> >> [snip] >> >> Uid: 500 500 500 500 >> >> Gid: 500 500 500 500 >> >> [snip] >> >> $ >> >> >> >> This patch fixes this problem. >> >> >> >> Thanks. >> >> Masayuki Igawa >> >> >> >> Signed-off-by: Masayuki Igawa <[email protected]> >> >> --- >> >> src/daemon/cgrulesengd.c | 2 -- >> >> 1 files changed, 0 insertions(+), 2 deletions(-) >> >> >> >> diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c >> >> index 07d4a5d..595c321 100644 >> >> --- a/src/daemon/cgrulesengd.c >> >> +++ b/src/daemon/cgrulesengd.c >> >> @@ -168,11 +168,9 @@ static int cgre_get_euid_egid_from_status(pid_t >> >> pid, uid_t *euid, gid_t *egid) >> >> if (!strncmp(buf, "Uid:", 4)) { >> >> sscanf((buf + 5), "%d%d%d%d", &ruid, euid, >> >> &suid, &fsuid); >> >> - break; >> >> } else if (!strncmp(buf, "Gid:", 4)) { >> > >> > while we are at it. I see another cleanup possible here. 4 is a magic >> > number. Can we have a macro replacing it? >> > >> > thanks, >> > -- >> > regards, >> > Dhaval >> > >> > ------------------------------------------------------------------------------ >> > The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your >> > production scanning environment may not be a perfect world - but thanks to >> > Kodak, there's a perfect scanner to get the job done! With the NEW KODAK >> > i700 >> > Series Scanner you'll get full speed at 300 dpi even with all image >> > processing features enabled. http://p.sf.net/sfu/kodak-com >> > _______________________________________________ >> > Libcg-devel mailing list >> > [email protected] >> > https://lists.sourceforge.net/lists/listinfo/libcg-devel >> > >> > > -- > regards, > Dhaval ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
