Skip to content

Commit

Permalink
serial-{get,reset}-counter: Close the fd before exiting
Browse files Browse the repository at this point in the history
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  • Loading branch information
miquelraynal committed Jun 22, 2021
1 parent d827182 commit 5ff6f1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#define SERIAL_RESET_COUNTER 0
#define SERIAL_GET_COUNTER 1
Expand All @@ -31,6 +32,14 @@ int main(int argc, char *argv[])
if (ret < 0) {
fprintf(stderr, "Unable to get counter: %s\n",
strerror(errno));
close(fd);
exit(1);
}

ret = close(fd);
if (ret < 0) {
fprintf(stderr, "Unable to close %s: %s\n", argv[1],
strerror(errno));
exit(1);
}

Expand Down
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#define SERIAL_RESET_COUNTER 0
#define SERIAL_GET_COUNTER 1
Expand All @@ -30,9 +31,16 @@ int main(int argc, char *argv[])
if (ret < 0) {
fprintf(stderr, "Unable to reset counter: %s\n",
strerror(errno));
close(fd);
exit(1);
}

ret = close(fd);
if (ret < 0) {
fprintf(stderr, "Unable to close %s: %s\n", argv[1],
strerror(errno));
exit(1);
}

printf("Counter reset\n");
return 0;
Expand Down

0 comments on commit 5ff6f1b

Please sign in to comment.