Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1466449ybl; Thu, 5 Dec 2019 01:46:34 -0800 (PST) X-Google-Smtp-Source: APXvYqybHTPaBuFk65lvrJszyuxlMuTVmaDyv8lzXeo+yjO/lCA5kEClGPdgwWblX1KSHXovm+R/ X-Received: by 2002:aca:ed46:: with SMTP id l67mr6255215oih.53.1575539194172; Thu, 05 Dec 2019 01:46:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575539194; cv=none; d=google.com; s=arc-20160816; b=kFz3ERBMcpIQMI/O0YB1xbxu3jkJOSgJ3MeFbdy2p9ufhc4MgnJXJEqOGPS2r7FlPK l+/EiWkLQkPOERjz3ityDpWaIjXBbdPgvi0hG/Hyqp9yXVaUO7at2oMcUTIymtczmzhx gQjXV2c6S0DgVqWgftlOYpaJtoUNA3dlYuRw8xyEc32QNZCEivhY3sL/HX3oA8fshh5E eNKi9R1fgB5jjx9fCiL20f3Xbq0rLkYySaF9MuwHRfkub844c7gitu2AtYTtHWiAI09s 0rCpOi1UXKAPirsfCkW2M9nC2djtIwamsxBCS15Wt1WsLz/GiM4D9+hYSfZZsmzlzEki 2MJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=34Yk9HvNolRmgsb9MDvApAfPhu7Lhp8WnNzDK/K5sLM=; b=L+nqt5KWUT4QGQ1px84iVwSyN57FV18kNcXiW0p3KY/Yk3Z4xkbl4hhkNL8K8k4lwi RO9riFHb0sCSR79W6g0uImqWvHkIte7a/a/hFTFZDLKSObUPN/KWdxbqu+jBG2fNuCJh PjyP9KDYivvSWqnuyTnrF4CYSVmAs65Cz5my8G/xktUjoZznZIKHFclwQdru4bfP2Dbl 7+Vd8Lfs96Ihe8nQdICR5f/uRsXtornLBSv4X/Mr6+y3BtKSXmM5X5p0wdGmPpy4yFHb 2C3UGPca4Qa+pbeHrp3LpfeUIc+22krwxzb8UpSl+pAMqSjWPZjn6R8mt9W+GNcA4Z2e Ml7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=wxq0JeTd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si4641969otn.241.2019.12.05.01.46.22; Thu, 05 Dec 2019 01:46:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=wxq0JeTd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729099AbfLEJpO (ORCPT + 99 others); Thu, 5 Dec 2019 04:45:14 -0500 Received: from mail-il1-f194.google.com ([209.85.166.194]:38914 "EHLO mail-il1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728794AbfLEJpN (ORCPT ); Thu, 5 Dec 2019 04:45:13 -0500 Received: by mail-il1-f194.google.com with SMTP id a7so2409420ild.6 for ; Thu, 05 Dec 2019 01:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=34Yk9HvNolRmgsb9MDvApAfPhu7Lhp8WnNzDK/K5sLM=; b=wxq0JeTdLlkZsEjds2AQo/g8aqwpimef519Av/sCVEoKd93d2HrVpQyKKD02PoBA4+ tlPhtxvom0uOuTlwTemb/AW0zsGDJGaCW0I+w0lLR6hcb55py8BbfWpL0v/4qHuA0NNq o/POPudLz0f8ODl4f6gjOF0VhY7mO44FgW5LF+LbftyeEOGduIF9XvBTgWmkvKsRi+ek opgsy2xpiI6wCiWGLemCgKCjiXXOqXZFFMAwVsLbDmPC70N1hIKEK7pzE/hN7F7LbRAO plhgywgA/iXQDicQR7I6m/DZqvy5xaCjUELo4CaSgxAJsXhFlw0Aezw7wPyOzwrOx5IW +KfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=34Yk9HvNolRmgsb9MDvApAfPhu7Lhp8WnNzDK/K5sLM=; b=fVEg0H8XWh7Gv0DIUWFuItSwVahBsepukCB+shCp8UURxmCgokiF2lfe94ftbE78+k FsXdMG7qglEU9arXN6GwYbXDt2mRG1rre5xStNgIUl1PoL8pnWq8FlcMnss9Buj0THsb r5xGabnMDfVALILfS2ufJAarxTiMGEJHnund4VLzKPoruQ6Vvxm7CNob0AdxKLSQJtQQ DqgoaPr9KVuIgVW81XftgYG/Kfwdje8IuM1B4YiTKI2LsqBNfozQdYZ89gLZHtWyJf1s WfWlu3qsmMaBJTekMOEVOYaik4kR1Zv7H6rhu4/lpHuMhZlsBxho7Ep1neYAB5qPa6tz E4jQ== X-Gm-Message-State: APjAAAWSYGGBuouLd/iZSBUir25x314IRnOZGEU1ElGHmKzBymju5s7+ XhNS7sVFbN6ii6PID9ie+/LUtaJw0XJkP8TN1OPcRg== X-Received: by 2002:a92:49d1:: with SMTP id k78mr8373692ilg.6.1575539112879; Thu, 05 Dec 2019 01:45:12 -0800 (PST) MIME-Version: 1.0 References: <20191204155941.17814-1-brgl@bgdev.pl> <20191204155941.17814-2-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Thu, 5 Dec 2019 10:45:01 +0100 Message-ID: Subject: Re: [PATCH v2 11/11] tools: gpio: implement gpio-watch To: Andy Shevchenko Cc: Kent Gibson , Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =C5=9Br., 4 gru 2019 o 23:42 Andy Shevchenko na= pisa=C5=82(a): > > On Wed, Dec 4, 2019 at 7:19 PM Bartosz Golaszewski wrote: > > Add a simple program that allows to test the new LINECHANGED_FD ioctl()= . > > > --- a/tools/gpio/.gitignore > > +++ b/tools/gpio/.gitignore > > @@ -1,4 +1,5 @@ > > gpio-event-mon > > gpio-hammer > > lsgpio > > +gpio-watch > > Perhaps keep it sorted? > Sure I can do this. > > +++ b/tools/gpio/gpio-watch.c > > @@ -0,0 +1,112 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +/* > > + * gpio-watch - monitor unrequested lines for property changes using t= he > > + * character device > > + * > > + * Copyright (C) 2019 BayLibre SAS > > + * Author: Bartosz Golaszewski > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static bool isnumber(const char *str) > > +{ > > + size_t sz =3D strlen(str); > > + int i; > > + > > + for (i =3D 0; i < sz; i++) { > > + if (!isdigit(str[i])) > > + return false; > > + } > > + > > + return true; > > +} > > strtoul() will do the same. > > char *p; > unsigned long dummy; // do we need it? > dummy =3D strtoul(..., &p); > return *p =3D=3D '\0'; Yeah strtoul does allow for error checking. I'll change this in v3. > > > +int main(int argc, char **argv) > > +{ > > + struct gpioline_info_changed chg; > > + struct gpioline_info req; > > + struct pollfd pfd; > > + int fd, i, j, ret; > > + char *event; > > + ssize_t rd; > > + > > + if (argc < 3) > > + goto err_usage; > > + > > + fd =3D open(argv[1], O_RDWR | O_CLOEXEC); > > + if (fd < 0) { > > + perror("unable to open gpiochip"); > > + return EXIT_FAILURE; > > + } > > + > > + for (i =3D 0, j =3D 2; i < argc - 2; i++, j++) { > > + if (!isnumber(argv[j])) > > + goto err_usage; > > + > > + memset(&req, 0, sizeof(req)); > > + req.line_offset =3D atoi(argv[j]); > > Oh, why not to call strtoul() directly? > > > + > > + ret =3D ioctl(fd, GPIO_GET_LINEINFO_WATCH_IOCTL, &req); > > + if (ret) { > > + perror("unable to set up line watch"); > > Don't you need to unwatch previously added ones? Nah, we're exiting anyway, the fd will be released. > > > + return EXIT_FAILURE; > > + } > > + } > > > + for (;;) { > > + ret =3D poll(&pfd, 1, 5000); > > + if (ret < 0) { > > + perror("error polling the linechanged fd"); > > + return EXIT_FAILURE; > > + } else if (ret > 0) { > > + memset(&chg, 0, sizeof(chg)); > > > + rd =3D read(pfd.fd, &chg, sizeof(chg)); > > + if (rd < 0 || rd !=3D sizeof(chg)) { > > + if (rd !=3D sizeof(chg)) > > + errno =3D EIO; > > + > > + perror("error reading line change event= "); > > + return EXIT_FAILURE; > > + } > > Shouldn't we handle the -EINTR? Indeed we should. Will fix. Bart > > > + } > > + } > > + > > + return 0; > > > -- > With Best Regards, > Andy Shevchenko