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>
This commit is contained in:
parent
18a3de4214
commit
9e9033166b
@ -1,23 +1,11 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "tempfile.h"
|
||||||
#include "credential.h"
|
#include "credential.h"
|
||||||
#include "unix-socket.h"
|
#include "unix-socket.h"
|
||||||
#include "sigchain.h"
|
#include "sigchain.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
|
||||||
static const char *socket_path;
|
static struct tempfile socket_file;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct credential_cache_entry {
|
struct credential_cache_entry {
|
||||||
struct credential item;
|
struct credential item;
|
||||||
@ -256,6 +244,7 @@ static void check_socket_directory(const char *path)
|
|||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
|
const char *socket_path;
|
||||||
static const char *usage[] = {
|
static const char *usage[] = {
|
||||||
"git-credential-cache--daemon [opts] <socket_path>",
|
"git-credential-cache--daemon [opts] <socket_path>",
|
||||||
NULL
|
NULL
|
||||||
@ -272,14 +261,11 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
if (!socket_path)
|
if (!socket_path)
|
||||||
usage_with_options(usage, options);
|
usage_with_options(usage, options);
|
||||||
|
|
||||||
check_socket_directory(socket_path);
|
check_socket_directory(socket_path);
|
||||||
|
register_tempfile(&socket_file, socket_path);
|
||||||
atexit(cleanup_socket);
|
|
||||||
sigchain_push_common(cleanup_socket_on_signal);
|
|
||||||
|
|
||||||
serve_cache(socket_path, debug);
|
serve_cache(socket_path, debug);
|
||||||
|
delete_tempfile(&socket_file);
|
||||||
unlink(socket_path);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user