From 18a3de4214668b5b82561ec096f7ef6858d25555 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 10 Aug 2015 11:47:50 +0200 Subject: credential-cache--daemon: delete socket from main() main() is responsible for cleaning up the socket in the case of errors, so it is reasonable to also make it responsible for cleaning it up when there are no errors. This change also makes the next step easier. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- credential-cache--daemon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'credential-cache--daemon.c') diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c index c2f00498f6..a671b2b53c 100644 --- a/credential-cache--daemon.c +++ b/credential-cache--daemon.c @@ -221,7 +221,6 @@ static void serve_cache(const char *socket_path, int debug) ; /* nothing */ close(fd); - unlink(socket_path); } static const char permissions_advice[] = @@ -280,5 +279,7 @@ int main(int argc, const char **argv) serve_cache(socket_path, debug); + unlink(socket_path); + return 0; } -- cgit v1.3 From 9e9033166b3a6b34aad917891b9210fa194fdfd9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 10 Aug 2015 11:47:51 +0200 Subject: credential-cache--daemon: use tempfile module Use the tempfile module to ensure that the socket file gets deleted on program exit. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- credential-cache--daemon.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'credential-cache--daemon.c') diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c index a671b2b53c..eef6fce4c7 100644 --- a/credential-cache--daemon.c +++ b/credential-cache--daemon.c @@ -1,23 +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; @@ -256,6 +244,7 @@ static void check_socket_directory(const char *path) int main(int argc, const char **argv) { + const char *socket_path; static const char *usage[] = { "git-credential-cache--daemon [opts] ", NULL @@ -272,14 +261,11 @@ int main(int argc, const char **argv) if (!socket_path) usage_with_options(usage, options); - check_socket_directory(socket_path); - - atexit(cleanup_socket); - sigchain_push_common(cleanup_socket_on_signal); + check_socket_directory(socket_path); + register_tempfile(&socket_file, socket_path); serve_cache(socket_path, debug); - - unlink(socket_path); + delete_tempfile(&socket_file); return 0; } -- cgit v1.3