summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/config.h6
-rw-r--r--src/fifo.c15
-rw-r--r--src/run.c4
4 files changed, 22 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 65dff9b..0b84c4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2011-11-13 Jiri Olsa <olsajiri@gmail.com>
+ * Fix leak of notify watch in fifo code
+
2011-09-05 Jiri Olsa <olsajiri@gmail.com>
* Fixes paraller building like 'make -j16'
(contributed by Tapani Pälli <tapani.palli@intel.com>)
diff --git a/src/config.h b/src/config.h
index 278771a..b4ff616 100644
--- a/src/config.h
+++ b/src/config.h
@@ -181,6 +181,9 @@ struct lt_config_app {
struct lt_thread *threads;
struct lt_thread *iter;
+
+ int notify_fd;
+ int notify_fd_watch;
};
struct lt_config_ctl {
@@ -326,7 +329,8 @@ int lt_run(struct lt_config_app *cfg);
/* fifo */
int lt_fifo_create(struct lt_config_audit *cfg, char *dir);
int lt_fifo_open(struct lt_config_app *cfg, char *dir, char *name);
-int lt_fifo_notify_fd(struct lt_config_app *cfg, char *dir);
+int lt_fifo_notify_init(struct lt_config_app *cfg, char *dir);
+void lt_fifo_notify_cleanup(struct lt_config_app *cfg);
int lt_fifo_send(struct lt_config_audit *cfg, int fd, char *buf, int len);
int lt_fifo_recv(struct lt_config_app *cfg, struct lt_thread *t,
void *buf, int bufsize);
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;
diff --git a/src/run.c b/src/run.c
index 3f1eb2d..fa50a3f 100644
--- a/src/run.c
+++ b/src/run.c
@@ -340,7 +340,7 @@ static int run_setup(struct lt_config_app *cfg,
/* new thread notification descriptor */
if (lt_sh(cfg, pipe) &&
- (-1 == (pa->fd_notify = lt_fifo_notify_fd(cfg, pa->dir))))
+ (-1 == (pa->fd_notify = lt_fifo_notify_init(cfg, pa->dir))))
return -1;
/* tty master descriptor */
@@ -355,7 +355,7 @@ static void run_cleanup(struct lt_config_app *cfg,
struct lt_process_args *pa)
{
if (lt_sh(cfg, pipe))
- close(pa->fd_notify);
+ lt_fifo_notify_cleanup(cfg);
if (cfg->output_tty)
tty_close(cfg);