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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Aug 10, 2015 at 11:47 UTC 9e9033166b3a6b34aad917891b9210fa194fdfd9
1 file changed +6 -20
credential-cache--daemon.c
+6 -20
@@ -1,23 +1,11 @@
1 #include "cache.h"
2 +#include "tempfile.h"
3 #include "credential.h"
4 #include "unix-socket.h"
5 #include "sigchain.h"
6 #include "parse-options.h"
7
7 -static const char *socket_path;
8 -
9 -static void cleanup_socket(void)
10 -{
11 - if (socket_path)
12 - unlink(socket_path);
13 -}
14 -
15 -static void cleanup_socket_on_signal(int sig)
16 -{
17 - cleanup_socket();
18 - sigchain_pop(sig);
19 - raise(sig);
20 -}
8 +static struct tempfile socket_file;
9
10 struct credential_cache_entry {
11 struct credential item;
@@ -256,6 +244,7 @@ static void check_socket_directory(const char *path)
244
245 int main(int argc, const char **argv)
246 {
247 + const char *socket_path;
248 static const char *usage[] = {
249 "git-credential-cache--daemon [opts] <socket_path>",
250 NULL
@@ -272,14 +261,11 @@ int main(int argc, const char **argv)
261
262 if (!socket_path)
263 usage_with_options(usage, options);
275 - check_socket_directory(socket_path);
276 -
277 - atexit(cleanup_socket);
278 - sigchain_push_common(cleanup_socket_on_signal);
264
265 + check_socket_directory(socket_path);
266 + register_tempfile(&socket_file, socket_path);
267 serve_cache(socket_path, debug);
281 -
282 - unlink(socket_path);
268 + delete_tempfile(&socket_file);
269
270 return 0;
271 }