getutxline can't find entry

Hello,

I try to play with utmpx and found strange problem.

tty(1) shows me that I'm at pts/11

Code:
0tyl2~(8)>tty
/dev/pts/11
0tyl2~(9)>

But when I run a small program:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utmpx.h>

#define MYTTY "pts/11"

int main(int argc, char *argv[]) {
    struct utmpx *ut;

    ut = (struct utmpx *) malloc(sizeof(struct utmpx));
    strncpy(ut->ut_line, MYTTY, sizeof(MYTTY));
    if ((ut = getutxline(ut)) == NULL) {
        perror("getutxline");
        return (1);
    }
    printf("tty: %s\n", ut->ut_line);

    return (0);
}

getutxline(3) can't find entry about pts/11.
who(1) and getent(1) also silent about pts/11.

What does it mean?

p.s. I use 9.0-STABLE FreeBSD 9.0-STABLE #0: Sat Jan 14 02:35:27 MSK 2012
 
Hi giantlock,

Which service did you use to log in? Is this on a fresh installation or an upgrade from 8 to 9? If it's an upgrade, can you please recompile the terminal emulator or login service you're using? You can also use the getent utmpx active command to dump all utmpx entries.

Thanks,
Ed Schouten
 
Hi Ed,

I found that my problem is appearing with x11/luit. When I run xterm it opens master terminal pts/2 (for example) and marks it in utmpx, after that xterm runs luit.

luit clones(?) pts/2 to master terminal pts/11 and doesn't make any changes in utmpx. So any program run by luit gets a terminal which is not in utmpx.

I suspect it's not the right behavior.

My installation was updated from 8, and I recompiled all software.

Thanks a lot for your answer.
 
It seems that luit simply doesn't do any logging to utmp/utmpx at all. Well, there's no real requirement that applications log to those databases anyway. For example, script(1) doesn't do this either. So be it. ;)
 
Ok,

But what is appropriate way if my program wants to record info about a user changing (for example)? Should I insert a new entry in utmpx if getutxline returns NULL?
 
You're implementing a su/sudo/login-like application? Well, the cool thing about utmpx is that you can safely write multiple entries per TTY. Just fill ut_id with random data (for example by using arc4random_buf(3)). So there's no need to overwrite the old entry. Just add a new entry and remove it during shutdown.
 
Back
Top