1
0

konfd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * konfd.c
  3. *
  4. * The konfd daemon to store user configuration commands.
  5. *
  6. */
  7. #ifdef HAVE_CONFIG_H
  8. #include "config.h"
  9. #endif /* HAVE_CONFIG_H */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>
  16. #include <sys/wait.h>
  17. #include <errno.h>
  18. #include <assert.h>
  19. #include <sys/socket.h>
  20. #include <sys/un.h>
  21. #include <string.h>
  22. #include <sys/select.h>
  23. #include <signal.h>
  24. #include <syslog.h>
  25. #ifdef HAVE_GETOPT_H
  26. #include <getopt.h>
  27. #endif
  28. #ifdef HAVE_PWD_H
  29. #include <pwd.h>
  30. #endif
  31. #ifdef HAVE_GRP_H
  32. #include <grp.h>
  33. #endif
  34. #include "konf/tree.h"
  35. #include "konf/query.h"
  36. #include "konf/buf.h"
  37. #include "konf/net.h"
  38. #include "lub/argv.h"
  39. #include "lub/string.h"
  40. #include "lub/log.h"
  41. #ifndef VERSION
  42. #define VERSION 1.2.2
  43. #endif
  44. #define QUOTE(t) #t
  45. #define version(v) printf("%s\n", v)
  46. #define KONFD_PIDFILE "/var/run/konfd.pid"
  47. /* UNIX socket path */
  48. /* Don't use UNIX_PATH_MAX due to portability issues */
  49. #define USOCK_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path)
  50. /* OpenBSD has no MSG_NOSIGNAL flag */
  51. #ifndef MSG_NOSIGNAL
  52. #define MSG_NOSIGNAL 0
  53. #endif
  54. /* Global signal vars */
  55. static volatile int sigterm = 0;
  56. static void sighandler(int signo);
  57. static void help(int status, const char *argv0);
  58. static char * process_query(int sock, konf_tree_t * conf, char *str);
  59. int answer_send(int sock, char *command);
  60. static int dump_running_config(int sock, konf_tree_t *conf, konf_query_t *query);
  61. int daemonize(int nochdir, int noclose);
  62. struct options *opts_init(void);
  63. void opts_free(struct options *opts);
  64. static int opts_parse(int argc, char *argv[], struct options *opts);
  65. static int create_listen_socket(const char *path,
  66. uid_t uid, gid_t gid);
  67. /* Command line options */
  68. struct options {
  69. char *socket_path;
  70. char *pidfile;
  71. char *chroot;
  72. int debug; /* Don't daemonize in debug mode */
  73. uid_t uid;
  74. gid_t gid;
  75. int log_facility;
  76. };
  77. /*--------------------------------------------------------- */
  78. int main(int argc, char **argv)
  79. {
  80. int retval = -1;
  81. unsigned i;
  82. char *str;
  83. konf_tree_t *conf;
  84. lub_bintree_t bufs;
  85. konf_buf_t *tbuf;
  86. struct options *opts = NULL;
  87. int pidfd = -1;
  88. /* Network vars */
  89. int sock = -1;
  90. struct sockaddr_un raddr;
  91. fd_set active_fd_set, read_fd_set;
  92. /* Signal vars */
  93. struct sigaction sig_act, sigpipe_act;
  94. sigset_t sig_set, sigpipe_set;
  95. /* Parse command line options */
  96. opts = opts_init();
  97. if (opts_parse(argc, argv, opts))
  98. goto err;
  99. /* Initialize syslog */
  100. openlog(argv[0], LOG_CONS, opts->log_facility);
  101. syslog(LOG_ERR, "Start daemon.\n");
  102. /* Fork the daemon */
  103. if (!opts->debug) {
  104. /* Daemonize */
  105. if (daemonize(0, 0) < 0) {
  106. syslog(LOG_ERR, "Can't daemonize\n");
  107. goto err;
  108. }
  109. /* Write pidfile */
  110. if ((pidfd = open(opts->pidfile,
  111. O_WRONLY | O_CREAT | O_EXCL | O_TRUNC,
  112. S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
  113. syslog(LOG_WARNING, "Can't open pidfile %s: %s",
  114. opts->pidfile, strerror(errno));
  115. } else {
  116. char str[20];
  117. snprintf(str, sizeof(str), "%u\n", getpid());
  118. if (write(pidfd, str, strlen(str)) < 0)
  119. syslog(LOG_WARNING, "Can't write to %s: %s",
  120. opts->pidfile, strerror(errno));
  121. close(pidfd);
  122. }
  123. }
  124. /* Create RW listen socket */
  125. if ((sock = create_listen_socket(opts->socket_path,
  126. opts->uid, opts->gid)) == -1) {
  127. goto err;
  128. }
  129. /* Change GID */
  130. if (opts->gid != getgid()) {
  131. if (setgid(opts->gid)) {
  132. syslog(LOG_ERR, "Can't set GID to %u: %s",
  133. opts->gid, strerror(errno));
  134. goto err;
  135. }
  136. }
  137. #ifdef HAVE_CHROOT
  138. /* Chroot */
  139. if (opts->chroot) {
  140. if (chroot(opts->chroot) < 0) {
  141. syslog(LOG_ERR, "Can't chroot to %s: %s",
  142. opts->chroot, strerror(errno));
  143. goto err;
  144. }
  145. }
  146. #endif
  147. /* Change UID */
  148. if (opts->uid != getuid()) {
  149. if (setuid(opts->uid)) {
  150. syslog(LOG_ERR, "Can't set UID to %u: %s",
  151. opts->uid, strerror(errno));
  152. goto err;
  153. }
  154. }
  155. /* Create configuration tree */
  156. conf = konf_tree_new("", 0);
  157. /* Initialize the tree of buffers */
  158. lub_bintree_init(&bufs,
  159. konf_buf_bt_offset(),
  160. konf_buf_bt_compare, konf_buf_bt_getkey);
  161. /* Set signal handler */
  162. sigemptyset(&sig_set);
  163. sigaddset(&sig_set, SIGTERM);
  164. sigaddset(&sig_set, SIGINT);
  165. sigaddset(&sig_set, SIGQUIT);
  166. sig_act.sa_flags = 0;
  167. sig_act.sa_mask = sig_set;
  168. sig_act.sa_handler = &sighandler;
  169. sigaction(SIGTERM, &sig_act, NULL);
  170. sigaction(SIGINT, &sig_act, NULL);
  171. sigaction(SIGQUIT, &sig_act, NULL);
  172. /* Ignore SIGPIPE */
  173. sigemptyset(&sigpipe_set);
  174. sigaddset(&sigpipe_set, SIGPIPE);
  175. sigpipe_act.sa_flags = 0;
  176. sigpipe_act.sa_mask = sigpipe_set;
  177. sigpipe_act.sa_handler = SIG_IGN;
  178. sigaction(SIGPIPE, &sigpipe_act, NULL);
  179. /* Initialize the set of active sockets. */
  180. FD_ZERO(&active_fd_set);
  181. FD_SET(sock, &active_fd_set);
  182. /* Main loop */
  183. while (!sigterm) {
  184. int num;
  185. /* Block until input arrives on one or more active sockets. */
  186. read_fd_set = active_fd_set;
  187. num = select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL);
  188. if (num < 0) {
  189. if (EINTR == errno)
  190. continue;
  191. break;
  192. }
  193. if (0 == num)
  194. continue;
  195. /* Service all the sockets with input pending. */
  196. for (i = 0; i < FD_SETSIZE; ++i) {
  197. if (!FD_ISSET(i, &read_fd_set))
  198. continue;
  199. if (i == sock) {
  200. /* Connection request on listen socket. */
  201. int new;
  202. socklen_t size = sizeof(raddr);
  203. new = accept(sock,
  204. (struct sockaddr *)&raddr, &size);
  205. if (new < 0) {
  206. continue;
  207. }
  208. #ifdef DEBUG
  209. fprintf(stderr, "Connection established %u\n", new);
  210. #endif
  211. konf_buftree_remove(&bufs, new);
  212. tbuf = konf_buf_new(new);
  213. /* insert it into the binary tree for this conf */
  214. lub_bintree_insert(&bufs, tbuf);
  215. FD_SET(new, &active_fd_set);
  216. } else {
  217. int nbytes;
  218. /* Data arriving on an already-connected socket. */
  219. if ((nbytes = konf_buftree_read(&bufs, i)) <= 0) {
  220. close(i);
  221. FD_CLR(i, &active_fd_set);
  222. konf_buftree_remove(&bufs, i);
  223. continue;
  224. }
  225. while ((str = konf_buftree_parse(&bufs, i))) {
  226. char *answer;
  227. if (!(answer = process_query(i, conf, str)))
  228. answer = strdup("-e");
  229. free(str);
  230. answer_send(i, answer);
  231. free(answer);
  232. }
  233. }
  234. }
  235. }
  236. /* Free resources */
  237. konf_tree_delete(conf);
  238. /* delete each buf */
  239. while ((tbuf = lub_bintree_findfirst(&bufs))) {
  240. /* remove the buf from the tree */
  241. lub_bintree_remove(&bufs, tbuf);
  242. /* release the instance */
  243. konf_buf_delete(tbuf);
  244. }
  245. retval = 0;
  246. err:
  247. /* Close listen socket */
  248. if (sock >= 0) {
  249. close(sock);
  250. unlink(opts->socket_path);
  251. }
  252. /* Remove pidfile */
  253. if (pidfd >= 0) {
  254. if (unlink(opts->pidfile) < 0) {
  255. syslog(LOG_ERR, "Can't remove pid-file %s: %s\n",
  256. opts->pidfile, strerror(errno));
  257. }
  258. }
  259. /* Free command line options */
  260. opts_free(opts);
  261. syslog(LOG_ERR, "Stop daemon.\n");
  262. return retval;
  263. }
  264. /*--------- Create listen socket--------------------------- */
  265. static int create_listen_socket(const char *path,
  266. uid_t uid, gid_t gid)
  267. {
  268. int sock = -1;
  269. struct sockaddr_un laddr;
  270. const int reuseaddr = 1;
  271. if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
  272. syslog(LOG_ERR, "Can't create socket: %s\n", strerror(errno));
  273. goto err1;
  274. }
  275. if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
  276. &reuseaddr, sizeof(reuseaddr))) {
  277. syslog(LOG_ERR, "Can't set socket options: %s\n", strerror(errno));
  278. goto err1;
  279. }
  280. laddr.sun_family = AF_UNIX;
  281. strncpy(laddr.sun_path, path, USOCK_PATH_MAX);
  282. laddr.sun_path[USOCK_PATH_MAX - 1] = '\0';
  283. if (bind(sock, (struct sockaddr *)&laddr, sizeof(laddr))) {
  284. syslog(LOG_ERR, "Can't bind socket: %s\n", strerror(errno));
  285. goto err1;
  286. }
  287. if (chown(path, uid, gid)) {
  288. syslog(LOG_ERR, "Can't chown socket: %s\n", strerror(errno));
  289. goto err2;
  290. }
  291. if (listen(sock, 10)) {
  292. syslog(LOG_ERR, "Can't listen socket: %s\n", strerror(errno));
  293. goto err2;
  294. }
  295. return sock;
  296. err2:
  297. unlink(path);
  298. err1:
  299. if (sock >= 0)
  300. close(sock);
  301. return -1;
  302. }
  303. /*--------------------------------------------------------- */
  304. static char * process_query(int sock, konf_tree_t * conf, char *str)
  305. {
  306. unsigned i;
  307. int res;
  308. konf_tree_t *iconf;
  309. konf_tree_t *tmpconf;
  310. konf_query_t *query;
  311. char *retval = NULL;
  312. konf_query_op_t ret = KONF_QUERY_OP_ERROR;
  313. #ifdef DEBUG
  314. fprintf(stderr, "----------------------\n");
  315. fprintf(stderr, "REQUEST: %s\n", str);
  316. #endif
  317. /* Parse query */
  318. query = konf_query_new();
  319. res = konf_query_parse_str(query, str);
  320. if (res < 0) {
  321. konf_query_free(query);
  322. return NULL;
  323. }
  324. #ifdef DEBUG
  325. konf_query_dump(query);
  326. #endif
  327. /* Go through the pwd */
  328. iconf = conf;
  329. for (i = 0; i < konf_query__get_pwdc(query); i++) {
  330. if (!(iconf = konf_tree_find_conf(iconf,
  331. konf_query__get_pwd(query, i), 0, 0))) {
  332. iconf = NULL;
  333. break;
  334. }
  335. }
  336. if (!iconf) {
  337. fprintf(stderr, "Unknown path\n");
  338. konf_query_free(query);
  339. return NULL;
  340. }
  341. switch (konf_query__get_op(query)) {
  342. case KONF_QUERY_OP_SET:
  343. if (konf_query__get_unique(query)) {
  344. int exist = 0;
  345. exist = konf_tree_del_pattern(iconf,
  346. konf_query__get_line(query),
  347. konf_query__get_unique(query),
  348. konf_query__get_pattern(query),
  349. konf_query__get_priority(query),
  350. konf_query__get_seq(query),
  351. konf_query__get_seq_num(query));
  352. if (exist < 0)
  353. break;
  354. if (exist > 0) {
  355. ret = KONF_QUERY_OP_OK;
  356. break;
  357. }
  358. }
  359. tmpconf = konf_tree_new_conf(iconf,
  360. konf_query__get_line(query), konf_query__get_priority(query),
  361. konf_query__get_seq(query), konf_query__get_seq_num(query));
  362. if (!tmpconf)
  363. break;
  364. konf_tree__set_splitter(tmpconf, konf_query__get_splitter(query));
  365. konf_tree__set_depth(tmpconf, konf_query__get_pwdc(query));
  366. ret = KONF_QUERY_OP_OK;
  367. break;
  368. case KONF_QUERY_OP_UNSET:
  369. if (konf_tree_del_pattern(iconf,
  370. NULL,
  371. BOOL_TRUE,
  372. konf_query__get_pattern(query),
  373. konf_query__get_priority(query),
  374. konf_query__get_seq(query),
  375. konf_query__get_seq_num(query)) < 0)
  376. break;
  377. ret = KONF_QUERY_OP_OK;
  378. break;
  379. case KONF_QUERY_OP_DUMP:
  380. if (dump_running_config(sock, iconf, query))
  381. break;
  382. ret = KONF_QUERY_OP_OK;
  383. break;
  384. default:
  385. break;
  386. }
  387. #ifdef DEBUG
  388. /* Print whole tree */
  389. konf_tree_fprintf(conf, stderr, NULL, -1, -1, BOOL_TRUE, 0);
  390. #endif
  391. /* Free resources */
  392. konf_query_free(query);
  393. switch (ret) {
  394. case KONF_QUERY_OP_OK:
  395. lub_string_cat(&retval, "-o");
  396. break;
  397. case KONF_QUERY_OP_ERROR:
  398. lub_string_cat(&retval, "-e");
  399. break;
  400. default:
  401. lub_string_cat(&retval, "-e");
  402. break;
  403. };
  404. #ifdef DEBUG
  405. fprintf(stderr, "ANSWER: %s\n", retval);
  406. #endif
  407. return retval;
  408. }
  409. /*--------------------------------------------------------- */
  410. /*
  411. * Signal handler for temination signals (like SIGTERM, SIGINT, ...)
  412. */
  413. static void sighandler(int signo)
  414. {
  415. sigterm = 1;
  416. }
  417. /*--------------------------------------------------------- */
  418. int answer_send(int sock, char *command)
  419. {
  420. return send(sock, command, strlen(command) + 1, MSG_NOSIGNAL);
  421. }
  422. /*--------------------------------------------------------- */
  423. static int dump_running_config(int sock, konf_tree_t *conf, konf_query_t *query)
  424. {
  425. FILE *fd;
  426. char *filename;
  427. int dupsock = -1;
  428. if ((filename = konf_query__get_path(query))) {
  429. if (!(fd = fopen(filename, "w")))
  430. return -1;
  431. } else {
  432. if ((dupsock = dup(sock)) < 0)
  433. return -1;
  434. fd = fdopen(dupsock, "w");
  435. }
  436. if (!filename) {
  437. fprintf(fd, "-t\n");
  438. #ifdef DEBUG
  439. fprintf(stderr, "ANSWER: -t\n");
  440. #endif
  441. }
  442. konf_tree_fprintf(conf,
  443. fd,
  444. konf_query__get_pattern(query),
  445. konf_query__get_pwdc(query) - 1,
  446. konf_query__get_depth(query),
  447. konf_query__get_seq(query),
  448. 0);
  449. if (!filename) {
  450. fprintf(fd, "\n");
  451. #ifdef DEBUG
  452. fprintf(stderr, "SEND DATA: \n");
  453. #endif
  454. }
  455. fclose(fd);
  456. return 0;
  457. }
  458. /*--------------------------------------------------------- */
  459. /* Implement own simple daemon() to don't use Non-POSIX */
  460. int daemonize(int nochdir, int noclose)
  461. {
  462. int fd;
  463. int pid;
  464. pid = fork();
  465. if (-1 == pid)
  466. return -1;
  467. if (pid > 0)
  468. _exit(0); /* Exit parent */
  469. if (setsid() == -1)
  470. return -1;
  471. if (!nochdir) {
  472. if (chdir("/"))
  473. return -1;
  474. }
  475. if (!noclose) {
  476. fd = open("/dev/null", O_RDWR, 0);
  477. if (fd < 0)
  478. return -1;
  479. dup2(fd, STDIN_FILENO);
  480. dup2(fd, STDOUT_FILENO);
  481. dup2(fd, STDERR_FILENO);
  482. if (fd > 2)
  483. close(fd);
  484. }
  485. return 0;
  486. }
  487. /*--------------------------------------------------------- */
  488. /* Initialize option structure by defaults */
  489. struct options *opts_init(void)
  490. {
  491. struct options *opts = NULL;
  492. opts = malloc(sizeof(*opts));
  493. assert(opts);
  494. opts->debug = 0; /* daemonize by default */
  495. opts->socket_path = strdup(KONFD_SOCKET_PATH);
  496. opts->pidfile = strdup(KONFD_PIDFILE);
  497. opts->chroot = NULL;
  498. opts->uid = getuid();
  499. opts->gid = getgid();
  500. opts->log_facility = LOG_DAEMON;
  501. return opts;
  502. }
  503. /*--------------------------------------------------------- */
  504. /* Free option structure */
  505. void opts_free(struct options *opts)
  506. {
  507. if (opts->socket_path)
  508. free(opts->socket_path);
  509. if (opts->pidfile)
  510. free(opts->pidfile);
  511. if (opts->chroot)
  512. free(opts->chroot);
  513. free(opts);
  514. }
  515. /*--------------------------------------------------------- */
  516. /* Parse command line options */
  517. static int opts_parse(int argc, char *argv[], struct options *opts)
  518. {
  519. static const char *shortopts = "hvs:p:u:g:dr:O:";
  520. #ifdef HAVE_GETOPT_H
  521. static const struct option longopts[] = {
  522. {"help", 0, NULL, 'h'},
  523. {"version", 0, NULL, 'v'},
  524. {"socket", 1, NULL, 's'},
  525. {"pid", 1, NULL, 'p'},
  526. {"user", 1, NULL, 'u'},
  527. {"group", 1, NULL, 'g'},
  528. {"debug", 0, NULL, 'd'},
  529. {"chroot", 1, NULL, 'r'},
  530. {"facility", 1, NULL, 'O'},
  531. {NULL, 0, NULL, 0}
  532. };
  533. #endif
  534. optind = 1;
  535. while(1) {
  536. int opt;
  537. #ifdef HAVE_GETOPT_H
  538. opt = getopt_long(argc, argv, shortopts, longopts, NULL);
  539. #else
  540. opt = getopt(argc, argv, shortopts);
  541. #endif
  542. if (-1 == opt)
  543. break;
  544. switch (opt) {
  545. case 's':
  546. if (opts->socket_path)
  547. free(opts->socket_path);
  548. opts->socket_path = strdup(optarg);
  549. break;
  550. case 'p':
  551. if (opts->pidfile)
  552. free(opts->pidfile);
  553. opts->pidfile = strdup(optarg);
  554. break;
  555. case 'r':
  556. #ifdef HAVE_CHROOT
  557. if (opts->chroot)
  558. free(opts->chroot);
  559. opts->chroot = strdup(optarg);
  560. #else
  561. fprintf(stderr, "Error: The --chroot option is not supported.\n");
  562. return -1;
  563. #endif
  564. break;
  565. case 'd':
  566. opts->debug = 1;
  567. break;
  568. case 'u': {
  569. #ifdef HAVE_PWD_H
  570. struct passwd *pwd = getpwnam(optarg);
  571. if (!pwd) {
  572. fprintf(stderr, "Error: Can't identify user \"%s\"\n",
  573. optarg);
  574. return -1;
  575. }
  576. opts->uid = pwd->pw_uid;
  577. #else
  578. fprintf(stderr, "The --user option is not supported.\n");
  579. return -1;
  580. #endif
  581. break;
  582. }
  583. case 'g': {
  584. #ifdef HAVE_GRP_H
  585. struct group *grp = getgrnam(optarg);
  586. if (!grp) {
  587. fprintf(stderr, "Can't identify group \"%s\"\n",
  588. optarg);
  589. return -1;
  590. }
  591. opts->gid = grp->gr_gid;
  592. #else
  593. fprintf(stderr, "The --group option is not supported.\n");
  594. return -1;
  595. #endif
  596. break;
  597. }
  598. case 'O':
  599. if (lub_log_facility(optarg, &(opts->log_facility))) {
  600. fprintf(stderr, "Error: Illegal syslog facility %s.\n", optarg);
  601. help(-1, argv[0]);
  602. exit(-1);
  603. }
  604. break;
  605. case 'h':
  606. help(0, argv[0]);
  607. exit(0);
  608. break;
  609. case 'v':
  610. version(VERSION);
  611. exit(0);
  612. break;
  613. default:
  614. help(-1, argv[0]);
  615. exit(-1);
  616. break;
  617. }
  618. }
  619. return 0;
  620. }
  621. /*--------------------------------------------------------- */
  622. /* Print help message */
  623. static void help(int status, const char *argv0)
  624. {
  625. const char *name = NULL;
  626. if (!argv0)
  627. return;
  628. /* Find the basename */
  629. name = strrchr(argv0, '/');
  630. if (name)
  631. name++;
  632. else
  633. name = argv0;
  634. if (status != 0) {
  635. fprintf(stderr, "Try `%s -h' for more information.\n",
  636. name);
  637. } else {
  638. printf("Usage: %s [options]\n", name);
  639. printf("Daemon to store user configuration (i.e. commands). "
  640. "The part of the klish project.\n");
  641. printf("Options:\n");
  642. printf("\t-v, --version\tPrint version.\n");
  643. printf("\t-h, --help\tPrint this help.\n");
  644. printf("\t-d, --debug\tDebug mode. Don't daemonize.\n");
  645. printf("\t-s <path>, --socket=<path>\tSpecify the UNIX socket "
  646. "filesystem path to listen on.\n");
  647. printf("\t-p <path>, --pid=<path>\tFile to save daemon's PID to.\n");
  648. printf("\t-r <path>, --chroot=<path>\tDirectory to chroot.\n");
  649. printf("\t-u <user>, --user=<user>\tExecute process as"
  650. " specified user.\n");
  651. printf("\t-g <group>, --group=<group>\tExecute process as"
  652. " specified group.\n");
  653. printf("\t-O, --facility\tSyslog facility. Default is DAEMON.\n");
  654. }
  655. }