X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Ffatal-signal.c;h=81805214383df9945a3f3f042c106d0d8c0a8f27;hb=8e5421180d1acd5856f41e6dd33ff69ccb7af92b;hp=ff011363e307b8dce9b1e1a70a6a1b3cef6da975;hpb=411baaacb8672cd9b231328b77a5f1c8a11aad9c;p=openvswitch diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index ff011363..81805214 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -26,6 +26,9 @@ #include "shash.h" #include "util.h" +#define THIS_MODULE VLM_fatal_signal +#include "vlog.h" + /* Signals to catch. */ static const int fatal_signals[] = { SIGTERM, SIGINT, SIGHUP, SIGALRM }; @@ -57,7 +60,11 @@ static void call_hooks(int sig_nr); /* Registers 'hook' to be called when a process termination signal is raised. * If 'run_at_exit' is true, 'hook' is also called during normal process - * termination, e.g. when exit() is called or when main() returns. */ + * termination, e.g. when exit() is called or when main() returns. + * + * 'func' will be invoked from an asynchronous signal handler, so it must be + * written appropriately. For example, it must not call most C library + * functions, including malloc() or free(). */ void fatal_signal_add_hook(void (*func)(void *aux), void *aux, bool run_at_exit) { @@ -204,12 +211,33 @@ fatal_signal_remove_file_to_unlink(const char *file) fatal_signal_unblock(); } +/* Like fatal_signal_remove_file_to_unlink(), but also unlinks 'file'. + * Returns 0 if successful, otherwise a positive errno value. */ +int +fatal_signal_unlink_file_now(const char *file) +{ + int error = unlink(file) ? errno : 0; + if (error) { + VLOG_WARN("could not unlink \"%s\" (%s)", file, strerror(error)); + } + + fatal_signal_remove_file_to_unlink(file); + + return error; +} + static void unlink_files(void *aux UNUSED) { do_unlink_files(); } +/* This is a fatal_signal_add_hook() callback (via unlink_files()). It will be + * invoked from an asynchronous signal handler, so it cannot call most C + * library functions (unlink() is an explicit exception, see + * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html). + * That includes free(), so it doesn't try to free the 'files' data + * structure. */ static void do_unlink_files(void) {