mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-09-24 05:54:03 +08:00
gpio: unexport sysfs gpio on close
This commit is contained in:
+15
@@ -197,6 +197,9 @@ static const char *gpio_sysfs_edge_to_string[] = {
|
||||
};
|
||||
|
||||
static int gpio_sysfs_close(gpio_t *gpio) {
|
||||
char buf[16];
|
||||
int fd;
|
||||
|
||||
if (gpio->line_fd < 0)
|
||||
return 0;
|
||||
|
||||
@@ -206,6 +209,18 @@ static int gpio_sysfs_close(gpio_t *gpio) {
|
||||
|
||||
gpio->line_fd = -1;
|
||||
|
||||
/* Unexport the GPIO */
|
||||
snprintf(buf, sizeof(buf), "%d", gpio->line);
|
||||
if ((fd = open("/sys/class/gpio/unexport", O_WRONLY)) < 0)
|
||||
return _gpio_error(gpio, GPIO_ERROR_CLOSE, errno, "Closing GPIO: opening 'unexport'");
|
||||
if (write(fd, buf, strlen(buf)+1) < 0) {
|
||||
int errsv = errno;
|
||||
close(fd);
|
||||
return _gpio_error(gpio, GPIO_ERROR_CLOSE, errsv, "Closing GPIO: writing 'unexport'");
|
||||
}
|
||||
if (close(fd) < 0)
|
||||
return _gpio_error(gpio, GPIO_ERROR_CLOSE, errno, "Closing GPIO: closing 'unexport'");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user