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