Skip to content

Commit 9713e98

Browse files
committed
Address PR review comments: add OpenBSD comments and deduplicate utmp setup
1 parent f225186 commit 9713e98

4 files changed

Lines changed: 25 additions & 39 deletions

File tree

.github/workflows/CICD.yml

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -739,24 +739,7 @@ jobs:
739739
# selinux and systemd headers needed to build tests
740740
sudo apt-get -y update
741741
sudo apt-get -y install libselinux1-dev libsystemd-dev
742-
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
743-
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands, and "system boot" entry is missing.
744-
# The account also has empty gecos fields.
745-
# To work around these issues for pinky (and who) tests, we create a fake utmp file with a
746-
# system boot entry and a login entry for the GH runner account.
747-
printf '%s\n%s\n%s' \
748-
'[2] [00000] [~~ ] [reboot ] [~ ] [6.0.0-test ] [0.0.0.0 ] [2022-02-22T22:11:22,222222+0000]' \
749-
'[7] [999999] [tty2] [runner ] [tty2 ] [ ] [0.0.0.0 ] [2022-02-22T22:22:22,222222+0000]' \
750-
'[7] [00001] [tty3] [runner ] [tty3 ] [ ] [0.0.0.0 ] [2022-02-22T22:22:22,222222+0000]' \
751-
| sudo utmpdump -r -o /var/run/utmp
752-
# ... and add a full name to each account with a gecos field but no full name.
753-
sudo sed -i 's/:,/:runner name,/' /etc/passwd
754-
# We also create a couple optional files pinky looks for
755-
touch /home/runner/.project
756-
echo "foo" > /home/runner/.plan
757-
# add user with digital username for testing with issue #7787
758-
echo 200:x:2000:2000::/home/200:/bin/bash | sudo tee -a /etc/passwd
759-
echo 200:x:2000: | sudo tee -a /etc/group
742+
bash util/setup-gh-runner-utmp.sh
760743
;;
761744
esac
762745
- uses: taiki-e/install-action@v2
@@ -1104,24 +1087,7 @@ jobs:
11041087
# selinux and systemd headers needed to build tests
11051088
sudo apt-get -y update
11061089
sudo apt-get -y install libselinux1-dev libsystemd-dev
1107-
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
1108-
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands, and "system boot" entry is missing.
1109-
# The account also has empty gecos fields.
1110-
# To work around these issues for pinky (and who) tests, we create a fake utmp file with a
1111-
# system boot entry and a login entry for the GH runner account.
1112-
printf '%s\n%s\n%s' \
1113-
'[2] [00000] [~~ ] [reboot ] [~ ] [6.0.0-test ] [0.0.0.0 ] [2022-02-22T22:11:22,222222+0000]' \
1114-
'[7] [999999] [tty2] [runner ] [tty2 ] [ ] [0.0.0.0 ] [2022-02-22T22:22:22,222222+0000]' \
1115-
'[7] [00001] [tty3] [runner ] [tty3 ] [ ] [0.0.0.0 ] [2022-02-22T22:22:22,222222+0000]' \
1116-
| sudo utmpdump -r -o /var/run/utmp
1117-
# ... and add a full name to each account with a gecos field but no full name.
1118-
sudo sed -i 's/:,/:runner name,/' /etc/passwd
1119-
# We also create a couple optional files pinky looks for
1120-
touch /home/runner/.project
1121-
echo "foo" > /home/runner/.plan
1122-
# add user with digital username for testing with issue #7787
1123-
echo 200:x:2000:2000::/home/200:/bin/bash | sudo tee -a /etc/passwd
1124-
echo 200:x:2000: | sudo tee -a /etc/group
1090+
bash util/setup-gh-runner-utmp.sh
11251091
;;
11261092
esac
11271093

src/uu/users/src/users.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use clap::builder::ValueParser;
1212
use clap::{Arg, Command};
1313
use uucore::error::UResult;
1414
use uucore::format_usage;
15-
#[cfg(not(target_os = "openbsd"))]
16-
use uucore::process::pid_is_alive;
1715
use uucore::translate;
1816

1917
#[cfg(target_os = "openbsd")]
@@ -63,8 +61,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6361
}
6462
}
6563
};
64+
// OpenBSD uses the older UTMP format (not UTMPX) which doesn't reliably track PIDs,
65+
// so we only filter by pid_is_alive on non-OpenBSD systems.
6666
#[cfg(not(target_os = "openbsd"))]
6767
{
68+
use uucore::process::pid_is_alive;
6869
let filename = maybe_file.unwrap_or(utmpx::DEFAULT_FILE.as_ref());
6970

7071
users = Utmpx::iter_all_records_from(filename)

src/uu/who/src/platform/unix.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::uu_app;
1111
use uucore::display::Quotable;
1212
use uucore::error::{FromIo, UResult};
1313
use uucore::libc::{S_IWGRP, STDIN_FILENO, ttyname};
14-
#[cfg(not(target_os = "openbsd"))]
1514
use uucore::process::pid_is_alive;
1615
use uucore::translate;
1716

util/setup-gh-runner-utmp.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# spell-checker:ignore utmpdump gecos
3+
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
4+
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands, and "system boot" entry is missing.
5+
# The account also has empty gecos fields.
6+
# To work around these issues for pinky (and who) tests, we create a fake utmp file with a
7+
# system boot entry and a login entry for the GH runner account.
8+
printf '%s\n%s\n%s' \
9+
'[2] [00000] [~~ ] [reboot ] [~ ] [6.0.0-test ] [0.0.0.0 ] [2022-02-22T22:11:22,222222+0000]' \
10+
'[7] [999999] [tty2] [runner ] [tty2 ] [ ] [0.0.0.0 ] [2022-02-22T22:22:22,222222+0000]' \
11+
'[7] [00001] [tty3] [runner ] [tty3 ] [ ] [0.0.0.0 ] [2022-02-22T22:22:22,222222+0000]' \
12+
| sudo utmpdump -r -o /var/run/utmp
13+
# ... and add a full name to each account with a gecos field but no full name.
14+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
15+
# We also create a couple optional files pinky looks for
16+
touch /home/runner/.project
17+
echo "foo" > /home/runner/.plan
18+
# add user with digital username for testing with issue #7787
19+
echo 200:x:2000:2000::/home/200:/bin/bash | sudo tee -a /etc/passwd
20+
echo 200:x:2000: | sudo tee -a /etc/group

0 commit comments

Comments
 (0)