From: val4oss Date: Wed, 19 Nov 2025 09:18:30 +0000 (+0100) Subject: pam_systemd: fix OSC write failure message appearing in error logs X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6c3249293221c9bade4fd645da80b1566069d73b;p=thirdparty%2Fsystemd.git pam_systemd: fix OSC write failure message appearing in error logs 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. --- diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index e4eb72553e5..267839197b2 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -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) { diff --git a/src/shared/pam-util.h b/src/shared/pam-util.h index 8f31ffd2f80..204eab04cad 100644 --- a/src/shared/pam-util.h +++ b/src/shared/pam-util.h @@ -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.");