Jeff King <[email protected]> writes:

> On Tue, Feb 23, 2016 at 01:06:10PM -0800, Junio C Hamano wrote:
>
>> Jeff King <[email protected]> writes:
>> 
>> > +  /*
>> > +   * We don't actually care what our cwd is; we chdir here just to
>> > +   * be a friendly daemon and avoid tying up our original cwd.
>> > +   * If this fails, it's OK to just continue without that benefit.
>> > +   */
>> > +  chdir(dir);
>> 
>> I fully do agree with this comment, but my copy of gcc and system
>> headers doesn't, unfortunately.
>> 
>> credential-cache--daemon.c: In function 'init_socket_directory':
>> credential-cache--daemon.c:245:7: error: ignoring return value of 'chdir', 
>> declared with attribute warn_unused_result [-Werror=unused-result]
>>   chdir(dir);
>>        ^
>> cc1: all warnings being treated as errors
>> make: *** [credential-cache--daemon.o] Error 1
>
> Ugh. Is:
>
>   (void)chdir(dir);
>
> enough? Or do we have to do:
>
>   if (chdir(dir))
>       ; /* nothing */
>
> ?
>
> -Peff

I tentatively squashed this, which I think reads better.

diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index 9a3a7a3..6b00ee0 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -237,12 +237,13 @@ static void init_socket_directory(const char *path)
                        die_errno("unable to mkdir '%s'", dir);
        }
 
-       /*
-        * We don't actually care what our cwd is; we chdir here just to
-        * be a friendly daemon and avoid tying up our original cwd.
-        * If this fails, it's OK to just continue without that benefit.
-        */
-       chdir(dir);
+       if (chdir(dir))
+               /*
+                * We don't actually care what our cwd is; we chdir here just to
+                * be a friendly daemon and avoid tying up our original cwd.
+                * If this fails, it's OK to just continue without that benefit.
+                */
+               ;
 
        free(path_copy);
 }
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to