|
From: <abe...@us...> - 2017-07-27 13:11:26
|
Revision: 8458
http://sourceforge.net/p/astlinux/code/8458
Author: abelbeck
Date: 2017-07-27 13:11:25 +0000 (Thu, 27 Jul 2017)
Log Message:
-----------
monit, add upstream patch to fix missing 'check program' output
Ref: https://bitbucket.org/tildeslash/monit/commits/fe66bb14d5f77cb2ebac8f94c3d699922e25abac
Added Paths:
-----------
branches/1.0/package/monit/monit-0900-upstream-check-program-output.patch
Added: branches/1.0/package/monit/monit-0900-upstream-check-program-output.patch
===================================================================
--- branches/1.0/package/monit/monit-0900-upstream-check-program-output.patch (rev 0)
+++ branches/1.0/package/monit/monit-0900-upstream-check-program-output.patch 2017-07-27 13:11:25 UTC (rev 8458)
@@ -0,0 +1,167 @@
+From fe66bb14d5f77cb2ebac8f94c3d699922e25abac Mon Sep 17 00:00:00 2001
+From: tildeslash <in...@ti...>
+Date: Wed, 21 Jun 2017 22:45:48 +0200
+Subject: [PATCH] Fixed: Issue #634: Check program output
+
+---
+ CHANGES | 2 ++
+ src/gc.c | 3 ++-
+ src/http/cervlet.c | 6 +++---
+ src/http/xml.c | 2 +-
+ src/monit.h | 3 ++-
+ src/p.y | 6 ++++--
+ src/validate.c | 20 ++++++++++++--------
+ 7 files changed, 26 insertions(+), 16 deletions(-)
+
+diff --git a/src/gc.c b/src/gc.c
+index 74dd141..912652e 100644
+--- a/src/gc.c
++++ b/src/gc.c
+@@ -186,7 +186,8 @@ static void _gc_service(Service_T *s) {
+ Command_free(&(*s)->program->C);
+ if ((*s)->program->args)
+ gccmd(&(*s)->program->args);
+- StringBuffer_free(&((*s)->program->output));
++ StringBuffer_free(&((*s)->program->lastOutput));
++ StringBuffer_free(&((*s)->program->inprogressOutput));
+ FREE((*s)->program);
+ }
+ if ((*s)->portlist)
+diff --git a/src/http/cervlet.c b/src/http/cervlet.c
+index ab91921..d2e6325 100644
+--- a/src/http/cervlet.c
++++ b/src/http/cervlet.c
+@@ -433,7 +433,7 @@ static void _printStatus(Output_Type type, HttpResponse res, Service_T s) {
+ case Service_Program:
+ if (s->program->started) {
+ _formatStatus("last exit value", Event_Status, type, res, s, true, "%d", s->program->exitStatus);
+- _formatStatus("last output", Event_Status, type, res, s, StringBuffer_length(s->program->output), "%s", StringBuffer_toString(s->program->output));
++ _formatStatus("last output", Event_Status, type, res, s, StringBuffer_length(s->program->lastOutput), "%s", StringBuffer_toString(s->program->lastOutput));
+ }
+ break;
+
+@@ -1314,9 +1314,9 @@ static void do_home_program(HttpResponse res) {
+ } else {
+ if (s->program->started) {
+ StringBuffer_append(res->outputbuffer, "<td class='left short'>");
+- if (StringBuffer_length(s->program->output)) {
++ if (StringBuffer_length(s->program->lastOutput)) {
+ // Print first line only (escape HTML characters if any)
+- const char *output = StringBuffer_toString(s->program->output);
++ const char *output = StringBuffer_toString(s->program->lastOutput);
+ for (int i = 0; output[i]; i++) {
+ if (output[i] == '<')
+ StringBuffer_append(res->outputbuffer, "<");
+diff --git a/src/http/xml.c b/src/http/xml.c
+index 7208883..b19f195 100644
+--- a/src/http/xml.c
++++ b/src/http/xml.c
+@@ -511,7 +511,7 @@ static void status_service(Service_T S, StringBuffer_T B, int V) {
+ "<output><![CDATA[",
+ (long long)S->program->started,
+ S->program->exitStatus);
+- _escapeCDATA(B, StringBuffer_toString(S->program->output));
++ _escapeCDATA(B, StringBuffer_toString(S->program->lastOutput));
+ StringBuffer_append(B,
+ "]]></output>"
+ "</program>");
+diff --git a/src/monit.h b/src/monit.h
+index 78727ce..9d47596 100644
+--- a/src/monit.h
++++ b/src/monit.h
+@@ -813,7 +813,8 @@ typedef struct Program_T {
+ time_t started; /**< When the sub-process was started */
+ int timeout; /**< Seconds the program may run until it is killed */
+ int exitStatus; /**< Sub-process exit status for reporting */
+- StringBuffer_T output; /**< Last program output */
++ StringBuffer_T lastOutput; /**< Last program output */
++ StringBuffer_T inprogressOutput; /**< Output of the pending program instance */
+ } *Program_T;
+
+
+diff --git a/src/p.y b/src/p.y
+index fe4adad..25b612c 100644
+--- a/src/p.y
++++ b/src/p.y
+@@ -1233,14 +1233,16 @@ checkprogram : CHECKPROGRAM SERVICENAME PATHTOK argumentlist programtimeout {
+ check_exec(c->arg[0]);
+ createservice(Service_Program, $<string>2, NULL, check_program);
+ current->program->timeout = $<number>5;
+- current->program->output = StringBuffer_create(64);
++ current->program->lastOutput = StringBuffer_create(64);
++ current->program->inprogressOutput = StringBuffer_create(64);
+ }
+ | CHECKPROGRAM SERVICENAME PATHTOK argumentlist useroptionlist programtimeout {
+ command_t c = command; // Current command
+ check_exec(c->arg[0]);
+ createservice(Service_Program, $<string>2, NULL, check_program);
+ current->program->timeout = $<number>6;
+- current->program->output = StringBuffer_create(64);
++ current->program->lastOutput = StringBuffer_create(64);
++ current->program->inprogressOutput = StringBuffer_create(64);
+ }
+ ;
+
+diff --git a/src/validate.c b/src/validate.c
+index 069fa89..1e46bce 100644
+--- a/src/validate.c
++++ b/src/validate.c
+@@ -1592,9 +1592,8 @@ State_Type check_program(Service_T s) {
+ Process_T P = s->program->P;
+ if (P) {
+ // Process program output
+- _programOutput(Process_getErrorStream(P), s->program->output);
+- _programOutput(Process_getInputStream(P), s->program->output);
+- StringBuffer_trim(s->program->output);
++ _programOutput(Process_getErrorStream(P), s->program->inprogressOutput);
++ _programOutput(Process_getInputStream(P), s->program->inprogressOutput);
+ // Is the program still running?
+ if (Process_exitStatus(P) < 0) {
+ int64_t execution_time = (now - s->program->started) * 1000;
+@@ -1611,15 +1610,20 @@ State_Type check_program(Service_T s) {
+ }
+ }
+ s->program->exitStatus = Process_exitStatus(P); // Save exit status for web-view display
++ StringBuffer_trim(s->program->inprogressOutput);
++ // Swap program output (instance finished)
++ StringBuffer_clear(s->program->lastOutput);
++ StringBuffer_append(s->program->lastOutput, "%s", StringBuffer_toString(s->program->inprogressOutput));
+ // Evaluate program's exit status against our status checks.
++ const char *output = StringBuffer_length(s->program->inprogressOutput) ? StringBuffer_toString(s->program->inprogressOutput) : "no output";
+ for (Status_T status = s->statuslist; status; status = status->next) {
+ if (status->operator == Operator_Changed) {
+ if (status->initialized) {
+ if (Util_evalQExpression(status->operator, s->program->exitStatus, status->return_value)) {
+- Event_post(s, Event_Status, State_Changed, status->action, "status changed (%d -> %d) -- %s", status->return_value, s->program->exitStatus, StringBuffer_length(s->program->output) ? StringBuffer_toString(s->program->output) : "no output");
++ Event_post(s, Event_Status, State_Changed, status->action, "status changed (%d -> %d) -- %s", status->return_value, s->program->exitStatus, output);
+ status->return_value = s->program->exitStatus;
+ } else {
+- Event_post(s, Event_Status, State_ChangedNot, status->action, "status didn't change (%d) -- %s", s->program->exitStatus, StringBuffer_length(s->program->output) ? StringBuffer_toString(s->program->output) : "no output");
++ Event_post(s, Event_Status, State_ChangedNot, status->action, "status didn't change (%d) -- %s", s->program->exitStatus, output);
+ }
+ } else {
+ status->initialized = true;
+@@ -1628,9 +1632,9 @@ State_Type check_program(Service_T s) {
+ } else {
+ if (Util_evalQExpression(status->operator, s->program->exitStatus, status->return_value)) {
+ rv = State_Failed;
+- Event_post(s, Event_Status, State_Failed, status->action, "status failed (%d) -- %s", s->program->exitStatus, StringBuffer_length(s->program->output) ? StringBuffer_toString(s->program->output) : "no output");
++ Event_post(s, Event_Status, State_Failed, status->action, "status failed (%d) -- %s", s->program->exitStatus, output);
+ } else {
+- Event_post(s, Event_Status, State_Succeeded, status->action, "status succeeded (%d) -- %s", s->program->exitStatus, StringBuffer_length(s->program->output) ? StringBuffer_toString(s->program->output) : "no output");
++ Event_post(s, Event_Status, State_Succeeded, status->action, "status succeeded (%d) -- %s", s->program->exitStatus, output);
+ }
+ }
+ }
+@@ -1641,7 +1645,7 @@ State_Type check_program(Service_T s) {
+ //FIXME: the current off-by-one-cycle based design requires that the check program will collect the exit value next cycle even if program startup should be skipped in the given cycle => must test skip here (new scheduler will obsolete this deferred skip checking)
+ if (! _checkSkip(s) && s->monitor != Monitor_Not) { // The status evaluation may disable service monitoring
+ // Start program
+- StringBuffer_clear(s->program->output);
++ StringBuffer_clear(s->program->inprogressOutput);
+ s->program->P = Command_execute(s->program->C);
+ if (! s->program->P) {
+ rv = State_Failed;
+--
+2.7.4.1.g5468f9e
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|