mirror of
https://github.com/openvswitch/ovs
synced 2025-09-03 07:45:30 +00:00
fatal-signal: Clean up code by using shash.
This simplifies the code here and should speed it up, too, when there are lots of files to unlink on a fatal signal.
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "shash.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* Signals to catch. */
|
/* Signals to catch. */
|
||||||
@@ -165,8 +166,7 @@ call_hooks(int sig_nr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **files;
|
static struct shash files = SHASH_INITIALIZER(&files);
|
||||||
static size_t n_files, max_files;
|
|
||||||
|
|
||||||
static void unlink_files(void *aux);
|
static void unlink_files(void *aux);
|
||||||
static void do_unlink_files(void);
|
static void do_unlink_files(void);
|
||||||
@@ -183,10 +183,9 @@ fatal_signal_add_file_to_unlink(const char *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fatal_signal_block();
|
fatal_signal_block();
|
||||||
if (n_files >= max_files) {
|
if (!shash_find(&files, file)) {
|
||||||
files = x2nrealloc(files, &max_files, sizeof *files);
|
shash_add(&files, file, NULL);
|
||||||
}
|
}
|
||||||
files[n_files++] = xstrdup(file);
|
|
||||||
fatal_signal_unblock();
|
fatal_signal_unblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,15 +194,12 @@ fatal_signal_add_file_to_unlink(const char *file)
|
|||||||
void
|
void
|
||||||
fatal_signal_remove_file_to_unlink(const char *file)
|
fatal_signal_remove_file_to_unlink(const char *file)
|
||||||
{
|
{
|
||||||
size_t i;
|
struct shash_node *node;
|
||||||
|
|
||||||
fatal_signal_block();
|
fatal_signal_block();
|
||||||
for (i = 0; i < n_files; i++) {
|
node = shash_find(&files, file);
|
||||||
if (!strcmp(files[i], file)) {
|
if (node) {
|
||||||
free(files[i]);
|
shash_delete(&files, node);
|
||||||
files[i] = files[--n_files];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fatal_signal_unblock();
|
fatal_signal_unblock();
|
||||||
}
|
}
|
||||||
@@ -217,10 +213,10 @@ unlink_files(void *aux UNUSED)
|
|||||||
static void
|
static void
|
||||||
do_unlink_files(void)
|
do_unlink_files(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
struct shash_node *node;
|
||||||
|
|
||||||
for (i = 0; i < n_files; i++) {
|
SHASH_FOR_EACH (node, &files) {
|
||||||
unlink(files[i]);
|
unlink(node->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user