Skip to content

Commit

Permalink
Merge pull request systemd#34291 from poettering/utmpx-all-the-way
Browse files Browse the repository at this point in the history
tree-wide: complete the switch to utmpx
  • Loading branch information
poettering committed Sep 6, 2024
2 parents 22f3f2c + 51da613 commit 9a78f9e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/basic/user-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <sys/file.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utmp.h>
#include <utmpx.h>

#include "sd-messages.h"

Expand Down Expand Up @@ -802,7 +802,7 @@ bool valid_user_group_name(const char *u, ValidUserFlags flags) {
return false;
if (l > NAME_MAX) /* must fit in a filename: 255 */
return false;
if (l > UT_NAMESIZE - 1) /* must fit in utmp: 31 */
if (l > sizeof_field(struct utmpx, ut_user) - 1) /* must fit in utmp: 31 */
return false;
}

Expand Down
12 changes: 6 additions & 6 deletions src/login/logind-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ int manager_read_utmp(Manager *m) {

assert(m);

if (utmpxname(_PATH_UTMPX) < 0)
return log_error_errno(errno, "Failed to set utmp path to " _PATH_UTMPX ": %m");
if (utmpxname(UTMPX_FILE) < 0)
return log_error_errno(errno, "Failed to set utmp path to " UTMPX_FILE ": %m");

utmpx = utxent_start();

Expand All @@ -725,9 +725,9 @@ int manager_read_utmp(Manager *m) {
u = getutxent();
if (!u) {
if (errno == ENOENT)
log_debug_errno(errno, _PATH_UTMPX " does not exist, ignoring.");
log_debug_errno(errno, UTMPX_FILE " does not exist, ignoring.");
else if (errno != 0)
log_warning_errno(errno, "Failed to read " _PATH_UTMPX ", ignoring: %m");
log_warning_errno(errno, "Failed to read " UTMPX_FILE ", ignoring: %m");
return 0;
}

Expand Down Expand Up @@ -808,9 +808,9 @@ void manager_connect_utmp(Manager *m) {
* Yes, relying on utmp is pretty ugly, but it's good enough for informational purposes, as well as idle
* detection (which, for tty sessions, relies on the TTY used) */

r = sd_event_add_inotify(m->event, &s, _PATH_UTMPX, IN_MODIFY|IN_MOVE_SELF|IN_DELETE_SELF|IN_ATTRIB, manager_dispatch_utmp, m);
r = sd_event_add_inotify(m->event, &s, UTMPX_FILE, IN_MODIFY|IN_MOVE_SELF|IN_DELETE_SELF|IN_ATTRIB, manager_dispatch_utmp, m);
if (r < 0)
log_full_errno(r == -ENOENT ? LOG_DEBUG: LOG_WARNING, r, "Failed to create inotify watch on " _PATH_UTMPX ", ignoring: %m");
log_full_errno(r == -ENOENT ? LOG_DEBUG: LOG_WARNING, r, "Failed to create inotify watch on " UTMPX_FILE ", ignoring: %m");
else {
r = sd_event_source_set_priority(s, SD_EVENT_PRIORITY_IDLE);
if (r < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/shared/utmp-wtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int utmp_get_runlevel(int *runlevel, int *previous) {
return 0;
}

if (utmpxname(_PATH_UTMPX) < 0)
if (utmpxname(UTMPX_FILE) < 0)
return -errno;

utmpx = utxent_start();
Expand Down Expand Up @@ -91,7 +91,7 @@ static int write_entry_utmp(const struct utmpx *store) {
* each entry type resp. user; i.e. basically a key/value
* table. */

if (utmpxname(_PATH_UTMPX) < 0)
if (utmpxname(UTMPX_FILE) < 0)
return -errno;

utmpx = utxent_start();
Expand Down
2 changes: 1 addition & 1 deletion src/shared/wall.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static int wall_utmp(

/* libc's setutxent() unfortunately doesn't inform us about success, i.e. whether /var/run/utmp
* exists. Hence we have to check manually first. */
if (access(_PATH_UTMPX, F_OK) < 0) {
if (access(UTMPX_FILE, F_OK) < 0) {
if (errno == ENOENT)
return -ENOPROTOOPT;

Expand Down
1 change: 0 additions & 1 deletion src/sysusers/sysusers.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include <getopt.h>
#include <utmp.h>

#include "alloc-util.h"
#include "build.h"
Expand Down
18 changes: 6 additions & 12 deletions src/test/test-utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
#include "utmp-wtmp.h"
#include "tests.h"

#ifndef UT_LINESIZE
# define UT_LINESIZE 32
#endif
#ifndef UT_NAMESIZE
# define UT_NAMESIZE 32
#endif
#ifndef UT_HOSTSIZE
# define UT_HOSTSIZE 256
#endif
#define UTX_LINESIZE sizeof_field(struct utmpx, ut_line)
#define UTX_NAMESIZE sizeof_field(struct utmpx, ut_user)
#define UTX_HOSTSIZE sizeof_field(struct utmpx, ut_host)

TEST(dump_run_utmp) {
_unused_ _cleanup_(utxent_cleanup) bool utmpx = false;
Expand Down Expand Up @@ -46,11 +40,11 @@ TEST(dump_run_utmp) {
log_info("%14s %10"PID_PRI" line=%-7.*s id=%-4.4s name=%-8.*s session=%lu host=%.*s addr=%s",
type,
u->ut_pid,
UT_LINESIZE, u->ut_line,
(int) UTX_LINESIZE, u->ut_line,
u->ut_id,
UT_NAMESIZE, u->ut_user,
(int) UTX_NAMESIZE, u->ut_user,
(long unsigned) u->ut_session,
UT_HOSTSIZE, u->ut_host,
(int) UTX_HOSTSIZE, u->ut_host,
IN_ADDR_TO_STRING(is_ipv4 ? AF_INET : AF_INET6, &addr));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/userdb/userdbctl.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include <getopt.h>
#include <utmp.h>

#include "build.h"
#include "dirent-util.h"
Expand Down

0 comments on commit 9a78f9e

Please sign in to comment.