Skip to content

Commit 9e90331

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18a3de4 commit 9e90331

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

credential-cache--daemon.c

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
#include "cache.h"
2+
#include "tempfile.h"
23
#include "credential.h"
34
#include "unix-socket.h"
45
#include "sigchain.h"
56
#include "parse-options.h"
67

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;
219

2210
struct credential_cache_entry {
2311
struct credential item;
@@ -256,6 +244,7 @@ static void check_socket_directory(const char *path)
256244

257245
int main(int argc, const char **argv)
258246
{
247+
const char *socket_path;
259248
static const char *usage[] = {
260249
"git-credential-cache--daemon [opts] <socket_path>",
261250
NULL
@@ -272,14 +261,11 @@ int main(int argc, const char **argv)
272261

273262
if (!socket_path)
274263
usage_with_options(usage, options);
275-
check_socket_directory(socket_path);
276-
277-
atexit(cleanup_socket);
278-
sigchain_push_common(cleanup_socket_on_signal);
279264

265+
check_socket_directory(socket_path);
266+
register_tempfile(&socket_file, socket_path);
280267
serve_cache(socket_path, debug);
281-
282-
unlink(socket_path);
268+
delete_tempfile(&socket_file);
283269

284270
return 0;
285271
}

0 commit comments

Comments
 (0)