core: close GPIO chip device files on exec
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 6 Feb 2017 09:59:00 +0000 (10:59 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 6 Feb 2017 09:59:00 +0000 (10:59 +0100)
Pass the O_CLOEXEC flag to open() so that we don't leak open GPIO
chip descriptors to any processes spawned by users of the library.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
src/lib/core.c

index 71ac7d23bcb3cecd39395f6e52f49a30bbc938a5..f5beeb769ab7062db64e5fd217c282d8de3ca034 100644 (file)
@@ -899,7 +899,7 @@ struct gpiod_chip * gpiod_chip_open(const char *path)
        struct gpiod_chip *chip;
        int status, fd;
 
-       fd = open(path, O_RDWR);
+       fd = open(path, O_RDWR | O_CLOEXEC);
        if (fd < 0) {
                last_error_from_errno();
                return NULL;