Skip to content

Commit

Permalink
credential-cache--daemon: use tempfile module
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mhagger authored and gitster committed Aug 12, 2015
1 parent 18a3de4 commit 9e90331
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions 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;
Expand Down Expand Up @@ -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] <socket_path>",
NULL
Expand All @@ -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;
}

0 comments on commit 9e90331

Please sign in to comment.