All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: yegorslists@googlemail.com
Cc: linux-can@vger.kernel.org
Subject: Re: [PATCH] candump: add option to ignore ENOBUFS
Date: Fri, 26 Oct 2012 11:46:45 +0200	[thread overview]
Message-ID: <508A5C05.6050803@pengutronix.de> (raw)
In-Reply-To: <1351244569-11398-1-git-send-email-yegorslists@googlemail.com>

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

On 10/26/2012 11:42 AM, yegorslists@googlemail.com wrote:
> From: Yegor Yefremov <yegorslists@googlemail.com>
> 
> -f option replicated -i option from cangen and allows to
> ignore ENOBUFS error in bridge mode

Better not ignore, but handle the error. If socket would support, wait
with select/poll that the socket get writable and try again. For now
sleep and try again. (or fix the poll/select bug in the kernel).

Marc

> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
>  candump.c |   19 ++++++++++++++++---
>  1 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/candump.c b/candump.c
> index ac51192..3a6be62 100644
> --- a/candump.c
> +++ b/candump.c
> @@ -53,6 +53,7 @@
>  #include <ctype.h>
>  #include <libgen.h>
>  #include <time.h>
> +#include <errno.h>
>  
>  #include <sys/time.h>
>  #include <sys/types.h>
> @@ -122,6 +123,7 @@ void print_usage(char *prg)
>  	fprintf(stderr, "         -r <size>   (set socket receive buffer to <size>)\n");
>  	fprintf(stderr, "         -d          (monitor dropped CAN frames)\n");
>  	fprintf(stderr, "         -e          (dump CAN error frames in human-readable format)\n");
> +	fprintf(stderr, "         -f          (ignore -ENOBUFS return values on write() syscalls)\n");
>  	fprintf(stderr, "\n");
>  	fprintf(stderr, "Up to %d CAN interfaces with optional filter sets can be specified\n", MAXSOCK);
>  	fprintf(stderr, "on the commandline in the form: <ifname>[,filter]*\n");
> @@ -211,6 +213,7 @@ int main(int argc, char **argv)
>  	unsigned char view = 0;
>  	unsigned char log = 0;
>  	unsigned char logfrmt = 0;
> +	unsigned char ignore_enobufs = 0;
>  	int count = 0;
>  	int rcvbuf_size = 0;
>  	int opt, ret;
> @@ -236,7 +239,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:ldLn:r:he?")) != -1) {
> +	while ((opt = getopt(argc, argv, "ft:ciaSs:b:B:u:ldLn:r:he?")) != -1) {
>  		switch (opt) {
>  		case 't':
>  			timestamp = optarg[0];
> @@ -347,6 +350,10 @@ int main(int argc, char **argv)
>  			}
>  			break;
>  
> +		case 'f':
> +			ignore_enobufs = 1;
> +			break;
> +
>  		default:
>  			print_usage(basename(argv[0]));
>  			exit(1);
> @@ -625,8 +632,14 @@ int main(int argc, char **argv)
>  
>  					nbytes = write(bridge, &frame, sizeof(struct can_frame));
>  					if (nbytes < 0) {
> -						perror("bridge write");
> -						return 1;
> +						if (errno != ENOBUFS) {
> +							perror("bridge write");
> +							return 1;
> +						}
> +						if (!ignore_enobufs) {
> +							perror("bridge write");
> +							return 1;
> +						}
>  					} else if ((size_t)nbytes < sizeof(struct can_frame)) {
>  						fprintf(stderr,"bridge write: incomplete CAN frame\n");
>  						return 1;
> 


-- 
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:[~2012-10-26  9:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26  9:42 [PATCH] candump: add option to ignore ENOBUFS yegorslists
2012-10-26  9:46 ` Marc Kleine-Budde [this message]
2012-10-28 20:02   ` Oliver Hartkopp
2012-10-29  8:00     ` Yegor Yefremov
2014-01-10 22:02     ` Oliver Hartkopp
2014-01-13 10:00       ` Yegor Yefremov
2014-01-13 18:15         ` Oliver Hartkopp

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=508A5C05.6050803@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=yegorslists@googlemail.com \
    /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.