* [PATCH 01/10] logger: fix memory leak [ASAN and valgrind]
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 02/10] getopt: fix memory leaks and integer overflows [ASAN & valgrind] Sami Kerola
` (9 subsequent siblings)
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 7b88b17..1ef12cd 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -341,8 +341,10 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
for (lines = 0; /* nothing */ ; lines++) {
buf = NULL;
sz = getline(&buf, &dummy, fp);
- if (sz == -1)
+ if (sz == -1) {
+ free(buf);
break;
+ }
if (0 < sz && buf[sz - 1] == '\n') {
sz--;
buf[sz] = '\0';
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 02/10] getopt: fix memory leaks and integer overflows [ASAN & valgrind]
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
2016-03-13 10:31 ` [PATCH 01/10] logger: fix memory leak [ASAN and valgrind] Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 12:11 ` Yuriy M. Kaminskiy
2016-03-13 10:31 ` [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime() Sami Kerola
` (8 subsequent siblings)
10 siblings, 1 reply; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
The getopt(1) is short living command, and one could argue ensuring all
allocations are freed at end of execution is waste of time. There is a
point in that, but making test-suite runs to be less noisy with ASAN is also
nice as it encourages reading the errors when/if they happen.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/getopt.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
index c4144f6..be2ed38 100644
--- a/misc-utils/getopt.c
+++ b/misc-utils/getopt.c
@@ -79,13 +79,23 @@
/* The shells recognized. */
typedef enum { BASH, TCSH } shell_t;
+/* This is a copy of getopt_long(3) structure, in which *name does not have
+ * const, so that is can be free'd at end of execution. */
+struct getoption {
+ char *name;
+ int has_arg;
+ int *flag;
+ int val;
+};
+
struct getopt_control {
shell_t shell; /* the shell we generate output for */
char *optstr; /* getopt(3) optstring */
- struct option *long_options; /* long options */
+ struct getoption *long_options; /* long options */
int long_options_length; /* length of options array */
int long_options_nr; /* number of used elements in array */
unsigned int
+ free_name:1, /* free up argv[0] after printout */
compatible:1, /* compatibility mode for 'difficult' programs */
quiet_errors:1, /* print errors */
quiet_output:1, /* print output */
@@ -181,7 +191,7 @@ static void print_normalized(const struct getopt_control *ctl, const char *arg)
* optstr must contain the short options, and longopts the long options.
* Other settings are found in global variables.
*/
-static int generate_output(const struct getopt_control *ctl, char *argv[], int argc)
+static int generate_output(struct getopt_control *ctl, char *argv[], int argc)
{
int exit_code = EXIT_SUCCESS; /* Assume everything will be OK */
int opt;
@@ -195,8 +205,10 @@ static int generate_output(const struct getopt_control *ctl, char *argv[], int a
optind = 0;
while ((opt =
- (getopt_long_fp(argc, argv, ctl->optstr, ctl->long_options, &longindex)))
- != EOF)
+ (getopt_long_fp
+ (argc, argv, ctl->optstr,
+ (const struct option *)ctl->long_options, &longindex)))
+ != EOF) {
if (opt == '?' || opt == ':')
exit_code = GETOPT_EXIT_CODE;
else if (!ctl->quiet_output) {
@@ -216,13 +228,19 @@ static int generate_output(const struct getopt_control *ctl, char *argv[], int a
print_normalized(ctl, optarg ? optarg : "");
}
}
-
+ }
if (!ctl->quiet_output) {
printf(" --");
while (optind < argc)
print_normalized(ctl, argv[optind++]);
printf("\n");
}
+ for (longindex = 0; longindex < ctl->long_options_nr; longindex++)
+ free(ctl->long_options[longindex].name);
+ free(ctl->long_options);
+ free(ctl->optstr);
+ if (ctl->free_name)
+ free(argv[0]);
return exit_code;
}
@@ -373,9 +391,6 @@ int main(int argc, char *argv[])
textdomain(PACKAGE);
atexit(close_stdout);
- add_longopt(&ctl, NULL, 0); /* init */
- getopt_long_fp = getopt_long;
-
if (getenv("GETOPT_COMPATIBLE"))
ctl.compatible = 1;
@@ -391,6 +406,9 @@ int main(int argc, char *argv[])
parse_error(_("missing optstring argument"));
}
+ add_longopt(&ctl, NULL, 0); /* init */
+ getopt_long_fp = getopt_long;
+
if (argv[1][0] != '-' || ctl.compatible) {
ctl.quote = 0;
ctl.optstr = xmalloc(strlen(argv[1]) + 1);
@@ -417,6 +435,7 @@ int main(int argc, char *argv[])
case 'n':
free(name);
name = xstrdup(optarg);
+ ctl.free_name = 1;
break;
case 'q':
ctl.quiet_errors = 1;
@@ -428,6 +447,7 @@ int main(int argc, char *argv[])
ctl.shell = shell_type(optarg);
break;
case 'T':
+ free(ctl.long_options);
return TEST_EXIT_CODE;
case 'u':
ctl.quote = 0;
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH 02/10] getopt: fix memory leaks and integer overflows [ASAN & valgrind]
2016-03-13 10:31 ` [PATCH 02/10] getopt: fix memory leaks and integer overflows [ASAN & valgrind] Sami Kerola
@ 2016-03-13 12:11 ` Yuriy M. Kaminskiy
2016-03-14 21:24 ` Sami Kerola
0 siblings, 1 reply; 17+ messages in thread
From: Yuriy M. Kaminskiy @ 2016-03-13 12:11 UTC (permalink / raw)
To: util-linux
On 03/13/16 13:31 , Sami Kerola wrote:
> The getopt(1) is short living command, and one could argue ensuring all
> allocations are freed at end of execution is waste of time. There is a
> point in that, but making test-suite runs to be less noisy with ASAN is also
> nice as it encourages reading the errors when/if they happen.
>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> misc-utils/getopt.c | 36 ++++++++++++++++++++++++++++--------
> 1 file changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
> index c4144f6..be2ed38 100644
> --- a/misc-utils/getopt.c
> +++ b/misc-utils/getopt.c
> @@ -79,13 +79,23 @@
> /* The shells recognized. */
> typedef enum { BASH, TCSH } shell_t;
>
> +/* This is a copy of getopt_long(3) structure, in which *name does not have
> + * const, so that is can be free'd at end of execution. */
> +struct getoption {
> + char *name;
> + int has_arg;
> + int *flag;
> + int val;
> +};
What will happen if some implementation will add new fields in `struct
option`? (Sure, unlikely, but).
IMO, `free((char *)option->name)` is *much* safer.
> struct getopt_control {
> shell_t shell; /* the shell we generate output for */
> char *optstr; /* getopt(3) optstring */
> - struct option *long_options; /* long options */
> + struct getoption *long_options; /* long options */
> int long_options_length; /* length of options array */
> int long_options_nr; /* number of used elements in array */
> unsigned int
> + free_name:1, /* free up argv[0] after printout */
> compatible:1, /* compatibility mode for 'difficult' programs */
> quiet_errors:1, /* print errors */
> quiet_output:1, /* print output */
> @@ -181,7 +191,7 @@ static void print_normalized(const struct getopt_control *ctl, const char *arg)
> * optstr must contain the short options, and longopts the long options.
> * Other settings are found in global variables.
> */
> -static int generate_output(const struct getopt_control *ctl, char *argv[], int argc)
> +static int generate_output(struct getopt_control *ctl, char *argv[], int argc)
> {
> int exit_code = EXIT_SUCCESS; /* Assume everything will be OK */
> int opt;
> @@ -195,8 +205,10 @@ static int generate_output(const struct getopt_control *ctl, char *argv[], int a
> optind = 0;
>
> while ((opt =
> - (getopt_long_fp(argc, argv, ctl->optstr, ctl->long_options, &longindex)))
> - != EOF)
> + (getopt_long_fp
> + (argc, argv, ctl->optstr,
> + (const struct option *)ctl->long_options, &longindex)))
> + != EOF) {
> if (opt == '?' || opt == ':')
> exit_code = GETOPT_EXIT_CODE;
> else if (!ctl->quiet_output) {
> @@ -216,13 +228,19 @@ static int generate_output(const struct getopt_control *ctl, char *argv[], int a
> print_normalized(ctl, optarg ? optarg : "");
> }
> }
> -
> + }
> if (!ctl->quiet_output) {
> printf(" --");
> while (optind < argc)
> print_normalized(ctl, argv[optind++]);
> printf("\n");
> }
> + for (longindex = 0; longindex < ctl->long_options_nr; longindex++)
> + free(ctl->long_options[longindex].name);
> + free(ctl->long_options);
> + free(ctl->optstr);
> + if (ctl->free_name)
> + free(argv[0]);
> return exit_code;
> }
>
> @@ -373,9 +391,6 @@ int main(int argc, char *argv[])
> textdomain(PACKAGE);
> atexit(close_stdout);
>
> - add_longopt(&ctl, NULL, 0); /* init */
> - getopt_long_fp = getopt_long;
> -
> if (getenv("GETOPT_COMPATIBLE"))
> ctl.compatible = 1;
>
> @@ -391,6 +406,9 @@ int main(int argc, char *argv[])
> parse_error(_("missing optstring argument"));
> }
>
> + add_longopt(&ctl, NULL, 0); /* init */
> + getopt_long_fp = getopt_long;
> +
> if (argv[1][0] != '-' || ctl.compatible) {
> ctl.quote = 0;
> ctl.optstr = xmalloc(strlen(argv[1]) + 1);
> @@ -417,6 +435,7 @@ int main(int argc, char *argv[])
> case 'n':
> free(name);
> name = xstrdup(optarg);
> + ctl.free_name = 1;
> break;
> case 'q':
> ctl.quiet_errors = 1;
> @@ -428,6 +447,7 @@ int main(int argc, char *argv[])
> ctl.shell = shell_type(optarg);
> break;
> case 'T':
> + free(ctl.long_options);
> return TEST_EXIT_CODE;
> case 'u':
> ctl.quote = 0;
> --
> 2.7.2
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH 02/10] getopt: fix memory leaks and integer overflows [ASAN & valgrind]
2016-03-13 12:11 ` Yuriy M. Kaminskiy
@ 2016-03-14 21:24 ` Sami Kerola
0 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-14 21:24 UTC (permalink / raw)
To: Yuriy M. Kaminskiy; +Cc: util-linux
On Sun, 13 Mar 2016, Yuriy M. Kaminskiy wrote:
> On 03/13/16 13:31 , Sami Kerola wrote:
> > The getopt(1) is short living command, and one could argue ensuring all
> > allocations are freed at end of execution is waste of time. There is a
> > point in that, but making test-suite runs to be less noisy with ASAN is also
> > nice as it encourages reading the errors when/if they happen.
> >
> > Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> > ---
> > misc-utils/getopt.c | 36 ++++++++++++++++++++++++++++--------
> > 1 file changed, 28 insertions(+), 8 deletions(-)
> >
> > diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
> > index c4144f6..be2ed38 100644
> > --- a/misc-utils/getopt.c
> > +++ b/misc-utils/getopt.c
> > @@ -79,13 +79,23 @@
> > /* The shells recognized. */
> > typedef enum { BASH, TCSH } shell_t;
> >
> > +/* This is a copy of getopt_long(3) structure, in which *name does not have
> > + * const, so that is can be free'd at end of execution. */
> > +struct getoption {
> > + char *name;
> > + int has_arg;
> > + int *flag;
> > + int val;
> > +};
>
> What will happen if some implementation will add new fields in `struct
> option`? (Sure, unlikely, but).
> IMO, `free((char *)option->name)` is *much* safer.
Hi Yuriy and Karel,
Okay, sounds fair adding a 'copy struct' wasn't the brightest idea ever.
See below a const cast to read-write char pointer. This seems to make
compiler happy.
--->8----
From: Sami Kerola <kerolasa@iki.fi>
Date: Mon, 14 Mar 2016 21:06:30 +0000
Subject: getopt: fix memory leaks and integer overflows [ASAN & valgrind]
The getopt(1) is short living command, and one could argue ensuring all
allocations are freed at end of execution is waste of time. There is a
point in that, but making test-suite runs to be less noisy with ASAN is
also nice as it encourages reading the errors when/if they happen.
Reviewed-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/getopt.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
index c4144f6..7f4547c 100644
--- a/misc-utils/getopt.c
+++ b/misc-utils/getopt.c
@@ -86,6 +86,7 @@ struct getopt_control {
int long_options_length; /* length of options array */
int long_options_nr; /* number of used elements in array */
unsigned int
+ free_name:1, /* free up argv[0] after printout */
compatible:1, /* compatibility mode for 'difficult' programs */
quiet_errors:1, /* print errors */
quiet_output:1, /* print output */
@@ -181,7 +182,7 @@ static void print_normalized(const struct getopt_control *ctl, const char *arg)
* optstr must contain the short options, and longopts the long options.
* Other settings are found in global variables.
*/
-static int generate_output(const struct getopt_control *ctl, char *argv[], int argc)
+static int generate_output(struct getopt_control *ctl, char *argv[], int argc)
{
int exit_code = EXIT_SUCCESS; /* Assume everything will be OK */
int opt;
@@ -195,8 +196,10 @@ static int generate_output(const struct getopt_control *ctl, char *argv[], int a
optind = 0;
while ((opt =
- (getopt_long_fp(argc, argv, ctl->optstr, ctl->long_options, &longindex)))
- != EOF)
+ (getopt_long_fp
+ (argc, argv, ctl->optstr,
+ (const struct option *)ctl->long_options, &longindex)))
+ != EOF) {
if (opt == '?' || opt == ':')
exit_code = GETOPT_EXIT_CODE;
else if (!ctl->quiet_output) {
@@ -216,13 +219,19 @@ static int generate_output(const struct getopt_control *ctl, char *argv[], int a
print_normalized(ctl, optarg ? optarg : "");
}
}
-
+ }
if (!ctl->quiet_output) {
printf(" --");
while (optind < argc)
print_normalized(ctl, argv[optind++]);
printf("\n");
}
+ for (longindex = 0; longindex < ctl->long_options_nr; longindex++)
+ free((char *)ctl->long_options[longindex].name);
+ free(ctl->long_options);
+ free(ctl->optstr);
+ if (ctl->free_name)
+ free(argv[0]);
return exit_code;
}
@@ -373,9 +382,6 @@ int main(int argc, char *argv[])
textdomain(PACKAGE);
atexit(close_stdout);
- add_longopt(&ctl, NULL, 0); /* init */
- getopt_long_fp = getopt_long;
-
if (getenv("GETOPT_COMPATIBLE"))
ctl.compatible = 1;
@@ -391,6 +397,9 @@ int main(int argc, char *argv[])
parse_error(_("missing optstring argument"));
}
+ add_longopt(&ctl, NULL, 0); /* init */
+ getopt_long_fp = getopt_long;
+
if (argv[1][0] != '-' || ctl.compatible) {
ctl.quote = 0;
ctl.optstr = xmalloc(strlen(argv[1]) + 1);
@@ -417,6 +426,7 @@ int main(int argc, char *argv[])
case 'n':
free(name);
name = xstrdup(optarg);
+ ctl.free_name = 1;
break;
case 'q':
ctl.quiet_errors = 1;
@@ -428,6 +438,7 @@ int main(int argc, char *argv[])
ctl.shell = shell_type(optarg);
break;
case 'T':
+ free(ctl.long_options);
return TEST_EXIT_CODE;
case 'u':
ctl.quote = 0;
--
2.7.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime()
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
2016-03-13 10:31 ` [PATCH 01/10] logger: fix memory leak [ASAN and valgrind] Sami Kerola
2016-03-13 10:31 ` [PATCH 02/10] getopt: fix memory leaks and integer overflows [ASAN & valgrind] Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 11:28 ` Ruediger Meier
2016-03-13 13:20 ` Yuriy M. Kaminskiy
2016-03-13 10:31 ` [PATCH 04/10] isosize: stop unmeaningful printing errno message Sami Kerola
` (7 subsequent siblings)
10 siblings, 2 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
POSIX.1-2008 marks asctime() and asctime_r() as obsolete, recommending the
use of strftime(3) instead.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
include/timeutils.h | 3 +++
login-utils/lslogins.c | 5 ++---
sys-utils/lsipc.c | 6 ++----
sys-utils/rtcwake.c | 15 +++++++++------
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/include/timeutils.h b/include/timeutils.h
index 8ed501b..427f833 100644
--- a/include/timeutils.h
+++ b/include/timeutils.h
@@ -51,6 +51,9 @@ typedef uint64_t nsec_t;
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
#define FORMAT_TIMESPAN_MAX 64
+/* Original asctime(3) format ends to '\n' that we do not do here. */
+#define STRFTIME_ASCTIME_FORMAT "%a %b %e %T %Y"
+
int parse_timestamp(const char *t, usec_t *usec);
#endif /* UTIL_LINUX_TIME_UTIL_H */
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index 40a1343..554a1a3 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -56,6 +56,7 @@
#include "pathnames.h"
#include "logindefs.h"
#include "procutils.h"
+#include "timeutils.h"
/*
* column description
@@ -333,9 +334,7 @@ static char *make_time(int mode, time_t time)
switch(mode) {
case TIME_FULL:
- asctime_r(&tm, buf);
- if (*(s = buf + strlen(buf) - 1) == '\n')
- *s = '\0';
+ strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
break;
case TIME_SHORT:
if (date_is_today(time))
diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
index 938728a..19cf5a8 100644
--- a/sys-utils/lsipc.c
+++ b/sys-utils/lsipc.c
@@ -39,6 +39,7 @@
#include "xalloc.h"
#include "procutils.h"
#include "ipcutils.h"
+#include "timeutils.h"
/*
* time modes
@@ -445,7 +446,6 @@ static int date_is_thisyear(time_t t)
static char *make_time(int mode, time_t time)
{
- char *s;
struct tm tm;
char buf[64] = {0};
@@ -453,9 +453,7 @@ static char *make_time(int mode, time_t time)
switch(mode) {
case TIME_FULL:
- asctime_r(&tm, buf);
- if (*(s = buf + strlen(buf) - 1) == '\n')
- *s = '\0';
+ strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
break;
case TIME_SHORT:
if (date_is_today(time))
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index 7c748dc..32df785 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -173,7 +173,7 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
return -1;
}
/* Convert rtc_time to normal arithmetic-friendly form,
- * updating tm.tm_wday as used by asctime().
+ * updating tm.tm_wday as used by strftime().
*/
tm.tm_sec = rtc.tm_sec;
tm.tm_min = rtc.tm_min;
@@ -193,14 +193,17 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
/* Unless the system uses UTC, either delta or tzone
* reflects a seconds offset from UTC. The value can
* help sort out problems like bugs in your C library. */
+ char buf[64] = { 0 };
+ struct tm sys_tm = { 0 };
+
printf("\tdelta = %ld\n", ctl->sys_time - ctl->rtc_time);
printf("\ttzone = %ld\n", timezone);
printf("\ttzname = %s\n", tzname[daylight]);
- gmtime_r(&ctl->rtc_time, &tm);
- printf("\tsystime = %ld, (UTC) %s",
- (long) ctl->sys_time, asctime(gmtime(&ctl->sys_time)));
- printf("\trtctime = %ld, (UTC) %s",
- (long) ctl->rtc_time, asctime(&tm));
+ gmtime_r(&ctl->sys_time, &sys_tm);
+ strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &sys_tm);
+ printf("\tsystime = %ld, (UTC) %s\n", (long) ctl->sys_time, buf);
+ strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
+ printf("\trtctime = %ld, (UTC) %s\n", (long) ctl->rtc_time, buf);
}
return 0;
}
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime()
2016-03-13 10:31 ` [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime() Sami Kerola
@ 2016-03-13 11:28 ` Ruediger Meier
2016-03-13 13:20 ` Yuriy M. Kaminskiy
1 sibling, 0 replies; 17+ messages in thread
From: Ruediger Meier @ 2016-03-13 11:28 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sunday 13 March 2016, Sami Kerola wrote:
> POSIX.1-2008 marks asctime() and asctime_r() as obsolete,
> recommending the use of strftime(3) instead.
>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> include/timeutils.h | 3 +++
> login-utils/lslogins.c | 5 ++---
> sys-utils/lsipc.c | 6 ++----
> sys-utils/rtcwake.c | 15 +++++++++------
> 4 files changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/include/timeutils.h b/include/timeutils.h
> index 8ed501b..427f833 100644
> --- a/include/timeutils.h
> +++ b/include/timeutils.h
> @@ -51,6 +51,9 @@ typedef uint64_t nsec_t;
> #define FORMAT_TIMESTAMP_RELATIVE_MAX 256
> #define FORMAT_TIMESPAN_MAX 64
>
> +/* Original asctime(3) format ends to '\n' that we do not do here.
> */ +#define STRFTIME_ASCTIME_FORMAT "%a %b %e %T %Y"
> +
> int parse_timestamp(const char *t, usec_t *usec);
>
> #endif /* UTIL_LINUX_TIME_UTIL_H */
> diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
> index 40a1343..554a1a3 100644
> --- a/login-utils/lslogins.c
> +++ b/login-utils/lslogins.c
> @@ -56,6 +56,7 @@
> #include "pathnames.h"
> #include "logindefs.h"
> #include "procutils.h"
> +#include "timeutils.h"
>
> /*
> * column description
> @@ -333,9 +334,7 @@ static char *make_time(int mode, time_t time)
>
> switch(mode) {
> case TIME_FULL:
> - asctime_r(&tm, buf);
> - if (*(s = buf + strlen(buf) - 1) == '\n')
> - *s = '\0';
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
char *s is now unused and could be removed.
> break;
> case TIME_SHORT:
> if (date_is_today(time))
> diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
> index 938728a..19cf5a8 100644
> --- a/sys-utils/lsipc.c
> +++ b/sys-utils/lsipc.c
> @@ -39,6 +39,7 @@
> #include "xalloc.h"
> #include "procutils.h"
> #include "ipcutils.h"
> +#include "timeutils.h"
>
> /*
> * time modes
> @@ -445,7 +446,6 @@ static int date_is_thisyear(time_t t)
>
> static char *make_time(int mode, time_t time)
> {
> - char *s;
> struct tm tm;
> char buf[64] = {0};
>
> @@ -453,9 +453,7 @@ static char *make_time(int mode, time_t time)
>
> switch(mode) {
> case TIME_FULL:
> - asctime_r(&tm, buf);
> - if (*(s = buf + strlen(buf) - 1) == '\n')
> - *s = '\0';
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
> break;
> case TIME_SHORT:
> if (date_is_today(time))
> diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
> index 7c748dc..32df785 100644
> --- a/sys-utils/rtcwake.c
> +++ b/sys-utils/rtcwake.c
> @@ -173,7 +173,7 @@ static int get_basetimes(struct rtcwake_control
> *ctl, int fd) return -1;
> }
> /* Convert rtc_time to normal arithmetic-friendly form,
> - * updating tm.tm_wday as used by asctime().
> + * updating tm.tm_wday as used by strftime().
> */
> tm.tm_sec = rtc.tm_sec;
> tm.tm_min = rtc.tm_min;
> @@ -193,14 +193,17 @@ static int get_basetimes(struct rtcwake_control
> *ctl, int fd) /* Unless the system uses UTC, either delta or tzone
> * reflects a seconds offset from UTC. The value can
> * help sort out problems like bugs in your C library. */
> + char buf[64] = { 0 };
> + struct tm sys_tm = { 0 };
> +
> printf("\tdelta = %ld\n", ctl->sys_time - ctl->rtc_time);
> printf("\ttzone = %ld\n", timezone);
> printf("\ttzname = %s\n", tzname[daylight]);
> - gmtime_r(&ctl->rtc_time, &tm);
> - printf("\tsystime = %ld, (UTC) %s",
> - (long) ctl->sys_time, asctime(gmtime(&ctl->sys_time)));
> - printf("\trtctime = %ld, (UTC) %s",
> - (long) ctl->rtc_time, asctime(&tm));
> + gmtime_r(&ctl->sys_time, &sys_tm);
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &sys_tm);
> + printf("\tsystime = %ld, (UTC) %s\n", (long) ctl->sys_time, buf);
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
> + printf("\trtctime = %ld, (UTC) %s\n", (long) ctl->rtc_time, buf);
> }
> return 0;
> }
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime()
2016-03-13 10:31 ` [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime() Sami Kerola
2016-03-13 11:28 ` Ruediger Meier
@ 2016-03-13 13:20 ` Yuriy M. Kaminskiy
2016-03-14 12:08 ` Karel Zak
1 sibling, 1 reply; 17+ messages in thread
From: Yuriy M. Kaminskiy @ 2016-03-13 13:20 UTC (permalink / raw)
To: util-linux
[-- Attachment #1: Type: text/plain, Size: 389 bytes --]
On 03/13/16 13:31 , Sami Kerola wrote:
> POSIX.1-2008 marks asctime() and asctime_r() as obsolete, recommending the
> use of strftime(3) instead.
stftime uses locale, asctime is not. And if you want *locale-specific*
time presentation, it is "%c" --- it can be very different from your "%a
%b...", e.g. compare with attached
gcc -o asctime asctime.c
LC_ALL=ja_JP.UTF-8 ./asctime
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: asctime.c --]
[-- Type: text/x-csrc, Size: 312 bytes --]
#include <stdio.h>
#include <time.h>
#include <locale.h>
int main()
{
time_t t = time(NULL);
char buf[64];
struct tm *tm;
setlocale(LC_ALL, "");
puts(asctime(tm = localtime(&t)));
strftime(buf, sizeof(buf), "%a %b %e %T %Y", tm);
puts(buf);
strftime(buf, sizeof(buf), "%c", tm);
puts(buf);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 3735 bytes --]
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> include/timeutils.h | 3 +++
> login-utils/lslogins.c | 5 ++---
> sys-utils/lsipc.c | 6 ++----
> sys-utils/rtcwake.c | 15 +++++++++------
> 4 files changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/include/timeutils.h b/include/timeutils.h
> index 8ed501b..427f833 100644
> --- a/include/timeutils.h
> +++ b/include/timeutils.h
> @@ -51,6 +51,9 @@ typedef uint64_t nsec_t;
> #define FORMAT_TIMESTAMP_RELATIVE_MAX 256
> #define FORMAT_TIMESPAN_MAX 64
>
> +/* Original asctime(3) format ends to '\n' that we do not do here. */
> +#define STRFTIME_ASCTIME_FORMAT "%a %b %e %T %Y"
> +
> int parse_timestamp(const char *t, usec_t *usec);
>
> #endif /* UTIL_LINUX_TIME_UTIL_H */
> diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
> index 40a1343..554a1a3 100644
> --- a/login-utils/lslogins.c
> +++ b/login-utils/lslogins.c
> @@ -56,6 +56,7 @@
> #include "pathnames.h"
> #include "logindefs.h"
> #include "procutils.h"
> +#include "timeutils.h"
>
> /*
> * column description
> @@ -333,9 +334,7 @@ static char *make_time(int mode, time_t time)
>
> switch(mode) {
> case TIME_FULL:
> - asctime_r(&tm, buf);
> - if (*(s = buf + strlen(buf) - 1) == '\n')
> - *s = '\0';
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
> break;
> case TIME_SHORT:
> if (date_is_today(time))
> diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
> index 938728a..19cf5a8 100644
> --- a/sys-utils/lsipc.c
> +++ b/sys-utils/lsipc.c
> @@ -39,6 +39,7 @@
> #include "xalloc.h"
> #include "procutils.h"
> #include "ipcutils.h"
> +#include "timeutils.h"
>
> /*
> * time modes
> @@ -445,7 +446,6 @@ static int date_is_thisyear(time_t t)
>
> static char *make_time(int mode, time_t time)
> {
> - char *s;
> struct tm tm;
> char buf[64] = {0};
>
> @@ -453,9 +453,7 @@ static char *make_time(int mode, time_t time)
>
> switch(mode) {
> case TIME_FULL:
> - asctime_r(&tm, buf);
> - if (*(s = buf + strlen(buf) - 1) == '\n')
> - *s = '\0';
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
> break;
> case TIME_SHORT:
> if (date_is_today(time))
> diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
> index 7c748dc..32df785 100644
> --- a/sys-utils/rtcwake.c
> +++ b/sys-utils/rtcwake.c
> @@ -173,7 +173,7 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
> return -1;
> }
> /* Convert rtc_time to normal arithmetic-friendly form,
> - * updating tm.tm_wday as used by asctime().
> + * updating tm.tm_wday as used by strftime().
> */
> tm.tm_sec = rtc.tm_sec;
> tm.tm_min = rtc.tm_min;
> @@ -193,14 +193,17 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
> /* Unless the system uses UTC, either delta or tzone
> * reflects a seconds offset from UTC. The value can
> * help sort out problems like bugs in your C library. */
> + char buf[64] = { 0 };
> + struct tm sys_tm = { 0 };
> +
> printf("\tdelta = %ld\n", ctl->sys_time - ctl->rtc_time);
> printf("\ttzone = %ld\n", timezone);
> printf("\ttzname = %s\n", tzname[daylight]);
> - gmtime_r(&ctl->rtc_time, &tm);
> - printf("\tsystime = %ld, (UTC) %s",
> - (long) ctl->sys_time, asctime(gmtime(&ctl->sys_time)));
> - printf("\trtctime = %ld, (UTC) %s",
> - (long) ctl->rtc_time, asctime(&tm));
> + gmtime_r(&ctl->sys_time, &sys_tm);
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &sys_tm);
> + printf("\tsystime = %ld, (UTC) %s\n", (long) ctl->sys_time, buf);
> + strftime(buf, sizeof(buf), STRFTIME_ASCTIME_FORMAT, &tm);
> + printf("\trtctime = %ld, (UTC) %s\n", (long) ctl->rtc_time, buf);
> }
> return 0;
> }
> --
> 2.7.2
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime()
2016-03-13 13:20 ` Yuriy M. Kaminskiy
@ 2016-03-14 12:08 ` Karel Zak
0 siblings, 0 replies; 17+ messages in thread
From: Karel Zak @ 2016-03-14 12:08 UTC (permalink / raw)
To: Yuriy M. Kaminskiy; +Cc: util-linux
On Sun, Mar 13, 2016 at 04:20:42PM +0300, Yuriy M. Kaminskiy wrote:
>
> On 03/13/16 13:31 , Sami Kerola wrote:
> > POSIX.1-2008 marks asctime() and asctime_r() as obsolete, recommending the
> > use of strftime(3) instead.
>
> stftime uses locale, asctime is not. And if you want *locale-specific*
> time presentation, it is "%c" --- it can be very different from your "%a
> %b...", e.g. compare with attached
This is why I have asked for functions in lib/timeutils.c to make
short, full or iso formats explicitly defined on one place to avoid
creativity in utils code and such discussions.
We need:
- human readable times:
* full (%c -- now asctime)
* short ("%H:%M:%S, "%b%d/%H:%M", "%Y-%b%d")
- ISO:
* full
* short
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 04/10] isosize: stop unmeaningful printing errno message
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (2 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 03/10] lsipc, lslogins, rtcwake: replace asctime() with strftime() Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 05/10] setsid: fix argument count bug Sami Kerola
` (6 subsequent siblings)
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Earlier printout had strange looking 'Success'.
$ isosize --sectors /dev/urandom
isosize: /dev/urandom: might not be an ISO filesystem
isosize: 733error: le=-1971599244 be=1633181607: Success
...
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/isosize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/disk-utils/isosize.c b/disk-utils/isosize.c
index 43569ae..0f676ca 100644
--- a/disk-utils/isosize.c
+++ b/disk-utils/isosize.c
@@ -84,7 +84,7 @@ static int isonum_733(unsigned char *p, int xflag)
int be = isonum_732(p + 4);
if (xflag && le != be)
/* translation is useless */
- warn("733error: le=%d be=%d", le, be);
+ warnx("733error: le=%d be=%d", le, be);
return (le);
}
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 05/10] setsid: fix argument count bug
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (3 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 04/10] isosize: stop unmeaningful printing errno message Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 06/10] bash-completion: fsck.cramfs, isosize: find files an argument Sami Kerola
` (5 subsequent siblings)
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
The below demonstrates what happen before this change.
$ setsid --wait
setsid: child 3252 did not exit normally: Success
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/setsid.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c
index adc34ec..bb089df 100644
--- a/sys-utils/setsid.c
+++ b/sys-utils/setsid.c
@@ -83,7 +83,7 @@ int main(int argc, char **argv)
usage(stderr);
}
- if (argc < 2)
+ if (argc - optind < 1)
usage(stderr);
if (getpgrp() == getpid()) {
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 06/10] bash-completion: fsck.cramfs, isosize: find files an argument
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (4 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 05/10] setsid: fix argument count bug Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 07/10] bash-completion: ipcmk: add missing completion file Sami Kerola
` (4 subsequent siblings)
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Earlier completion suggested only options for the command, this changes
options to be proposed when first character of an argument is dash.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/fsck.cramfs | 11 +++++++++--
bash-completion/isosize | 11 +++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/bash-completion/fsck.cramfs b/bash-completion/fsck.cramfs
index acf6564..b3276b9 100644
--- a/bash-completion/fsck.cramfs
+++ b/bash-completion/fsck.cramfs
@@ -15,8 +15,15 @@ _fsck.cramfs_module()
return 0
;;
esac
- OPTS='--verbose --destination --help --version file'
- COMPREPLY=( $(compgen -W "${OPTS[*]}" -S ' ' -- $cur) )
+ case $cur in
+ -*)
+ COMPREPLY=( $(compgen -W "--verbose --blocksize --extract --help --version" -- $cur) )
+ return 0
+ ;;
+ esac
+ local IFS=$'\n'
+ compopt -o filenames
+ COMPREPLY=( $(compgen -f -- $cur) )
return 0
}
complete -F _fsck.cramfs_module fsck.cramfs
diff --git a/bash-completion/isosize b/bash-completion/isosize
index 13d4d29..fec2f8b 100644
--- a/bash-completion/isosize
+++ b/bash-completion/isosize
@@ -13,8 +13,15 @@ _isosize_module()
return 0
;;
esac
- OPTS='--divisor --sectors --help --version'
- COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+ case $cur in
+ -*)
+ COMPREPLY=( $(compgen -W "--divisor --sectors --help --version" -- $cur) )
+ return 0
+ ;;
+ esac
+ local IFS=$'\n'
+ compopt -o filenames
+ COMPREPLY=( $(compgen -f -- $cur) )
return 0
}
complete -F _isosize_module isosize
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 07/10] bash-completion: ipcmk: add missing completion file
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (5 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 06/10] bash-completion: fsck.cramfs, isosize: find files an argument Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 08/10] bash-completion: lslogins: " Sami Kerola
` (3 subsequent siblings)
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/Makemodule.am | 3 +++
bash-completion/ipcmk | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 bash-completion/ipcmk
diff --git a/bash-completion/Makemodule.am b/bash-completion/Makemodule.am
index 5372ed0..e4196a3 100644
--- a/bash-completion/Makemodule.am
+++ b/bash-completion/Makemodule.am
@@ -30,6 +30,9 @@ endif
if BUILD_HEXDUMP
dist_bashcompletion_DATA += bash-completion/hexdump
endif
+if BUILD_IPCMK
+dist_bashcompletion_DATA += bash-completion/ipcmk
+endif
if BUILD_IPCRM
dist_bashcompletion_DATA += bash-completion/ipcrm
endif
diff --git a/bash-completion/ipcmk b/bash-completion/ipcmk
new file mode 100644
index 0000000..696266c
--- /dev/null
+++ b/bash-completion/ipcmk
@@ -0,0 +1,27 @@
+_ipcmk_module()
+{
+ local cur prev
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ case $prev in
+ '-M'|'--shmem')
+ COMPREPLY=( $(compgen -W "size" -- $cur) )
+ return 0
+ ;;
+ '-S'|'--semaphore')
+ COMPREPLY=( $(compgen -W "number" -- $cur) )
+ return 0
+ ;;
+ '-p'|'--mode')
+ COMPREPLY=( $(compgen -W "mode" -- $cur) )
+ return 0
+ ;;
+ '-h'|'--help'|'-V'|'--version')
+ return 0
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W "--shmem --semaphore --queue --mode --help --version" -- $cur) )
+ return 0
+}
+complete -F _ipcmk_module ipcmk
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 08/10] bash-completion: lslogins: add missing completion file
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (6 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 07/10] bash-completion: ipcmk: add missing completion file Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 09/10] bash-completion: lsns: " Sami Kerola
` (2 subsequent siblings)
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/Makemodule.am | 3 ++
bash-completion/lslogins | 76 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
create mode 100755 bash-completion/lslogins
diff --git a/bash-completion/Makemodule.am b/bash-completion/Makemodule.am
index e4196a3..9479087 100644
--- a/bash-completion/Makemodule.am
+++ b/bash-completion/Makemodule.am
@@ -150,6 +150,9 @@ endif
if BUILD_LAST
dist_bashcompletion_DATA += bash-completion/last
endif
+if BUILD_LSLOGINS
+dist_bashcompletion_DATA += bash-completion/lslogins
+endif
if BUILD_NEWGRP
dist_bashcompletion_DATA += bash-completion/newgrp
endif
diff --git a/bash-completion/lslogins b/bash-completion/lslogins
new file mode 100755
index 0000000..967b644
--- /dev/null
+++ b/bash-completion/lslogins
@@ -0,0 +1,76 @@
+_lslogins_module()
+{
+ local cur prev OPTS LSLOGINS_COLS_ALL
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ LSLOGINS_COLS_ALL="
+ USER UID GECOS HOMEDIR SHELL NOLOGIN PWD-LOCK PWD-EMPTY
+ PWD-DENY GROUP GID SUPP-GROUPS SUPP-GIDS LAST-LOGIN LAST-TTY
+ LAST-HOSTNAME FAILED-LOGIN FAILED-TTY HUSHED PWD-WARN
+ PWD-CHANGE PWD-MIN PWD-MAX PWD-EXPIR CONTEXT PROC
+ "
+ case $prev in
+ '-g'|'--groups')
+ COMPREPLY=( $(compgen -W "$(getent group | awk -F: '{print $1}')" -- $cur) )
+ return 0
+ ;;
+ '-l'|'--logins')
+ COMPREPLY=( $(compgen -W "$(getent passwd | awk -F: '{print $1}')" -- $cur) )
+ return 0
+ ;;
+ '--time-format')
+ COMPREPLY=( $(compgen -W "short full iso" -- $cur) )
+ return 0
+ ;;
+ '--wtmp-file'|'--btmp-file')
+ local IFS=$'\n'
+ compopt -o filenames
+ COMPREPLY=( $(compgen -f -- $cur) )
+ return 0
+ ;;
+ '-o'|'--output')
+ local prefix realcur LSLOGINS_COLS
+ realcur="${cur##*,}"
+ prefix="${cur%$realcur}"
+ for WORD in $LSLOGINS_COLS_ALL; do
+ if ! [[ $prefix == *"$WORD"* ]]; then
+ LSLOGINS_COLS="$WORD $LSLOGINS_COLS"
+ fi
+ done
+ compopt -o nospace
+ COMPREPLY=( $(compgen -P "$prefix" -W "$LSLOGINS_COLS" -S ',' -- $realcur) )
+ return 0
+ ;;
+ '-h'|'--help'|'-V'|'--version')
+ return 0
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W "
+ --acc-expiration
+ --colon-separate
+ --export
+ --failed
+ --supp-groups
+ --groups
+ --last
+ --logins
+ --newline
+ --noheadings
+ --notruncate
+ --output
+ --pwd
+ --raw
+ --system-accs
+ --time-format
+ --user-accs
+ --context
+ --print0
+ --wtmp-file
+ --btmp-file
+ --help
+ --version
+ " -- $cur) )
+ return 0
+}
+complete -F _lslogins_module lslogins
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 09/10] bash-completion: lsns: add missing completion file
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (7 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 08/10] bash-completion: lslogins: " Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-13 10:31 ` [PATCH 10/10] docs: update AUTHORS file Sami Kerola
2016-03-14 12:17 ` [PATCH 00/10] pull: release v2.28 prep work Karel Zak
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/Makemodule.am | 3 +++
bash-completion/lsns | 56 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+)
create mode 100644 bash-completion/lsns
diff --git a/bash-completion/Makemodule.am b/bash-completion/Makemodule.am
index 9479087..56fdd32 100644
--- a/bash-completion/Makemodule.am
+++ b/bash-completion/Makemodule.am
@@ -51,6 +51,9 @@ endif
if BUILD_LSIPC
dist_bashcompletion_DATA += bash-completion/lsipc
endif
+if BUILD_LSNS
+dist_bashcompletion_DATA += bash-completion/lsns
+endif
if BUILD_MCOOKIE
dist_bashcompletion_DATA += bash-completion/mcookie
endif
diff --git a/bash-completion/lsns b/bash-completion/lsns
new file mode 100644
index 0000000..8e6a335
--- /dev/null
+++ b/bash-completion/lsns
@@ -0,0 +1,56 @@
+_lsns_module()
+{
+ local cur prev OPTS LSNS_COLS_ALL
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ LSNS_COLS_ALL="
+ NS TYPE PATH NPROCS PID PPID COMMAND UID USER
+ "
+ case $prev in
+ '-o'|'--output')
+ local prefix realcur LSNS_COLS
+ realcur="${cur##*,}"
+ prefix="${cur%$realcur}"
+ for WORD in $LSNS_COLS_ALL; do
+ if ! [[ $prefix == *"$WORD"* ]]; then
+ LSNS_COLS="$WORD $LSNS_COLS"
+ fi
+ done
+ compopt -o nospace
+ COMPREPLY=( $(compgen -P "$prefix" -W "$LSNS_COLS" -S ',' -- $realcur) )
+ return 0
+ ;;
+ '-p'|'--task')
+ COMPREPLY=( $(compgen -W "$(cd /proc && echo [0-9]*)" -- $cur) )
+ return 0
+ ;;
+ '-t'|'--type')
+ COMPREPLY=( $(compgen -W "mnt net ipc user pid uts" -- $cur) )
+ return 0
+ ;;
+ '-h'|'--help'|'-V'|'--version')
+ return 0
+ ;;
+ esac
+ case $cur in
+ -*)
+ COMPREPLY=( $(compgen -W "
+ --json
+ --list
+ --noheadings
+ --output
+ --task
+ --raw
+ --notruncate
+ --type
+ --help
+ --version
+ " -- $cur) )
+ return 0
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W "mnt net pid uts ipc user" -- $cur ) )
+ return 0
+}
+complete -F _lsns_module lsns
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 10/10] docs: update AUTHORS file
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (8 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 09/10] bash-completion: lsns: " Sami Kerola
@ 2016-03-13 10:31 ` Sami Kerola
2016-03-14 12:17 ` [PATCH 00/10] pull: release v2.28 prep work Karel Zak
10 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-03-13 10:31 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Former email address has not reached me since summer 2015.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
AUTHORS | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/AUTHORS b/AUTHORS
index c788396..a0835b6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -459,7 +459,7 @@ CONTRIBUTORS:
Ross Biro <biro@yggdrasil.com>
Roy Peled <the.roy.peled@gmail.com>
Ruediger Meier <ruediger.meier@ga-group.nl>
- Sami Kerola <sami.kerola@lastminute.com>
+ Sami Kerola <kerolasa@iki.fi>
Sami Liedes <sami.liedes@iki.fi>
Samuel Thibault <samuel.thibault@ens-lyon.org>
Sam Varshavchik <mrsam@courier-mta.com>
--
2.7.2
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH 00/10] pull: release v2.28 prep work
2016-03-13 10:31 [PATCH 00/10] pull: release v2.28 prep work Sami Kerola
` (9 preceding siblings ...)
2016-03-13 10:31 ` [PATCH 10/10] docs: update AUTHORS file Sami Kerola
@ 2016-03-14 12:17 ` Karel Zak
10 siblings, 0 replies; 17+ messages in thread
From: Karel Zak @ 2016-03-14 12:17 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Mar 13, 2016 at 10:31:39AM +0000, Sami Kerola wrote:
> getopt: fix memory leaks and integer overflows [ASAN & valgrind]
Not applied, it's really not elegant to have private definition of
options struct for getopt_long().
> lsipc, lslogins, rtcwake: replace asctime() with strftime()
Not applied, I think we need more discussion about it.
> isosize: stop unmeaningful printing errno message
> setsid: fix argument count bug
> bash-completion: fsck.cramfs, isosize: find files an argument
> bash-completion: ipcmk: add missing completion file
> bash-completion: lslogins: add missing completion file
> bash-completion: lsns: add missing completion file
> docs: update AUTHORS file
Applied, thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 17+ messages in thread