+2025-02-19 Bruno Haible <bruno@clisp.org>
+
+ readutmp: Let callers distinguish LOGINs from USERs.
+ Reported by Paul Eggert in
+ <https://lists.gnu.org/archive/html/bug-gnulib/2025-02/msg00123.html>.
+ * lib/readutmp.h (LOGIN_PROCESS, UT_TYPE_LOGIN_PROCESS): New macros.
+ * lib/readutmp.c (read_utmp_from_systemd): Possibly use LOGIN_PROCESS
+ instead of USER_PROCESS, depending on the session's class.
+
2025-02-17 Bruno Haible <bruno@clisp.org>
readutmp, boot-time: Improve documentation.
}
}
- /* Create up to two USER_PROCESS entries: one for the seat,
- one for the tty. */
+ /* Create up to two USER_PROCESS or LOGIN_PROCESS entries:
+ one for the seat, one for the tty. */
if (seat != NULL || tty != NULL)
{
char *user;
if (sd_session_get_leader (session, &leader_pid) < 0)
leader_pid = 0;
+ char *clasz;
+ if (sd_session_get_class (session, &clasz) < 0)
+ clasz = missing;
+ short ctype =
+ (strncmp (clasz, "manager", 7) == 0 ? LOGIN_PROCESS :
+ USER_PROCESS);
+
char *host;
char *remote_host;
if (sd_session_get_remote_host (session, &remote_host) < 0)
seat, strlen (seat),
host, strlen (host),
leader_pid /* the best we have */,
- USER_PROCESS, start_ts, leader_pid, 0, 0);
+ ctype, start_ts, leader_pid, 0, 0);
if (tty != NULL)
a = add_utmp (a, options,
user, strlen (user),
tty, strlen (tty),
host, strlen (host),
leader_pid /* the best we have */,
- USER_PROCESS, start_ts, leader_pid, 0, 0);
+ ctype, start_ts, leader_pid, 0, 0);
if (host != missing)
free (host);
+ if (clasz != missing)
+ free (clasz);
if (user != missing)
free (user);
}
# include <utmp.h>
#endif
-/* Needed for BOOT_TIME and USER_PROCESS. */
+/* Needed for BOOT_TIME, USER_PROCESS, LOGIN_PROCESS. */
#if HAVE_UTMPX_H
# if defined _THREAD_SAFE && defined UTMP_DATA_INIT
/* When including both utmp.h and utmpx.h on AIX 4.3, with _THREAD_SAFE
struct timespec ut_ts; /* time */
pid_t ut_pid; /* process ID of ? */
pid_t ut_session; /* process ID of session leader */
- short ut_type; /* BOOT_TIME, USER_PROCESS, or other */
+ short ut_type; /* BOOT_TIME, USER_PROCESS, LOGIN_PROCESS,
+ or other */
struct { int e_termination; int e_exit; } ut_exit;
};
# define WTMP_FILE "/etc/wtmp"
#endif
-/* In early versions of Android, <utmp.h> did not define BOOT_TIME, only
- USER_PROCESS. We need to use the value that is defined in newer versions
- of Android. */
+/* In early versions of Android, <utmp.h> did not define BOOT_TIME or
+ LOGIN_PROCESS, only USER_PROCESS. We need to use the value that is defined
+ in newer versions of Android. */
#if defined __ANDROID__ && !defined BOOT_TIME
# define BOOT_TIME 2
+# define LOGIN_PROCESS 6
#endif
/* Some platforms, such as OpenBSD, don't have an ut_type field and don't have
- the BOOT_TIME and USER_PROCESS macros. But we want to support them in
- 'struct gl_utmp'. */
+ the BOOT_TIME, USER_PROCESS, and LOGIN_PROCESS macros. But we want to
+ support them in 'struct gl_utmp'. */
#if !(HAVE_UTMPX_H ? HAVE_STRUCT_UTMPX_UT_TYPE : HAVE_STRUCT_UTMP_UT_TYPE)
# define BOOT_TIME 2
# define USER_PROCESS 0
+# define LOGIN_PROCESS 6
#endif
/* Macros that test (UT)->ut_type. */
#else
# define UT_TYPE_USER_PROCESS(UT) 0
#endif
+#ifdef LOGIN_PROCESS
+# define UT_TYPE_LOGIN_PROCESS(UT) ((UT)->ut_type == LOGIN_PROCESS)
+#else
+# define UT_TYPE_LOGIN_PROCESS(UT) 0
+#endif
/* Determines whether an entry *UT corresponds to a user process. */
#define IS_USER_PROCESS(UT) \