Date: Fri, 2 May 2008 17:01:53 +0300 (EEST) From: Jaakko Heinonen <jh@saunalahti.fi> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/123329: [patch] usage strings for fifolog_create(1) and fifolog_writer(1) Message-ID: <200805021401.m42E1raj001617@ws64.jh.dy.fi> Resent-Message-ID: <200805021410.m42EA1T8076434@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 123329 >Category: bin >Synopsis: [patch] usage strings for fifolog_create(1) and fifolog_writer(1) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri May 02 14:10:00 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Jaakko Heinonen >Release: FreeBSD 8.0-CURRENT i386 >Organization: >Environment: System: FreeBSD x 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Thu May 1 15:28:32 EEST 2008 x i386 >Description: fifolog_create(1) and fifolog_writer(1) print empty usage strings if they are invoked without parameters. >How-To-Repeat: $ fifolog_create fifolog_create: Usage $ fifolog_writer fifolog_writer: Usage $ fifolog_reader >From 0 Thu Jan 1 02:00:00 1970 To 1209736020 Fri May 2 16:47:00 2008 fifolog_reader: Usage: fifolog_reader [options] fifolog After applying the patch: $ fifolog_create Usage: fifolog_create [-l record-size] [-r record-count] [-s size] file $ fifolog_writer Usage: fifolog_writer [-w write-rate] [-s sync-rate] [-z compression] file $ fifolog_reader Usage: fiforead [options] fifofile -b <start time integer> -B <start time> -e <end time integer> -E <end time> -o <output file> -R <regexp> # match regexp -t # format timestamps as %Y%m%d%H%M%S -T <timestamp format> >Fix: This patch also changes them to return EX_USAGE when usage is displayed and fifolog_reader doesn't display times when argv[0] == NULL. --- fifolog-usage.diff begins here --- Index: fifolog_create/fifolog_create.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/fifolog/fifolog_create/fifolog_create.c,v retrieving revision 1.1 diff -p -u -r1.1 fifolog_create.c --- fifolog_create/fifolog_create.c 9 Mar 2008 19:14:36 -0000 1.1 +++ fifolog_create/fifolog_create.c 2 May 2008 13:50:14 -0000 @@ -27,6 +27,8 @@ */ #include <stdio.h> +#include <stdlib.h> +#include <sysexits.h> #include <unistd.h> #include <err.h> #include <libutil.h> @@ -36,6 +38,14 @@ #define DEF_RECSIZE 512 #define DEF_RECCNT (24 * 60 * 60) +static void +usage(void) +{ + fprintf(stderr, "Usage: fifolog_create [-l record-size] " + "[-r record-count] [-s size] file\n"); + exit(EX_USAGE); +} + int main(int argc, char * const *argv) { @@ -63,13 +73,13 @@ main(int argc, char * const *argv) err(1, "Couldn't parse -s argument"); break; default: - errx(1, "Usage"); + usage(); } } argc -= optind; argv += optind; if (argc != 1) - errx(1, "Usage"); + usage(); if (size != 0 && reccnt != 0 && recsize != 0) { /* N N N */ if (size != reccnt * recsize) Index: fifolog_reader/fifolog_reader.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c,v retrieving revision 1.2 diff -p -u -r1.2 fifolog_reader.c --- fifolog_reader/fifolog_reader.c 31 Mar 2008 13:56:15 -0000 1.2 +++ fifolog_reader/fifolog_reader.c 2 May 2008 13:50:14 -0000 @@ -33,6 +33,7 @@ #include <time.h> #include <string.h> #include <stdlib.h> +#include <sysexits.h> #include <regex.h> #include "libfifolog.h" @@ -87,7 +88,7 @@ Usage(void) "\t-t # format timestamps as %%Y%%m%%d%%H%%M%%S\n" "\t-T <timestamp format>\n" ); - exit (2); + exit (EX_USAGE); } int @@ -149,13 +150,14 @@ main(int argc, char * const *argv) } } + if (argv[0] == NULL) + Usage(); + fprintf(stderr, "From\t%jd %s", (intmax_t)opt_B, ctime(&opt_B)); fprintf(stderr, "To\t%jd %s", (intmax_t)opt_E, ctime(&opt_E)); if (opt_B >= opt_E) errx(1, "Begin time not before End time"); - if (argv[0] == NULL) - errx(1, "Usage: %s [options] fifolog", progname); fl = fifolog_reader_open(argv[0]); if (!strcmp(opt_o, "-")) Index: fifolog_writer/fifolog_writer.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c,v retrieving revision 1.1 diff -p -u -r1.1 fifolog_writer.c --- fifolog_writer/fifolog_writer.c 9 Mar 2008 19:14:36 -0000 1.1 +++ fifolog_writer/fifolog_writer.c 2 May 2008 13:50:14 -0000 @@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> +#include <sysexits.h> #include <err.h> #include <unistd.h> #include <ctype.h> @@ -38,6 +39,14 @@ #include "libfifolog.h" +static void +usage(void) +{ + fprintf(stderr, "Usage: fifolog_writer [-w write-rate] [-s sync-rate] " + "[-z compression] file\n"); + exit(EX_USAGE); +} + int main(int argc, char * const *argv) { @@ -62,19 +71,19 @@ main(int argc, char * const *argv) z_opt = strtoul(optarg, NULL, 0); break; default: - errx(1, "Usage"); + usage(); } } argc -= optind; argv += optind; if (argc != 1) - errx(1, "Usage"); + usage(); if (z_opt > 9) - errx(1, "Usage"); + usage(); if (w_opt > s_opt) - errx(1, "Usage"); + usage(); f = fifolog_write_new(); assert(f != NULL); --- fifolog-usage.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805021401.m42E1raj001617>