summaryrefslogtreecommitdiffstats
path: root/util/userlist.c
blob: 9a142926527c9e99fc54dccd3b478f8089cca669 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* $id:$ */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "config.h"
#include "pttstruct.h"

struct utmpfile_t *u;

int main(int argc, char **argv) {
    int i, shm, counter;
    
    shm = shmget(UTMPSHM_KEY, USHM_SIZE, SHM_R | SHM_W);
    if(shm == -1) {
    perror("shmget");
    exit(0);
    }
    
    u = shmat(shm, NULL, 0);
    if(u == (struct utmpfile_t *)-1) {
    perror("shmat");
    exit(0);
    }
    
    if(argc > 1) {
    for(i = 1; i < argc; i++)
        u->uinfo[atoi(argv[i])].pid = 0;
    } else {
    for(i = counter = 0; i < USHM_SIZE; i++)
        if(u->uinfo[i].pid) {
        userinfo_t *f;
        
        f = &u->uinfo[i];
        printf(
            "%4d(%d) p[%d] i[%d] u[%s] n[%s] f[%s] m[%d] d[%d] t[%ld]\n",
            ++counter, i, f->pager, f->invisible, f->userid,
            f->username, f->from, f->mode, f->mind, f->lastact);
        }
    printf("\nTotal: %d(%d)\n", counter, u->number);
    if(counter != u->number) {
        u->number = counter;
        printf("adjust user number!\n");
    }
    }
    return 0;
}