22#include "credential.h"
33#include "unix-socket.h"
44#include "sigchain.h"
5+ #include "parse-options.h"
56
67static const char * socket_path ;
78
@@ -201,7 +202,7 @@ static int serve_cache_loop(int fd)
201202 return 1 ;
202203}
203204
204- static void serve_cache (const char * socket_path )
205+ static void serve_cache (const char * socket_path , int debug )
205206{
206207 int fd ;
207208
@@ -211,6 +212,10 @@ static void serve_cache(const char *socket_path)
211212
212213 printf ("ok\n" );
213214 fclose (stdout );
215+ if (!debug ) {
216+ if (!freopen ("/dev/null" , "w" , stderr ))
217+ die_errno ("unable to point stderr to /dev/null" );
218+ }
214219
215220 while (serve_cache_loop (fd ))
216221 ; /* nothing */
@@ -252,16 +257,28 @@ static void check_socket_directory(const char *path)
252257
253258int main (int argc , const char * * argv )
254259{
255- socket_path = argv [1 ];
260+ static const char * usage [] = {
261+ "git-credential-cache--daemon [opts] <socket_path>" ,
262+ NULL
263+ };
264+ int debug = 0 ;
265+ const struct option options [] = {
266+ OPT_BOOL (0 , "debug" , & debug ,
267+ N_ ("print debugging messages to stderr" )),
268+ OPT_END ()
269+ };
270+
271+ argc = parse_options (argc , argv , NULL , options , usage , 0 );
272+ socket_path = argv [0 ];
256273
257274 if (!socket_path )
258- die ( " usage: git-credential-cache--daemon <socket_path>" );
275+ usage_with_options ( usage , options );
259276 check_socket_directory (socket_path );
260277
261278 atexit (cleanup_socket );
262279 sigchain_push_common (cleanup_socket_on_signal );
263280
264- serve_cache (socket_path );
281+ serve_cache (socket_path , debug );
265282
266283 return 0 ;
267284}
0 commit comments