1 #include <elliptics/srw/srw.hpp>
3 static void kill_all_fds(const char *log
)
7 for (int i
= 3; i
< 1024; ++i
) {
11 fd
= open("/dev/null", O_RDWR
);
14 fprintf(stderr
, "Can not open /dev/null: %d\n", fd
);
20 dup2(fd
, STDIN_FILENO
);
22 fd
= open(log
, O_RDWR
| O_APPEND
);
27 dup2(fd
, STDERR_FILENO
);
28 dup2(fd
, STDOUT_FILENO
);
31 static void worker_usage(char *arg
)
33 std::cerr
<< "Usage: " << arg
<< " <options>\n" <<
34 " -i init-file - shared library path to load worker code from\n" <<
35 " -c config-file - config file for worker\n" <<
36 " -l log-file - log file for worker\n" <<
37 " -p pipe-base - pipe base for worker: it will write to @pipe-base.w2c and read from @pipe-base.c2w\n" <<
42 int main(int argc
, char *argv
[])
45 std::string
log("/dev/stdout"), pipe("/tmp/test-pipe"), init
, conf
;
47 while ((ch
= getopt(argc
, argv
, "c:i:l:p:h")) != -1) {
63 worker_usage(argv
[0]);
67 kill_all_fds(log
.c_str());
70 ioremap::srw::worker
<ioremap::srw::shared
> w(log
, pipe
, init
, conf
);
72 } catch (const std::exception
&e
) {
73 std::ofstream
l(log
.c_str(), std::ios::app
);
74 l
<< getpid() << ": worker exception: " << e
.what() << std::endl
;