From efb567f66701b4227d290ca26bdb5155be91e109 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sat, 17 Jun 2023 11:57:07 -0500 Subject: [PATCH] Make sure to unexport the GPIO port during close https://github.com/Hamlib/Hamlib/issues/1316 --- src/gpio.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gpio.c b/src/gpio.c index 298b8a2d4..1b2602eee 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -99,7 +99,28 @@ int gpio_open(hamlib_port_t *port, int output, int on_value) int gpio_close(hamlib_port_t *port) { - return close(port->fd); + int retval; + char pathname[HAMLIB_FILPATHLEN * 2]; + FILE *fexp; + + retval = close(port->fd); + + SNPRINTF(pathname, HAMLIB_FILPATHLEN, "/sys/class/gpio/unexport"); + fexp = fopen(pathname, "w"); + + if (!fexp) + { + rig_debug(RIG_DEBUG_ERR, + "Export GPIO%s (using %s): %s\n", + port->pathname, + pathname, + strerror(errno)); + return -RIG_EIO; + } + + fprintf(fexp, "%s\n", port->pathname); + fclose(fexp); + return retval; }