summaryrefslogtreecommitdiffstats
path: root/src/fifo.c
diff options
context:
space:
mode:
authorJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-11-13 15:41:29 +0100
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-11-13 15:41:29 +0100
commitcd4cfc841b45022d113b39a2ecefc6951a22c5fe (patch)
tree66d609e305becc3ea5a798cf0e11145bf709adc3 /src/fifo.c
parent01166acb9da9ea2aea40349c44d78764f8e2f3cd (diff)
downloadlatrace-cd4cfc841b45022d113b39a2ecefc6951a22c5fe.tar.gz
latrace-cd4cfc841b45022d113b39a2ecefc6951a22c5fe.tar.xz
latrace-cd4cfc841b45022d113b39a2ecefc6951a22c5fe.zip
fifo: Fix leak of notify watchnotify_leak1notify_leak
The watch descriptor was not properly released. Added proper cleanup for both inotify fd and the watch descriptor.
Diffstat (limited to 'src/fifo.c')
-rw-r--r--src/fifo.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/fifo.c b/src/fifo.c
index bb4a26d..a167a3e 100644
--- a/src/fifo.c
+++ b/src/fifo.c
@@ -86,9 +86,9 @@ int lt_fifo_open(struct lt_config_app *cfg, char *dir, char *name)
return fd;
}
-int lt_fifo_notify_fd(struct lt_config_app *cfg, char *dir)
+int lt_fifo_notify_init(struct lt_config_app *cfg, char *dir)
{
- int fd;
+ int fd, fd_watch;
char *notify_dir = get_notify_dir(dir);
struct stat st;
@@ -114,15 +114,24 @@ int lt_fifo_notify_fd(struct lt_config_app *cfg, char *dir)
return -1;
}
- if (-1 == inotify_add_watch(fd, notify_dir, IN_CREATE)) {
+ if (-1 == (fd_watch = inotify_add_watch(fd, notify_dir, IN_CREATE))) {
perror("inotify_add_watch failed");
return -1;
}
+ cfg->notify_fd = fd;
+ cfg->notify_fd_watch = fd_watch;
+
PRINT_VERBOSE(cfg, 1, "fifo notification set to: %s\n", notify_dir);
return fd;
}
+void lt_fifo_notify_cleanup(struct lt_config_app *cfg)
+{
+ inotify_rm_watch(cfg->notify_fd, cfg->notify_fd_watch);
+ close(cfg->notify_fd);
+}
+
int lt_fifo_send(struct lt_config_audit *cfg, int fd, char *buf, int len)
{
static unsigned int written = 0;