sessreg -w changed at 1.0.6, will not honor moving wtmp file
Submitted by Jacob Hunt
Assigned to Xorg Project Team
Description
How reproducible: Can it be reproduced? Yes How often? Everytime Steps to Reproduce: Please provide step by step instruction on how to reproduce the issue.
-
Touch a new wtmp file as root touch /tmp/wtmp
-
Run /usr/bin/sessreg from xorg-x11-server-utils-7.5.13.el6 (which uses sessreg-1.0.6)
/usr/bin/sessreg -a -w /tmp/wtmp -l ":0.0,1" -h test72 rbeldin
- Run last -f /tmp/wtmp to see the entry
Observe that there is no entry put in the /tmp/wtmp file specified on the command line.
Repeat the test with the sessreg from xorg-x11-server-utils-7.5-5.2.el6.x86_64.rpm (which uses sessreg-1.0.5
last -f /tmp/wtmp will now display a line similar to:
[root@playero-1 old-xorg]# last -f /tmp/wtmp rbeldin :0.0,1 test72 Tue Jun 25 16:43 still logged in
Summary of actions taken to resolve/troubleshoot issue:
- source comparison of sessreg appears to show changes in sessreg.h and sessreg.c
- changes are introduction of new macro defines that control UTMP and UTMPX
- built the earlier version of sessreg with new Makefile and no changes there
- .h and .c changes go hand in hand
The problem is a mix of the macro definition and the way the code is written.
98 #ifdef USE_UTMPX 99 #ifdef HAVE_UPDWTMPX 100 static char *wtmpx_file = NULL; <<<<< 101 #endif
Since wtmpx_file is NULL, and never initialized, we never write the entry.
343 if (!wtmp_none) { 344 #ifdef USE_UTMPX 345 # ifdef HAVE_UPDWTMPX 346 if (wtmpx_file != NULL) { <<<< wtmpx_file is NULL at this point 347 updwtmpx(wtmpx_file, &utmpx_entry); 348 } 349 # endif 350 #else 351 wtmp = open (wtmp_file, O_WRONLY|O_APPEND); 352 if (wtmp != -1) { 353 sysnerr (write (wtmp, (char *) &utmp_entry, sizeof (utmp_entry)) 354 == sizeof (utmp_entry), "write wtmp entry"); 355 close (wtmp); 356 } 357 #endif 358 }
I think the ifdef USE_UTMPX is incorrect and to restore the older behavior, you would need to remove that but there is some logic here that escapes. Obviously, USE_UTMPX and HAVE_UPDWTMPX are set and we drop into the code, but that is wrong if we want to keep the previous behavior.