Commit 18001cd1 authored by Alessio Netti's avatar Alessio Netti
Browse files

dcdbslurmjob: re-opening STDIN/STDOUT/STDERR if closed

- This prevents libuv from crashing dcdbslurmjob when the Cassandra
insertion mode is being used
parent 4f0cd26e
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <mosquitto.h> #include <mosquitto.h>
#include "dcdb/version.h" #include "dcdb/version.h"
#include "version.h" #include "version.h"
#include "fcntl.h"
#include "unistd.h"
#define SLURM_JOBSTEP_SEP "." #define SLURM_JOBSTEP_SEP "."
...@@ -54,6 +56,20 @@ void publishCallback(struct mosquitto *mosq, void *obj, int mid) { ...@@ -54,6 +56,20 @@ void publishCallback(struct mosquitto *mosq, void *obj, int mid) {
done = true; done = true;
} }
// Re-opens STDIN, STDOUT or STDERR to /dev/null if they are closed.
// Prevents libuv from making dcdbslurmjob crash when using Cassandra.
void fixFileDescriptors() {
std::string stdArr[3] = {"STDIN", "STDOUT", "STDERR"};
int fd = -1;
for(int idx=0; idx<=2; idx++) {
if(fcntl(idx, F_GETFD) < 0) {
std::cerr << "Warning: detected closed " << stdArr[idx] << " channel. Fixing..." << std::endl;
if((fd=open("/dev/null", O_RDWR)) < 0 || dup2(fd, idx) < 0) {
std::cerr << "Error: cannot re-open " << stdArr[idx] << " channel." << std::endl;
}
}
}
}
/* /*
* Print usage information * Print usage information
...@@ -347,6 +363,7 @@ int main(int argc, char** argv) { ...@@ -347,6 +363,7 @@ int main(int argc, char** argv) {
// Initialize transport // Initialize transport
if (cassandra) { if (cassandra) {
fixFileDescriptors();
// Allocate and initialize connection to Cassandra. // Allocate and initialize connection to Cassandra.
pickRandomHost(hostList, host, port); pickRandomHost(hostList, host, port);
if (port == 0) { if (port == 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment