Skip to content

Commit

Permalink
fatal-signal: New function fatal_signal_unlink_file_now().
Browse files Browse the repository at this point in the history
This is a helper function that combines two actions that callers commonly
wanted.  It will have an additional user in an upcoming commit.
  • Loading branch information
blp committed Sep 21, 2009
1 parent 411baaa commit 6a0061c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
18 changes: 18 additions & 0 deletions lib/fatal-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion lib/fatal-signal.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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. */
Expand Down
6 changes: 2 additions & 4 deletions lib/unixctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/vlog-modules.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6a0061c

Please sign in to comment.