summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ask-password-api.c1
-rw-r--r--src/automount.c1
-rw-r--r--src/cryptsetup/cryptsetup-generator.c1
-rw-r--r--src/dbus.c1
-rw-r--r--src/getty-generator.c1
-rw-r--r--src/install.c1
-rw-r--r--src/journal/coredump.c1
-rw-r--r--src/journal/journald.c1
-rw-r--r--src/locale/localed.c1
-rw-r--r--src/login/logind-dbus.c1
-rw-r--r--src/login/logind-seat.c1
-rw-r--r--src/login/logind-session.c1
-rw-r--r--src/login/logind-user.c1
-rw-r--r--src/login/multi-seat-x.c1
-rw-r--r--src/machine-id-setup.c1
-rw-r--r--src/manager.c1
-rw-r--r--src/mount-setup.c1
-rw-r--r--src/mount.c1
-rw-r--r--src/nspawn.c1
-rw-r--r--src/path-lookup.c1
-rw-r--r--src/path.c1
-rw-r--r--src/random-seed.c1
-rw-r--r--src/rc-local-generator.c1
-rw-r--r--src/shared/cgroup-util.c1
-rw-r--r--src/shared/mkdir.c99
-rw-r--r--src/shared/mkdir.h28
-rw-r--r--src/shared/socket-util.c1
-rw-r--r--src/shared/util.c68
-rw-r--r--src/shared/util.h3
-rw-r--r--src/shutdown.c1
-rw-r--r--src/socket.c1
-rw-r--r--src/tmpfiles.c1
-rw-r--r--src/tty-ask-password-agent.c1
33 files changed, 156 insertions, 71 deletions
diff --git a/src/ask-password-api.c b/src/ask-password-api.c
index ce2f3cbe77..4b50d28d30 100644
--- a/src/ask-password-api.c
+++ b/src/ask-password-api.c
@@ -32,6 +32,7 @@
#include <sys/signalfd.h>
#include "util.h"
+#include "mkdir.h"
#include "strv.h"
#include "ask-password-api.h"
diff --git a/src/automount.c b/src/automount.c
index cf2fb60cdf..6857a6fd76 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -38,6 +38,7 @@
#include "bus-errors.h"
#include "special.h"
#include "label.h"
+#include "mkdir.h"
static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index ba59b49b01..5e92fb9af8 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -26,6 +26,7 @@
#include "log.h"
#include "util.h"
#include "unit-name.h"
+#include "mkdir.h"
const char *arg_dest = "/tmp";
diff --git a/src/dbus.c b/src/dbus.c
index 8e6e9fd520..ddf91f225a 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -29,6 +29,7 @@
#include "log.h"
#include "strv.h"
#include "cgroup.h"
+#include "mkdir.h"
#include "dbus-unit.h"
#include "dbus-job.h"
#include "dbus-manager.h"
diff --git a/src/getty-generator.c b/src/getty-generator.c
index 7fac43a0ba..dc979e9e8e 100644
--- a/src/getty-generator.c
+++ b/src/getty-generator.c
@@ -25,6 +25,7 @@
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#include "unit-name.h"
#include "virt.h"
diff --git a/src/install.c b/src/install.c
index 9256116805..45018043c2 100644
--- a/src/install.c
+++ b/src/install.c
@@ -26,6 +26,7 @@
#include <fnmatch.h>
#include "util.h"
+#include "mkdir.h"
#include "hashmap.h"
#include "set.h"
#include "path-lookup.h"
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 7dea66e6fd..5ecdef37a7 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -29,6 +29,7 @@
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#include "special.h"
#define COREDUMP_MAX (24*1024*1024)
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 442d2eb5ae..073bb890ab 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -35,6 +35,7 @@
#include <systemd/sd-messages.h>
#include <systemd/sd-daemon.h>
+#include "mkdir.h"
#include "hashmap.h"
#include "journal-file.h"
#include "socket-util.h"
diff --git a/src/locale/localed.c b/src/locale/localed.c
index e9f9f86878..e6aaa5cab3 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include "util.h"
+#include "mkdir.h"
#include "strv.h"
#include "dbus-common.h"
#include "polkit.h"
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index ea6b89faa1..1c6dc979ed 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -27,6 +27,7 @@
#include "logind.h"
#include "dbus-common.h"
#include "strv.h"
+#include "mkdir.h"
#include "polkit.h"
#include "special.h"
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index be37c1cc2e..906ede6cda 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -30,6 +30,7 @@
#include "logind-seat.h"
#include "logind-acl.h"
#include "util.h"
+#include "mkdir.h"
Seat *seat_new(Manager *m, const char *id) {
Seat *s;
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 4e0af8656b..641678210f 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -28,6 +28,7 @@
#include "logind-session.h"
#include "strv.h"
#include "util.h"
+#include "mkdir.h"
#include "cgroup-util.h"
#define IDLE_THRESHOLD_USEC (5*USEC_PER_MINUTE)
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 717f0e20a2..92ba2c2208 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -25,6 +25,7 @@
#include "logind-user.h"
#include "util.h"
+#include "mkdir.h"
#include "cgroup-util.h"
#include "hashmap.h"
#include "strv.h"
diff --git a/src/login/multi-seat-x.c b/src/login/multi-seat-x.c
index 7133e026dc..96554462a8 100644
--- a/src/login/multi-seat-x.c
+++ b/src/login/multi-seat-x.c
@@ -25,6 +25,7 @@
#include <libudev.h>
#include "util.h"
+#include "mkdir.h"
int main(int argc, char *argv[]) {
diff --git a/src/machine-id-setup.c b/src/machine-id-setup.c
index 0f97433804..0ee3cd7ae1 100644
--- a/src/machine-id-setup.c
+++ b/src/machine-id-setup.c
@@ -32,6 +32,7 @@
#include "machine-id-setup.h"
#include "macro.h"
#include "util.h"
+#include "mkdir.h"
#include "log.h"
#include "virt.h"
diff --git a/src/manager.c b/src/manager.c
index be47766a73..971990b037 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -49,6 +49,7 @@
#include "strv.h"
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#include "ratelimit.h"
#include "cgroup.h"
#include "mount-setup.h"
diff --git a/src/mount-setup.c b/src/mount-setup.c
index aaffb655ee..7d6cdf6cb4 100644
--- a/src/mount-setup.c
+++ b/src/mount-setup.c
@@ -36,6 +36,7 @@
#include "label.h"
#include "set.h"
#include "strv.h"
+#include "mkdir.h"
#ifndef TTY_GID
#define TTY_GID 5
diff --git a/src/mount.c b/src/mount.c
index ed0f819c7b..7dbeaf9cf0 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -31,6 +31,7 @@
#include "load-dropin.h"
#include "log.h"
#include "strv.h"
+#include "mkdir.h"
#include "mount-setup.h"
#include "unit-name.h"
#include "dbus-mount.h"
diff --git a/src/nspawn.c b/src/nspawn.c
index 66910bc684..9e21c5e8b5 100644
--- a/src/nspawn.c
+++ b/src/nspawn.c
@@ -43,6 +43,7 @@
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#include "audit.h"
#include "missing.h"
#include "cgroup-util.h"
diff --git a/src/path-lookup.c b/src/path-lookup.c
index 5464cedbbd..d33ebc71be 100644
--- a/src/path-lookup.c
+++ b/src/path-lookup.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include "util.h"
+#include "mkdir.h"
#include "strv.h"
#include "path-lookup.h"
diff --git a/src/path.c b/src/path.c
index e97cd09810..1d50885ed4 100644
--- a/src/path.c
+++ b/src/path.c
@@ -28,6 +28,7 @@
#include "unit.h"
#include "unit-name.h"
#include "path.h"
+#include "mkdir.h"
#include "dbus-path.h"
#include "special.h"
#include "bus-errors.h"
diff --git a/src/random-seed.c b/src/random-seed.c
index 8b43bacadc..c1022c719f 100644
--- a/src/random-seed.c
+++ b/src/random-seed.c
@@ -27,6 +27,7 @@
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#define POOL_SIZE_MIN 512
diff --git a/src/rc-local-generator.c b/src/rc-local-generator.c
index 56785cf402..108827d699 100644
--- a/src/rc-local-generator.c
+++ b/src/rc-local-generator.c
@@ -26,6 +26,7 @@
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#if defined(TARGET_FEDORA) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA)
#define SCRIPT_PATH "/etc/rc.d/rc.local"
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 904d300952..5647624e8d 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -34,6 +34,7 @@
#include "set.h"
#include "macro.h"
#include "util.h"
+#include "mkdir.h"
int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
char *fs;
diff --git a/src/shared/mkdir.c b/src/shared/mkdir.c
new file mode 100644
index 0000000000..e668cc2558
--- /dev/null
+++ b/src/shared/mkdir.c
@@ -0,0 +1,99 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "mkdir.h"
+#include "label.h"
+#include "util.h"
+#include "log.h"
+
+int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
+ struct stat st;
+
+ if (label_mkdir(path, mode) >= 0)
+ if (chmod_and_chown(path, mode, uid, gid) < 0)
+ return -errno;
+
+ if (lstat(path, &st) < 0)
+ return -errno;
+
+ if ((st.st_mode & 0777) != mode ||
+ st.st_uid != uid ||
+ st.st_gid != gid ||
+ !S_ISDIR(st.st_mode)) {
+ errno = EEXIST;
+ return -errno;
+ }
+
+ return 0;
+}
+
+int mkdir_parents(const char *path, mode_t mode) {
+ const char *p, *e;
+
+ assert(path);
+
+ /* Creates every parent directory in the path except the last
+ * component. */
+
+ p = path + strspn(path, "/");
+ for (;;) {
+ int r;
+ char *t;
+
+ e = p + strcspn(p, "/");
+ p = e + strspn(e, "/");
+
+ /* Is this the last component? If so, then we're
+ * done */
+ if (*p == 0)
+ return 0;
+
+ if (!(t = strndup(path, e - path)))
+ return -ENOMEM;
+
+ r = label_mkdir(t, mode);
+ free(t);
+
+ if (r < 0 && errno != EEXIST)
+ return -errno;
+ }
+}
+
+int mkdir_p(const char *path, mode_t mode) {
+ int r;
+
+ /* Like mkdir -p */
+
+ if ((r = mkdir_parents(path, mode)) < 0)
+ return r;
+
+ if (label_mkdir(path, mode) < 0 && errno != EEXIST)
+ return -errno;
+
+ return 0;
+}
diff --git a/src/shared/mkdir.h b/src/shared/mkdir.h
new file mode 100644
index 0000000000..c006e7ccdb
--- /dev/null
+++ b/src/shared/mkdir.h
@@ -0,0 +1,28 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef foomkdirhfoo
+#define foomkdirhfoo
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid);
+int mkdir_parents(const char *path, mode_t mode);
+int mkdir_p(const char *path, mode_t mode);
+#endif
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index acc4d33372..554f8ac965 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -34,6 +34,7 @@
#include "macro.h"
#include "util.h"
+#include "mkdir.h"
#include "socket-util.h"
#include "missing.h"
#include "label.h"
diff --git a/src/shared/util.c b/src/shared/util.c
index 563853fad6..fef58d5f30 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1591,74 +1591,6 @@ char *file_in_same_dir(const char *path, const char *filename) {
return r;
}
-int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
- struct stat st;
-
- if (label_mkdir(path, mode) >= 0)
- if (chmod_and_chown(path, mode, uid, gid) < 0)
- return -errno;
-
- if (lstat(path, &st) < 0)
- return -errno;
-
- if ((st.st_mode & 0777) != mode ||
- st.st_uid != uid ||
- st.st_gid != gid ||
- !S_ISDIR(st.st_mode)) {
- errno = EEXIST;
- return -errno;
- }
-
- return 0;
-}
-
-
-int mkdir_parents(const char *path, mode_t mode) {
- const char *p, *e;
-
- assert(path);
-
- /* Creates every parent directory in the path except the last
- * component. */
-
- p = path + strspn(path, "/");
- for (;;) {
- int r;
- char *t;
-
- e = p + strcspn(p, "/");
- p = e + strspn(e, "/");
-
- /* Is this the last component? If so, then we're
- * done */
- if (*p == 0)
- return 0;
-
- if (!(t = strndup(path, e - path)))
- return -ENOMEM;
-
- r = label_mkdir(t, mode);
- free(t);
-
- if (r < 0 && errno != EEXIST)
- return -errno;
- }
-}
-
-int mkdir_p(const char *path, mode_t mode) {
- int r;
-
- /* Like mkdir -p */
-
- if ((r = mkdir_parents(path, mode)) < 0)
- return r;
-
- if (label_mkdir(path, mode) < 0 && errno != EEXIST)
- return -errno;
-
- return 0;
-}
-
int rmdir_parents(const char *path, const char *stop) {
size_t l;
int r = 0;
diff --git a/src/shared/util.h b/src/shared/util.h
index e96d56dd2a..a45f54d661 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -242,9 +242,6 @@ char *delete_chars(char *s, const char *bad);
char *truncate_nl(char *s);
char *file_in_same_dir(const char *path, const char *filename);
-int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid);
-int mkdir_parents(const char *path, mode_t mode);
-int mkdir_p(const char *path, mode_t mode);
int parent_of_path(const char *path, char **parent);
diff --git a/src/shutdown.c b/src/shutdown.c
index 9f65b1dab0..b0c680a030 100644
--- a/src/shutdown.c
+++ b/src/shutdown.c
@@ -41,6 +41,7 @@
#include "log.h"
#include "umount.h"
#include "util.h"
+#include "mkdir.h"
#include "virt.h"
#include "watchdog.h"
diff --git a/src/socket.c b/src/socket.c
index bb75d960ab..5b24b3422b 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -36,6 +36,7 @@
#include "load-dropin.h"
#include "load-fragment.h"
#include "strv.h"
+#include "mkdir.h"
#include "unit-name.h"
#include "dbus-socket.h"
#include "missing.h"
diff --git a/src/tmpfiles.c b/src/tmpfiles.c
index 873bf233fd..5e85e37411 100644
--- a/src/tmpfiles.c
+++ b/src/tmpfiles.c
@@ -41,6 +41,7 @@
#include "log.h"
#include "util.h"
+#include "mkdir.h"
#include "strv.h"
#include "label.h"
#include "set.h"
diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c
index 13481b29e9..c928b5f454 100644
--- a/src/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent.c
@@ -33,6 +33,7 @@
#include <fcntl.h>
#include "util.h"
+#include "mkdir.h"
#include "conf-parser.h"
#include "utmp-wtmp.h"
#include "socket-util.h"