@matheusbsbs / matheus-bagliano / commits / 57b235a4bc
Fork 0

refactor signal handling for cleanup functions

The current code is very inconsistent about which signals are caught for doing cleanup of temporary files and lock files. Some callsites checked only SIGINT, while others checked a variety of death-dealing signals. This patch factors out those signals to a single function, and then calls it everywhere. For some sites, that means this is a simple clean up. For others, it is an improvement in that they will now properly clean themselves up after a larger variety of signals. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 22, 2009 at 01:03 UTC 57b235a4bc8884a57c6f863605a54b7bfceb0997
8 files changed +17 -13
builtin-clone.c
+1 -1
@@ -439,7 +439,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
439 }
440 junk_git_dir = git_dir;
441 atexit(remove_junk);
442 - sigchain_push(SIGINT, remove_junk_on_signal);
442 + sigchain_push_common(remove_junk_on_signal);
443
444 setenv(CONFIG_ENVIRONMENT, xstrdup(mkpath("%s/config", git_dir)), 1);
445
builtin-fetch--tool.c
+1 -1
@@ -246,7 +246,7 @@ static int fetch_native_store(FILE *fp,
246 char buffer[1024];
247 int err = 0;
248
249 - sigchain_push(SIGINT, remove_keep_on_signal);
249 + sigchain_push_common(remove_keep_on_signal);
250 atexit(remove_keep);
251
252 while (fgets(buffer, sizeof(buffer), stdin)) {
builtin-fetch.c
+1 -1
@@ -673,7 +673,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
673 ref_nr = j;
674 }
675
676 - sigchain_push(SIGINT, unlock_pack_on_signal);
676 + sigchain_push_common(unlock_pack_on_signal);
677 atexit(unlock_pack);
678 exit_code = do_fetch(transport,
679 parse_fetch_refspec(ref_nr, refs), ref_nr);
diff.c
+1 -1
@@ -1903,7 +1903,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
1903
1904 if (!remove_tempfile_installed) {
1905 atexit(remove_tempfile);
1906 - sigchain_push(SIGINT, remove_tempfile_on_signal);
1906 + sigchain_push_common(remove_tempfile_on_signal);
1907 remove_tempfile_installed = 1;
1908 }
1909
http-push.c
+1 -4
@@ -2262,10 +2262,7 @@ int main(int argc, char **argv)
2262 goto cleanup;
2263 }
2264
2265 - sigchain_push(SIGINT, remove_locks_on_signal);
2266 - sigchain_push(SIGHUP, remove_locks_on_signal);
2267 - sigchain_push(SIGQUIT, remove_locks_on_signal);
2268 - sigchain_push(SIGTERM, remove_locks_on_signal);
2265 + sigchain_push_common(remove_locks_on_signal);
2266
2267 /* Check whether the remote has server info files */
2268 remote->can_update_info_refs = 0;
lockfile.c
+1 -5
@@ -137,11 +137,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
137 lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
138 if (0 <= lk->fd) {
139 if (!lock_file_list) {
140 - sigchain_push(SIGINT, remove_lock_file_on_signal);
141 - sigchain_push(SIGHUP, remove_lock_file_on_signal);
142 - sigchain_push(SIGTERM, remove_lock_file_on_signal);
143 - sigchain_push(SIGQUIT, remove_lock_file_on_signal);
144 - sigchain_push(SIGPIPE, remove_lock_file_on_signal);
140 + sigchain_push_common(remove_lock_file_on_signal);
141 atexit(remove_lock_file);
142 }
143 lk->owner = getpid();
sigchain.c
+9
@@ -41,3 +41,12 @@ int sigchain_pop(int sig)
41 s->n--;
42 return 0;
43 }
44 +
45 +void sigchain_push_common(sigchain_fun f)
46 +{
47 + sigchain_push(SIGINT, f);
48 + sigchain_push(SIGHUP, f);
49 + sigchain_push(SIGTERM, f);
50 + sigchain_push(SIGQUIT, f);
51 + sigchain_push(SIGPIPE, f);
52 +}
sigchain.h
+2
@@ -6,4 +6,6 @@ typedef void (*sigchain_fun)(int);
6 int sigchain_push(int sig, sigchain_fun f);
7 int sigchain_pop(int sig);
8
9 +void sigchain_push_common(sigchain_fun f);
10 +
11 #endif /* SIGCHAIN_H */