Add process UID parameter

This commit is contained in:
2018-01-23 12:02:20 +01:00
parent ae3a70bd5a
commit 63da1c324c
+20 -1
View File
@@ -3,6 +3,8 @@
#include <zmq.hpp>
#include <cstdlib>
#include <chrono>
#include <unistd.h>
#include <stdexcept>
#include <boost/property_tree/json_parser.hpp>
#include <boost/thread.hpp>
@@ -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;