summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2017-04-18 22:00:19 +0200
committerDavid Härdeman <david@hardeman.nu>2017-04-18 22:00:19 +0200
commit22f81fbe86e2920658948608ef9e87f8c1a03dc2 (patch)
tree6dbaef75940c0871fc2e32434b005a2966145bed
parentfdfc2d240a775086b701929599dce4104f282256 (diff)
Add lirc_close
-rw-r--r--rcm-server-lirc.c18
-rw-r--r--rcm-server-lirc.h2
2 files changed, 15 insertions, 5 deletions
diff --git a/rcm-server-lirc.c b/rcm-server-lirc.c
index 150df8b..e9a82a6 100644
--- a/rcm-server-lirc.c
+++ b/rcm-server-lirc.c
@@ -27,7 +27,7 @@ lirc_write(int fd, const uint32_t *v, unsigned count)
l, write(fd, nv, l), errno, strerror(errno));
}
-int
+static int
lirc_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
struct device *device = userdata;
@@ -39,8 +39,7 @@ lirc_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
if (revents & EPOLLHUP) {
fprintf(stderr, "lirc connection closed!\n");
- close(fd);
- device->lirc_fd = -1;
+ lirc_close(device);
return 0;
}
@@ -55,6 +54,16 @@ lirc_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
return 0;
}
+void
+lirc_close(struct device *device)
+{
+ if (device->lirc_fd < 0)
+ return;
+
+ close(device->lirc_fd);
+ device->lirc_fd = -1;
+}
+
int
lirc_setup(struct device *device, const char *path)
{
@@ -76,8 +85,7 @@ lirc_setup(struct device *device, const char *path)
device->lirc_fd, EPOLLIN, lirc_read, device) < 0) {
printf("Failed to add event source for lirc device %s: %s\n",
path, strerror(errno));
- close(device->lirc_fd);
- device->lirc_fd = -1;
+ lirc_close(device);
return -errno;
}
diff --git a/rcm-server-lirc.h b/rcm-server-lirc.h
index f0bf798..08bb2cb 100644
--- a/rcm-server-lirc.h
+++ b/rcm-server-lirc.h
@@ -3,6 +3,8 @@
void lirc_write(int fd, const uint32_t *v, unsigned count);
+void lirc_close(struct device *device);
+
int lirc_setup(struct device *device, const char *path);
#endif