[systemd-commits] 3 commits - Makefile.am src/core src/shared units/rescue.service.m4.in units/rescue.target

Lennart Poettering lennart at kemper.freedesktop.org
Tue May 22 07:16:18 PDT 2012


 Makefile.am                |    6 +--
 src/core/switch-root.c     |    4 +-
 src/shared/util.c          |   76 +++++++++++++++------------------------------
 units/rescue.service.m4.in |    2 -
 units/rescue.target        |    4 +-
 5 files changed, 36 insertions(+), 56 deletions(-)

New commits:
commit b46178e5c2b95062b84257c0601c21c400089c09
Author: Harald Hoyer <harald at redhat.com>
Date:   Tue May 22 15:28:45 2012 +0200

    switch-root: do not use close old_root_fd after rm_rf_children()
    
    rm_rf_children() has already closed the fd with closedir().

diff --git a/src/core/switch-root.c b/src/core/switch-root.c
index ed0a31e..9832a52 100644
--- a/src/core/switch-root.c
+++ b/src/core/switch-root.c
@@ -111,8 +111,10 @@ int switch_root(const char *new_root) {
 
                 if (fstat(old_root_fd, &rb) < 0)
                         log_warning("Failed to stat old root directory, leaving: %m");
-                else
+                else {
                         rm_rf_children(old_root_fd, false, false, &rb);
+                        old_root_fd = -1;
+                }
         }
 
         r = 0;

commit 7925c22a78d44b705c22a0d0972fb151d540697b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue May 22 16:14:34 2012 +0200

    util: make sure to fstatat() at most once in rm_rf_children()

diff --git a/src/shared/util.c b/src/shared/util.c
index 4b84149..7d98dc6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3146,7 +3146,7 @@ int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root
         assert(fd >= 0);
 
         /* This returns the first error we run into, but nevertheless
-         * tries to go on */
+         * tries to go on. This closes the passed fd. */
 
         d = fdopendir(fd);
         if (!d) {
@@ -3157,7 +3157,8 @@ int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root
 
         for (;;) {
                 struct dirent buf, *de;
-                bool is_dir, keep_around = false;
+                bool is_dir, keep_around;
+                struct stat st;
                 int r;
 
                 r = readdir_r(d, &buf, &de);
@@ -3172,73 +3173,50 @@ int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root
                 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
                         continue;
 
-                if (de->d_type == DT_UNKNOWN) {
-                        struct stat st;
-
+                if (de->d_type == DT_UNKNOWN ||
+                    honour_sticky ||
+                    (de->d_type == DT_DIR && root_dev)) {
                         if (fstatat(fd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
                                 if (ret == 0 && errno != ENOENT)
                                         ret = -errno;
                                 continue;
                         }
 
-                        if (honour_sticky)
-                                keep_around =
-                                        (st.st_uid == 0 || st.st_uid == getuid()) &&
-                                        (st.st_mode & S_ISVTX);
-
                         is_dir = S_ISDIR(st.st_mode);
-
+                        keep_around =
+                                honour_sticky &&
+                                (st.st_uid == 0 || st.st_uid == getuid()) &&
+                                (st.st_mode & S_ISVTX);
                 } else {
-                        if (honour_sticky) {
-                                struct stat st;
-
-                                if (fstatat(fd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
-                                        if (ret == 0 && errno != ENOENT)
-                                                ret = -errno;
-                                        continue;
-                                }
-
-                                keep_around =
-                                        (st.st_uid == 0 || st.st_uid == getuid()) &&
-                                        (st.st_mode & S_ISVTX);
-                        }
-
                         is_dir = de->d_type == DT_DIR;
+                        keep_around = false;
                 }
 
                 if (is_dir) {
                         int subdir_fd;
-                        struct stat sb;
-                        if (root_dev) {
-                                if (fstatat(fd, de->d_name, &sb, AT_SYMLINK_NOFOLLOW)) {
-                                        if (ret == 0 && errno != ENOENT)
-                                                ret = -errno;
-                                        continue;
-                                }
-                        }
 
                         /* if root_dev is set, remove subdirectories only, if device is same as dir */
-                        if ((root_dev == NULL) || (sb.st_dev == root_dev->st_dev)) {
+                        if (root_dev && st.st_dev != root_dev->st_dev)
+                                continue;
 
-                                subdir_fd = openat(fd, de->d_name,
-                                                   O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
-                                if (subdir_fd < 0) {
+                        subdir_fd = openat(fd, de->d_name,
+                                           O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
+                        if (subdir_fd < 0) {
+                                if (ret == 0 && errno != ENOENT)
+                                        ret = -errno;
+                                continue;
+                        }
+
+                        r = rm_rf_children(subdir_fd, only_dirs, honour_sticky, root_dev);
+                        if (r < 0 && ret == 0)
+                                ret = r;
+
+                        if (!keep_around)
+                                if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) {
                                         if (ret == 0 && errno != ENOENT)
                                                 ret = -errno;
-                                        continue;
                                 }
 
-                                r = rm_rf_children(subdir_fd, only_dirs, honour_sticky, root_dev);
-                                if (r < 0 && ret == 0)
-                                        ret = r;
-
-                                if (!keep_around)
-                                        if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) {
-                                                if (ret == 0 && errno != ENOENT)
-                                                        ret = -errno;
-                                        }
-                        }
-
                 } else if (!only_dirs && !keep_around) {
 
                         if (unlinkat(fd, de->d_name, 0) < 0) {

commit 49e7f0277444ca10623fe790ff754f7c006f8c64
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue May 22 16:12:25 2012 +0200

    rescue: don't pull in sockets
    
    In rescue mode let's not establish all sockets, so that we don't end up
    starting a lot of additional services automatically.
    
    Instead of pulling in basic.target we now only pull in sysinit.target
    which pulls in local-fs.target and swap.target. That way rescue mode has
    all the really basic setup around, but normal services are not started
    and not autostarted either.

diff --git a/Makefile.am b/Makefile.am
index e9ac82c..4c1b295 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1446,9 +1446,9 @@ systemd-install-hook:
 	mkdir -p $(DESTDIR)$(systemunitdir)/sockets.target.wants
 	ln -sf ../systemd-udev-control.socket $(DESTDIR)$(systemunitdir)/sockets.target.wants/systemd-udev-control.socket
 	ln -sf ../systemd-udev-kernel.socket $(DESTDIR)$(systemunitdir)/sockets.target.wants/systemd-udev-kernel.socket
-	mkdir -p $(DESTDIR)$(systemunitdir)/basic.target.wants
-	ln -sf ../systemd-udev.service $(DESTDIR)$(systemunitdir)/basic.target.wants/systemd-udev.service
-	ln -sf ../systemd-udev-trigger.service $(DESTDIR)$(systemunitdir)/basic.target.wants/systemd-udev-trigger.service
+	mkdir -p $(DESTDIR)$(systemunitdir)/sysinit.target.wants
+	ln -sf ../systemd-udev.service $(DESTDIR)$(systemunitdir)/sysinit.target.wants/systemd-udev.service
+	ln -sf ../systemd-udev-trigger.service $(DESTDIR)$(systemunitdir)/sysinit.target.wants/systemd-udev-trigger.service
 
 INSTALL_DATA_HOOKS += systemd-install-hook
 
diff --git a/units/rescue.service.m4.in b/units/rescue.service.m4.in
index 75b9fde..5fb82e6 100644
--- a/units/rescue.service.m4.in
+++ b/units/rescue.service.m4.in
@@ -9,7 +9,7 @@
 Description=Rescue Shell
 DefaultDependencies=no
 Conflicts=shutdown.target
-After=basic.target plymouth-start.service
+After=sysinit.target plymouth-start.service
 Before=shutdown.target
 
 [Service]
diff --git a/units/rescue.target b/units/rescue.target
index c17a4e1..3f59b14 100644
--- a/units/rescue.target
+++ b/units/rescue.target
@@ -8,8 +8,8 @@
 [Unit]
 Description=Rescue Mode
 Documentation=man:systemd.special(7)
-Requires=basic.target rescue.service
-After=basic.target rescue.service
+Requires=sysinit.target rescue.service
+After=sysinit.target rescue.service
 AllowIsolate=yes
 
 [Install]



More information about the systemd-commits mailing list