]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pam_systemd: fix OSC write failure message appearing in error logs 39791/head
authorval4oss <val4oss@pm.me>
Wed, 19 Nov 2025 09:18:30 +0000 (10:18 +0100)
committerval4oss <val4oss@pm.me>
Thu, 20 Nov 2025 10:43:01 +0000 (11:43 +0100)
Create and use new function pam_debug_syslog_errno() instead to ensure the
message only appears when debug mode is enabled. Pass the debug flag to
open_osc_context() and close_osc_context() to support this change.

src/login/pam_systemd.c
src/shared/pam-util.h

index e4eb72553e5da9242320fef4521e3122d8f6264e..267839197b28720f788321c65a60dadc1b3f3f2b 100644 (file)
@@ -1599,7 +1599,7 @@ static int setup_environment(
         return setup_runtime_directory(handle, ur, runtime_directory, area);
 }
 
-static int open_osc_context(pam_handle_t *handle, const char *session_type, UserRecord *ur) {
+static int open_osc_context(pam_handle_t *handle, const char *session_type, UserRecord *ur, bool debug) {
         int r;
 
         assert(handle);
@@ -1628,7 +1628,7 @@ static int open_osc_context(pam_handle_t *handle, const char *session_type, User
          * so that we don't delay tty hang-up. */
         _cleanup_close_ int tty_opath_fd = fd_reopen(STDOUT_FILENO, O_PATH|O_CLOEXEC);
         if (tty_opath_fd < 0)
-                pam_syslog_errno(handle, LOG_DEBUG, tty_opath_fd, "Failed to pin TTY, ignoring: %m");
+                pam_debug_syslog_errno(handle, debug, tty_opath_fd, "Failed to pin TTY, ignoring: %m");
         else
                 tty_opath_fd = fd_move_above_stdio(tty_opath_fd);
 
@@ -1670,7 +1670,7 @@ static int open_osc_context(pam_handle_t *handle, const char *session_type, User
         return PAM_SUCCESS;
 }
 
-static int close_osc_context(pam_handle_t *handle) {
+static int close_osc_context(pam_handle_t *handle, bool debug) {
         int r;
 
         assert(handle);
@@ -1695,7 +1695,7 @@ static int close_osc_context(pam_handle_t *handle) {
         /* Now open the original TTY again, so that we can write on it */
         _cleanup_close_ int fd = fd_reopen(tty_opath_fd, O_WRONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0) {
-                pam_syslog_errno(handle, LOG_DEBUG, fd, "Failed to reopen TTY, ignoring: %m");
+                pam_debug_syslog_errno(handle, debug, fd, "Failed to reopen TTY, ignoring: %m");
                 return PAM_SUCCESS;
         }
 
@@ -1715,7 +1715,7 @@ static int close_osc_context(pam_handle_t *handle) {
         /* When we are closing things, the TTY might not take our writes anymore. Accept that gracefully. */
         r = loop_write(fd, osc, SIZE_MAX);
         if (r < 0)
-                pam_syslog_errno(handle, LOG_DEBUG, r, "Failed to write OSC sequence to TTY, ignoring: %m");
+                pam_debug_syslog_errno(handle, debug, r, "Failed to write OSC sequence to TTY, ignoring: %m");
 
         return PAM_SUCCESS;
 }
@@ -1807,7 +1807,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (r != PAM_SUCCESS)
                 return r;
 
-        return open_osc_context(handle, c.type, ur);
+        return open_osc_context(handle, c.type, ur, debug);
 }
 
 _public_ PAM_EXTERN int pam_sm_close_session(
@@ -1844,7 +1844,7 @@ _public_ PAM_EXTERN int pam_sm_close_session(
                 return pam_syslog_pam_error(handle, LOG_ERR, r,
                                             "Failed to get PAM systemd.existing data: @PAMERR@");
 
-        (void) close_osc_context(handle);
+        (void) close_osc_context(handle, debug);
 
         id = pam_getenv(handle, "XDG_SESSION_ID");
         if (id && !existing) {
index 8f31ffd2f809306df249a62d95dfaa43c4ee4c87..204eab04cade289f0091680a445f27895ba21b32 100644 (file)
@@ -35,13 +35,20 @@ int pam_syslog_errno(pam_handle_t *handle, int level, int error, const char *for
 
 int pam_syslog_pam_error(pam_handle_t *handle, int level, int error, const char *format, ...) _printf_(4,5);
 
-/* Call pam_vsyslog if debug is enabled */
+/* Call sym_pam_syslog if debug is enabled */
 #define pam_debug_syslog(handle, debug, fmt, ...)                       \
         ({                                                              \
                 if (debug)                                              \
                         sym_pam_syslog(handle, LOG_DEBUG, fmt, ## __VA_ARGS__); \
         })
 
+/* Call pam_syslog_errno if debug is enabled */
+#define pam_debug_syslog_errno(handle, debug, error, fmt, ...)          \
+        ({                                                              \
+                if (debug)                                              \
+                        pam_syslog_errno(handle, LOG_DEBUG, error, fmt, ## __VA_ARGS__); \
+        })
+
 static inline int pam_log_oom(pam_handle_t *handle) {
         /* This is like log_oom(), but uses PAM logging */
         return pam_syslog_errno(handle, LOG_ERR, ENOMEM, "Out of memory.");