diff --git a/src/common.c b/src/common.c
index 7cc1d9d44e591f5a93a917016752350cf2d2a649..1af2f144647b191c38321ddd4aed4264b2c79577 100644 (file)
--- a/src/common.c
+++ b/src/common.c
* Authors:
* Florian octo Forster <octo at verplant.org>
* Niki W. Waibel <niki.waibel@gmx.net>
+ * Sebastian Harl <sh at tokkee.org>
+ * Michał Mirosław <mirq-linux at rere.qmqm.pl>
**/
#if HAVE_CONFIG_H
char *saveptr;
int last_is_file = 1;
int path_is_absolute = 0;
- int len;
+ size_t len;
int i;
/*
*/
if (fields[i][0] == '.')
{
- ERROR ("Cowardly refusing to create a directory that begins with a `.' (dot): `%s'", file_orig);
+ ERROR ("Cowardly refusing to create a directory that "
+ "begins with a `.' (dot): `%s'", file_orig);
return (-2);
}
return (-1);
}
- if (stat (dir, &statbuf) == -1)
- {
- if (errno == ENOENT)
+ while (42) {
+ if (stat (dir, &statbuf) == -1)
{
- if (mkdir (dir, 0755) == -1)
+ if (errno == ENOENT)
{
+ if (mkdir (dir, 0755) == 0)
+ break;
+
+ /* this might happen, if a different thread created
+ * the directory in the meantime
+ * => call stat() again to check for S_ISDIR() */
+ if (EEXIST == errno)
+ continue;
+
char errbuf[1024];
ERROR ("check_create_dir: mkdir (%s): %s", dir,
sstrerror (errno,
errbuf, sizeof (errbuf)));
return (-1);
}
+ else
+ {
+ char errbuf[1024];
+ ERROR ("check_create_dir: stat (%s): %s", dir,
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
+ return (-1);
+ }
}
- else
+ else if (!S_ISDIR (statbuf.st_mode))
{
- char errbuf[1024];
- ERROR ("stat (%s): %s", dir,
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
+ ERROR ("check_create_dir: `%s' exists but is not "
+ "a directory!", dir);
return (-1);
}
- }
- else if (!S_ISDIR (statbuf.st_mode))
- {
- ERROR ("stat (%s): Not a directory!", dir);
- return (-1);
+ break;
}
}
int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
{
char ident[128];
+
+ *ksp_ptr = NULL;
if (kc == NULL)
return (-1);
ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
+ *ksp_ptr = kstat_lookup (kc, module, instance, name);
if (*ksp_ptr == NULL)
{
- if ((*ksp_ptr = kstat_lookup (kc, module, instance, name)) == NULL)
- {
- ERROR ("Cound not find kstat %s", ident);
- return (-1);
- }
+ ERROR ("get_kstat: Cound not find kstat %s", ident);
+ return (-1);
+ }
- if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
- {
- WARNING ("kstat %s has wrong type", ident);
- *ksp_ptr = NULL;
- return (-1);
- }
+ if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
+ {
+ ERROR ("get_kstat: kstat %s has wrong type", ident);
+ *ksp_ptr = NULL;
+ return (-1);
}
#ifdef assert
if (kstat_read (kc, *ksp_ptr, NULL) == -1)
{
- WARNING ("kstat %s could not be read", ident);
+ ERROR ("get_kstat: kstat %s could not be read", ident);
return (-1);
}
if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
{
- WARNING ("kstat %s has wrong type", ident);
+ ERROR ("get_kstat: kstat %s has wrong type", ident);
return (-1);
}