/* find an executable by name in $PATH. Exclude any that are links to exclude_name */ char *find_executable(const char *name, const char *exclude_name) { char *path; char *tok; struct stat st1, st2; if (*name == '/') { return x_strdup(name); } path = getenv("F90CACHE_PATH"); if (!path) { path = getenv("PATH"); } if (!path) { fc_log("no PATH variable!?\n"); return NULL; } path = x_strdup(path); /* search the path looking for the first compiler of the right name that isn't us */ for (tok=strtok(path,":"); tok; tok = strtok(NULL, ":")) { char *fname; x_asprintf(&fname, "%s/%s", tok, name); /* look for a normal executable file */ if (access(fname, X_OK) == 0 && lstat(fname, &st1) == 0 && stat(fname, &st2) == 0 && S_ISREG(st2.st_mode)) { /* if its a symlink then ensure it doesn't point at something called exclude_name */ if (S_ISLNK(st1.st_mode)) { char *buf = x_realpath(fname); if (buf) { char *p = str_basename(buf); if (strcmp(p, exclude_name) == 0) { /* its a link to "f90cache" ! */ free(p); free(buf); continue; } free(buf); free(p); } } /* found it! */ free(path); return fname; } free(fname); } return NULL; }
void fc_log_backtrace(fc_log_t *log, int level){ void *bt_buffer[32]; size_t bt_size, i; char **bt_strings; bt_size = backtrace(bt_buffer, sizeof(bt_buffer) / sizeof(bt_buffer[0])); bt_strings = backtrace_symbols(bt_buffer, bt_size); for (i = 0; i < bt_size; i++) { fc_log(log, level, "%s", bt_strings[i]); } free(bt_strings); }
void fc_signal_handler(int signo) { const char *action; fc_signal_t *sig; for (sig = signals; sig->signo != 0; sig++) { if (sig->signo == signo) { break; } } switch(signo) { case fc_signal_value(FC_SIGNAL_SHUTDOWN): fc_quit = 1; action = "shutting down"; break; case fc_signal_value(FC_SIGNAL_TERMINATE): fc_terminate = 1; action = "exiting"; break; case fc_signal_value(FC_SIGNAL_RECONFIGURE): fc_reconfigure = 1; action = "reconfiguring"; break; case fc_signal_value(FC_SIGNAL_REOPEN): fc_reopen = 1; action = "reopening logs"; break; default: break; } fc_log(fc_context->log, FC_LOG_NOTICE, "signal %d(%s) received, %s", signo, sig->signame, action); }