#include #include #include #include int main(void) { struct utmpx ut; struct utmpx * utp; const char * user = "foobar"; const char * line = "offline"; memset(&ut, 0, sizeof(ut)); memcpy(&ut.ut_user[0], user, strlen(user)); memcpy(&ut.ut_id[0], "1234", 4); memcpy(&ut.ut_line[0], line, strlen(line)); ut.ut_pid = getpid(); ut.ut_type = USER_PROCESS; setutxent(); /* Create entry */ if (pututxline(&ut) == NULL) { puts("putuxtline failed. are you superuser?"); return 1; } setutxent(); utp = getutxent(); while ((utp != NULL) && (utp->ut_pid != ut.ut_pid)) utp = getutxent(); if (utp == NULL) { puts("entry not found"); return 1; } utp->ut_type = DEAD_PROCESS; /* Should overwrite existing? */ pututxline(utp); setutxent(); utp = getutxid(&ut); if (utp == NULL) { puts("entry not found"); return 1; } utp->ut_type = DEAD_PROCESS; /* Should overwrite existing? */ pututxline(utp); setutxent(); utp = getutxline(&ut); if (utp == NULL) { puts("entry not found"); return 1; } utp->ut_type = DEAD_PROCESS; /* Should overwrite existing? */ pututxline(utp); return 0; }