git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 14/14] credential-cache--daemon: use tempfile module
Date: Mon,  8 Jun 2015 11:07:45 +0200	[thread overview]
Message-ID: <137a4c21a5e8f87a4ebea1314a19ead1b934b72e.1433751986.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1433751986.git.mhagger@alum.mit.edu>

Use the tempfile module to ensure that the socket file gets deleted on
program exit.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 credential-cache--daemon.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index a671b2b..eef6fce 100644
--- a/credential-cache--daemon.c
+++ b/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;
@@ -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
@@ -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;
 }
-- 
2.1.4

  parent reply	other threads:[~2015-06-08  9:08 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-08  9:07 [PATCH 00/14] Introduce a tempfile module Michael Haggerty
2015-06-08  9:07 ` [PATCH 01/14] Move lockfile API documentation to lockfile.h Michael Haggerty
2015-06-08  9:07 ` [PATCH 02/14] tempfile: a new module for handling temporary files Michael Haggerty
2015-06-10 17:36   ` Junio C Hamano
2015-06-10 20:56     ` Michael Haggerty
2015-06-10 21:35       ` Junio C Hamano
2015-06-08  9:07 ` [PATCH 03/14] lockfile: remove some redundant functions Michael Haggerty
2015-06-10 17:40   ` Junio C Hamano
2015-06-10 18:27     ` Johannes Sixt
2015-06-08  9:07 ` [PATCH 04/14] commit_lock_file(): use get_locked_file_path() Michael Haggerty
2015-06-08  9:07 ` [PATCH 05/14] register_tempfile_object(): new function, extracted from create_tempfile() Michael Haggerty
2015-06-08  9:07 ` [PATCH 06/14] tempfile: add several functions for creating temporary files Michael Haggerty
2015-06-10 17:48   ` Junio C Hamano
2015-08-10  3:08     ` Michael Haggerty
2015-06-08  9:07 ` [PATCH 07/14] register_tempfile(): new function to handle an existing temporary file Michael Haggerty
2015-06-10 17:55   ` Junio C Hamano
2015-08-10  3:40     ` Michael Haggerty
2015-06-08  9:07 ` [PATCH 08/14] write_shared_index(): use tempfile module Michael Haggerty
2015-06-10 17:56   ` Junio C Hamano
2015-06-08  9:07 ` [PATCH 09/14] setup_temporary_shallow(): " Michael Haggerty
2015-06-08  9:07 ` [PATCH 10/14] diff: " Michael Haggerty
2015-06-08  9:07 ` [PATCH 11/14] lock_repo_for_gc(): compute the path to "gc.pid" only once Michael Haggerty
2015-06-08  9:07 ` [PATCH 12/14] gc: use tempfile module to handle gc.pid file Michael Haggerty
2015-06-08  9:07 ` [PATCH 13/14] credential-cache--daemon: delete socket from main() Michael Haggerty
2015-06-08  9:07 ` Michael Haggerty [this message]
2015-06-10 18:34 ` [PATCH 00/14] Introduce a tempfile module Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=137a4c21a5e8f87a4ebea1314a19ead1b934b72e.1433751986.git.mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).