Bug fix (?): system() and popen() return codes

To our friends @Osimis and anyone experiencing problems while working with calling external programs from within an Orthanc plugin,

I’ve just came across an issue while working with calling programs from within an Orthanc plugin. Both system and popen were returning “-1” which, all things considered, meant no communication with child processes.

Which was a problem to me because I count on said programs status codes. But I digress.

Point being I worked out a “bug fix” (quotes meaning it requires further testing). That happened after I found this specific answer on StackOverflow: https://stackoverflow.com/questions/15992984/pclose-on-file-descriptor-opened-with-popen-returns-errno-10-no-child-proce#comment22804522_15993690

It’s really simple: after the mg_start call on Core/HttpServer/MongooseServer.cpp, we revert to the default handling for SIGCHLD. Fix is as follows:

diff --git a/Orthanc-1.3.2/Core/HttpServer/MongooseServer.cpp b/Orthanc-1.3.2/Core/HttpServer/MongooseServer.cpp
index 7452910…594e1a9 100644
— a/Orthanc-1.3.2/Core/HttpServer/MongooseServer.cpp
+++ b/Orthanc-1.3.2/Core/HttpServer/MongooseServer.cpp
@@ -68,6 +68,10 @@
#include <openssl/opensslv.h>
#endif

+#if !defined(_WIN32) || defined(SYMBIAN32)
+#include <signal.h>
+#endif
+
#define ORTHANC_REALM “Orthanc Secure Area”

@@ -977,12 +981,18 @@ namespace Orthanc

#if MONGOOSE_USE_CALLBACKS == 0
pimpl_->context_ = mg_start(&Callback, this, options);

  • #if !defined(_WIN32) || defined(SYMBIAN32)
  • signal( SIGCHLD, SIG_DFL );
  • #endif

#elif MONGOOSE_USE_CALLBACKS == 1
struct mg_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = Callback;
pimpl_->context_ = mg_start(&callbacks, this, options);

  • #if !defined(_WIN32) || defined(SYMBIAN32)
  • signal( SIGCHLD, SIG_DFL );
  • #endif

#else
#error Please set MONGOOSE_USE_CALLBACKS

PS: please, do apologise the unpolished “report”, it’s past 10PM, I must go back home but I had to write this just in case someone experiences the same problem

PPS: we’re working on 1.3.2 because that was the stable version when development began

Have a good one! =)

I forgot to mention the fix was actually a suggestion found in mongoose.h itself. On mg_start documentation it says something like “a side effect of calling this function is if you count on SIGCHLD handling behaviour, you can set it up after the call to mg_start”. And it turns out I did.

But further testing remains due since that same documentation says not handling SIGCHLD (now it means inside mongoose) would make the whole server exit. That’s what I’ll be testing tomorrow morning (slow connection and larger study archive download should do the trick).

The tests actually performed were submit Orthanc-1.3.2 to a reasonable workload and attempt downloading of a large enough study through CURL, only CTRL-C’ing before Orthanc had a chance to actually perform the download. It is believed that this is close enough to the browser cancelling the request. No problems were found.