Skip to content

Commit 254f121

Browse files
committed
Users (OpenBSD): add support
1 parent 090b6d7 commit 254f121

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ elseif(OpenBSD)
819819
src/detection/theme/theme_linux.c
820820
src/detection/tpm/tpm_nosupport.c
821821
src/detection/uptime/uptime_bsd.c
822-
src/detection/users/users_nosupport.c
822+
src/detection/users/users_obsd.c
823823
src/detection/wallpaper/wallpaper_linux.c
824824
src/detection/wifi/wifi_nosupport.c
825825
src/detection/wm/wm_nosupport.c

src/detection/users/users_obsd.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "fastfetch.h"
2+
#include "users.h"
3+
#include "common/io/io.h"
4+
5+
#include <utmp.h>
6+
7+
const char* ffDetectUsers(FF_MAYBE_UNUSED FFUsersOptions* options, FFlist* users)
8+
{
9+
FF_AUTO_CLOSE_FILE FILE* fp = fopen(_PATH_UTMP, "r");
10+
if (!fp) return "fopen(_PATH_UTMP, r) failed";
11+
12+
struct utmp n;
13+
next:
14+
while (fread(&n, sizeof(n), 1, fp) == 1)
15+
{
16+
if (!n.ut_name[0]) continue;
17+
18+
if (options->myselfOnly && !ffStrbufEqualS(&instance.state.platform.userName, n.ut_name))
19+
continue;
20+
21+
FF_LIST_FOR_EACH(FFUserResult, user, *users)
22+
{
23+
if (ffStrbufEqualS(&user->name, n.ut_name))
24+
goto next;
25+
}
26+
27+
FFUserResult* user = (FFUserResult*) ffListAdd(users);
28+
ffStrbufInitS(&user->name, n.ut_name);
29+
ffStrbufInitS(&user->hostName, n.ut_host);
30+
ffStrbufInitS(&user->sessionName, n.ut_line);
31+
ffStrbufInit(&user->clientIp);
32+
user->loginTime = (uint64_t) n.ut_time * 1000;
33+
}
34+
35+
return NULL;
36+
}

0 commit comments

Comments
 (0)