git-p4: do not terminate creating tag for unknown commit
[gitweb.git] / credential-cache--daemon.c
index c2f00498f6a171ecde3dd91a5cbdb30d88827495..eef6fce4c72ab37d75a0f75129666009a6a1ee54 100644 (file)
@@ -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;
@@ -221,7 +209,6 @@ static void serve_cache(const char *socket_path, int debug)
                ; /* nothing */
 
        close(fd);
-       unlink(socket_path);
 }
 
 static const char permissions_advice[] =
@@ -257,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] <socket_path>",
                NULL
@@ -273,12 +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);
+       delete_tempfile(&socket_file);
 
        return 0;
 }