X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd.c;h=1ccc1c08e1eca87d4975351d1764fe2116c38031;hb=1122c8fd30065b5990a5b798b7bfd8891736def9;hp=cdb0ee89d1053ab09a4a8bda068410e31191c189;hpb=9cb2694409620ae217ede92f78fe45c9eba83504;p=collectd.git diff --git a/src/collectd.c b/src/collectd.c index cdb0ee89..1ccc1c08 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -79,6 +79,7 @@ static void sig_usr1_handler (int __attribute__((unused)) signal) pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&thread, &attr, do_flush, NULL); + pthread_attr_destroy (&attr); } static int init_hostname (void) @@ -117,7 +118,7 @@ static int init_hostname (void) ERROR ("Looking up \"%s\" failed. You have set the " "\"FQDNLookup\" option, but I cannot resolve " "my hostname to a fully qualified domain " - "name. Please fix you network " + "name. Please fix the network " "configuration.", hostname_g); return (-1); } @@ -164,10 +165,11 @@ static int init_global_variables (void) static int change_basedir (const char *orig_dir) { - char *dir = strdup (orig_dir); - int dirlen; + char *dir; + size_t dirlen; int status; + dir = strdup (orig_dir); if (dir == NULL) { char errbuf[1024]; @@ -180,43 +182,47 @@ static int change_basedir (const char *orig_dir) while ((dirlen > 0) && (dir[dirlen - 1] == '/')) dir[--dirlen] = '\0'; - if (dirlen <= 0) + if (dirlen <= 0) { + free (dir); return (-1); + } status = chdir (dir); - free (dir); + if (status == 0) + { + free (dir); + return (0); + } + else if (errno != ENOENT) + { + char errbuf[1024]; + ERROR ("change_basedir: chdir (%s): %s", dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + free (dir); + return (-1); + } + status = mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO); if (status != 0) { - if (errno == ENOENT) - { - if (mkdir (orig_dir, 0755) == -1) - { - char errbuf[1024]; - ERROR ("change_basedir: mkdir (%s): %s", orig_dir, - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); - } - else if (chdir (orig_dir) == -1) - { - char errbuf[1024]; - ERROR ("chdir (%s): %s", orig_dir, - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); - } - } - else - { - char errbuf[1024]; - ERROR ("chdir (%s): %s", orig_dir, - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); - } + char errbuf[1024]; + ERROR ("change_basedir: mkdir (%s): %s", dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + free (dir); + return (-1); + } + + status = chdir (dir); + if (status != 0) + { + char errbuf[1024]; + ERROR ("change_basedir: chdir (%s): %s", dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + free (dir); + return (-1); } + free (dir); return (0); } /* static int change_basedir (char *dir) */ @@ -380,8 +386,9 @@ static int pidfile_create (void) static int pidfile_remove (void) { const char *file = global_option_get ("PIDFile"); + if (file == NULL) + return 0; - DEBUG ("unlink (%s)", (file != NULL) ? file : ""); return (unlink (file)); } /* static int pidfile_remove (const char *file) */ #endif /* COLLECT_DAEMON */