How would I retain info in utmp? - Unix

This is a discussion on How would I retain info in utmp? - Unix ; say I have something like #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX_USERS 10 typedef struct { uid_t uid; dev_t dev; pid_t pid; struct utmp in_login; }uinfo_t; uinfo_t uinfo[MAX_USERS]; static ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: How would I retain info in utmp?

  1. How would I retain info in utmp?

    say I have something like

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    #define MAX_USERS 10

    typedef struct {
    uid_t uid;
    dev_t dev;
    pid_t pid;
    struct utmp in_login;
    }uinfo_t;

    uinfo_t uinfo[MAX_USERS];

    static int count;

    int
    read_utmp(char *user)
    {
    static struct utmp logins;
    static int fd;
    static char tty[MAXPATHLEN];
    static int n;


    n = 0;

    if(( fd = open(_PATH_UTMP, O_RDONLY)) < 0){
    return 1;
    }

    while(read(fd, &logins, sizeof(logins)) == sizeof(logins)) {
    if (strncmp(logins.ut_name, user, UT_NAMESIZE)) {
    continue;
    }
    (void)strncpy(uinfo[n].in_login.ut_line, logins.ut_line,
    UT_LINESIZE);

    (void)snprintf(tty, sizeof(tty), "%s/%s", _PATH_DEV,
    logins.ut_line);
    count++;
    }

    close(fd);
    return 0;
    }


    int main(void)
    {
    int i;
    read_utmp("cdalten");
    for(i=0; i< count; i++)
    printf("%s\n", uinfo[i].in_login.ut_line);
    return 0;
    }

    What I'm trying to do is store uid, dev, pid, and all the enties of
    cdalten in struct utmp into one structure.called uinfo. What's my
    error in reasoning?

  2. Re: How would I retain info in utmp?

    On Dec 4, 7:41 pm, K-mart Cashier wrote:
    > say I have something like
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > #define MAX_USERS 10
    >
    > typedef struct {
    > uid_t uid;
    > dev_t dev;
    > pid_t pid;
    > struct utmp in_login;
    >
    > }uinfo_t;
    >
    > uinfo_t uinfo[MAX_USERS];
    >
    > static int count;
    >
    > int
    > read_utmp(char *user)
    > {
    > static struct utmp logins;
    > static int fd;
    > static char tty[MAXPATHLEN];
    > static int n;
    >
    > n = 0;
    >
    > if(( fd = open(_PATH_UTMP, O_RDONLY)) < 0){
    > return 1;
    > }
    >
    > while(read(fd, &logins, sizeof(logins)) == sizeof(logins)) {
    > if (strncmp(logins.ut_name, user, UT_NAMESIZE)) {
    > continue;
    > }
    > (void)strncpy(uinfo[n].in_login.ut_line, logins.ut_line,
    > UT_LINESIZE);


    Did you mean uinfo[count] ?

    > (void)snprintf(tty, sizeof(tty), "%s/%s", _PATH_DEV,
    > logins.ut_line);
    > count++;
    > }
    >
    > close(fd);
    > return 0;
    >
    > }
    >
    > int main(void)
    > {
    > int i;
    > read_utmp("cdalten");
    > for(i=0; i< count; i++)
    > printf("%s\n", uinfo[i].in_login.ut_line);
    > return 0;
    >
    > }
    >
    > What I'm trying to do is store uid, dev, pid, and all the enties of
    > cdalten in struct utmp into one structure.called uinfo. What's my
    > error in reasoning?


    I assume you left that part out.

+ Reply to Thread