xfs
[Top] [All Lists]

Re: [PATCH] Fix "quota -n" command in xfs_quota.

To: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Subject: Re: [PATCH] Fix "quota -n" command in xfs_quota.
From: Utako Kusaka <utako@xxxxxxxxxxxxxx>
Date: Tue, 24 Apr 2007 15:10:21 +0900
Cc: xfs@xxxxxxxxxxx
In-reply-to: <20070423212606.GE13572@xxxxxxxxxxxxx>
References: <20070423212606.GE13572@xxxxxxxxxxxxx>
Sender: xfs-bounce@xxxxxxxxxxx
Hi,

Thanks for your comment.
I have updated my patch as below.

Signed-off-by: Utako Kusaka <utako@xxxxxxxxxxxxxx>
---

--- quota.orig  2007-04-18 10:36:38.000000000 +0900
+++ quota.c     2007-04-24 11:42:18.000000000 +0900
@@ -202,10 +202,12 @@ getusername(
        int             numeric)
 {
        static char     buffer[32];
-       struct passwd   *u;
 
-       if (!numeric && (u = getpwuid(uid)))
-               return u->pw_name;
+       if (!numeric) {
+               struct passwd *u = getpwuid(uid);
+               if (u)
+                       return u->pw_name;
+       }
        snprintf(buffer, sizeof(buffer), "#%u", uid);
        return &buffer[0];
 }
@@ -247,10 +249,12 @@ getgroupname(
        int             numeric)
 {
        static char     buffer[32];
-       struct group    *g;
 
-       if (!numeric && (g = getgrgid(gid)))
-               return g->gr_name;
+       if (!numeric) {
+               struct group *g = getgrgid(gid);
+               if (g)
+                       return g->gr_name;
+       }
        snprintf(buffer, sizeof(buffer), "#%u", gid);
        return &buffer[0];
 }
@@ -310,10 +314,12 @@ getprojectname(
        int             numeric)
 {
        static char     buffer[32];
-       fs_project_t    *p;
 
-       if ((p = getprprid(prid)))
-               return p->pr_name;
+       if (!numeric) {
+               fs_project_t *p = getprprid(prid);
+               if (p)
+                       return p->pr_name;
+       }
        snprintf(buffer, sizeof(buffer), "#%u", (unsigned int)prid);
        return &buffer[0];
 }



Mon, 23 Apr 2007 22:26:06 +0100 Christoph Hellwig wrote:
>
>Looks good to me, but the even the original code could be a little bit cleaner:
>
>> --- xfsprogs-2.8.20/quota/quota.orig 2007-04-18 10:36:38.000000000 +0900
>> +++ xfsprogs-2.8.20/quota/quota.c    2007-04-18 11:09:10.000000000 +0900
>> @@ -312,7 +312,7 @@ getprojectname(
>>      static char     buffer[32];
>>      fs_project_t    *p;
>>  
>> -    if ((p = getprprid(prid)))
>> +    if (!numeric && (p = getprprid(prid)))
>>              return p->pr_name;
>>      snprintf(buffer, sizeof(buffer), "#%u", (unsigned int)prid);
>>      return &buffer[0];
>
>       if (!numeric) {
>               fs_project_t *p = getprprid(prid);
>               if (p)
>                       return p->pr_name;
>       }
>
>       snprintf(buffer, sizeof(buffer), "#%u", (unsigned int)prid);
>       return &buffer[0];
>
>               


<Prev in Thread] Current Thread [Next in Thread>