Skip to content

Commit

Permalink
close on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrabine-swi committed Mar 22, 2021
1 parent 80f7701 commit a4fda88
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ int main (int argc, char **argv)
if (chip == NULL)
{
syslog (LOG_ERR, "unable to open the gpio chip - %s", strerror (errno));
close (sfd);
_exit (EXIT_FAILURE);
}

Expand All @@ -214,13 +215,15 @@ int main (int argc, char **argv)
{
syslog (LOG_ERR, "unable to open line %ul - %s", pin, strerror (errno));
gpiod_chip_close (chip);
close (sfd);
_exit (EXIT_FAILURE);
}

if (gpiod_line_request_output (line, BINARY_NAME, 0) == -1)
{
syslog (LOG_ERR, "unable to get ownership on line %u - %s", pin, strerror (errno));
gpiod_chip_close (chip);
close (sfd);
_exit (EXIT_FAILURE);
}

Expand All @@ -246,6 +249,7 @@ int main (int argc, char **argv)
syslog (LOG_ERR, "signal poll failed - %s", strerror (errno));
gpiod_line_release (line);
gpiod_chip_close (chip);
close (sfd);
_exit (EXIT_FAILURE);
}

Expand All @@ -258,6 +262,7 @@ int main (int argc, char **argv)
syslog (LOG_ERR, "signal read failed - %s", strerror (errno));
gpiod_line_release (line);
gpiod_chip_close (chip);
close (sfd);
_exit (EXIT_FAILURE);
}

Expand All @@ -276,8 +281,7 @@ int main (int argc, char **argv)

gpiod_line_release (line);
gpiod_chip_close (chip);

closelog ();
close (sfd);

_exit (EXIT_SUCCESS);
}

0 comments on commit a4fda88

Please sign in to comment.