[asterisk-commits] res timing: Don't close FD 0 when out of open files. (asterisk[11])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 2 07:53:28 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: res_timing: Don't close FD 0 when out of open files.
......................................................................


res_timing: Don't close FD 0 when out of open files.

This fixes so a failure to get a timer file descriptor does not cascade
to closing FD 0.

On error, both res_timing_kqueue and res_timing_timerfd would call the
destructor before setting the file handle. The file handle had been
initialized to 0, causing FD 0 to be closed. This in turn, resulted in
floods of "CLI>" messages and an unusable terminal.

ASTERISK-19277 #close
Reported by: Barry Chern

Change-Id: I147d7e33726c6e5a2751928d56561494f5800350
---
M res/res_timing_kqueue.c
M res/res_timing_timerfd.c
2 files changed, 8 insertions(+), 6 deletions(-)

Approvals:
  Matt Jordan: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/res/res_timing_kqueue.c b/res/res_timing_kqueue.c
index 8ac2714..9ada1ae 100644
--- a/res/res_timing_kqueue.c
+++ b/res/res_timing_kqueue.c
@@ -93,7 +93,9 @@
 static void timer_destroy(void *obj)
 {
 	struct kqueue_timer *timer = obj;
-	close(timer->handle);
+	if (timer->handle > -1) {
+		close(timer->handle);
+	}
 }
 
 #define lookup_timer(a)	_lookup_timer(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
@@ -121,13 +123,12 @@
 		ast_log(LOG_ERROR, "Could not allocate memory for kqueue_timer structure\n");
 		return -1;
 	}
-	if ((handle = kqueue()) < 0) {
+	if ((timer->handle = handle = kqueue()) < 0) {
 		ast_log(LOG_ERROR, "Failed to create kqueue timer: %s\n", strerror(errno));
 		ao2_ref(timer, -1);
 		return -1;
 	}
 
-	timer->handle = handle;
 	ao2_link(kqueue_timers, timer);
 	/* Get rid of the reference from the allocation */
 	ao2_ref(timer, -1);
diff --git a/res/res_timing_timerfd.c b/res/res_timing_timerfd.c
index 5c96dd6..41b5f7d 100644
--- a/res/res_timing_timerfd.c
+++ b/res/res_timing_timerfd.c
@@ -90,7 +90,9 @@
 static void timer_destroy(void *obj)
 {
 	struct timerfd_timer *timer = obj;
-	close(timer->handle);
+	if (timer->handle > -1) {
+		close(timer->handle);
+	}
 	timer->handle = -1;
 }
 
@@ -103,13 +105,12 @@
 		ast_log(LOG_ERROR, "Could not allocate memory for timerfd_timer structure\n");
 		return -1;
 	}
-	if ((handle = timerfd_create(CLOCK_MONOTONIC, 0)) < 0) {
+	if ((timer->handle = handle = timerfd_create(CLOCK_MONOTONIC, 0)) < 0) {
 		ast_log(LOG_ERROR, "Failed to create timerfd timer: %s\n", strerror(errno));
 		ao2_ref(timer, -1);
 		return -1;
 	}
 
-	timer->handle = handle;
 	ao2_link(timerfd_timers, timer);
 	/* Get rid of the reference from the allocation */
 	ao2_ref(timer, -1);

-- 
To view, visit https://gerrit.asterisk.org/759
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I147d7e33726c6e5a2751928d56561494f5800350
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Walter Doekes <walter+asterisk at wjd.nu>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Walter Doekes <walter+asterisk at wjd.nu>



More information about the asterisk-commits mailing list