[systemd-commits] 4 commits - src/core src/cryptsetup src/fstab-generator src/gpt-auto-generator src/login src/remount-fs src/shared

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Oct 3 19:21:25 PDT 2013


 src/core/execute.c                          |   35 ++++++++++++++++------------
 src/core/mount.c                            |    5 +++-
 src/cryptsetup/cryptsetup.c                 |   19 ++++-----------
 src/fstab-generator/fstab-generator.c       |   17 ++++---------
 src/gpt-auto-generator/gpt-auto-generator.c |    8 ++++++
 src/login/pam-module.c                      |    3 +-
 src/remount-fs/remount-fs.c                 |   13 +++-------
 src/shared/util.h                           |    7 +++++
 8 files changed, 57 insertions(+), 50 deletions(-)

New commits:
commit 77009452cfd25208509b14ea985e81fdf9f7d40e
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Oct 3 22:15:08 2013 -0400

    systemd: order remote mounts from mountinfo before remote-fs.target
    
    Usually the network is stopped before filesystems are umounted.
    Ordering network filesystems before remote-fs.target means that their
    unmounting will be performed earlier, and can terminate sucessfully.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=70002

diff --git a/src/core/mount.c b/src/core/mount.c
index 3d46557..93bfa99 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -1440,6 +1440,9 @@ static int mount_add_one(
 
         u = manager_get_unit(m, e);
         if (!u) {
+                const char* const target =
+                        fstype_is_network(fstype) ? SPECIAL_REMOTE_FS_TARGET : SPECIAL_LOCAL_FS_TARGET;
+
                 delete = true;
 
                 u = unit_new(m, sizeof(Mount));
@@ -1466,7 +1469,7 @@ static int mount_add_one(
                         goto fail;
                 }
 
-                r = unit_add_dependency_by_name(u, UNIT_BEFORE, SPECIAL_LOCAL_FS_TARGET, NULL, true);
+                r = unit_add_dependency_by_name(u, UNIT_BEFORE, target, NULL, true);
                 if (r < 0)
                         goto fail;
 

commit 5862d652ba14178cff46b8a8fc6c6d8392bf32b1
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Oct 3 22:13:55 2013 -0400

    Introduce _cleanup_endmntent_

diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 769c3e4..4f2f52a 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -236,31 +236,24 @@ finish:
 }
 
 static char *disk_mount_point(const char *label) {
-        char *mp = NULL;
         _cleanup_free_ char *device = NULL;
-        FILE *f = NULL;
+        _cleanup_endmntent_ FILE *f = NULL;
         struct mntent *m;
 
         /* Yeah, we don't support native systemd unit files here for now */
 
         if (asprintf(&device, "/dev/mapper/%s", label) < 0)
-                goto finish;
+                return NULL;
 
         f = setmntent("/etc/fstab", "r");
         if (!f)
-                goto finish;
+                return NULL;
 
         while ((m = getmntent(f)))
-                if (path_equal(m->mnt_fsname, device)) {
-                        mp = strdup(m->mnt_dir);
-                        break;
-                }
-
-finish:
-        if (f)
-                endmntent(f);
+                if (path_equal(m->mnt_fsname, device))
+                        return strdup(m->mnt_dir);
 
-        return mp;
+        return NULL;
 }
 
 static int get_password(const char *name, usec_t until, bool accept_cached, char ***passwords) {
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 9efccb9..9e7d55d 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -301,15 +301,12 @@ static int add_mount(
 }
 
 static int parse_fstab(const char *prefix, bool initrd) {
-        _cleanup_free_ char *fstab_path = NULL;
-        FILE *f;
+        char *fstab_path;
+        _cleanup_endmntent_ FILE *f;
         int r = 0;
         struct mntent *me;
 
-        fstab_path = strjoin(strempty(prefix), "/etc/fstab", NULL);
-        if (!fstab_path)
-                return log_oom();
-
+        fstab_path = strappenda(strempty(prefix), "/etc/fstab");
         f = setmntent(fstab_path, "r");
         if (!f) {
                 if (errno == ENOENT)
@@ -328,10 +325,8 @@ static int parse_fstab(const char *prefix, bool initrd) {
 
                 what = fstab_node_to_udev_node(me->mnt_fsname);
                 where = strjoin(strempty(prefix), me->mnt_dir, NULL);
-                if (!what || !where) {
-                        r = log_oom();
-                        goto finish;
-                }
+                if (!what || !where)
+                        return log_oom();
 
                 if (is_path(where))
                         path_kill_slashes(where);
@@ -369,8 +364,6 @@ static int parse_fstab(const char *prefix, bool initrd) {
                         r = k;
         }
 
-finish:
-        endmntent(f);
         return r;
 }
 
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index f432718..847637a 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -40,7 +40,7 @@
 
 int main(int argc, char *argv[]) {
         int ret = EXIT_FAILURE;
-        FILE *f = NULL;
+        _cleanup_endmntent_ FILE *f = NULL;
         struct mntent* me;
         Hashmap *pids = NULL;
 
@@ -57,13 +57,11 @@ int main(int argc, char *argv[]) {
 
         f = setmntent("/etc/fstab", "r");
         if (!f) {
-                if (errno == ENOENT) {
-                        ret = EXIT_SUCCESS;
-                        goto finish;
-                }
+                if (errno == ENOENT)
+                        return EXIT_SUCCESS;
 
                 log_error("Failed to open /etc/fstab: %m");
-                goto finish;
+                return EXIT_FAILURE;
         }
 
         pids = hashmap_new(trivial_hash_func, trivial_compare_func);
@@ -162,8 +160,5 @@ finish:
         if (pids)
                 hashmap_free_free(pids);
 
-        if (f)
-                endmntent(f);
-
         return ret;
 }
diff --git a/src/shared/util.h b/src/shared/util.h
index c2e6a68..c9d0782 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -39,6 +39,7 @@
 #include <stddef.h>
 #include <unistd.h>
 #include <locale.h>
+#include <mntent.h>
 
 #include "macro.h"
 #include "time-util.h"
@@ -578,6 +579,11 @@ static inline void umaskp(mode_t *u) {
         umask(*u);
 }
 
+static inline void endmntentp(FILE **f) {
+        if (*f)
+                endmntent(*f);
+}
+
 #define _cleanup_free_ _cleanup_(freep)
 #define _cleanup_fclose_ _cleanup_(fclosep)
 #define _cleanup_pclose_ _cleanup_(pclosep)
@@ -585,6 +591,7 @@ static inline void umaskp(mode_t *u) {
 #define _cleanup_closedir_ _cleanup_(closedirp)
 #define _cleanup_umask_ _cleanup_(umaskp)
 #define _cleanup_globfree_ _cleanup_(globfree)
+#define _cleanup_endmntent_ _cleanup_(endmntentp)
 
 _malloc_  _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
         if (_unlikely_(b == 0 || a > ((size_t) -1) / b))

commit 9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64c
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Oct 3 22:13:01 2013 -0400

    gpt-auto-generator: exit immediately if in container
    
    Otherwise we get an ugly warning when running systemd in
    a container.

diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index ca54925..d2b4213 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -38,6 +38,7 @@
 #include "libudev.h"
 #include "special.h"
 #include "unit-name.h"
+#include "virt.h"
 
 /* TODO:
  *
@@ -481,6 +482,13 @@ int main(int argc, char *argv[]) {
         umask(0022);
 
         if (in_initrd()) {
+                log_debug("In initrd, exiting.");
+                r = 0;
+                goto finish;
+        }
+
+        if (detect_container(NULL) > 0) {
+                log_debug("In a container, exiting.");
                 r = 0;
                 goto finish;
         }

commit 970edce6efcd3a0cf284aa0f43e0b27ecbd415f5
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Aug 28 08:01:30 2013 -0400

    execute: more debugging messages

diff --git a/src/core/execute.c b/src/core/execute.c
index 3979f35..3f7ca52 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -317,12 +317,12 @@ static int setup_input(const ExecContext *context, int socket_fd, bool apply_tty
         case EXEC_INPUT_TTY_FAIL: {
                 int fd, r;
 
-                if ((fd = acquire_terminal(
-                                     tty_path(context),
-                                     i == EXEC_INPUT_TTY_FAIL,
-                                     i == EXEC_INPUT_TTY_FORCE,
-                                     false,
-                                     (usec_t) -1)) < 0)
+                fd = acquire_terminal(tty_path(context),
+                                      i == EXEC_INPUT_TTY_FAIL,
+                                      i == EXEC_INPUT_TTY_FORCE,
+                                      false,
+                                      (usec_t) -1);
+                if (fd < 0)
                         return fd;
 
                 if (fd != STDIN_FILENO) {
@@ -748,6 +748,7 @@ static int setup_pam(
         char **e = NULL;
         bool close_session = false;
         pid_t pam_pid = 0, parent_pid;
+        int flags = 0;
 
         assert(name);
         assert(user);
@@ -760,6 +761,9 @@ static int setup_pam(
          * daemon. We do things this way to ensure that the main PID
          * of the daemon is the one we initially fork()ed. */
 
+        if (log_get_max_level() < LOG_PRI(LOG_DEBUG))
+                flags |= PAM_SILENT;
+
         pam_code = pam_start(name, user, &conv, &handle);
         if (pam_code != PAM_SUCCESS) {
                 handle = NULL;
@@ -772,11 +776,11 @@ static int setup_pam(
                         goto fail;
         }
 
-        pam_code = pam_acct_mgmt(handle, PAM_SILENT);
+        pam_code = pam_acct_mgmt(handle, flags);
         if (pam_code != PAM_SUCCESS)
                 goto fail;
 
-        pam_code = pam_open_session(handle, PAM_SILENT);
+        pam_code = pam_open_session(handle, flags);
         if (pam_code != PAM_SUCCESS)
                 goto fail;
 
@@ -850,7 +854,7 @@ static int setup_pam(
 
                 /* If our parent died we'll end the session */
                 if (getppid() != parent_pid) {
-                        pam_code = pam_close_session(handle, PAM_DATA_SILENT);
+                        pam_code = pam_close_session(handle, flags);
                         if (pam_code != PAM_SUCCESS)
                                 goto child_finish;
                 }
@@ -858,7 +862,7 @@ static int setup_pam(
                 r = 0;
 
         child_finish:
-                pam_end(handle, pam_code | PAM_DATA_SILENT);
+                pam_end(handle, pam_code | flags);
                 _exit(r);
         }
 
@@ -880,16 +884,19 @@ static int setup_pam(
         return 0;
 
 fail:
-        if (pam_code != PAM_SUCCESS)
+        if (pam_code != PAM_SUCCESS) {
+                log_error("PAM failed: %s", pam_strerror(handle, pam_code));
                 err = -EPERM;  /* PAM errors do not map to errno */
-        else
+        } else {
+                log_error("PAM failed: %m");
                 err = -errno;
+        }
 
         if (handle) {
                 if (close_session)
-                        pam_code = pam_close_session(handle, PAM_DATA_SILENT);
+                        pam_code = pam_close_session(handle, flags);
 
-                pam_end(handle, pam_code | PAM_DATA_SILENT);
+                pam_end(handle, pam_code | flags);
         }
 
         strv_free(e);
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index 49296b5..973daf7 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -199,7 +199,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
         dbus_error_init(&error);
 
-        /* pam_syslog(handle, LOG_INFO, "pam-systemd initializing"); */
+        if (debug)
+                pam_syslog(handle, LOG_INFO, "pam-systemd initializing");
 
         /* Make this a NOP on non-logind systems */
         if (!logind_running())



More information about the systemd-commits mailing list