aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-01-25 14:32:55 +0200
committerSergey Poznyakoff <gray@gnu.org>2021-01-25 14:32:55 +0200
commit3e8ea8d7eab4c2b657be9732a4c5e846bac45458 (patch)
treef3867fe90bbd40fb08b1640926fc1b37d3f3bdd4
parent691f99bfe4243e6a72eddb124c185dc21c643e8b (diff)
downloadmicron-3e8ea8d7eab4c2b657be9732a4c5e846bac45458.tar.gz
micron-3e8ea8d7eab4c2b657be9732a4c5e846bac45458.tar.bz2
Bugfixes
* src/patmatch.c (patmatch): Fix NULL dereference. * src/runner.c: Fix race condition between creation of logger_pipe and first write to it. (logger_pipe): Initialize. (cron_thr_logger): Don't create logger_pipe here. (logger_enqueue): Create control pipe here instead.
-rw-r--r--src/patmatch.c10
-rw-r--r--src/runner.c16
2 files changed, 13 insertions, 13 deletions
diff --git a/src/patmatch.c b/src/patmatch.c
index dd670ff..2c18cb3 100644
--- a/src/patmatch.c
+++ b/src/patmatch.c
@@ -6,10 +6,12 @@
int
patmatch(char const **patterns, const char *name)
{
- int i;
- for (i = 0; patterns[i]; i++)
- if (fnmatch(patterns[i], name, FNM_PATHNAME|FNM_PERIOD) == 0)
- return 1;
+ if (patterns) {
+ int i;
+ for (i = 0; patterns[i]; i++)
+ if (fnmatch(patterns[i], name, FNM_PATHNAME|FNM_PERIOD) == 0)
+ return 1;
+ }
return 0;
}
diff --git a/src/runner.c b/src/runner.c
index 7aa8acd..12f2bb0 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -532,7 +532,7 @@ stop_thr_cleaner(pthread_t tid)
static pthread_mutex_t logger_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct list_head logger_queue = LIST_HEAD_INITIALIZER(logger_queue);
-static int logger_pipe[2];
+static int logger_pipe[2] = { -1, -1 };
static pthread_t logger_tid = 0;
struct logbuf {
@@ -580,12 +580,6 @@ cron_thr_logger(void *arg)
fd_set logger_set;
int logger_max_fd;
- if (pipe(logger_pipe)) {
- micron_log(LOG_ERR, "can't create control pipe: %s",
- strerror(errno));
- /* FIXME: Not the best solution, perhaps */
- exit(EXIT_FATAL);
- }
while (1) {
struct logbuf *bp, *prev;
fd_set rds;
@@ -676,8 +670,6 @@ cron_thr_logger(void *arg)
pthread_mutex_unlock(&logger_mutex);
}
micron_log(LOG_NOTICE, "logger thread terminating");
- close(logger_pipe[0]);
- close(logger_pipe[1]);
logger_tid = 0;
return NULL;
}
@@ -687,6 +679,12 @@ logger_enqueue(struct proctab *pt)
{
struct logbuf *bp;
+ if (logger_pipe[0] == -1 && pipe(logger_pipe)) {
+ micron_log(LOG_ERR, "can't create control pipe: %s",
+ strerror(errno));
+ /* FIXME: Not the best solution, perhaps */
+ exit(EXIT_FATAL);
+ }
if (!logger_tid) {
pthread_attr_t attr;
pthread_attr_init(&attr);

Return to:

Send suggestions and report system problems to the System administrator.