Skip to content

Commit ebebeae

Browse files
mhaggergitster
authored andcommitted
gc: use tempfile module to handle gc.pid file
Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 00539ce commit ebebeae

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

builtin/gc.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include "builtin.h"
14+
#include "tempfile.h"
1415
#include "lockfile.h"
1516
#include "parse-options.h"
1617
#include "run-command.h"
@@ -42,20 +43,7 @@ static struct argv_array prune = ARGV_ARRAY_INIT;
4243
static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
4344
static struct argv_array rerere = ARGV_ARRAY_INIT;
4445

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

6048
static void git_config_date_string(const char *key, const char **output)
6149
{
@@ -201,7 +189,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
201189
int fd;
202190
char *pidfile_path;
203191

204-
if (pidfile)
192+
if (is_tempfile_active(&pidfile))
205193
/* already locked */
206194
return NULL;
207195

@@ -248,11 +236,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
248236
write_in_full(fd, sb.buf, sb.len);
249237
strbuf_release(&sb);
250238
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);
256241
return NULL;
257242
}
258243

0 commit comments

Comments
 (0)