Mismatch of size of /var/run/utmp and `struct utmp` in Linux built with GLIBC 2.38 (Y2k38 fix)
2
votes
1
answer
116
views
I am working on an embedded Linux system (kernel-5.10.24), which is a **32bit** system, and it is using GLibc-2.38 to fix Y2k38.
The rootfs is built from buildroot rel.2023-aug with Y2k38 fix. (built with
-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
).
There are getty
and login
built from busybox-1.36.1
in the buildroot.
Now I found strange things when I tried to read the /var/run/utmp
with following codes (also built with -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
).
#include
#include
#include
#include
int main() {
FILE *fp;
struct utmp ut;
printf("XXXXXXXXX sizeof utmp: %ld\n", sizeof(ut));
fp = fopen("/var/run/utmp", "r");
if (fp == NULL) {
perror("Error opening UTMP file");
return 1;
}
while (fread(&ut, sizeof(struct utmp), 1, fp) == 1) {
if (ut.ut_type == USER_PROCESS) {
printf("Login Name: %s\n", ut.ut_user);
printf("Login Time: %s", ctime(&ut.ut_tv.tv_sec));
}
}
fclose(fp);
return 0;
}
When root is logged in and run the code, it showed,
# /tmp/utmpread
XXXXXXXXX sizeof utmp: 400
But the size of /var/run/utmp
is 384.
# stat /var/run/utmp
File: /var/run/utmp
Size: 384 Blocks: 8 IO Block: 4096 regular file
Device: fh/15d Inode: 8 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 1970-01-01 01:14:24.270002128 +0000
Modify: 1970-01-01 00:03:12.000000000 +0000
Change: 1970-01-01 01:12:47.210002082 +0000
So based on my tests, it seemed that struct utmp
is already built as 64bit of timeval_t
, and the login
and getty
also report its size is 400Bytes.
But the size of /var/run/utmp
is still 384 Bytes, which is using 32bit timeval_t
.
I don't know why there is the mismatch (the code reports size of struct utmp
is 400, but the file generated from struct utmp
is 384), is it from the GLIBC or from the busybox
?
Thanks,
Asked by wangt13
(631 rep)
Mar 7, 2024, 02:29 PM
Last activity: Mar 11, 2024, 12:57 AM
Last activity: Mar 11, 2024, 12:57 AM