[Pkg-nagios-changes] [pkg-nsca] 02/05: Add upstream patch to fix race condition when opening command file.
Bas Couwenberg
sebastic at debian.org
Mon Dec 5 20:30:09 UTC 2016
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository pkg-nsca.
commit 4adfb68c5f62a5b6d6bbdef79cb13362a3bd86b6
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Mon Dec 5 21:10:13 2016 +0100
Add upstream patch to fix race condition when opening command file.
---
debian/changelog | 2 +
..._race-condition-when-opening-command-file.patch | 80 ++++++++++++++++++++++
debian/patches/series | 1 +
3 files changed, 83 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 0792b2e..7cb6af6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -25,6 +25,8 @@ nsca (2.9.1-4) UNRELEASED; urgency=medium
* Redirect update-rc.d output to /dev/null.
* Add upstream patch to fix signal handling.
(closes: #743493)
+ * Add upstream patch to fix race condition when opening command file.
+ (closes: #663047)
-- Bas Couwenberg <sebastic at debian.org> Sun, 04 Dec 2016 00:04:22 +0100
diff --git a/debian/patches/08_race-condition-when-opening-command-file.patch b/debian/patches/08_race-condition-when-opening-command-file.patch
new file mode 100644
index 0000000..29d5fae
--- /dev/null
+++ b/debian/patches/08_race-condition-when-opening-command-file.patch
@@ -0,0 +1,80 @@
+Description: Race condition when opening command file
+ Fix for issue http://tracker.nagios.org/view.php?id=296
+Author: John C. Frickson <jfrickson at nagios.com>
+Origin: https://github.com/NagiosEnterprises/nsca/commit/9c98a1527c342eeacaa5905980a1dff9454c8b32
+
+--- a/src/nsca.c
++++ b/src/nsca.c
+@@ -1317,42 +1317,45 @@ static int write_check_result(char *host
+
+
+ /* opens the command file for writing */
+-static int open_command_file(void){
+- struct stat statbuf;
++static int open_command_file(void)
++{
++ int fd;
+
+- /* file is already open */
+- if(command_file_fp!=NULL && using_alternate_dump_file==FALSE)
+- return OK;
++ /* file is already open */
++ if(command_file_fp!=NULL && using_alternate_dump_file==FALSE)
++ return OK;
++
++ do
++ fd = open(command_file,O_WRONLY|((append_to_file==TRUE)?O_APPEND:0));
++ while(fd < 0 && errno == EINTR);
+
+ /* command file doesn't exist - monitoring app probably isn't running... */
+- if(stat(command_file,&statbuf)){
+-
+- if(debug==TRUE)
+- syslog(LOG_ERR,"Command file '%s' does not exist, attempting to use alternate dump file '%s' for output",command_file,alternate_dump_file);
++ if (fd < 0 && errno == ENOENT) {
++
++ if (debug == TRUE)
++ syslog(LOG_ERR, "Command file '%s' does not exist, attempting to use alternate dump file '%s' for output", command_file, alternate_dump_file);
+
+ /* try and write checks to alternate dump file */
+- command_file_fp=fopen(alternate_dump_file,"a");
+- if(command_file_fp==NULL){
+- if(debug==TRUE)
+- syslog(LOG_ERR,"Could not open alternate dump file '%s' for appending",alternate_dump_file);
++ command_file_fp = fopen(alternate_dump_file, "a");
++ if (command_file_fp == NULL) {
++ if(debug == TRUE)
++ syslog(LOG_ERR, "Could not open alternate dump file '%s' for appending", alternate_dump_file);
+ return ERROR;
+- }
+- using_alternate_dump_file=TRUE;
++ }
++ using_alternate_dump_file = TRUE;
+
+ return OK;
+- }
++ }
+
+- /* open the command file for writing or appending */
+- command_file_fp=fopen(command_file,(append_to_file==TRUE)?"a":"w");
+- if(command_file_fp==NULL){
+- if(debug==TRUE)
+- syslog(LOG_ERR,"Could not open command file '%s' for %s",command_file,(append_to_file==TRUE)?"appending":"writing");
+- return ERROR;
+- }
+-
+- using_alternate_dump_file=FALSE;
+- return OK;
+- }
++ if (fd < 0 || (command_file_fp = fdopen(fd, (append_to_file == TRUE) ? "a" : "w")) == NULL) {
++ if (debug == TRUE)
++ syslog(LOG_ERR, "Could not open command file '%s' for %s", command_file, (append_to_file == TRUE) ? "appending" : "writing");
++ return ERROR;
++ }
++
++ using_alternate_dump_file = FALSE;
++ return OK;
++}
+
+
+
diff --git a/debian/patches/series b/debian/patches/series
index fafae79..6e502cd 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -5,3 +5,4 @@
05_spelling-errors.patch
06_open-arguments.patch
07_signal-handler.patch
+08_race-condition-when-opening-command-file.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-nagios/pkg-nsca.git
More information about the Pkg-nagios-changes
mailing list