summaryrefslogtreecommitdiffstats
path: root/login-utils/lslogins.c
diff options
context:
space:
mode:
authorKarel Zak2014-07-16 11:25:03 +0200
committerKarel Zak2014-07-16 11:25:03 +0200
commitbdba3fd9b503041c50f3a4bdcc1852b7f57cd786 (patch)
tree2c0e226d283ca25ec69c8311f9efa7269ce3e2c4 /login-utils/lslogins.c
parentlslogins: add --noheadings (diff)
downloadkernel-qcow2-util-linux-bdba3fd9b503041c50f3a4bdcc1852b7f57cd786.tar.gz
kernel-qcow2-util-linux-bdba3fd9b503041c50f3a4bdcc1852b7f57cd786.tar.xz
kernel-qcow2-util-linux-bdba3fd9b503041c50f3a4bdcc1852b7f57cd786.zip
lslogins: make --notruncate more robust
- keep coldescs[] read-only - don't expect that only COL_GECOS uses truncate flag Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/lslogins.c')
-rw-r--r--login-utils/lslogins.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index 96f0c70c2..ed208f90d 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -212,7 +212,7 @@ static const char *const pretty_status[] = {
#define get_status(x) (outmode == OUT_PRETTY ? pretty_status[(x)] : status[(x)])
-static struct lslogins_coldesc coldescs[] =
+static const struct lslogins_coldesc coldescs[] =
{
[COL_USER] = { "USER", N_("user name"), N_("Username"), 0.1, SCOLS_FL_NOEXTREMES },
[COL_UID] = { "UID", N_("user ID"), "UID", 1, SCOLS_FL_RIGHT},
@@ -266,7 +266,8 @@ struct lslogins_control {
const char *journal_path;
unsigned int selinux_enabled : 1,
- noheadings : 1;
+ noheadings : 1,
+ notrunc : 1;
};
/* these have to remain global since there's no other reasonable way to pass
@@ -891,8 +892,15 @@ static struct libscols_table *setup_table(struct lslogins_control *ctl)
}
while (n < ncolumns) {
- if (!scols_table_new_column(tb, coldescs[columns[n]].name,
- coldescs[columns[n]].whint, coldescs[columns[n]].flag))
+ int flags = coldescs[columns[n]].flag;
+
+ if (ctl->notrunc)
+ flags &= ~SCOLS_FL_TRUNC;
+
+ if (!scols_table_new_column(tb,
+ coldescs[columns[n]].name,
+ coldescs[columns[n]].whint,
+ flags))
goto fail;
++n;
}
@@ -1188,7 +1196,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fprintf(out, _("\nAvailable columns:\n"));
for (i = 0; i < ARRAY_SIZE(coldescs); i++)
- fprintf(out, " %14s %s\n", coldescs[i].name, _(coldescs[i].help));
+ fprintf(out, " %14s %s\n", coldescs[i].name,
+ _(coldescs[i].help));
fprintf(out, _("\nFor more details see lslogins(1).\n"));
@@ -1352,7 +1361,7 @@ int main(int argc, char *argv[])
path_btmp = optarg;
break;
case OPT_NOTRUNC:
- coldescs[COL_GECOS].flag = 0;
+ ctl->notrunc = 1;
break;
case OPT_NOHEAD:
ctl->noheadings = 1;