Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Fix adaptername shutdown
@ 2012-04-28 15:16 Bastien Nocera
  2012-04-29 19:40 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Bastien Nocera @ 2012-04-28 15:16 UTC (permalink / raw)
  To: linux-bluetooth

An inotify watch descriptor isn't a file descriptor, so don't
treat it as such and remove it properly.
---
 plugins/adaptername.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index e154e92..9af19aa 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -52,7 +52,7 @@
 #define MACHINE_INFO_FILE "machine-info"
 
 static GIOChannel *inotify = NULL;
-static int watch_fd = -1;
+static int watch_d = -1;
 
 /* This file is part of systemd's hostnamed functionality:
  * http://0pointer.de/public/systemd-man/machine-info.html
@@ -292,8 +292,8 @@ static int adaptername_init(void)
 	mask |= IN_MOVED_FROM;
 	mask |= IN_MOVED_TO;
 
-	watch_fd = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
-	if (watch_fd < 0) {
+	watch_d = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
+	if (watch_d < 0) {
 		error("Failed to setup watch for '%s'", MACHINE_INFO_DIR);
 		close(inot_fd);
 		return 0;
@@ -310,8 +310,11 @@ static int adaptername_init(void)
 
 static void adaptername_exit(void)
 {
-	if (watch_fd >= 0)
-		close(watch_fd);
+	if (watch_d >= 0 && inotify != NULL) {
+		int inot_fd;
+		inot_fd = g_io_channel_unix_get_fd (inotify);
+		inotify_rm_watch(inot_fd, watch_d);
+	}
 	if (inotify != NULL) {
 		g_io_channel_shutdown(inotify, FALSE, NULL);
 		g_io_channel_unref(inotify);
-- 
1.7.10



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix adaptername shutdown
  2012-04-28 15:16 [PATCH] Fix adaptername shutdown Bastien Nocera
@ 2012-04-29 19:40 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2012-04-29 19:40 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: linux-bluetooth

Hi Bastien,

On Sat, Apr 28, 2012, Bastien Nocera wrote:
> An inotify watch descriptor isn't a file descriptor, so don't
> treat it as such and remove it properly.
> ---
>  plugins/adaptername.c |   13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-29 19:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-28 15:16 [PATCH] Fix adaptername shutdown Bastien Nocera
2012-04-29 19:40 ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox