summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5db9666)
raw | patch | inline | side by side (parent: 5db9666)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Sun, 4 Oct 2009 11:27:44 +0000 (11:27 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Sun, 4 Oct 2009 11:27:44 +0000 (11:27 +0000) |
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. -- Sebastian Harl
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1921 a5681a0c-68f1-0310-ab6d-d61299d08faa
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. -- Sebastian Harl
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1921 a5681a0c-68f1-0310-ab6d-d61299d08faa
program/src/rrd_daemon.c | patch | blob | history |
index 710fa017d747210882aeba6e9ecdba188b93c933..7913a599bf3995e70288a30666fe992c2804b386 100644 (file)
--- a/program/src/rrd_daemon.c
+++ b/program/src/rrd_daemon.c
#include <assert.h>
#include <sys/time.h>
#include <time.h>
+#include <libgen.h>
#include <glib-2.0/glib.h>
/* }}} */
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",
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)