ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
65878a
From a454e9c726630fe4811a1c93b2d88b0e77b3094f Mon Sep 17 00:00:00 2001
65878a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
65878a
Date: Wed, 28 Aug 2013 08:01:30 -0400
65878a
Subject: [PATCH] execute: more debugging messages
65878a
65878a
---
65878a
 src/core/execute.c     | 35 +++++++++++++++++++++--------------
65878a
 src/login/pam-module.c |  3 ++-
65878a
 2 files changed, 23 insertions(+), 15 deletions(-)
65878a
65878a
diff --git a/src/core/execute.c b/src/core/execute.c
65878a
index a53ef48..981b9e4 100644
65878a
--- a/src/core/execute.c
65878a
+++ b/src/core/execute.c
65878a
@@ -317,12 +317,12 @@ static int setup_input(const ExecContext *context, int socket_fd, bool apply_tty
65878a
         case EXEC_INPUT_TTY_FAIL: {
65878a
                 int fd, r;
65878a
 
65878a
-                if ((fd = acquire_terminal(
65878a
-                                     tty_path(context),
65878a
-                                     i == EXEC_INPUT_TTY_FAIL,
65878a
-                                     i == EXEC_INPUT_TTY_FORCE,
65878a
-                                     false,
65878a
-                                     (usec_t) -1)) < 0)
65878a
+                fd = acquire_terminal(tty_path(context),
65878a
+                                      i == EXEC_INPUT_TTY_FAIL,
65878a
+                                      i == EXEC_INPUT_TTY_FORCE,
65878a
+                                      false,
65878a
+                                      (usec_t) -1);
65878a
+                if (fd < 0)
65878a
                         return fd;
65878a
 
65878a
                 if (fd != STDIN_FILENO) {
65878a
@@ -748,6 +748,7 @@ static int setup_pam(
65878a
         char **e = NULL;
65878a
         bool close_session = false;
65878a
         pid_t pam_pid = 0, parent_pid;
65878a
+        int flags = 0;
65878a
 
65878a
         assert(name);
65878a
         assert(user);
65878a
@@ -760,6 +761,9 @@ static int setup_pam(
65878a
          * daemon. We do things this way to ensure that the main PID
65878a
          * of the daemon is the one we initially fork()ed. */
65878a
 
65878a
+        if (log_get_max_level() < LOG_PRI(LOG_DEBUG))
65878a
+                flags |= PAM_SILENT;
65878a
+
65878a
         pam_code = pam_start(name, user, &conv, &handle);
65878a
         if (pam_code != PAM_SUCCESS) {
65878a
                 handle = NULL;
65878a
@@ -772,11 +776,11 @@ static int setup_pam(
65878a
                         goto fail;
65878a
         }
65878a
 
65878a
-        pam_code = pam_acct_mgmt(handle, PAM_SILENT);
65878a
+        pam_code = pam_acct_mgmt(handle, flags);
65878a
         if (pam_code != PAM_SUCCESS)
65878a
                 goto fail;
65878a
 
65878a
-        pam_code = pam_open_session(handle, PAM_SILENT);
65878a
+        pam_code = pam_open_session(handle, flags);
65878a
         if (pam_code != PAM_SUCCESS)
65878a
                 goto fail;
65878a
 
65878a
@@ -850,7 +854,7 @@ static int setup_pam(
65878a
 
65878a
                 /* If our parent died we'll end the session */
65878a
                 if (getppid() != parent_pid) {
65878a
-                        pam_code = pam_close_session(handle, PAM_DATA_SILENT);
65878a
+                        pam_code = pam_close_session(handle, flags);
65878a
                         if (pam_code != PAM_SUCCESS)
65878a
                                 goto child_finish;
65878a
                 }
65878a
@@ -858,7 +862,7 @@ static int setup_pam(
65878a
                 r = 0;
65878a
 
65878a
         child_finish:
65878a
-                pam_end(handle, pam_code | PAM_DATA_SILENT);
65878a
+                pam_end(handle, pam_code | flags);
65878a
                 _exit(r);
65878a
         }
65878a
 
65878a
@@ -880,16 +884,19 @@ static int setup_pam(
65878a
         return 0;
65878a
 
65878a
 fail:
65878a
-        if (pam_code != PAM_SUCCESS)
65878a
+        if (pam_code != PAM_SUCCESS) {
65878a
+                log_error("PAM failed: %s", pam_strerror(handle, pam_code));
65878a
                 err = -EPERM;  /* PAM errors do not map to errno */
65878a
-        else
65878a
+        } else {
65878a
+                log_error("PAM failed: %m");
65878a
                 err = -errno;
65878a
+        }
65878a
 
65878a
         if (handle) {
65878a
                 if (close_session)
65878a
-                        pam_code = pam_close_session(handle, PAM_DATA_SILENT);
65878a
+                        pam_code = pam_close_session(handle, flags);
65878a
 
65878a
-                pam_end(handle, pam_code | PAM_DATA_SILENT);
65878a
+                pam_end(handle, pam_code | flags);
65878a
         }
65878a
 
65878a
         strv_free(e);
65878a
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
65878a
index 49296b5..973daf7 100644
65878a
--- a/src/login/pam-module.c
65878a
+++ b/src/login/pam-module.c
65878a
@@ -199,7 +199,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
65878a
 
65878a
         dbus_error_init(&error);
65878a
 
65878a
-        /* pam_syslog(handle, LOG_INFO, "pam-systemd initializing"); */
65878a
+        if (debug)
65878a
+                pam_syslog(handle, LOG_INFO, "pam-systemd initializing");
65878a
 
65878a
         /* Make this a NOP on non-logind systems */
65878a
         if (!logind_running())