summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-10-22 14:14:02 +0200
committerSimon Rettberg2019-10-22 14:14:02 +0200
commitbb7f5e0f18493996095a19dd8b6d162cc2eda33f (patch)
tree9369f0f34837db97bed81dac86d0dcf730ae4051 /src
parentGuess proper dbus socket (diff)
downloadidle-daemon-bb7f5e0f18493996095a19dd8b6d162cc2eda33f.tar.gz
idle-daemon-bb7f5e0f18493996095a19dd8b6d162cc2eda33f.tar.xz
idle-daemon-bb7f5e0f18493996095a19dd8b6d162cc2eda33f.zip
Handle duplicate entries in utmp for X sessions
Diffstat (limited to 'src')
-rw-r--r--src/userlist.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/userlist.c b/src/userlist.c
index d4dde86..4b03959 100644
--- a/src/userlist.c
+++ b/src/userlist.c
@@ -78,18 +78,44 @@ int getUserList( struct user *outbuf, int size )
fixString( u->ut_user, UT_NAMESIZE );
fixString( u->ut_line, UT_LINESIZE );
fixString( u->ut_host, UT_HOSTSIZE );
- // Find slot in outbuf (matching one, first free one if not found)
int use = -1;
- for ( int j = 0; j < deadzone; ++j ) {
- if ( outbuf[j].user[0] == '\0' ) {
- if ( use == -1 ) {
+ // Skip pts sessions within x (xterm)
+ if ( u->ut_host[0] == ':' && isdigit( u->ut_host[1] ) ) {
+ for ( int j = 0; j < deadzone; ++j ) {
+ if ( outbuf[j].user[0] != '\0' && strcmp( outbuf[j].display, u->ut_host ) == 0 ) {
+ if ( outbuf[j].sessionLeader == u->ut_pid
+ && strcmp( outbuf[j].user, u->ut_user ) == 0
+ && strcmp( outbuf[j].device, u->ut_line ) == 0 ) {
+ use = j;
+ break;
+ }
+ bool oldPts = strncmp( outbuf[j].device, "pts", 3 ) == 0;
+ bool newTty = strncmp( u->ut_line, "tty", 3 ) == 0;
+ if ( oldPts && newTty ) {
+ use = j; // Replace pts entry with tty entry
+ outbuf[j].user[0] = '\0';
+ } else if ( !newTty ) {
+ use = -2; // Ignore non-tty entry if we have another one for that display
+ }
+ break;
+ }
+ }
+ if ( use == -2 )
+ continue; // Ignore this entry, already taken care of
+ }
+ if ( use == -1 ) {
+ // OK so far, find slot in outbuf (matching one, first free one if not found)
+ for ( int j = 0; j < deadzone; ++j ) {
+ if ( outbuf[j].user[0] == '\0' ) {
+ if ( use == -1 ) {
+ use = j;
+ }
+ } else if ( outbuf[j].sessionLeader == u->ut_pid
+ && strcmp( outbuf[j].user, u->ut_user ) == 0
+ && strcmp( outbuf[j].device, u->ut_line ) == 0 ) {
use = j;
+ break;
}
- } else if ( outbuf[j].sessionLeader == u->ut_pid
- && strcmp( outbuf[j].user, u->ut_user ) == 0
- && strcmp( outbuf[j].device, u->ut_line ) == 0 ) {
- use = j;
- break;
}
}
if ( use == -1 ) { // Not found and no free slot, expand if possible