All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@systec-electronic.com>
To: linux-can@vger.kernel.org
Cc: Alexander Stein <alexander.stein@systec-electronic.com>
Subject: [PATCH] candump: Add timeout option if no message has been received
Date: Tue, 12 Feb 2013 11:31:22 +0100	[thread overview]
Message-ID: <1360665082-14256-1-git-send-email-alexander.stein@systec-electronic.com> (raw)

Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
---
 candump.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/candump.c b/candump.c
index bf3e8bb..7fce1d3 100644
--- a/candump.c
+++ b/candump.c
@@ -121,6 +121,7 @@ void print_usage(char *prg)
 	fprintf(stderr, "         -d          (monitor dropped CAN frames)\n");
 	fprintf(stderr, "         -e          (dump CAN error frames in human-readable format)\n");
 	fprintf(stderr, "         -x          (print extra message infos, rx/tx brs esi)\n");
+	fprintf(stderr, "         -T <msecs>  (terminate after <msecs> without any reception)\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");
@@ -227,6 +228,7 @@ int main(int argc, char **argv)
 	int nbytes, i, maxdlen;
 	struct ifreq ifr;
 	struct timeval tv, last_tv;
+	struct timeval timeout, timeout_config, *timeout_current = NULL;
 	FILE *logfile = NULL;
 
 	signal(SIGTERM, sigterm);
@@ -236,7 +238,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:he?")) != -1) {
+	while ((opt = getopt(argc, argv, "t:ciaSs:b:B:u:ldxLn:r:heT:?")) != -1) {
 		switch (opt) {
 		case 't':
 			timestamp = optarg[0];
@@ -351,6 +353,16 @@ int main(int argc, char **argv)
 			}
 			break;
 
+		case 'T':
+			timeout_config.tv_usec = atoi(optarg);
+			if (timeout_config.tv_usec < 1) {
+				print_usage(basename(argv[0]));
+				exit(1);
+			}
+			timeout_config.tv_sec = timeout_config.tv_usec / 1000;
+			timeout_config.tv_usec = (timeout_config.tv_usec % 1000) * 1000;
+			timeout_current = &timeout;
+			break;
 		default:
 			print_usage(basename(argv[0]));
 			exit(1);
@@ -594,7 +606,10 @@ int main(int argc, char **argv)
 		for (i=0; i<currmax; i++)
 			FD_SET(s[i], &rdfs);
 
-		if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, NULL)) < 0) {
+		if (timeout_current)
+			memcpy(timeout_current, &timeout_config, sizeof(timeout_config));
+
+		if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current)) <= 0) {
 			//perror("select");
 			running = 0;
 			continue;
-- 
1.8.1.2


             reply	other threads:[~2013-02-12 10:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-12 10:31 Alexander Stein [this message]
2013-02-12 10:51 ` [PATCH] candump: Add timeout option if no message has been received Marc Kleine-Budde
2013-02-12 14:05   ` Alexander Stein
2013-02-12 14:07     ` Marc Kleine-Budde
2013-02-12 14:17       ` [PATCH v2] " Alexander Stein
2013-02-12 14:19         ` Marc Kleine-Budde
2013-02-12 16:50       ` [PATCH v3] " Alexander Stein
2013-02-12 16:56         ` Marc Kleine-Budde
2013-02-12 17:38           ` 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=1360665082-14256-1-git-send-email-alexander.stein@systec-electronic.com \
    --to=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.