diff --git a/src/h5_zmq_writer.cpp b/src/h5_zmq_writer.cpp index e65ee66..f23f241 100644 --- a/src/h5_zmq_writer.cpp +++ b/src/h5_zmq_writer.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include @@ -245,18 +247,35 @@ void run_writer(string connect_address, string output_file, uint64_t n_images, u int main (int argc, char *argv[]) { - if (argc != 5) { + if (argc != 6) { cout << endl; cout << "Usage: h5_zmq_writer [connection_address] [output_file] [n_images] [rest_port]" << endl; cout << "\tconnection_address: Address to connect to the stream (PULL). Example: tcp://127.0.0.1:40000" << endl; cout << "\toutput_file: Name of the output file." << endl; cout << "\tn_images: Number of images to acquire. 0 for infinity (untill /stop is called)." << endl; cout << "\trest_port: Port to start the REST Api on." << endl; + cout << "\tuser_id: uid under which to run the writer. -1 to leave it as it is." << endl; cout << endl; exit(-1); } + // This process can be set to run under a different user. + auto user_id = atoi(argv[5]); + if (user_id != -1) { + + #ifdef DEBUG_OUTPUT + cout << "[h5_zmq_writer::main] Setting process uid to " << user_id << endl; + #endif + + if (setuid(user_id)) { + stringstream error_message; + error_message << "[h5_zmq_writer::main] Cannot set user_id to " << user_id << endl; + + throw runtime_error(error_message.str()); + } + } + run_writer(string(argv[1]), string(argv[2]), atoi(argv[3]), atoi(argv[4])); return 0;