git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] credential-cache--daemon: change to the socket dir on startup

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 23, 2016, 21:09 UTC
Message-ID
<xmqqbn77yvzb.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160223210725.GA25854@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 33 quoted lines
> On Tue, Feb 23, 2016 at 01:06:10PM -0800, Junio C Hamano wrote:
>
>> Jeff King <peff@peff.net> 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);
 }
Previous: Jeff KingNext: Jeff King
Message 7 of 8 in “credential-cache: give daemon a predictable cwd”
  1. 0/3 credential-cache: give daemon a predictable cwdJeff King, Feb 23, 2016
  2. 1/3 credential-cache--daemon: refactor check_socket_directoryJeff King, Feb 23, 2016
  3. 2/3 credential-cache--daemon: disallow relative socket pathJeff King, Feb 23, 2016
  4. 3/3 credential-cache--daemon: change to the socket dir on startupJeff King, Feb 23, 2016
  5. Junio C HamanoFeb 23, 2016
  6. Jeff KingFeb 23, 2016
  7. Junio C HamanoFeb 23, 2016
  8. Jeff KingFeb 23, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.