Lines Matching +full:remote +full:- +full:pid

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2009-2010 The FreeBSD Foundation
5 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
82 errx(EX_USAGE, "[-dFh] [-c config] [-P pidfile]"); in usage()
89 if (modfind("g_gate") == -1) { in g_gate_load()
91 if (kldload("geom_gate") == -1 || modfind("g_gate") == -1) { in g_gate_load()
106 TAILQ_FOREACH_SAFE(tres, &cfg->hc_resources, hr_next, tmres) { in descriptors_cleanup()
108 PJDLOG_VERIFY(res->hr_role == HAST_ROLE_SECONDARY || in descriptors_cleanup()
109 (res->hr_remotein == NULL && in descriptors_cleanup()
110 res->hr_remoteout == NULL)); in descriptors_cleanup()
113 if (tres->hr_remotein != NULL) in descriptors_cleanup()
114 proto_close(tres->hr_remotein); in descriptors_cleanup()
115 if (tres->hr_remoteout != NULL) in descriptors_cleanup()
116 proto_close(tres->hr_remoteout); in descriptors_cleanup()
117 if (tres->hr_ctrl != NULL) in descriptors_cleanup()
118 proto_close(tres->hr_ctrl); in descriptors_cleanup()
119 if (tres->hr_event != NULL) in descriptors_cleanup()
120 proto_close(tres->hr_event); in descriptors_cleanup()
121 if (tres->hr_conn != NULL) in descriptors_cleanup()
122 proto_close(tres->hr_conn); in descriptors_cleanup()
123 TAILQ_REMOVE(&cfg->hc_resources, tres, hr_next); in descriptors_cleanup()
126 if (cfg->hc_controlin != NULL) in descriptors_cleanup()
127 proto_close(cfg->hc_controlin); in descriptors_cleanup()
128 proto_close(cfg->hc_controlconn); in descriptors_cleanup()
129 while ((lst = TAILQ_FIRST(&cfg->hc_listen)) != NULL) { in descriptors_cleanup()
130 TAILQ_REMOVE(&cfg->hc_listen, lst, hl_next); in descriptors_cleanup()
131 if (lst->hl_conn != NULL) in descriptors_cleanup()
132 proto_close(lst->hl_conn); in descriptors_cleanup()
182 if (maxfd == -1) { in descriptors_assert()
184 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, in descriptors_assert()
185 role2str(res->hr_role)); in descriptors_assert()
212 } else if (fd == proto_descriptor(res->hr_event)) { in descriptors_assert()
225 } else if (fd == proto_descriptor(res->hr_ctrl)) { in descriptors_assert()
238 } else if (res->hr_role == HAST_ROLE_PRIMARY && in descriptors_assert()
239 fd == proto_descriptor(res->hr_conn)) { in descriptors_assert()
252 } else if (res->hr_role == HAST_ROLE_SECONDARY && in descriptors_assert()
253 res->hr_conn != NULL && in descriptors_assert()
254 fd == proto_descriptor(res->hr_conn)) { in descriptors_assert()
261 } else if (res->hr_role == HAST_ROLE_SECONDARY && in descriptors_assert()
262 fd == proto_descriptor(res->hr_remotein)) { in descriptors_assert()
265 "Descriptor %d (remote in) is closed, but should be open.", in descriptors_assert()
271 "Descriptor %d (remote in) is %s, but should be %s.", in descriptors_assert()
275 } else if (res->hr_role == HAST_ROLE_SECONDARY && in descriptors_assert()
276 fd == proto_descriptor(res->hr_remoteout)) { in descriptors_assert()
279 "Descriptor %d (remote out) is closed, but should be open.", in descriptors_assert()
285 "Descriptor %d (remote out) is %s, but should be %s.", in descriptors_assert()
300 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, in descriptors_assert()
301 role2str(res->hr_role)); in descriptors_assert()
307 child_exit_log(unsigned int pid, int status) in child_exit_log() argument
311 pjdlog_debug(1, "Worker process exited gracefully (pid=%u).", in child_exit_log()
312 pid); in child_exit_log()
314 pjdlog_error("Worker process killed (pid=%u, signal=%d).", in child_exit_log()
315 pid, WTERMSIG(status)); in child_exit_log()
317 pjdlog_error("Worker process exited ungracefully (pid=%u, exitcode=%d).", in child_exit_log()
318 pid, WIFEXITED(status) ? WEXITSTATUS(status) : -1); in child_exit_log()
327 pid_t pid; in child_exit() local
329 while ((pid = wait3(&status, WNOHANG, NULL)) > 0) { in child_exit()
331 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { in child_exit()
332 if (pid == res->hr_workerpid) in child_exit()
341 hook_check_one(pid, status); in child_exit()
344 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, in child_exit()
345 role2str(res->hr_role)); in child_exit()
346 child_exit_log(pid, status); in child_exit()
348 if (res->hr_role == HAST_ROLE_PRIMARY) { in child_exit()
360 res->hr_role = HAST_ROLE_INIT; in child_exit()
362 role2str(res->hr_role)); in child_exit()
374 PJDLOG_ASSERT(strcmp(res0->hr_name, res1->hr_name) == 0); in resource_needs_restart()
376 if (strcmp(res0->hr_provname, res1->hr_provname) != 0) in resource_needs_restart()
378 if (strcmp(res0->hr_localpath, res1->hr_localpath) != 0) in resource_needs_restart()
380 if (res0->hr_role == HAST_ROLE_INIT || in resource_needs_restart()
381 res0->hr_role == HAST_ROLE_SECONDARY) { in resource_needs_restart()
382 if (strcmp(res0->hr_remoteaddr, res1->hr_remoteaddr) != 0) in resource_needs_restart()
384 if (strcmp(res0->hr_sourceaddr, res1->hr_sourceaddr) != 0) in resource_needs_restart()
386 if (res0->hr_replication != res1->hr_replication) in resource_needs_restart()
388 if (res0->hr_checksum != res1->hr_checksum) in resource_needs_restart()
390 if (res0->hr_compression != res1->hr_compression) in resource_needs_restart()
392 if (res0->hr_timeout != res1->hr_timeout) in resource_needs_restart()
394 if (strcmp(res0->hr_exec, res1->hr_exec) != 0) in resource_needs_restart()
400 if (res0->hr_metaflush != res1->hr_metaflush) in resource_needs_restart()
411 PJDLOG_ASSERT(strcmp(res0->hr_name, res1->hr_name) == 0); in resource_needs_reload()
412 PJDLOG_ASSERT(strcmp(res0->hr_provname, res1->hr_provname) == 0); in resource_needs_reload()
413 PJDLOG_ASSERT(strcmp(res0->hr_localpath, res1->hr_localpath) == 0); in resource_needs_reload()
415 if (res0->hr_role != HAST_ROLE_PRIMARY) in resource_needs_reload()
418 if (strcmp(res0->hr_remoteaddr, res1->hr_remoteaddr) != 0) in resource_needs_reload()
420 if (strcmp(res0->hr_sourceaddr, res1->hr_sourceaddr) != 0) in resource_needs_reload()
422 if (res0->hr_replication != res1->hr_replication) in resource_needs_reload()
424 if (res0->hr_checksum != res1->hr_checksum) in resource_needs_reload()
426 if (res0->hr_compression != res1->hr_compression) in resource_needs_reload()
428 if (res0->hr_timeout != res1->hr_timeout) in resource_needs_reload()
430 if (strcmp(res0->hr_exec, res1->hr_exec) != 0) in resource_needs_reload()
432 if (res0->hr_metaflush != res1->hr_metaflush) in resource_needs_reload()
443 PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY); in resource_reload()
447 nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr"); in resource_reload()
448 nv_add_string(nvout, res->hr_sourceaddr, "sourceaddr"); in resource_reload()
449 nv_add_int32(nvout, (int32_t)res->hr_replication, "replication"); in resource_reload()
450 nv_add_int32(nvout, (int32_t)res->hr_checksum, "checksum"); in resource_reload()
451 nv_add_int32(nvout, (int32_t)res->hr_compression, "compression"); in resource_reload()
452 nv_add_int32(nvout, (int32_t)res->hr_timeout, "timeout"); in resource_reload()
453 nv_add_string(nvout, res->hr_exec, "exec"); in resource_reload()
454 nv_add_int32(nvout, (int32_t)res->hr_metaflush, "metaflush"); in resource_reload()
460 if (hast_proto_send(res, res->hr_ctrl, nvout, NULL, 0) == -1) { in resource_reload()
468 if (hast_proto_recv_hdr(res->hr_ctrl, &nvin) == -1) { in resource_reload()
502 if (strcmp(cfg->hc_controladdr, newcfg->hc_controladdr) != 0) { in hastd_reload()
503 if (proto_server(newcfg->hc_controladdr, in hastd_reload()
504 &newcfg->hc_controlconn) == -1) { in hastd_reload()
507 newcfg->hc_controladdr); in hastd_reload()
515 TAILQ_FOREACH(nlst, &newcfg->hc_listen, hl_next) { in hastd_reload()
516 TAILQ_FOREACH(clst, &cfg->hc_listen, hl_next) { in hastd_reload()
517 if (strcmp(nlst->hl_addr, clst->hl_addr) == 0) in hastd_reload()
520 if (clst != NULL && clst->hl_conn != NULL) { in hastd_reload()
522 nlst->hl_addr); in hastd_reload()
523 nlst->hl_conn = clst->hl_conn; in hastd_reload()
525 } else if (proto_server(nlst->hl_addr, &nlst->hl_conn) == 0) { in hastd_reload()
527 nlst->hl_addr); in hastd_reload()
531 "Unable to listen on address %s", nlst->hl_addr); in hastd_reload()
542 strcmp(cfg->hc_pidfile, newcfg->hc_pidfile) != 0) { in hastd_reload()
543 newpfh = pidfile_open(newcfg->hc_pidfile, 0600, &otherpid); in hastd_reload()
547 "Another hastd is already running, pidfile: %s, pid: %jd.", in hastd_reload()
548 newcfg->hc_pidfile, (intmax_t)otherpid); in hastd_reload()
552 newcfg->hc_pidfile); in hastd_reload()
554 } else if (pidfile_write(newpfh) == -1) { in hastd_reload()
555 /* Write PID to a file. */ in hastd_reload()
557 "Unable to write PID to file %s", in hastd_reload()
558 newcfg->hc_pidfile); in hastd_reload()
560 pjdlog_debug(1, "PID stored in %s.", in hastd_reload()
561 newcfg->hc_pidfile); in hastd_reload()
570 if (newcfg->hc_controlconn != NULL) { in hastd_reload()
572 cfg->hc_controladdr, newcfg->hc_controladdr); in hastd_reload()
573 proto_close(cfg->hc_controlconn); in hastd_reload()
574 cfg->hc_controlconn = newcfg->hc_controlconn; in hastd_reload()
575 newcfg->hc_controlconn = NULL; in hastd_reload()
576 strlcpy(cfg->hc_controladdr, newcfg->hc_controladdr, in hastd_reload()
577 sizeof(cfg->hc_controladdr)); in hastd_reload()
583 pjdlog_info("Pidfile changed from %s to %s.", cfg->hc_pidfile, in hastd_reload()
584 newcfg->hc_pidfile); in hastd_reload()
587 (void)strlcpy(cfg->hc_pidfile, newcfg->hc_pidfile, in hastd_reload()
588 sizeof(cfg->hc_pidfile)); in hastd_reload()
593 while ((clst = TAILQ_FIRST(&cfg->hc_listen)) != NULL) { in hastd_reload()
594 TAILQ_FOREACH(nlst, &newcfg->hc_listen, hl_next) { in hastd_reload()
595 if (strcmp(nlst->hl_addr, clst->hl_addr) == 0) in hastd_reload()
598 if (nlst == NULL && clst->hl_conn != NULL) { in hastd_reload()
599 proto_close(clst->hl_conn); in hastd_reload()
601 clst->hl_addr); in hastd_reload()
603 TAILQ_REMOVE(&cfg->hc_listen, clst, hl_next); in hastd_reload()
606 TAILQ_CONCAT(&cfg->hc_listen, &newcfg->hc_listen, hl_next); in hastd_reload()
611 TAILQ_FOREACH_SAFE(cres, &cfg->hc_resources, hr_next, tres) { in hastd_reload()
612 TAILQ_FOREACH(nres, &newcfg->hc_resources, hr_next) { in hastd_reload()
613 if (strcmp(cres->hr_name, nres->hr_name) == 0) in hastd_reload()
618 TAILQ_REMOVE(&cfg->hc_resources, cres, hr_next); in hastd_reload()
619 pjdlog_info("Resource %s removed.", cres->hr_name); in hastd_reload()
626 TAILQ_FOREACH_SAFE(nres, &newcfg->hc_resources, hr_next, tres) { in hastd_reload()
627 TAILQ_FOREACH(cres, &cfg->hc_resources, hr_next) { in hastd_reload()
628 if (strcmp(cres->hr_name, nres->hr_name) == 0) in hastd_reload()
632 TAILQ_REMOVE(&newcfg->hc_resources, nres, hr_next); in hastd_reload()
633 TAILQ_INSERT_TAIL(&cfg->hc_resources, nres, hr_next); in hastd_reload()
634 pjdlog_info("Resource %s added.", nres->hr_name); in hastd_reload()
651 * PRIMARY, but only if remote address, source address, replication in hastd_reload()
654 * If PRIMARY receives SIGHUP, it will reconnect if remote address or in hastd_reload()
659 TAILQ_FOREACH_SAFE(nres, &newcfg->hc_resources, hr_next, tres) { in hastd_reload()
660 TAILQ_FOREACH(cres, &cfg->hc_resources, hr_next) { in hastd_reload()
661 if (strcmp(cres->hr_name, nres->hr_name) == 0) in hastd_reload()
667 cres->hr_name); in hastd_reload()
668 role = cres->hr_role; in hastd_reload()
670 TAILQ_REMOVE(&cfg->hc_resources, cres, hr_next); in hastd_reload()
672 TAILQ_REMOVE(&newcfg->hc_resources, nres, hr_next); in hastd_reload()
673 TAILQ_INSERT_TAIL(&cfg->hc_resources, nres, hr_next); in hastd_reload()
677 cres->hr_name); in hastd_reload()
678 strlcpy(cres->hr_remoteaddr, nres->hr_remoteaddr, in hastd_reload()
679 sizeof(cres->hr_remoteaddr)); in hastd_reload()
680 strlcpy(cres->hr_sourceaddr, nres->hr_sourceaddr, in hastd_reload()
681 sizeof(cres->hr_sourceaddr)); in hastd_reload()
682 cres->hr_replication = nres->hr_replication; in hastd_reload()
683 cres->hr_checksum = nres->hr_checksum; in hastd_reload()
684 cres->hr_compression = nres->hr_compression; in hastd_reload()
685 cres->hr_timeout = nres->hr_timeout; in hastd_reload()
686 strlcpy(cres->hr_exec, nres->hr_exec, in hastd_reload()
687 sizeof(cres->hr_exec)); in hastd_reload()
688 cres->hr_metaflush = nres->hr_metaflush; in hastd_reload()
689 if (cres->hr_workerpid != 0) in hastd_reload()
699 if (newcfg->hc_controlconn != NULL) in hastd_reload()
700 proto_close(newcfg->hc_controlconn); in hastd_reload()
701 while ((nlst = TAILQ_FIRST(&newcfg->hc_listen)) != NULL) { in hastd_reload()
702 if (nlst->hl_conn != NULL) { in hastd_reload()
703 TAILQ_FOREACH(clst, &cfg->hc_listen, hl_next) { in hastd_reload()
704 if (strcmp(nlst->hl_addr, in hastd_reload()
705 clst->hl_addr) == 0) { in hastd_reload()
709 if (clst == NULL || clst->hl_conn == NULL) in hastd_reload()
710 proto_close(nlst->hl_conn); in hastd_reload()
712 TAILQ_REMOVE(&newcfg->hc_listen, nlst, hl_next); in hastd_reload()
728 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { in terminate_workers()
729 if (res->hr_workerpid == 0) in terminate_workers()
731 pjdlog_info("Terminating worker process (resource=%s, role=%s, pid=%u).", in terminate_workers()
732 res->hr_name, role2str(res->hr_role), res->hr_workerpid); in terminate_workers()
733 if (kill(res->hr_workerpid, SIGTERM) == 0) in terminate_workers()
736 "Unable to send signal to worker process (resource=%s, role=%s, pid=%u).", in terminate_workers()
737 res->hr_name, role2str(res->hr_role), res->hr_workerpid); in terminate_workers()
752 pid_t pid; in listen_accept() local
755 proto_local_address(lst->hl_conn, laddr, sizeof(laddr)); in listen_accept()
758 if (proto_accept(lst->hl_conn, &conn) == -1) { in listen_accept()
768 if (proto_timeout(conn, HAST_TIMEOUT) == -1) in listen_accept()
774 * Before receiving any data see if remote host have access to any in listen_accept()
777 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { in listen_accept()
778 if (proto_address_match(conn, res->hr_remoteaddr)) in listen_accept()
785 /* Ok, remote host can access at least one resource. */ in listen_accept()
787 if (hast_proto_recv_hdr(conn, &nvin) == -1) { in listen_accept()
812 if (token != NULL && size != sizeof(res->hr_token)) { in listen_accept()
814 raddr, sizeof(res->hr_token), size); in listen_accept()
819 * From now on we want to send errors to the remote node. in listen_accept()
824 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { in listen_accept()
825 if (strcmp(resname, res->hr_name) == 0) in listen_accept()
837 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role)); in listen_accept()
839 /* Does the remote host have access to this resource? */ in listen_accept()
840 if (!proto_address_match(conn, res->hr_remoteaddr)) { in listen_accept()
846 if (res->hr_role != HAST_ROLE_SECONDARY) { in listen_accept()
848 role2str(res->hr_role), role2str(HAST_ROLE_SECONDARY), in listen_accept()
851 "Remote node acts as %s for the resource and not as %s.", in listen_accept()
852 role2str(res->hr_role), role2str(HAST_ROLE_SECONDARY)); in listen_accept()
853 if (res->hr_role == HAST_ROLE_PRIMARY) { in listen_accept()
863 if (token != NULL && memcmp(token, res->hr_token, in listen_accept()
864 sizeof(res->hr_token)) != 0) { in listen_accept()
870 * If there is no token, but we have half-open connection in listen_accept()
875 PJDLOG_ASSERT(res->hr_remoteout == NULL); in listen_accept()
877 if (res->hr_workerpid != 0) { in listen_accept()
878 PJDLOG_ASSERT(res->hr_remotein == NULL); in listen_accept()
880 "Worker process exists (pid=%u), stopping it.", in listen_accept()
881 (unsigned int)res->hr_workerpid); in listen_accept()
883 if (kill(res->hr_workerpid, SIGINT) == -1) { in listen_accept()
885 "Unable to stop worker process (pid=%u)", in listen_accept()
886 (unsigned int)res->hr_workerpid); in listen_accept()
889 * ignore it - nothing smart to do. in listen_accept()
893 else if ((pid = waitpid(res->hr_workerpid, in listen_accept()
894 &status, 0)) != res->hr_workerpid) { in listen_accept()
897 "Waiting for worker process (pid=%u) failed", in listen_accept()
898 (unsigned int)res->hr_workerpid); in listen_accept()
900 child_exit_log(res->hr_workerpid, status); in listen_accept()
903 } else if (res->hr_remotein != NULL) { in listen_accept()
906 proto_remote_address(res->hr_remotein, oaddr, in listen_accept()
909 "Canceling half-open connection from %s on connection from %s.", in listen_accept()
911 proto_close(res->hr_remotein); in listen_accept()
912 res->hr_remotein = NULL; in listen_accept()
922 pjdlog_info("Remote protocol version %hhu is not supported, falling back to version %hhu.", in listen_accept()
927 res->hr_version = version; in listen_accept()
928 arc4random_buf(res->hr_token, sizeof(res->hr_token)); in listen_accept()
931 nv_add_uint8_array(nvout, res->hr_token, in listen_accept()
932 sizeof(res->hr_token), "token"); in listen_accept()
937 "Remote node was unable to prepare return header: %s.", in listen_accept()
941 if (hast_proto_send(res, conn, nvout, NULL, 0) == -1) { in listen_accept()
947 "Remote node was unable to send response: %s.", in listen_accept()
951 res->hr_remotein = conn; in listen_accept()
955 res->hr_remoteout = conn; in listen_accept()
970 if (hast_proto_send(NULL, conn, nverr, NULL, 0) == -1) { in listen_accept()
991 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role)); in connection_migrate()
993 PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY); in connection_migrate()
995 if (proto_recv(res->hr_conn, &val, sizeof(val)) == -1) { in connection_migrate()
1000 if (proto_client(res->hr_sourceaddr[0] != '\0' ? res->hr_sourceaddr : NULL, in connection_migrate()
1001 res->hr_remoteaddr, &conn) == -1) { in connection_migrate()
1005 res->hr_remoteaddr); in connection_migrate()
1008 if (proto_connect(conn, -1) == -1) { in connection_migrate()
1011 res->hr_remoteaddr); in connection_migrate()
1017 if (proto_send(res->hr_conn, &val, sizeof(val)) == -1) { in connection_migrate()
1021 if (val == 0 && proto_connection_send(res->hr_conn, conn) == -1) in connection_migrate()
1043 while ((signo = sigtimedwait(&mask, NULL, &sigtimeout)) != -1) { in check_signals()
1049 proto_close(cfg->hc_controlconn); in check_signals()
1083 maxfd = fd = proto_descriptor(cfg->hc_controlconn); in main_loop()
1086 TAILQ_FOREACH(lst, &cfg->hc_listen, hl_next) { in main_loop()
1087 if (lst->hl_conn == NULL) in main_loop()
1089 fd = proto_descriptor(lst->hl_conn); in main_loop()
1094 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { in main_loop()
1095 if (res->hr_event == NULL) in main_loop()
1097 fd = proto_descriptor(res->hr_event); in main_loop()
1101 if (res->hr_role == HAST_ROLE_PRIMARY) { in main_loop()
1103 PJDLOG_ASSERT(res->hr_conn != NULL); in main_loop()
1104 fd = proto_descriptor(res->hr_conn); in main_loop()
1109 PJDLOG_ASSERT(res->hr_conn == NULL); in main_loop()
1126 } else if (ret == -1) { in main_loop()
1139 if (FD_ISSET(proto_descriptor(cfg->hc_controlconn), &rfds)) in main_loop()
1141 TAILQ_FOREACH(lst, &cfg->hc_listen, hl_next) { in main_loop()
1142 if (lst->hl_conn == NULL) in main_loop()
1144 if (FD_ISSET(proto_descriptor(lst->hl_conn), &rfds)) in main_loop()
1147 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { in main_loop()
1148 if (res->hr_event == NULL) in main_loop()
1150 if (FD_ISSET(proto_descriptor(res->hr_event), &rfds)) { in main_loop()
1154 proto_close(res->hr_event); in main_loop()
1155 res->hr_event = NULL; in main_loop()
1156 if (res->hr_conn != NULL) { in main_loop()
1157 proto_close(res->hr_conn); in main_loop()
1158 res->hr_conn = NULL; in main_loop()
1162 if (res->hr_role == HAST_ROLE_PRIMARY) { in main_loop()
1163 PJDLOG_ASSERT(res->hr_conn != NULL); in main_loop()
1164 if (FD_ISSET(proto_descriptor(res->hr_conn), in main_loop()
1169 PJDLOG_ASSERT(res->hr_conn == NULL); in main_loop()
1196 if (ch == -1) in main()
1216 argc -= optind; in main()
1245 if (strlcpy(cfg->hc_pidfile, pidfile, in main()
1246 sizeof(cfg->hc_pidfile)) >= sizeof(cfg->hc_pidfile)) { in main()
1252 pfh = pidfile_open(cfg->hc_pidfile, 0600, &otherpid); in main()
1256 "Another hastd is already running, pidfile: %s, pid: %jd.", in main()
1257 cfg->hc_pidfile, (intmax_t)otherpid); in main()
1265 cfg->hc_pidfile); in main()
1290 if (proto_server(cfg->hc_controladdr, &cfg->hc_controlconn) == -1) { in main()
1293 cfg->hc_controladdr); in main()
1295 /* Listen for remote connections. */ in main()
1296 TAILQ_FOREACH(lst, &cfg->hc_listen, hl_next) { in main()
1297 if (proto_server(lst->hl_addr, &lst->hl_conn) == -1) { in main()
1300 lst->hl_addr); in main()
1305 if (daemon(0, 0) == -1) { in main()
1314 /* Write PID to a file. */ in main()
1315 if (pidfile_write(pfh) == -1) { in main()
1317 "Unable to write PID to a file %s", in main()
1318 cfg->hc_pidfile); in main()
1320 pjdlog_debug(1, "PID stored in %s.", cfg->hc_pidfile); in main()
1328 cfg->hc_controladdr); in main()
1329 TAILQ_FOREACH(lst, &cfg->hc_listen, hl_next) in main()
1330 pjdlog_info("Listening on address %s.", lst->hl_addr); in main()