[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH 2/2] time: implement -a and -o
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2017-04-28 16:02:15
Message-ID: CAK1hOcM0UzuWknwd7pCroe-qqS_vMw9J5TyV9Oxu6ZrcEoSDmg () mail ! gmail ! com
[Download RAW message or body]

Applied both, thanks!

On Mon, Apr 24, 2017 at 6:08 PM, Tommi Rantala <tt.rantala@gmail.com> wrote:
> From: Tommi Rantala <tommi.t.rantala@nokia.com>
>
> Add support for -a and -o options, similar to GNU time.
>
> Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
> ---
>  miscutils/time.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/miscutils/time.c b/miscutils/time.c
> index 7c457a9..5437731 100644
> --- a/miscutils/time.c
> +++ b/miscutils/time.c
> @@ -21,11 +21,13 @@
>  //kbuild:lib-$(CONFIG_TIME) += time.o
>
>  //usage:#define time_trivial_usage
> -//usage:       "[-vp] PROG ARGS"
> +//usage:       "[-vpa] [-o FILE] PROG ARGS"
>  //usage:#define time_full_usage "\n\n"
>  //usage:       "Run PROG, display resource usage when it exits\n"
>  //usage:     "\n       -v      Verbose"
>  //usage:     "\n       -p      POSIX output format"
> +//usage:     "\n       -a      Append to the file specified with -o"
> +//usage:     "\n       -o FILE Write result to FILE instead of stderr"
>
>  #include "libbb.h"
>  #include <sys/resource.h> /* getrusage */
> @@ -414,21 +416,30 @@ int time_main(int argc UNUSED_PARAM, char **argv)
>  {
>         resource_t res;
>         const char *output_format = default_format;
> +       char *output_filename = NULL;
> +       int output_fd = STDERR_FILENO;
>         int opt;
>
>         opt_complementary = "-1"; /* at least one arg */
>         /* "+": stop on first non-option */
> -       opt = getopt32(argv, "+vp");
> +       opt = getopt32(argv, "+vpao:", &output_filename);
>         argv += optind;
>         if (opt & 1)
>                 output_format = long_format;
>         if (opt & 2)
>                 output_format = posix_format;
> +       if (opt & 8) {
> +               int append = opt & 4;
> +               /* O_CLOEXEC: do not inherit the fd to the child process. */
> +               int flags = O_CREAT | O_WRONLY | O_CLOEXEC |
> +                       (append ? O_APPEND : O_TRUNC);
> +               output_fd = xopen(output_filename, flags);
> +       }
>
>         run_command(argv, &res);
>
>         /* Cheat. printf's are shorter :) */
> -       xdup2(STDERR_FILENO, STDOUT_FILENO);
> +       xdup2(output_fd, STDOUT_FILENO);
>         summarize(output_format, argv, &res);
>
>         if (WIFSTOPPED(res.waitstatus))
> --
> 2.9.3
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic