diff options
Diffstat (limited to 'credential-cache--daemon.c')
| -rw-r--r-- | credential-cache--daemon.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c index 3b370ca5e5..eef6fce4c7 100644 --- a/credential-cache--daemon.c +++ b/credential-cache--daemon.c @@ -1,22 +1,11 @@ #include "cache.h" +#include "tempfile.h" #include "credential.h" #include "unix-socket.h" #include "sigchain.h" +#include "parse-options.h" -static const char *socket_path; - -static void cleanup_socket(void) -{ - if (socket_path) - unlink(socket_path); -} - -static void cleanup_socket_on_signal(int sig) -{ - cleanup_socket(); - sigchain_pop(sig); - raise(sig); -} +static struct tempfile socket_file; struct credential_cache_entry { struct credential item; @@ -201,7 +190,7 @@ static int serve_cache_loop(int fd) return 1; } -static void serve_cache(const char *socket_path) +static void serve_cache(const char *socket_path, int debug) { int fd; @@ -211,12 +200,15 @@ static void serve_cache(const char *socket_path) printf("ok\n"); fclose(stdout); + if (!debug) { + if (!freopen("/dev/null", "w", stderr)) + die_errno("unable to point stderr to /dev/null"); + } while (serve_cache_loop(fd)) ; /* nothing */ close(fd); - unlink(socket_path); } static const char permissions_advice[] = @@ -252,16 +244,28 @@ static void check_socket_directory(const char *path) int main(int argc, const char **argv) { - socket_path = argv[1]; + const char *socket_path; + static const char *usage[] = { + "git-credential-cache--daemon [opts] <socket_path>", + NULL + }; + int debug = 0; + const struct option options[] = { + OPT_BOOL(0, "debug", &debug, + N_("print debugging messages to stderr")), + OPT_END() + }; + + argc = parse_options(argc, argv, NULL, options, usage, 0); + socket_path = argv[0]; if (!socket_path) - die("usage: git-credential-cache--daemon <socket_path>"); - check_socket_directory(socket_path); + usage_with_options(usage, options); - atexit(cleanup_socket); - sigchain_push_common(cleanup_socket_on_signal); - - serve_cache(socket_path); + check_socket_directory(socket_path); + register_tempfile(&socket_file, socket_path); + serve_cache(socket_path, debug); + delete_tempfile(&socket_file); return 0; } |
