[PATCH evemu 2/5] evemu-record: Unify the error path

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Feb 25 09:11:35 UTC 2016


On Thu, Feb 25, 2016 at 1:41 AM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  tools/evemu-record.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/tools/evemu-record.c b/tools/evemu-record.c
> index eedf4fa..9d215ab 100644
> --- a/tools/evemu-record.c
> +++ b/tools/evemu-record.c
> @@ -90,10 +90,13 @@ enum mode {
>  int main(int argc, char *argv[])
>  {
>         enum mode mode = EVEMU_RECORD;
> -       int fd;
> +       int fd = -1;
>         struct sigaction act;
>         char *prgm_name = program_invocation_short_name;
> -       char *device;
> +       char *device = NULL;
> +       int rc = 1;
> +
> +       output = stdout;
>
>         if (prgm_name && (strcmp(prgm_name, "evemu-describe") == 0 ||
>                         /* when run directly from the sources (not installed) */
> @@ -104,12 +107,12 @@ int main(int argc, char *argv[])
>
>         if (device == NULL) {
>                 fprintf(stderr, "Usage: %s <device> [output file]\n", argv[0]);
> -               return -1;
> +               goto out;
>         }
>         fd = open(device, O_RDONLY | O_NONBLOCK);
>         if (fd < 0) {
>                 fprintf(stderr, "error: could not open device (%m)\n");
> -               return -1;
> +               goto out;

The 2 previous returns are now changed from -1 to 1. Not sure it
really matters, so I still took the 5 patches and pushed them:
   7f89dd9..47193d1  master -> master

I will wait for your rolling logs before tagging a new version.

Cheers,
Benjamin

>         }
>
>         memset (&act, '\0', sizeof(act));
> @@ -117,11 +120,11 @@ int main(int argc, char *argv[])
>
>         if (sigaction(SIGTERM, &act, NULL) < 0) {
>                 fprintf (stderr, "Could not attach TERM signal handler (%m)\n");
> -               return 1;
> +               goto out;
>         }
>         if (sigaction(SIGINT, &act, NULL) < 0) {
>                 fprintf (stderr, "Could not attach INT signal handler (%m)\n");
> -               return 1;
> +               goto out;
>         }
>
>         if (argc < 3)
> @@ -146,7 +149,7 @@ int main(int argc, char *argv[])
>                 if (ioctl(fd, EVIOCGRAB, (void*)1) < 0) {
>                         fprintf(stderr, "error: this device is grabbed and I cannot record events\n");
>                         fprintf(stderr, "see the evemu-record man page for more information\n");
> -                       return -1;
> +                       goto out;
>                 } else
>                         ioctl(fd, EVIOCGRAB, (void*)0);
>
> @@ -157,6 +160,7 @@ int main(int argc, char *argv[])
>                         fprintf(stderr, "error: could not describe device\n");
>         }
>
> +       rc = 0;
>  out:
>         free(device);
>         close(fd);
> @@ -164,5 +168,5 @@ out:
>                 fclose(output);
>                 output = stdout;
>         }
> -       return 0;
> +       return rc;
>  }
> --
> 2.5.0
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/input-tools


More information about the Input-tools mailing list