aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-09-21 12:37:20 -0700
committerBen Pfaff <blp@nicira.com>2009-09-21 16:44:58 -0700
commit6a0061cbf5d8e2637040c54140c90e474b6543ca (patch)
tree1a1280d2a21b6ae503cd9ce074992bd6d1374a52
parent411baaacb8672cd9b231328b77a5f1c8a11aad9c (diff)
fatal-signal: New function fatal_signal_unlink_file_now().
This is a helper function that combines two actions that callers commonly wanted. It will have an additional user in an upcoming commit.
-rw-r--r--lib/fatal-signal.c18
-rw-r--r--lib/fatal-signal.h3
-rw-r--r--lib/unixctl.c6
-rw-r--r--lib/vlog-modules.def1
4 files changed, 23 insertions, 5 deletions
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index ff011363..d8862bbf 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 };
@@ -204,6 +207,21 @@ 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)
{
diff --git a/lib/fatal-signal.h b/lib/fatal-signal.h
index 0bce1e27..c96db86d 100644
--- a/lib/fatal-signal.h
+++ b/lib/fatal-signal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008 Nicira Networks.
+ * Copyright (c) 2008, 2009 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ void fatal_signal_fork(void);
* exit(). */
void fatal_signal_add_file_to_unlink(const char *);
void fatal_signal_remove_file_to_unlink(const char *);
+int fatal_signal_unlink_file_now(const char *);
/* Interface for other code that catches one of our signals and needs to pass
* it through. */
diff --git a/lib/unixctl.c b/lib/unixctl.c
index 7d6fdd67..e774ffe4 100644
--- a/lib/unixctl.c
+++ b/lib/unixctl.c
@@ -438,8 +438,7 @@ unixctl_server_destroy(struct unixctl_server *server)
}
close(server->fd);
- unlink(server->path);
- fatal_signal_remove_file_to_unlink(server->path);
+ fatal_signal_unlink_file_now(server->path);
free(server->path);
free(server);
}
@@ -504,8 +503,7 @@ void
unixctl_client_destroy(struct unixctl_client *client)
{
if (client) {
- unlink(client->bind_path);
- fatal_signal_remove_file_to_unlink(client->bind_path);
+ fatal_signal_unlink_file_now(client->bind_path);
free(client->bind_path);
free(client->connect_path);
fclose(client->stream);
diff --git a/lib/vlog-modules.def b/lib/vlog-modules.def
index 849c867b..ce298b55 100644
--- a/lib/vlog-modules.def
+++ b/lib/vlog-modules.def
@@ -36,6 +36,7 @@ VLOG_MODULE(dpctl)
VLOG_MODULE(executer)
VLOG_MODULE(ezio_term)
VLOG_MODULE(fail_open)
+VLOG_MODULE(fatal_signal)
VLOG_MODULE(fault)
VLOG_MODULE(flow)
VLOG_MODULE(in_band)