From 3b3b199302393e4346cbc2c3cf33e6212f14e3b0 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Wed, 19 Dec 2018 14:19:56 +0100 Subject: [PATCH] Replaced /tmp/elog-shell by unique temporary file to avoid problems if several elogd servers run on the same computer. Thanks to Kristjan J. --- src/elogd.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/elogd.c b/src/elogd.c index a746263d..93b94f40 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -937,7 +937,13 @@ int my_shell(char *cmd, char *result, int size) pid_t child_pid; int fh, status, wait_status; char str[1024]; + char tmp_filename[1024]; + if (tmpnam(tmp_filename)==NULL) { + eprintf("Error getting TMP file name.\n"); + return 0; + } + if ((child_pid = fork()) < 0) return 0; else if (child_pid > 0) { @@ -948,14 +954,14 @@ int my_shell(char *cmd, char *result, int size) /* read back result */ memset(result, 0, size); - fh = open("/tmp/elog-shell", O_RDONLY); + fh = open(tmp_filename, O_RDONLY); if (fh > 0) { read(fh, result, size-1); close(fh); } /* remove temporary file */ - remove("/tmp/elog-shell"); + remove(tmp_filename); /* strip trailing CR/LF */ while (strlen(result) > 0 && (result[strlen(result) - 1] == '\r' || result[strlen(result) - 1] == '\n')) @@ -998,7 +1004,7 @@ int my_shell(char *cmd, char *result, int size) } /* execute shell with redirection to /tmp/elog-shell */ - sprintf(str, "/bin/sh -c \"%s\" > /tmp/elog-shell 2>&1", cmd); + sprintf(str, "/bin/sh -c \"%s\" > %s 2>&1", cmd, tmp_filename); if (get_verbose() >= VERBOSE_INFO) { efputs("Going to execute: ");