All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: Re: [PATCH] candump: Add possibility to specify logfile
Date: Wed, 21 Aug 2013 10:28:23 +0200	[thread overview]
Message-ID: <52147A27.9020601@pengutronix.de> (raw)
In-Reply-To: <1377073026-30202-1-git-send-email-alexander.stein@systec-electronic.com>

[-- Attachment #1: Type: text/plain, Size: 3607 bytes --]

On 08/21/2013 10:17 AM, Alexander Stein wrote:
> You need to use -l/tmp/logfile (wihtout space!) because -l takes an
> optional parameter.
> 
> Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>

Please use the Kernel Coding Style.

Marc

> ---
>  candump.c | 37 ++++++++++++++++++++++---------------
>  1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/candump.c b/candump.c
> index c865bd7..72193fc 100644
> --- a/candump.c
> +++ b/candump.c
> @@ -115,7 +115,7 @@ void print_usage(char *prg)
>  	fprintf(stderr, "         -b <can>    (bridge mode - send received frames to <can>)\n");
>  	fprintf(stderr, "         -B <can>    (bridge mode - like '-b' with disabled loopback)\n");
>  	fprintf(stderr, "         -u <usecs>  (delay bridge forwarding by <usecs> microseconds)\n");
> -	fprintf(stderr, "         -l          (log CAN-frames into file. Sets '-s %d' by default)\n", SILENT_ON);
> +	fprintf(stderr, "         -l[logfile] (log CAN-frames into file. Sets '-s %d' by default)\n", SILENT_ON);
>  	fprintf(stderr, "         -L          (use log file format on stdout)\n");
>  	fprintf(stderr, "         -n <count>  (terminate after receiption of <count> CAN frames)\n");
>  	fprintf(stderr, "         -r <size>   (set socket receive buffer to <size>)\n");
> @@ -231,6 +231,7 @@ int main(int argc, char **argv)
>  	struct timeval tv, last_tv;
>  	struct timeval timeout, timeout_config = { 0, 0 }, *timeout_current = NULL;
>  	FILE *logfile = NULL;
> +	const char* fname = NULL;

chat *fname

>  
>  	signal(SIGTERM, sigterm);
>  	signal(SIGHUP, sigterm);
> @@ -239,7 +240,7 @@ int main(int argc, char **argv)
>  	last_tv.tv_sec  = 0;
>  	last_tv.tv_usec = 0;
>  
> -	while ((opt = getopt(argc, argv, "t:ciaSs:b:B:u:ldxLn:r:heT:?")) != -1) {
> +	while ((opt = getopt(argc, argv, "t:ciaSs:b:B:u:l::dxLn:r:heT:?")) != -1) {
>  		switch (opt) {
>  		case 't':
>  			timestamp = optarg[0];
> @@ -324,6 +325,7 @@ int main(int argc, char **argv)
>  
>  		case 'l':
>  			log = 1;
> +			fname = optarg;
>  			break;
>  
>  		case 'd':
> @@ -566,22 +568,27 @@ int main(int argc, char **argv)
>  	if (log) {
>  		time_t currtime;
>  		struct tm now;
> -		char fname[sizeof("candump-2006-11-20_202026.log")+1];
> +		char filename[sizeof("candump-2006-11-20_202026.log")+1];
                                                                    ^^^^

Space between  ) and +
>  
> -		if (time(&currtime) == (time_t)-1) {
> -			perror("time");
> -			return 1;
> -		}
> +		if (fname == NULL)
> +		{

if () {

> +			if (time(&currtime) == (time_t)-1) {
> +				perror("time");
> +				return 1;
> +			}
> +
> +			localtime_r(&currtime, &now);
>  
> -		localtime_r(&currtime, &now);
> +			sprintf(filename, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
> +				now.tm_year + 1900,
> +				now.tm_mon + 1,
> +				now.tm_mday,
> +				now.tm_hour,
> +				now.tm_min,
> +				now.tm_sec);
>  
> -		sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
> -			now.tm_year + 1900,
> -			now.tm_mon + 1,
> -			now.tm_mday,
> -			now.tm_hour,
> -			now.tm_min,
> -			now.tm_sec);
> +			fname = filename;
> +		}
>  
>  		if (silent != SILENT_ON)
>  			printf("\nWarning: console output active while logging!");
> 


-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

  reply	other threads:[~2013-08-21  8:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-21  8:17 [PATCH] candump: Add possibility to specify logfile Alexander Stein
2013-08-21  8:28 ` Marc Kleine-Budde [this message]
2013-08-21  8:29   ` Marc Kleine-Budde
2013-08-21  9:21     ` [PATCH v2] " Alexander Stein
2013-08-21 16:58       ` Oliver Hartkopp
2013-08-22  6:04         ` Alexander Stein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52147A27.9020601@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=alexander.stein@systec-electronic.com \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.