From nobody Wed Nov 18 07:29:20 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTtX048ssz6ywXw for ; Wed, 18 Nov 2026 07:29:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTtX01sZWz4GBJ for ; Wed, 18 Nov 2026 07:29:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794986960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8rORXR9mFhYAiWUnTk0fJvo7svLbL9BZ6WNGee8B/kQ=; b=cNV9pNC71foQpM/ZSlE7q9gxzZDNqYFxpPoONLS8Vmc8bdCb5VTGva87K8WlORG/1062AP C8C4sikIjSn4nc8GnruGS1g3g7DtNhR7Fn5ivtumcTRedNbRV4HlHL5qryp4XexatMG73e HZ5oKROdVPp3zVDisjuxe+OGREwh/UW4eHkJLNvo4CrtyS6ee6vS58XZ6OLsPmoPgldmkL m2iUfdDxQ++qJES7Ao67nr3dFUUHVfCfmqCDZ8+ynlg+af90n2nSRthPfLQCuEIc74fDcA dE66zSOKeMWElHdWlKOolrFxdzqjz3fxG+KdaxsZ/6LtQLz6u/AzJ53fYESGBw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794986960; b=Xt+SpQ337H3XLctGQuQd1TYzcbC+QJ6o3ev/QUlztZRS+QDwqcB0Kioig9p+6zFWQNnPCr oITv4zfX5XuuoNxRvdgJcbLHa5l0gjAByeUrT+WBhHKIkZEGx6IKay97s3aXGMh0Zpcb5q 1pitRHya0u/BHV4NIOiZAAwolhrpSDEmXkrtc5neF20GxPjnHGp7ygMNsQr6i4+l1AVwgy /z0nn2ibYg/cCpkeCD7onXzPHdstKg93AwwZx9nYXxOuQeDNRHqUSGN2LFI31huaEFilUI U5fDChaYFOVKP5BzXscycAwZUjO1bgTTJvEn53EpNimx+hZZcfUlbF7UnyUvRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794986960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8rORXR9mFhYAiWUnTk0fJvo7svLbL9BZ6WNGee8B/kQ=; b=WOT8gl9icl0GK2IhY5Jn3M48SPwCxkvllEtDAe/0BpIkxKNdw58DdQ1RJQozAZR9oHtdjR 66+V2gwrIVEmPpnpGa8BZLp7rDLEHgbtUdF5lnxV4b2unq9jG/aKpxuJOXp+IE7TSyEYcu LKd/tbj+3K+tjzioqY0Eg+SGLkKCMGfklGaptCdMKTc1S7DHHMG0QPwbNVxlU+k7KS0VFd L/+bnRieCPtSsL8IreWvtykM+lviaNCuy+hfbAr2Se+BYnuDmq5s8u1hCDWgLBKgMk4k+2 k17RMqt64Sqm8Kl3iHTXrCcsFN6NGw+bNektiiyj6zCsjzlHI0/sp7KmQRfIyA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTtX00sdsz1Htr for ; Wed, 18 Nov 2026 07:29:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 12a45 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 18 Nov 2026 07:29:20 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Ross Williams From: Emmanuel Vadot Subject: git: ecd6631b19d9 - main - pam_xdg: Add linger option List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ecd6631b19d9a98f045ad1a0ece0b73b6946d02a Auto-Submitted: auto-generated Date: Wed, 18 Nov 2026 07:29:20 +0000 Message-Id: <6afd53d0.12a45.392ee005@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=ecd6631b19d9a98f045ad1a0ece0b73b6946d02a commit ecd6631b19d9a98f045ad1a0ece0b73b6946d02a Author: Ross Williams AuthorDate: 2026-11-18 07:28:18 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-18 07:28:18 +0000 pam_xdg: Add linger option The pam_xdg module deletes a user's XDG_RUNTIME_DIR when the last interactive session logs out. If the user leaves background processes running on the system, like a terminal multiplexer, that puts state or domain sockets in XDG_RUNTIME_DIR, then that state gets destroyed and the processes become effectively orphaned. On Linux, systemd-logind not only unlinks XDG_RUNTIME_DIR but also kills all user processes on logout. To allow long-lived background processes, it implements a per-user "linger" mode to disable the unlink and kill. Because FreeBSD's pam_xdg does not implement process killing, this "linger" option implementation skips only XDG_RUNTIME_DIR unlinking when the user still has running processes after the last session logs out. Differential Revision: https://reviews.freebsd.org/D61332 --- lib/libpam/modules/pam_xdg/pam_xdg.8 | 9 +++++++- lib/libpam/modules/pam_xdg/pam_xdg.c | 40 ++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/libpam/modules/pam_xdg/pam_xdg.8 b/lib/libpam/modules/pam_xdg/pam_xdg.8 index 031010953e98..5043be0915a9 100644 --- a/lib/libpam/modules/pam_xdg/pam_xdg.8 +++ b/lib/libpam/modules/pam_xdg/pam_xdg.8 @@ -41,10 +41,17 @@ according to the Cross Desktop Group Base Directory Specification. By default the directory is created under .Pa /var/run/xdg/ Ns $ Ns Ev USER . .Pp -The following option may be passed to the authentication module: +The following options may be passed to the +.Nm +module: .Bl -tag -width "runtime_dir_prefix=directory" .It Cm runtime_dir_prefix Ns = Ns Ar directory Use an alternate base directory +.It Cm linger +Keeps the runtime directory of a user if they have running processes, even when +their last session logs out. Allows the user to continue running processes in +the background that create sockets or files in +.Ev XDG_RUNTIME_DIR. .El .Sh ENVIRONMENT .Bl -tag -width indent diff --git a/lib/libpam/modules/pam_xdg/pam_xdg.c b/lib/libpam/modules/pam_xdg/pam_xdg.c index 10c6467776a3..a9d37ed27e19 100644 --- a/lib/libpam/modules/pam_xdg/pam_xdg.c +++ b/lib/libpam/modules/pam_xdg/pam_xdg.c @@ -26,6 +26,8 @@ */ #include +#include +#include #include #include #include @@ -205,6 +207,27 @@ remove_dir(int fd) return (0); } +static int +uid_has_procs(int uid) +{ + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_UID, 0}; + struct kinfo_proc kp; + size_t kp_len = sizeof(kp); + + mib[3] = uid; + + /* + * Only pass a stack allocation with room for one kinfo_proc, and ignore + * ENOMEM. This gives a zero-allocation way to discover whether the UID + * has any processes. + */ + if (sysctl(mib, nitems(mib), &kp, &kp_len, NULL, 0) && errno != ENOMEM) { + return -1; + } + + return (kp_len > 0); +} + static int _pam_xdg_close(pam_handle_t *pamh __unused, int flags __unused, int argc __unused, const char *argv[] __unused) @@ -291,13 +314,18 @@ _pam_xdg_close(pam_handle_t *pamh __unused, int flags __unused, } close(session_file); - /* Final cleanup if last user session */ + /* + * Final cleanup if last user session and linger not enabled, + * or linger enabled but user has no processes + */ if (i == 0) { - remove_dir(rt_dir); - if (unlinkat(rt_dir_prefix, user, AT_REMOVEDIR) != 0) { - PAM_VERBOSE_ERROR("Can't cleanup %s/%s\n", runtime_dir_prefix, user); - rv = PAM_SESSION_ERR; - goto out; + if (openpam_get_option(pamh, "linger") == NULL || !uid_has_procs(passwd->pw_uid)) { + remove_dir(rt_dir); + if (unlinkat(rt_dir_prefix, user, AT_REMOVEDIR) != 0) { + PAM_VERBOSE_ERROR("Can't cleanup %s/%s\n", runtime_dir_prefix, user); + rv = PAM_SESSION_ERR; + goto out; + } } }