* time modes
* */
enum {
+ TIME_INVALID = 0,
TIME_SHORT_RELATIVE,
TIME_SHORT,
TIME_FULL,
case TIME_ISO:
strftime(buf, 32, "%Y-%m-%dT%H:%M:%S%z", &tm);
break;
+ default:
+ exit(1);
}
return xstrdup(buf);
}
#endif
free(u);
}
+struct lslogins_timefmt {
+ const char *name;
+ int val;
+};
+static struct lslogins_timefmt timefmts[] = {
+ { "short", TIME_SHORT_RELATIVE },
+ { "full", TIME_FULL },
+ { "iso", TIME_ISO },
+};
int main(int argc, char *argv[])
{
OPT_BTMP,
OPT_NOTRUNC,
OPT_FULLT,
+ OPT_TIME_FMT,
};
static const struct option longopts[] = {
{ "raw", no_argument, 0, 'r' },
{ "system-accs", no_argument, 0, 's' },
{ "sort-by-name", no_argument, 0, 't' },
+ { "time-format", required_argument, 0, OPT_TIME_FMT },
{ "user-accs", no_argument, 0, 'u' },
{ "version", no_argument, 0, OPT_VER },
{ "extra", no_argument, 0, 'x' },
static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
{ 'c','e','n','r','z' },
+ { 'i', OPT_TIME_FMT, OPT_FULLT },
{ 0 }
};
int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
atexit(close_stdout);
ctl->cmp_fn = cmp_uid;
+ ctl->time_mode = TIME_SHORT_RELATIVE;
while ((c = getopt_long(argc, argv, "acefg:hil:mno:rstuxzZ",
longopts, NULL)) != -1) {
case OPT_FULLT:
ctl->time_mode = TIME_FULL;
break;
+ case OPT_TIME_FMT:
+ {
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
+ if (strcmp(timefmts[i].name, optarg) == 0) {
+ ctl->time_mode = timefmts[i].val;
+ break;
+ }
+ }
+ if (ctl->time_mode == TIME_INVALID)
+ usage(stderr);
+ }
+ break;
case 'Z':
#ifdef HAVE_LIBSELINUX
lslogins_flag |= F_SELINUX;
usage(stderr);
}
}
+
if (argc - optind == 1) {
if (strchr(argv[optind], ','))
err(EXIT_FAILURE, "%s", "Only one user may be specified. Use -l for multiple users");