239
239
/* Temporary files to remove at program exit. */
240
240
static struct pending_tmp_file *pending_tmp_files = NULL;
242
static sigset_t fatal_signal_set;
244
/* PID of currently executing compiler that we have started, if any. 0 means no
245
* ongoing compilation. */
246
static pid_t compiler_pid = 0;
243
249
* This is a string that identifies the current "version" of the hash sum
244
250
* computed by ccache. If, for any reason, we want to force the hash sum to be
326
sigprocmask(SIG_BLOCK, &fatal_signal_set, NULL);
330
unblock_signals(void)
334
sigprocmask(SIG_SETMASK, &empty, NULL);
318
338
add_pending_tmp_file(const char *path)
320
struct pending_tmp_file *e = x_malloc(sizeof(*e));
340
struct pending_tmp_file *e;
343
e = x_malloc(sizeof(*e));
321
344
e->path = x_strdup(path);
322
345
e->next = pending_tmp_files;
323
346
pending_tmp_files = e;
327
clean_up_pending_tmp_files(void)
351
do_clean_up_pending_tmp_files(void)
329
353
struct pending_tmp_file *p = pending_tmp_files;
340
signal_handler(int signo)
343
clean_up_pending_tmp_files();
364
clean_up_pending_tmp_files(void)
367
do_clean_up_pending_tmp_files();
372
signal_handler(int signum)
374
/* Unregister handler for this signal so that we can send the signal to
375
* ourselves at the end of the handler. */
376
signal(signum, SIG_DFL);
378
/* If ccache was killed explicitly, then bring the compiler subprocess (if
379
* any) with us as well. */
380
if (signum == SIGTERM
382
&& waitpid(compiler_pid, NULL, WNOHANG) == 0) {
383
kill(compiler_pid, signum);
386
do_clean_up_pending_tmp_files();
388
if (compiler_pid != 0) {
389
/* Wait for compiler subprocess to exit before we snuff it. */
390
waitpid(compiler_pid, NULL, 0);
393
/* Resend signal to ourselves to exit properly after returning from the
395
kill(getpid(), signum);
399
register_signal_handler(int signum)
401
struct sigaction act;
402
memset(&act, 0, sizeof(act));
403
act.sa_handler = signal_handler;
404
act.sa_mask = fatal_signal_set;
405
act.sa_flags = SA_RESTART;
406
sigaction(signum, &act, NULL);
410
set_up_signal_handlers(void)
412
sigemptyset(&fatal_signal_set);
413
sigaddset(&fatal_signal_set, SIGINT);
414
sigaddset(&fatal_signal_set, SIGTERM);
416
sigaddset(&fatal_signal_set, SIGHUP);
419
sigaddset(&fatal_signal_set, SIGQUIT);
422
register_signal_handler(SIGINT);
423
register_signal_handler(SIGTERM);
425
register_signal_handler(SIGHUP);
428
register_signal_handler(SIGQUIT);
720
805
ret = link(source, dest);
722
ret = copy_file(source, dest, conf->compression);
808
source, dest, conf->compression ? conf->compression_level : 0);
725
811
cc_log("Failed to %s %s to %s: %s",
879
965
cc_log("Running real compiler");
880
status = execute(args->argv, tmp_stdout_fd, tmp_stderr_fd);
966
status = execute(args->argv, tmp_stdout_fd, tmp_stderr_fd, &compiler_pid);
881
967
args_pop(args, 3);
883
969
if (x_stat(tmp_stdout, &st) != 0) {
1140
1226
args_add(args, "-E");
1141
1227
args_add(args, input_file);
1142
1228
cc_log("Running preprocessor");
1143
status = execute(args->argv, path_stdout_fd, path_stderr_fd);
1229
status = execute(args->argv, path_stdout_fd, path_stderr_fd, &compiler_pid);
1144
1230
args_pop(args, 2);
1263
1349
compiler_is_clang(struct args *args)
1265
1351
char *name = basename(args->argv[0]);
1266
bool is = strstr(name, "clang");
1352
bool is = strstr(name, "clang") != NULL;
2858
2944
/* Arguments to send to the real compiler. */
2859
2945
struct args *compiler_args;
2947
set_up_signal_handlers();
2861
2949
orig_args = args_init(argc, argv);
2864
2952
find_compiler(argv);
2867
signal(SIGHUP, signal_handler);
2869
signal(SIGINT, signal_handler);
2870
signal(SIGTERM, signal_handler);
2872
2954
if (str_eq(conf->temporary_dir, "")) {
2873
2955
clean_up_internal_tempdir();