|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[PATCH] rrdcached: Create the pidfile and (UNIX) socket directories as well.Those files may be located in a subdirectory of, e.g., /var/run/. To avoid the
need to manually create (and recreate, e.g. in case /var/run/ is on a tmpfs) that subdirectory, let the daemon handle the creation of those directories. --- program/src/rrd_daemon.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-) diff --git a/program/src/rrd_daemon.c b/program/src/rrd_daemon.c index 710fa01..7913a59 100644 --- a/program/src/rrd_daemon.c +++ b/program/src/rrd_daemon.c @@ -105,6 +105,7 @@ #include <assert.h> #include <sys/time.h> #include <time.h> +#include <libgen.h> #include <glib-2.0/glib.h> /* }}} */ @@ -348,12 +349,32 @@ static void install_signal_handlers(void) /* {{{ */ static int open_pidfile(char *action, int oflag) /* {{{ */ { int fd; - char *file; + const char *file; + char *file_copy, *dir; file = (config_pid_file != NULL) ? config_pid_file : LOCALSTATEDIR "/run/rrdcached.pid"; + /* dirname may modify its argument */ + file_copy = strdup(file); + if (file_copy == NULL) + { + fprintf(stderr, "rrdcached: strdup(): %s\n", + rrd_strerror(errno)); + return -1; + } + + dir = dirname(file_copy); + if (rrd_mkdir_p(dir, 0777) != 0) + { + fprintf(stderr, "Failed to create pidfile directory '%s': %s\n", + dir, rrd_strerror(errno)); + return -1; + } + + free(file_copy); + fd = open(file, oflag, S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH); if (fd < 0) fprintf(stderr, "rrdcached: can't %s pid file '%s' (%s)\n", @@ -2239,11 +2260,31 @@ static int open_listen_socket_unix (const listen_socket_t *sock) /* {{{ */ listen_socket_t *temp; int status; const char *path; + char *path_copy, *dir; path = sock->addr; if (strncmp(path, "unix:", strlen("unix:")) == 0) path += strlen("unix:"); + /* dirname may modify its argument */ + path_copy = strdup(path); + if (path_copy == NULL) + { + fprintf(stderr, "rrdcached: strdup(): %s\n", + rrd_strerror(errno)); + return (-1); + } + + dir = dirname(path_copy); + if (rrd_mkdir_p(dir, 0777) != 0) + { + fprintf(stderr, "Failed to create socket directory '%s': %s\n", + dir, rrd_strerror(errno)); + return (-1); + } + + free(path_copy); + temp = (listen_socket_t *) rrd_realloc (listen_fds, sizeof (listen_fds[0]) * (listen_fds_num + 1)); if (temp == NULL) -- 1.6.5.rc2 _______________________________________________ rrd-developers mailing list rrd-developers@... https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers |
|
|
Re: [PATCH] rrdcached: Create the pidfile and (UNIX) socket directories as well.Yesterday Sebastian Harl wrote:
> Those files may be located in a subdirectory of, e.g., /var/run/. To avoid the > need to manually create (and recreate, e.g. in case /var/run/ is on a tmpfs) > that subdirectory, let the daemon handle the creation of those directories. > --- > program/src/rrd_daemon.c | 43 ++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 42 insertions(+), 1 deletions(-) thanks, applied, tobi -- Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland http://it.oetiker.ch tobi@... ++41 62 775 9902 / sb: -9900 _______________________________________________ rrd-developers mailing list rrd-developers@... https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers |
| Free embeddable forum powered by Nabble | Forum Help |