s3-lsasd: User new prefork helpers to simplify code.
[Samba/bjacke.git] / source3 / rpc_server / lsasd.c
blobc53eb5f37975f4be572509fd36735ef4c0d72e0f
1 /*
2 * Unix SMB/CIFS implementation.
4 * LSA service daemon
6 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "serverid.h"
24 #include "messages.h"
25 #include "ntdomain.h"
27 #include "../lib/tsocket/tsocket.h"
28 #include "lib/server_prefork.h"
29 #include "lib/server_prefork_util.h"
30 #include "librpc/rpc/dcerpc_ep.h"
32 #include "rpc_server/rpc_server.h"
33 #include "rpc_server/rpc_ep_register.h"
34 #include "rpc_server/rpc_sock_helper.h"
36 #include "librpc/gen_ndr/srv_lsa.h"
37 #include "librpc/gen_ndr/srv_samr.h"
38 #include "librpc/gen_ndr/srv_netlogon.h"
40 #define DAEMON_NAME "lsasd"
41 #define LSASD_MAX_SOCKETS 64
43 static struct prefork_pool *lsasd_pool = NULL;
44 static int lsasd_child_id = 0;
46 static struct pf_daemon_config default_pf_lsasd_cfg = {
47 .prefork_status = PFH_INIT,
48 .min_children = 5,
49 .max_children = 25,
50 .spawn_rate = 5,
51 .max_allowed_clients = 100,
52 .child_min_life = 60 /* 1 minute minimum life time */
54 static struct pf_daemon_config pf_lsasd_cfg = { 0 };
56 void start_lsasd(struct tevent_context *ev_ctx,
57 struct messaging_context *msg_ctx);
59 static void lsasd_reopen_logs(int child_id)
61 char *lfile = lp_logfile();
62 char *extension;
63 int rc;
65 if (child_id) {
66 rc = asprintf(&extension, "%s.%d", DAEMON_NAME, child_id);
67 } else {
68 rc = asprintf(&extension, "%s", DAEMON_NAME);
70 if (rc == -1) {
71 return;
74 rc = 0;
75 if (lfile == NULL || lfile[0] == '\0') {
76 rc = asprintf(&lfile, "%s/log.%s",
77 get_dyn_LOGFILEBASE(), extension);
78 } else {
79 if (strstr(lfile, extension) == NULL) {
80 if (child_id) {
81 rc = asprintf(&lfile, "%s.%d",
82 lp_logfile(),
83 child_id);
84 } else {
85 rc = asprintf(&lfile, "%s.%s",
86 lp_logfile(),
87 extension);
92 if (rc > 0) {
93 lp_set_logfile(lfile);
94 SAFE_FREE(lfile);
97 SAFE_FREE(extension);
99 reopen_logs();
102 static void lsasd_smb_conf_updated(struct messaging_context *msg,
103 void *private_data,
104 uint32_t msg_type,
105 struct server_id server_id,
106 DATA_BLOB *data)
108 struct tevent_context *ev_ctx;
110 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
111 ev_ctx = talloc_get_type_abort(private_data, struct tevent_context);
113 change_to_root_user();
114 lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
116 lsasd_reopen_logs(lsasd_child_id);
117 if (lsasd_child_id == 0) {
118 pfh_daemon_config(DAEMON_NAME,
119 &pf_lsasd_cfg,
120 &default_pf_lsasd_cfg);
121 pfh_manage_pool(ev_ctx, msg, &pf_lsasd_cfg, lsasd_pool);
125 static void lsasd_sig_term_handler(struct tevent_context *ev,
126 struct tevent_signal *se,
127 int signum,
128 int count,
129 void *siginfo,
130 void *private_data)
132 rpc_netlogon_shutdown();
133 rpc_samr_shutdown();
134 rpc_lsarpc_shutdown();
136 DEBUG(0, ("termination signal\n"));
137 exit(0);
140 static void lsasd_setup_sig_term_handler(struct tevent_context *ev_ctx)
142 struct tevent_signal *se;
144 se = tevent_add_signal(ev_ctx,
145 ev_ctx,
146 SIGTERM, 0,
147 lsasd_sig_term_handler,
148 NULL);
149 if (!se) {
150 DEBUG(0, ("failed to setup SIGTERM handler\n"));
151 exit(1);
155 static void lsasd_sig_hup_handler(struct tevent_context *ev,
156 struct tevent_signal *se,
157 int signum,
158 int count,
159 void *siginfo,
160 void *pvt)
163 change_to_root_user();
164 lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
166 lsasd_reopen_logs(lsasd_child_id);
167 pfh_daemon_config(DAEMON_NAME,
168 &pf_lsasd_cfg,
169 &default_pf_lsasd_cfg);
171 /* relay to all children */
172 prefork_send_signal_to_all(lsasd_pool, SIGHUP);
175 static void lsasd_setup_sig_hup_handler(struct tevent_context *ev_ctx)
177 struct tevent_signal *se;
179 se = tevent_add_signal(ev_ctx,
180 ev_ctx,
181 SIGHUP, 0,
182 lsasd_sig_hup_handler,
183 NULL);
184 if (!se) {
185 DEBUG(0, ("failed to setup SIGHUP handler\n"));
186 exit(1);
190 /**********************************************************
191 * Children
192 **********************************************************/
194 struct lsasd_chld_sig_hup_ctx {
195 struct messaging_context *msg_ctx;
196 struct pf_worker_data *pf;
199 static void lsasd_chld_sig_hup_handler(struct tevent_context *ev,
200 struct tevent_signal *se,
201 int signum,
202 int count,
203 void *siginfo,
204 void *pvt)
206 struct pf_worker_data *pf = (struct pf_worker_data *)pvt;
208 /* avoid wasting CPU cycles if we are going to exit soon anyways */
209 if (pf->cmds == PF_SRV_MSG_EXIT) {
210 return;
213 change_to_root_user();
214 lsasd_reopen_logs(lsasd_child_id);
217 static bool lsasd_setup_chld_hup_handler(struct tevent_context *ev_ctx,
218 struct pf_worker_data *pf)
220 struct tevent_signal *se;
222 se = tevent_add_signal(ev_ctx,
223 ev_ctx,
224 SIGHUP, 0,
225 lsasd_chld_sig_hup_handler,
226 pf);
227 if (!se) {
228 DEBUG(1, ("failed to setup SIGHUP handler"));
229 return false;
232 return true;
235 static bool lsasd_child_init(struct tevent_context *ev_ctx,
236 int child_id,
237 struct pf_worker_data *pf)
239 NTSTATUS status;
240 struct messaging_context *msg_ctx = server_messaging_context();
241 bool ok;
243 status = reinit_after_fork(msg_ctx, ev_ctx,
244 procid_self(), true);
245 if (!NT_STATUS_IS_OK(status)) {
246 DEBUG(0,("reinit_after_fork() failed\n"));
247 smb_panic("reinit_after_fork() failed");
250 lsasd_child_id = child_id;
251 lsasd_reopen_logs(child_id);
253 ok = lsasd_setup_chld_hup_handler(ev_ctx, pf);
254 if (!ok) {
255 return false;
258 if (!serverid_register(procid_self(), FLAG_MSG_GENERAL)) {
259 return false;
262 messaging_register(msg_ctx, ev_ctx,
263 MSG_SMB_CONF_UPDATED, lsasd_smb_conf_updated);
265 status = rpc_lsarpc_init(NULL);
266 if (!NT_STATUS_IS_OK(status)) {
267 DEBUG(0, ("Failed to register lsarpc rpc inteface! (%s)\n",
268 nt_errstr(status)));
269 return false;
272 status = rpc_samr_init(NULL);
273 if (!NT_STATUS_IS_OK(status)) {
274 DEBUG(0, ("Failed to register samr rpc inteface! (%s)\n",
275 nt_errstr(status)));
276 return false;
279 status = rpc_netlogon_init(NULL);
280 if (!NT_STATUS_IS_OK(status)) {
281 DEBUG(0, ("Failed to register netlogon rpc inteface! (%s)\n",
282 nt_errstr(status)));
283 return false;
286 return true;
289 struct lsasd_children_data {
290 struct tevent_context *ev_ctx;
291 struct messaging_context *msg_ctx;
292 struct pf_worker_data *pf;
293 int listen_fd_size;
294 int *listen_fds;
297 static void lsasd_next_client(void *pvt);
299 static int lsasd_children_main(struct tevent_context *ev_ctx,
300 struct messaging_context *msg_ctx,
301 struct pf_worker_data *pf,
302 int child_id,
303 int listen_fd_size,
304 int *listen_fds,
305 void *private_data)
307 struct lsasd_children_data *data;
308 bool ok;
309 int ret;
311 ok = lsasd_child_init(ev_ctx, child_id, pf);
312 if (!ok) {
313 return 1;
316 data = talloc(ev_ctx, struct lsasd_children_data);
317 if (!data) {
318 return 1;
320 data->pf = pf;
321 data->ev_ctx = ev_ctx;
322 data->msg_ctx = msg_ctx;
323 data->listen_fd_size = listen_fd_size;
324 data->listen_fds = listen_fds;
326 /* loop until it is time to exit */
327 while (pf->status != PF_WORKER_EXITING) {
328 /* try to see if it is time to schedule the next client */
329 lsasd_next_client(data);
331 ret = tevent_loop_once(ev_ctx);
332 if (ret != 0) {
333 DEBUG(0, ("tevent_loop_once() exited with %d: %s\n",
334 ret, strerror(errno)));
335 pf->status = PF_WORKER_EXITING;
339 return ret;
342 static void lsasd_client_terminated(void *pvt)
344 struct lsasd_children_data *data;
346 data = talloc_get_type_abort(pvt, struct lsasd_children_data);
348 pfh_client_terminated(data->pf);
350 lsasd_next_client(pvt);
353 struct lsasd_new_client {
354 struct lsasd_children_data *data;
357 static void lsasd_handle_client(struct tevent_req *req);
359 static void lsasd_next_client(void *pvt)
361 struct tevent_req *req;
362 struct lsasd_children_data *data;
363 struct lsasd_new_client *next;
365 data = talloc_get_type_abort(pvt, struct lsasd_children_data);
367 if (!pfh_child_allowed_to_accept(data->pf)) {
368 /* nothing to do for now we are already listening
369 * or we are not allowed to listen further */
370 return;
373 next = talloc_zero(data, struct lsasd_new_client);
374 if (!next) {
375 DEBUG(1, ("Out of memory!?\n"));
376 return;
378 next->data = data;
380 req = prefork_listen_send(next,
381 data->ev_ctx,
382 data->pf,
383 data->listen_fd_size,
384 data->listen_fds);
385 if (!req) {
386 DEBUG(1, ("Failed to make listening request!?\n"));
387 talloc_free(next);
388 return;
390 tevent_req_set_callback(req, lsasd_handle_client, next);
393 static void lsasd_handle_client(struct tevent_req *req)
395 struct lsasd_children_data *data;
396 struct lsasd_new_client *client;
397 int rc;
398 int sd;
399 TALLOC_CTX *tmp_ctx;
400 struct tsocket_address *srv_addr;
401 struct tsocket_address *cli_addr;
403 client = tevent_req_callback_data(req, struct lsasd_new_client);
404 data = client->data;
406 tmp_ctx = talloc_stackframe();
407 if (tmp_ctx == NULL) {
408 DEBUG(1, ("Failed to allocate stackframe!\n"));
409 return;
412 rc = prefork_listen_recv(req,
413 tmp_ctx,
414 &sd,
415 &srv_addr,
416 &cli_addr);
418 /* this will free the request too */
419 talloc_free(client);
421 if (rc != 0) {
422 DEBUG(6, ("No client connection was available after all!\n"));
423 goto done;
426 DEBUG(2, ("LSASD preforked child %d got client connection!\n",
427 (int)(data->pf->pid)));
429 if (tsocket_address_is_inet(srv_addr, "ip")) {
430 DEBUG(3, ("Got a tcpip client connection from %s on inteface %s\n",
431 tsocket_address_string(cli_addr, tmp_ctx),
432 tsocket_address_string(srv_addr, tmp_ctx)));
434 dcerpc_ncacn_accept(data->ev_ctx,
435 data->msg_ctx,
436 NCACN_IP_TCP,
437 "IP",
438 cli_addr,
439 srv_addr,
441 NULL);
442 } else if (tsocket_address_is_unix(srv_addr)) {
443 char *p;
445 p = tsocket_address_unix_path(srv_addr, tmp_ctx);
446 if (p == NULL) {
447 talloc_free(tmp_ctx);
448 return;
451 if (strstr(p, "/np/")) {
452 p = basename(p);
454 named_pipe_accept_function(data->ev_ctx,
455 data->msg_ctx,
458 lsasd_client_terminated,
459 data);
460 } else {
461 p = basename(p);
463 dcerpc_ncacn_accept(data->ev_ctx,
464 data->msg_ctx,
465 NCALRPC,
467 cli_addr,
468 srv_addr,
470 NULL);
472 } else {
473 DEBUG(0, ("ERROR: Unsupported socket!\n"));
476 done:
477 talloc_free(tmp_ctx);
481 * MAIN
484 static bool lsasd_schedule_check(struct tevent_context *ev_ctx,
485 struct messaging_context *msg_ctx,
486 struct timeval current_time);
488 static void lsasd_check_children(struct tevent_context *ev_ctx,
489 struct tevent_timer *te,
490 struct timeval current_time,
491 void *pvt);
493 static void lsasd_sigchld_handler(struct tevent_context *ev_ctx,
494 struct prefork_pool *pfp,
495 void *pvt)
497 struct messaging_context *msg_ctx;
499 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
501 /* run pool management so we can fork/retire or increase
502 * the allowed connections per child based on load */
503 pfh_manage_pool(ev_ctx, msg_ctx, &pf_lsasd_cfg, lsasd_pool);
506 static bool lsasd_setup_children_monitor(struct tevent_context *ev_ctx,
507 struct messaging_context *msg_ctx)
509 bool ok;
511 /* add our oun sigchld callback */
512 prefork_set_sigchld_callback(lsasd_pool, lsasd_sigchld_handler, msg_ctx);
514 ok = lsasd_schedule_check(ev_ctx, msg_ctx, tevent_timeval_current());
516 return ok;
519 static bool lsasd_schedule_check(struct tevent_context *ev_ctx,
520 struct messaging_context *msg_ctx,
521 struct timeval current_time)
523 struct tevent_timer *te;
524 struct timeval next_event;
526 /* check situation again in 10 seconds */
527 next_event = tevent_timeval_current_ofs(10, 0);
529 /* TODO: check when the socket becomes readable, so that children
530 * are checked only when there is some activity ? */
531 te = tevent_add_timer(ev_ctx, lsasd_pool, next_event,
532 lsasd_check_children, msg_ctx);
533 if (!te) {
534 DEBUG(2, ("Failed to set up children monitoring!\n"));
535 return false;
538 return true;
541 static void lsasd_check_children(struct tevent_context *ev_ctx,
542 struct tevent_timer *te,
543 struct timeval current_time,
544 void *pvt)
546 struct messaging_context *msg_ctx;
548 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
550 pfh_manage_pool(ev_ctx, msg_ctx, &pf_lsasd_cfg, lsasd_pool);
552 lsasd_schedule_check(ev_ctx, msg_ctx, current_time);
556 * start it up
559 static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
560 struct messaging_context *msg_ctx,
561 int *listen_fd,
562 int *listen_fd_size)
564 struct dcerpc_binding_vector *v, *v_orig;
565 TALLOC_CTX *tmp_ctx;
566 NTSTATUS status;
567 uint32_t i;
568 int fd;
569 int rc;
570 bool ok = true;
572 tmp_ctx = talloc_stackframe();
573 if (tmp_ctx == NULL) {
574 return false;
577 status = dcerpc_binding_vector_new(tmp_ctx, &v_orig);
578 if (!NT_STATUS_IS_OK(status)) {
579 ok = false;
580 goto done;
583 /* Create only one tcpip listener for all services */
584 status = rpc_create_tcpip_sockets(&ndr_table_lsarpc,
585 v_orig,
587 listen_fd,
588 listen_fd_size);
589 if (!NT_STATUS_IS_OK(status)) {
590 ok = false;
591 goto done;
594 /* Start to listen on tcpip sockets */
595 for (i = 0; i < *listen_fd_size; i++) {
596 rc = listen(listen_fd[i], pf_lsasd_cfg.max_allowed_clients);
597 if (rc == -1) {
598 DEBUG(0, ("Failed to listen on tcpip socket - %s\n",
599 strerror(errno)));
600 ok = false;
601 goto done;
605 /* LSARPC */
606 fd = create_named_pipe_socket("lsarpc");
607 if (fd < 0) {
608 ok = false;
609 goto done;
611 listen_fd[*listen_fd_size] = fd;
612 (*listen_fd_size)++;
614 rc = listen(fd, pf_lsasd_cfg.max_allowed_clients);
615 if (rc == -1) {
616 DEBUG(0, ("Failed to listen on lsarpc pipe - %s\n",
617 strerror(errno)));
618 ok = false;
619 goto done;
622 v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
623 if (v == NULL) {
624 ok = false;
625 goto done;
628 status = dcerpc_binding_vector_replace_iface(&ndr_table_lsarpc, v);
629 if (!NT_STATUS_IS_OK(status)) {
630 return false;
633 status = dcerpc_binding_vector_add_np_default(&ndr_table_lsarpc, v);
634 if (!NT_STATUS_IS_OK(status)) {
635 ok = false;
636 goto done;
639 status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_lsarpc, v);
640 if (!NT_STATUS_IS_OK(status)) {
641 ok = false;
642 goto done;
645 /* SAMR */
646 fd = create_named_pipe_socket("samr");
647 if (fd < 0) {
648 ok = false;
649 goto done;
652 rc = listen(fd, pf_lsasd_cfg.max_allowed_clients);
653 if (rc == -1) {
654 DEBUG(0, ("Failed to listen on samr pipe - %s\n",
655 strerror(errno)));
656 ok = false;
657 goto done;
659 listen_fd[*listen_fd_size] = fd;
660 (*listen_fd_size)++;
662 v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
663 if (v == NULL) {
664 ok = false;
665 goto done;
668 status = dcerpc_binding_vector_replace_iface(&ndr_table_samr, v);
669 if (!NT_STATUS_IS_OK(status)) {
670 return false;
673 status = dcerpc_binding_vector_add_np_default(&ndr_table_samr, v);
674 if (!NT_STATUS_IS_OK(status)) {
675 ok = false;
676 goto done;
679 status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_samr, v);
680 if (!NT_STATUS_IS_OK(status)) {
681 ok = false;
682 goto done;
685 /* NETLOGON */
686 fd = create_named_pipe_socket("netlogon");
687 if (fd < 0) {
688 ok = false;
689 goto done;
692 rc = listen(fd, pf_lsasd_cfg.max_allowed_clients);
693 if (rc == -1) {
694 DEBUG(0, ("Failed to listen on samr pipe - %s\n",
695 strerror(errno)));
696 ok = false;
697 goto done;
699 listen_fd[*listen_fd_size] = fd;
700 (*listen_fd_size)++;
702 v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
703 if (v == NULL) {
704 ok = false;
705 goto done;
708 status = dcerpc_binding_vector_replace_iface(&ndr_table_netlogon, v);
709 if (!NT_STATUS_IS_OK(status)) {
710 return false;
713 status = dcerpc_binding_vector_add_np_default(&ndr_table_netlogon, v);
714 if (!NT_STATUS_IS_OK(status)) {
715 ok = false;
716 goto done;
719 status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_netlogon, v);
720 if (!NT_STATUS_IS_OK(status)) {
721 ok = false;
722 goto done;
725 done:
726 talloc_free(tmp_ctx);
727 return ok;
730 void start_lsasd(struct tevent_context *ev_ctx,
731 struct messaging_context *msg_ctx)
733 NTSTATUS status;
734 int listen_fd[LSASD_MAX_SOCKETS];
735 int listen_fd_size = 0;
736 pid_t pid;
737 int rc;
738 bool ok;
740 DEBUG(1, ("Forking LSA Service Daemon\n"));
743 * Block signals before forking child as it will have to
744 * set its own handlers. Child will re-enable SIGHUP as
745 * soon as the handlers are set up.
747 BlockSignals(true, SIGTERM);
748 BlockSignals(true, SIGHUP);
750 pid = sys_fork();
751 if (pid == -1) {
752 DEBUG(0, ("Failed to fork LSASD [%s], aborting ...\n",
753 strerror(errno)));
754 exit(1);
757 /* parent or error */
758 if (pid != 0) {
760 /* Re-enable SIGHUP before returnig */
761 BlockSignals(false, SIGTERM);
762 BlockSignals(false, SIGHUP);
764 return;
767 /* child */
768 close_low_fds(false);
770 status = reinit_after_fork(msg_ctx,
771 ev_ctx,
772 procid_self(), true);
773 if (!NT_STATUS_IS_OK(status)) {
774 DEBUG(0,("reinit_after_fork() failed\n"));
775 smb_panic("reinit_after_fork() failed");
778 lsasd_reopen_logs(0);
779 pfh_daemon_config(DAEMON_NAME,
780 &pf_lsasd_cfg,
781 &default_pf_lsasd_cfg);
783 lsasd_setup_sig_term_handler(ev_ctx);
784 lsasd_setup_sig_hup_handler(ev_ctx);
786 BlockSignals(false, SIGTERM);
787 BlockSignals(false, SIGHUP);
789 ok = lsasd_create_sockets(ev_ctx, msg_ctx, listen_fd, &listen_fd_size);
790 if (!ok) {
791 exit(1);
794 /* start children before any more initialization is done */
795 ok = prefork_create_pool(ev_ctx, /* mem_ctx */
796 ev_ctx,
797 msg_ctx,
798 listen_fd_size,
799 listen_fd,
800 pf_lsasd_cfg.min_children,
801 pf_lsasd_cfg.max_children,
802 &lsasd_children_main,
803 NULL,
804 &lsasd_pool);
805 if (!ok) {
806 exit(1);
809 if (!serverid_register(procid_self(), FLAG_MSG_GENERAL)) {
810 exit(1);
813 messaging_register(msg_ctx,
814 ev_ctx,
815 MSG_SMB_CONF_UPDATED,
816 lsasd_smb_conf_updated);
818 status = rpc_lsarpc_init(NULL);
819 if (!NT_STATUS_IS_OK(status)) {
820 DEBUG(0, ("Failed to register winreg rpc inteface! (%s)\n",
821 nt_errstr(status)));
822 exit(1);
825 status = rpc_samr_init(NULL);
826 if (!NT_STATUS_IS_OK(status)) {
827 DEBUG(0, ("Failed to register lsasd rpc inteface! (%s)\n",
828 nt_errstr(status)));
829 exit(1);
832 status = rpc_netlogon_init(NULL);
833 if (!NT_STATUS_IS_OK(status)) {
834 DEBUG(0, ("Failed to register lsasd rpc inteface! (%s)\n",
835 nt_errstr(status)));
836 exit(1);
839 ok = lsasd_setup_children_monitor(ev_ctx, msg_ctx);
840 if (!ok) {
841 DEBUG(0, ("Failed to setup children monitoring!\n"));
842 exit(1);
845 DEBUG(1, ("LSASD Daemon Started (%d)\n", getpid()));
847 /* loop forever */
848 rc = tevent_loop_wait(ev_ctx);
850 /* should not be reached */
851 DEBUG(0,("lsasd: tevent_loop_wait() exited with %d - %s\n",
852 rc, (rc == 0) ? "out of events" : strerror(errno)));
853 exit(1);