diff options
Diffstat (limited to 'credential-cache--daemon.c')
-rw-r--r-- | credential-cache--daemon.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c index c2f00498f6..cc65a9c0d3 100644 --- a/credential-cache--daemon.c +++ b/credential-cache--daemon.c @@ -1,23 +1,10 @@ #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; @@ -109,12 +96,12 @@ static int read_request(FILE *fh, struct credential *c, static struct strbuf item = STRBUF_INIT; const char *p; - strbuf_getline(&item, fh, '\n'); + strbuf_getline_lf(&item, fh); if (!skip_prefix(item.buf, "action=", &p)) return error("client sent bogus action line: %s", item.buf); strbuf_addstr(action, p); - strbuf_getline(&item, fh, '\n'); + strbuf_getline_lf(&item, fh); if (!skip_prefix(item.buf, "timeout=", &p)) return error("client sent bogus timeout line: %s", item.buf); *timeout = atoi(p); @@ -221,7 +208,6 @@ static void serve_cache(const char *socket_path, int debug) ; /* nothing */ close(fd); - unlink(socket_path); } static const char permissions_advice[] = @@ -257,6 +243,8 @@ static void check_socket_directory(const char *path) int main(int argc, const char **argv) { + const char *socket_path; + int ignore_sighup = 0; static const char *usage[] = { "git-credential-cache--daemon [opts] <socket_path>", NULL @@ -268,17 +256,22 @@ int main(int argc, const char **argv) OPT_END() }; + git_config_get_bool("credentialcache.ignoresighup", &ignore_sighup); + argc = parse_options(argc, argv, NULL, options, usage, 0); socket_path = argv[0]; if (!socket_path) usage_with_options(usage, options); + check_socket_directory(socket_path); + register_tempfile(&socket_file, socket_path); - atexit(cleanup_socket); - sigchain_push_common(cleanup_socket_on_signal); + if (ignore_sighup) + signal(SIGHUP, SIG_IGN); serve_cache(socket_path, debug); + delete_tempfile(&socket_file); return 0; } |