From patchwork Mon Feb 11 08:43:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Hundeb=C3=B8ll?= X-Patchwork-Id: 1039695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=geanix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=geanix.com header.i=@geanix.com header.b="YngEOtr/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43yfbq6vMYz9s3l for ; Mon, 11 Feb 2019 19:49:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbfBKIt0 (ORCPT ); Mon, 11 Feb 2019 03:49:26 -0500 Received: from mail.hundeboll.net ([88.198.92.70]:45250 "EHLO mail.hundeboll.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbfBKIt0 (ORCPT ); Mon, 11 Feb 2019 03:49:26 -0500 X-Greylist: delayed 364 seconds by postgrey-1.27 at vger.kernel.org; Mon, 11 Feb 2019 03:49:25 EST Received: from xps.lan (unknown [85.184.147.232]) by mail.hundeboll.net (Postfix) with ESMTPSA id BE35F1C2D3E; Mon, 11 Feb 2019 09:43:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=hundeboll; t=1549874599; bh=WzeNbbfP/RilREAuJtSeJknvw/6uThdRMAeXrtJp8EA=; h=From:To:Cc:Subject:Date; b=YngEOtr/AjGflG4vtYNy2Wc5eonMjoqRoGU4HuJw9KHK38+ZjdeaF0JptYtCQ7lZx fgoBWyu3edHpXgFj/iZ0P6LdJGvhIFoJv2+ZsvSf4zXFu3CabrNkPiViQUm7k43yba UZuJk8qydG+PdP7dFQ1nOBvuApRQ8VLvksnLOQfYy8h3kDbHBpjfzpUybY21n70sK3 zoJbooe9twgoa68E4Wly8stFkURuY9MnkNAGCiVA7HDSU+c8s6TQ7z9bqrT4wVwOa+ qNF6nrs8NuRescnF/rsCfU+EwYvyenUBPXi8IQVjyLIkRyVFXwb5+V3LqnLhJvn+fU ALBp8BhV7zr+A== From: =?utf-8?q?Martin_Hundeb=C3=B8ll?= To: linux-gpio@vger.kernel.org Cc: =?utf-8?q?Martin_Hundeb=C3=B8ll?= Subject: [libgpiod][PATCH] gpiomon: add option to set line buffered output Date: Mon, 11 Feb 2019 09:43:17 +0100 Message-Id: <20190211084317.2695-1-martin@geanix.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Some applications call gpiomon in a sub process, in which case glibc defaults to block buffered output on stdout. This makes the output arrive to the calling process only when the (4kB) buffer is filled (or when gpiomon exists), making the information obsolete and pretty much useless. Support such scenarios by adding a switch to configure line buffered output on stdout. Similar switches are available in other applications (e.g. `rsync`s --output argument). Signed-off-by: Martin Hundebøll --- src/tools/gpiomon.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tools/gpiomon.c b/src/tools/gpiomon.c index c13ab38..e79b458 100644 --- a/src/tools/gpiomon.c +++ b/src/tools/gpiomon.c @@ -26,11 +26,12 @@ static const struct option longopts[] = { { "silent", no_argument, NULL, 's' }, { "rising-edge", no_argument, NULL, 'r' }, { "falling-edge", no_argument, NULL, 'f' }, + { "linebuffered", no_argument, NULL, 'b' }, { "format", required_argument, NULL, 'F' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvln:srfF:"; +static const char *const shortopts = "+hvln:srfbF:"; static void print_help(void) { @@ -46,6 +47,7 @@ static void print_help(void) printf(" -s, --silent:\t\tdon't print event info\n"); printf(" -r, --rising-edge:\tonly process rising edge events\n"); printf(" -f, --falling-edge:\tonly process falling edge events\n"); + printf(" -l, --linebuffered:\tset line buffered output\n"); printf(" -F, --format=FMT\tspecify custom output format\n"); printf("\n"); printf("Format specifiers:\n"); @@ -242,6 +244,7 @@ int main(int argc, char **argv) { unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES], num_lines = 0, offset; bool active_low = false, watch_rising = false, watch_falling = false; + bool linebuffered = false; struct timespec timeout = { 10, 0 }; int optc, opti, ret, i, event_type; struct mon_ctx ctx; @@ -278,6 +281,9 @@ int main(int argc, char **argv) case 'f': watch_falling = true; break; + case 'b': + linebuffered = true; + break; case 'F': ctx.fmt = optarg; break; @@ -298,6 +304,9 @@ int main(int argc, char **argv) else event_type = GPIOD_CTXLESS_EVENT_BOTH_EDGES; + if (linebuffered && setvbuf(stdout, NULL, _IOLBF, 0) != 0) + die("failed to set line buffering"); + if (argc < 1) die("gpiochip must be specified");