summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2003-02-24 02:09:02 +0000
committergad <gad@FreeBSD.org>2003-02-24 02:09:02 +0000
commit371919ba7e1991c5112be6f568369cd5e2a66d50 (patch)
tree62ce372ad41a6972ab646b8bca8e8c78258d849e /usr.sbin
parent5c4b278a9c2a732748764c7b374dc597557b41f7 (diff)
downloadFreeBSD-src-371919ba7e1991c5112be6f568369cd5e2a66d50.zip
FreeBSD-src-371919ba7e1991c5112be6f568369cd5e2a66d50.tar.gz
1) Fix so -a honors the -n ("do nothing") option. Before, if the directory
given for -a did not exist, then newsyslog would always try to create it, even if -n was specified. 2) When -a processing *does* create the directory, have it check the result from mkdir(), and immediately error-out if that failed. PR: bin/46974 MFC after: 3 weeks
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/newsyslog/newsyslog.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index a9eeb97..ab52ed8 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1186,6 +1186,7 @@ movefile(char *from, char *to, int perm, int owner_uid, int group_gid)
static void
createdir(char *dirpart)
{
+ int res;
char *s, *d;
char mkdirpath[MAXPATHLEN];
struct stat st;
@@ -1195,14 +1196,25 @@ createdir(char *dirpart)
for (;;) {
*d++ = *s++;
- if (*s == '/' || *s == '\0') {
- *d = '\0';
- if (lstat(mkdirpath, &st))
- mkdir(mkdirpath, 0755);
+ if (*s != '/' && *s != '\0')
+ continue;
+ *d = '\0';
+ res = lstat(mkdirpath, &st);
+ if (res != 0) {
+ if (noaction) {
+ printf("mkdir %s\n", mkdirpath);
+ } else {
+ res = mkdir(mkdirpath, 0755);
+ if (res != 0)
+ err(1, "Error on mkdir(\"%s\") for -a",
+ mkdirpath);
+ }
}
if (*s == '\0')
break;
}
+ if (verbose)
+ printf("created directory '%s' for -a\n", dirpart);
}
/*-
OpenPOWER on IntegriCloud