gc: use tempfile module to handle gc.pid file
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
ebebeaea0a2b4861c00f31c42880599ec701adb9
1 file changed
+5
-20
builtin/gc.c
+5
-20
@@ -11,6 +11,7 @@
11
*/
12
13
#include "builtin.h"
14
+#include "tempfile.h"
15
#include "lockfile.h"
16
#include "parse-options.h"
17
#include "run-command.h"
@@ -42,20 +43,7 @@ static struct argv_array prune = ARGV_ARRAY_INIT;
43
static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
44
static struct argv_array rerere = ARGV_ARRAY_INIT;
45
45
-static char *pidfile;
46
-
47
-static void remove_pidfile(void)
48
-{
49
- if (pidfile)
50
- unlink(pidfile);
51
-}
52
-
53
-static void remove_pidfile_on_signal(int signo)
54
-{
55
- remove_pidfile();
56
- sigchain_pop(signo);
57
- raise(signo);
58
-}
46
+static struct tempfile pidfile;
47
48
static void git_config_date_string(const char *key, const char **output)
49
{
@@ -201,7 +189,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
189
int fd;
190
char *pidfile_path;
191
204
- if (pidfile)
192
+ if (is_tempfile_active(&pidfile))
193
/* already locked */
194
return NULL;
195
@@ -248,11 +236,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
236
write_in_full(fd, sb.buf, sb.len);
237
strbuf_release(&sb);
238
commit_lock_file(&lock);
251
-
252
- pidfile = pidfile_path;
253
- sigchain_push_common(remove_pidfile_on_signal);
254
- atexit(remove_pidfile);
255
-
239
+ register_tempfile(&pidfile, pidfile_path);
240
+ free(pidfile_path);
241
return NULL;
242
}
243