utmpx(int argc, char *argv[])
{
const struct utmpx *ut;
- int rv = RV_OK, db;
+ const char *file = NULL;
+ int rv = RV_OK, db = 0;
assert(argc > 1);
assert(argv != NULL);
- if (argc == 2) {
- db = UTXDB_ACTIVE;
- } else if (argc == 3) {
+ if (argc == 3 || argc == 4) {
if (strcmp(argv[2], "active") == 0)
db = UTXDB_ACTIVE;
else if (strcmp(argv[2], "lastlogin") == 0)
db = UTXDB_LOG;
else
rv = RV_USAGE;
+ if (argc == 4)
+ file = argv[3];
} else {
rv = RV_USAGE;
}
if (rv == RV_USAGE) {
- fprintf(stderr, "Usage: %s utmpx [active | lastlogin | log]\n",
+ fprintf(stderr,
+ "Usage: %s utmpx active | lastlogin | log [filename]\n",
getprogname());
} else if (rv == RV_OK) {
- if (setutxdb(db, NULL) != 0)
+ if (setutxdb(db, file) != 0)
return (RV_NOTFOUND);
while ((ut = getutxent()) != NULL)
utmpxprint(ut);