2 * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static krb5_log_facility
*log_facility
;
39 const char *slave_stats_file
;
40 const char *slave_time_missing
= "2 min";
41 const char *slave_time_gone
= "5 min";
43 static int time_before_missing
;
44 static int time_before_gone
;
46 const char *master_hostname
;
49 make_signal_socket (krb5_context context
)
51 #ifndef NO_UNIX_SOCKETS
52 struct sockaddr_un addr
;
56 fn
= kadm5_log_signal_socket(context
);
58 fd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
60 krb5_err (context
, 1, errno
, "socket AF_UNIX");
61 memset (&addr
, 0, sizeof(addr
));
62 addr
.sun_family
= AF_UNIX
;
63 strlcpy (addr
.sun_path
, fn
, sizeof(addr
.sun_path
));
64 unlink (addr
.sun_path
);
65 if (bind (fd
, (struct sockaddr
*)&addr
, sizeof(addr
)) < 0)
66 krb5_err (context
, 1, errno
, "bind %s", addr
.sun_path
);
69 struct addrinfo
*ai
= NULL
;
72 kadm5_log_signal_socket_info(context
, 1, &ai
);
74 fd
= socket(ai
->ai_family
, ai
->ai_socktype
, ai
->ai_protocol
);
75 if (rk_IS_BAD_SOCKET(fd
))
76 krb5_err (context
, 1, rk_SOCK_ERRNO
, "socket AF=%d", ai
->ai_family
);
78 if (rk_IS_SOCKET_ERROR( bind (fd
, ai
->ai_addr
, ai
->ai_addrlen
) ))
79 krb5_err (context
, 1, rk_SOCK_ERRNO
, "bind");
85 make_listen_socket (krb5_context context
, const char *port_str
)
89 struct sockaddr_in addr
;
91 fd
= socket (AF_INET
, SOCK_STREAM
, 0);
92 if (rk_IS_BAD_SOCKET(fd
))
93 krb5_err (context
, 1, rk_SOCK_ERRNO
, "socket AF_INET");
94 setsockopt (fd
, SOL_SOCKET
, SO_REUSEADDR
, (void *)&one
, sizeof(one
));
95 memset (&addr
, 0, sizeof(addr
));
96 addr
.sin_family
= AF_INET
;
99 addr
.sin_port
= krb5_getportbyname (context
,
102 if (addr
.sin_port
== 0) {
106 port
= strtol (port_str
, &ptr
, 10);
107 if (port
== 0 && ptr
== port_str
)
108 krb5_errx (context
, 1, "bad port `%s'", port_str
);
109 addr
.sin_port
= htons(port
);
112 addr
.sin_port
= krb5_getportbyname (context
, IPROP_SERVICE
,
115 if(bind(fd
, (struct sockaddr
*)&addr
, sizeof(addr
)) < 0)
116 krb5_err (context
, 1, errno
, "bind");
117 if (listen(fd
, SOMAXCONN
) < 0)
118 krb5_err (context
, 1, errno
, "listen");
124 struct sockaddr_in addr
;
126 krb5_auth_context ac
;
130 #define SLAVE_F_DEAD 0x1
131 #define SLAVE_F_AYT 0x2
135 typedef struct slave slave
;
138 check_acl (krb5_context context
, const char *name
)
146 asprintf(&slavefile
, "%s/slaves", hdb_db_dir(context
));
148 fn
= krb5_config_get_string_default(context
,
155 fp
= fopen (fn
, "r");
159 while (fgets(buf
, sizeof(buf
), fp
) != NULL
) {
160 buf
[strcspn(buf
, "\r\n")] = '\0';
161 if (strcmp (buf
, name
) == 0) {
173 s
->flags
&= ~SLAVE_F_AYT
;
174 s
->seen
= time(NULL
);
178 slave_missing_p (slave
*s
)
180 if (time(NULL
) > s
->seen
+ time_before_missing
)
186 slave_gone_p (slave
*s
)
188 if (time(NULL
) > s
->seen
+ time_before_gone
)
194 slave_dead(krb5_context context
, slave
*s
)
196 krb5_warnx(context
, "slave %s dead", s
->name
);
198 if (!rk_IS_BAD_SOCKET(s
->fd
)) {
199 rk_closesocket (s
->fd
);
200 s
->fd
= rk_INVALID_SOCKET
;
202 s
->flags
|= SLAVE_F_DEAD
;
207 remove_slave (krb5_context context
, slave
*s
, slave
**root
)
211 if (!rk_IS_BAD_SOCKET(s
->fd
))
212 rk_closesocket (s
->fd
);
216 krb5_auth_con_free (context
, s
->ac
);
218 for (p
= root
; *p
; p
= &(*p
)->next
)
227 add_slave (krb5_context context
, krb5_keytab keytab
, slave
**root
,
230 krb5_principal server
;
234 krb5_ticket
*ticket
= NULL
;
237 s
= malloc(sizeof(*s
));
239 krb5_warnx (context
, "add_slave: no memory");
245 addr_len
= sizeof(s
->addr
);
246 s
->fd
= accept (fd
, (struct sockaddr
*)&s
->addr
, &addr_len
);
247 if (rk_IS_BAD_SOCKET(s
->fd
)) {
248 krb5_warn (context
, rk_SOCK_ERRNO
, "accept");
252 strlcpy(hostname
, master_hostname
, sizeof(hostname
));
254 gethostname(hostname
, sizeof(hostname
));
256 ret
= krb5_sname_to_principal (context
, hostname
, IPROP_NAME
,
257 KRB5_NT_SRV_HST
, &server
);
259 krb5_warn (context
, ret
, "krb5_sname_to_principal");
263 ret
= krb5_recvauth (context
, &s
->ac
, &s
->fd
,
264 IPROP_VERSION
, server
, 0, keytab
, &ticket
);
265 krb5_free_principal (context
, server
);
267 krb5_warn (context
, ret
, "krb5_recvauth");
270 ret
= krb5_unparse_name (context
, ticket
->client
, &s
->name
);
271 krb5_free_ticket (context
, ticket
);
273 krb5_warn (context
, ret
, "krb5_unparse_name");
276 if (check_acl (context
, s
->name
)) {
277 krb5_warnx (context
, "%s not in acl", s
->name
);
285 if (strcmp(l
->name
, s
->name
) == 0)
290 if (l
->flags
& SLAVE_F_DEAD
) {
291 remove_slave(context
, l
, root
);
293 krb5_warnx (context
, "second connection from %s", s
->name
);
299 krb5_warnx (context
, "connection from %s", s
->name
);
308 remove_slave(context
, s
, root
);
311 struct prop_context
{
312 krb5_auth_context auth_context
;
317 prop_one (krb5_context context
, HDB
*db
, hdb_entry_ex
*entry
, void *v
)
322 struct slave
*s
= (struct slave
*)v
;
324 ret
= hdb_entry2value (context
, &entry
->entry
, &data
);
327 ret
= krb5_data_realloc (&data
, data
.length
+ 4);
329 krb5_data_free (&data
);
332 memmove ((char *)data
.data
+ 4, data
.data
, data
.length
- 4);
333 sp
= krb5_storage_from_data(&data
);
335 krb5_data_free (&data
);
338 krb5_store_int32(sp
, ONE_PRINC
);
339 krb5_storage_free(sp
);
341 ret
= krb5_write_priv_message (context
, s
->ac
, &s
->fd
, &data
);
342 krb5_data_free (&data
);
347 send_complete (krb5_context context
, slave
*s
,
348 const char *database
, uint32_t current_version
)
356 ret
= hdb_create (context
, &db
, database
);
358 krb5_err (context
, 1, ret
, "hdb_create: %s", database
);
359 ret
= db
->hdb_open (context
, db
, O_RDONLY
, 0);
361 krb5_err (context
, 1, ret
, "db->open");
363 sp
= krb5_storage_from_mem (buf
, 4);
365 krb5_errx (context
, 1, "krb5_storage_from_mem");
366 krb5_store_int32 (sp
, TELL_YOU_EVERYTHING
);
367 krb5_storage_free (sp
);
372 ret
= krb5_write_priv_message(context
, s
->ac
, &s
->fd
, &data
);
375 krb5_warn (context
, ret
, "krb5_write_priv_message");
376 slave_dead(context
, s
);
380 ret
= hdb_foreach (context
, db
, HDB_F_ADMIN_DATA
, prop_one
, s
);
382 krb5_warn (context
, ret
, "hdb_foreach");
383 slave_dead(context
, s
);
387 (*db
->hdb_close
)(context
, db
);
388 (*db
->hdb_destroy
)(context
, db
);
390 sp
= krb5_storage_from_mem (buf
, 8);
392 krb5_errx (context
, 1, "krb5_storage_from_mem");
393 krb5_store_int32 (sp
, NOW_YOU_HAVE
);
394 krb5_store_int32 (sp
, current_version
);
395 krb5_storage_free (sp
);
399 s
->version
= current_version
;
401 ret
= krb5_write_priv_message(context
, s
->ac
, &s
->fd
, &data
);
403 slave_dead(context
, s
);
404 krb5_warn (context
, ret
, "krb5_write_priv_message");
414 send_are_you_there (krb5_context context
, slave
*s
)
421 if (s
->flags
& (SLAVE_F_DEAD
|SLAVE_F_AYT
))
424 krb5_warnx(context
, "slave %s missing, sending AYT", s
->name
);
426 s
->flags
|= SLAVE_F_AYT
;
431 sp
= krb5_storage_from_mem (buf
, 4);
433 krb5_warnx (context
, "are_you_there: krb5_data_alloc");
434 slave_dead(context
, s
);
437 krb5_store_int32 (sp
, ARE_YOU_THERE
);
438 krb5_storage_free (sp
);
440 ret
= krb5_write_priv_message(context
, s
->ac
, &s
->fd
, &data
);
443 krb5_warn (context
, ret
, "are_you_there: krb5_write_priv_message");
444 slave_dead(context
, s
);
452 send_diffs (krb5_context context
, slave
*s
, int log_fd
,
453 const char *database
, uint32_t current_version
)
464 if (s
->version
== current_version
) {
465 krb5_warnx(context
, "slave %s in sync already at version %ld",
466 s
->name
, (long)s
->version
);
470 if (s
->flags
& SLAVE_F_DEAD
)
473 /* if slave is a fresh client, starting over */
474 if (s
->version
== 0) {
475 krb5_warnx(context
, "sending complete log to fresh slave %s",
477 return send_complete (context
, s
, database
, current_version
);
480 sp
= kadm5_log_goto_end (log_fd
);
481 right
= krb5_storage_seek(sp
, 0, SEEK_CUR
);
483 ret
= kadm5_log_previous (context
, sp
, &ver
, ×tamp
, &op
, &len
);
485 krb5_err(context
, 1, ret
,
486 "send_diffs: failed to find previous entry");
487 left
= krb5_storage_seek(sp
, -16, SEEK_CUR
);
488 if (ver
== s
->version
)
490 if (ver
== s
->version
+ 1)
493 krb5_storage_free(sp
);
495 "slave %s (version %lu) out of sync with master "
496 "(first version in log %lu), sending complete database",
497 s
->name
, (unsigned long)s
->version
, (unsigned long)ver
);
498 return send_complete (context
, s
, database
, current_version
);
503 "syncing slave %s from version %lu to version %lu",
504 s
->name
, (unsigned long)s
->version
,
505 (unsigned long)current_version
);
507 ret
= krb5_data_alloc (&data
, right
- left
+ 4);
509 krb5_storage_free(sp
);
510 krb5_warn (context
, ret
, "send_diffs: krb5_data_alloc");
511 slave_dead(context
, s
);
514 krb5_storage_read (sp
, (char *)data
.data
+ 4, data
.length
- 4);
515 krb5_storage_free(sp
);
517 sp
= krb5_storage_from_data (&data
);
519 krb5_warnx (context
, "send_diffs: krb5_storage_from_data");
520 slave_dead(context
, s
);
523 krb5_store_int32 (sp
, FOR_YOU
);
524 krb5_storage_free(sp
);
526 ret
= krb5_write_priv_message(context
, s
->ac
, &s
->fd
, &data
);
527 krb5_data_free(&data
);
530 krb5_warn (context
, ret
, "send_diffs: krb5_write_priv_message");
531 slave_dead(context
, s
);
536 s
->version
= current_version
;
542 process_msg (krb5_context context
, slave
*s
, int log_fd
,
543 const char *database
, uint32_t current_version
)
550 ret
= krb5_read_priv_message(context
, s
->ac
, &s
->fd
, &out
);
552 krb5_warn (context
, ret
, "error reading message from %s", s
->name
);
556 sp
= krb5_storage_from_mem (out
.data
, out
.length
);
558 krb5_warnx (context
, "process_msg: no memory");
559 krb5_data_free (&out
);
562 if (krb5_ret_int32 (sp
, &tmp
) != 0) {
563 krb5_warnx (context
, "process_msg: client send too short command");
564 krb5_data_free (&out
);
569 ret
= krb5_ret_int32 (sp
, &tmp
);
571 krb5_warnx (context
, "process_msg: client send too I_HAVE data");
574 /* new started slave that have old log */
575 if (s
->version
== 0 && tmp
!= 0) {
576 if (current_version
< tmp
) {
577 krb5_warnx (context
, "Slave %s have later version the master "
578 "OUT OF SYNC", s
->name
);
582 if (tmp
< s
->version
) {
583 krb5_warnx (context
, "Slave claims to not have "
584 "version we already sent to it");
586 ret
= send_diffs (context
, s
, log_fd
, database
, current_version
);
594 krb5_warnx (context
, "Ignoring command %d", tmp
);
598 krb5_data_free (&out
);
599 krb5_storage_free (sp
);
606 #define SLAVE_NAME "Name"
607 #define SLAVE_ADDRESS "Address"
608 #define SLAVE_VERSION "Version"
609 #define SLAVE_STATUS "Status"
610 #define SLAVE_SEEN "Last Seen"
613 open_stats(krb5_context context
)
615 char *statfile
= NULL
;
619 if (slave_stats_file
)
620 fn
= slave_stats_file
;
622 asprintf(&statfile
, "%s/slaves-stats", hdb_db_dir(context
));
623 fn
= krb5_config_get_string_default(context
,
638 write_master_down(krb5_context context
)
641 time_t t
= time(NULL
);
644 fp
= open_stats(context
);
647 krb5_format_time(context
, t
, str
, sizeof(str
), TRUE
);
648 fprintf(fp
, "master down at %s\n", str
);
654 write_stats(krb5_context context
, slave
*slaves
, uint32_t current_version
)
658 time_t t
= time(NULL
);
661 fp
= open_stats(context
);
665 krb5_format_time(context
, t
, str
, sizeof(str
), TRUE
);
666 fprintf(fp
, "Status for slaves, last updated: %s\n\n", str
);
668 fprintf(fp
, "Master version: %lu\n\n", (unsigned long)current_version
);
676 rtbl_add_column(tbl
, SLAVE_NAME
, 0);
677 rtbl_add_column(tbl
, SLAVE_ADDRESS
, 0);
678 rtbl_add_column(tbl
, SLAVE_VERSION
, RTBL_ALIGN_RIGHT
);
679 rtbl_add_column(tbl
, SLAVE_STATUS
, 0);
680 rtbl_add_column(tbl
, SLAVE_SEEN
, 0);
682 rtbl_set_prefix(tbl
, " ");
683 rtbl_set_column_prefix(tbl
, SLAVE_NAME
, "");
688 rtbl_add_column_entry(tbl
, SLAVE_NAME
, slaves
->name
);
689 ret
= krb5_sockaddr2address (context
,
690 (struct sockaddr
*)&slaves
->addr
, &addr
);
692 krb5_print_address(&addr
, str
, sizeof(str
), NULL
);
693 krb5_free_address(context
, &addr
);
694 rtbl_add_column_entry(tbl
, SLAVE_ADDRESS
, str
);
696 rtbl_add_column_entry(tbl
, SLAVE_ADDRESS
, "<unknown>");
698 snprintf(str
, sizeof(str
), "%u", (unsigned)slaves
->version
);
699 rtbl_add_column_entry(tbl
, SLAVE_VERSION
, str
);
701 if (slaves
->flags
& SLAVE_F_DEAD
)
702 rtbl_add_column_entry(tbl
, SLAVE_STATUS
, "Down");
704 rtbl_add_column_entry(tbl
, SLAVE_STATUS
, "Up");
706 ret
= krb5_format_time(context
, slaves
->seen
, str
, sizeof(str
), TRUE
);
707 rtbl_add_column_entry(tbl
, SLAVE_SEEN
, str
);
709 slaves
= slaves
->next
;
712 rtbl_format(tbl
, fp
);
720 static int version_flag
;
721 static int help_flag
;
722 static char *keytab_str
= "HDB:";
723 static char *database
;
724 static char *config_file
;
725 static char *port_str
;
726 #ifdef SUPPORT_DETACH
727 static int detach_from_console
= 0;
730 static struct getargs args
[] = {
731 { "config-file", 'c', arg_string
, &config_file
},
732 { "realm", 'r', arg_string
, &realm
},
733 { "keytab", 'k', arg_string
, &keytab_str
,
734 "keytab to get authentication from", "kspec" },
735 { "database", 'd', arg_string
, &database
, "database", "file"},
736 { "slave-stats-file", 0, arg_string
, &slave_stats_file
,
737 "file for slave status information", "file"},
738 { "time-missing", 0, arg_string
, &slave_time_missing
,
739 "time before slave is polled for presence", "time"},
740 { "time-gone", 0, arg_string
, &slave_time_gone
,
741 "time of inactivity after which a slave is considered gone", "time"},
742 { "port", 0, arg_string
, &port_str
,
743 "port ipropd will listen to", "port"},
744 #ifdef SUPPORT_DETACH
745 { "detach", 0, arg_flag
, &detach_from_console
,
746 "detach from console" },
748 { "hostname", 0, arg_string
, &master_hostname
,
749 "hostname of master (if not same as hostname)", "hostname" },
750 { "version", 0, arg_flag
, &version_flag
},
751 { "help", 0, arg_flag
, &help_flag
}
753 static int num_args
= sizeof(args
) / sizeof(args
[0]);
756 main(int argc
, char **argv
)
759 krb5_context context
;
761 kadm5_server_context
*server_context
;
762 kadm5_config_params conf
;
763 krb5_socket_t signal_fd
, listen_fd
;
765 slave
*slaves
= NULL
;
766 uint32_t current_version
= 0, old_version
= 0;
771 optidx
= krb5_program_setup(&context
, argc
, argv
, args
, num_args
, NULL
);
774 krb5_std_usage(0, args
, num_args
);
782 if (config_file
== NULL
) {
783 asprintf(&config_file
, "%s/kdc.conf", hdb_db_dir(context
));
784 if (config_file
== NULL
)
785 errx(1, "out of memory");
788 ret
= krb5_prepend_config_files_default(config_file
, &files
);
790 krb5_err(context
, 1, ret
, "getting configuration files");
792 ret
= krb5_set_config_files(context
, files
);
793 krb5_free_config_files(files
);
795 krb5_err(context
, 1, ret
, "reading configuration files");
797 time_before_gone
= parse_time (slave_time_gone
, "s");
798 if (time_before_gone
< 0)
799 krb5_errx (context
, 1, "couldn't parse time: %s", slave_time_gone
);
800 time_before_missing
= parse_time (slave_time_missing
, "s");
801 if (time_before_missing
< 0)
802 krb5_errx (context
, 1, "couldn't parse time: %s", slave_time_missing
);
804 #ifdef SUPPORT_DETACH
805 if (detach_from_console
)
809 krb5_openlog (context
, "ipropd-master", &log_facility
);
810 krb5_set_warn_dest(context
, log_facility
);
812 ret
= krb5_kt_register(context
, &hdb_kt_ops
);
814 krb5_err(context
, 1, ret
, "krb5_kt_register");
816 ret
= krb5_kt_resolve(context
, keytab_str
, &keytab
);
818 krb5_err(context
, 1, ret
, "krb5_kt_resolve: %s", keytab_str
);
820 memset(&conf
, 0, sizeof(conf
));
822 conf
.mask
|= KADM5_CONFIG_REALM
;
825 ret
= kadm5_init_with_skey_ctx (context
,
832 krb5_err (context
, 1, ret
, "kadm5_init_with_password_ctx");
834 server_context
= (kadm5_server_context
*)kadm_handle
;
836 log_fd
= open (server_context
->log_context
.log_file
, O_RDONLY
, 0);
838 krb5_err (context
, 1, errno
, "open %s",
839 server_context
->log_context
.log_file
);
841 signal_fd
= make_signal_socket (context
);
842 listen_fd
= make_listen_socket (context
, port_str
);
844 kadm5_log_get_version_fd (log_fd
, ¤t_version
);
846 krb5_warnx(context
, "ipropd-master started at version: %lu",
847 (unsigned long)current_version
);
849 while(exit_flag
== 0){
853 struct timeval to
= {30, 0};
856 #ifndef NO_LIMIT_FD_SETSIZE
857 if (signal_fd
>= FD_SETSIZE
|| listen_fd
>= FD_SETSIZE
)
858 krb5_errx (context
, 1, "fd too large");
862 FD_SET(signal_fd
, &readset
);
863 max_fd
= max(max_fd
, signal_fd
);
864 FD_SET(listen_fd
, &readset
);
865 max_fd
= max(max_fd
, listen_fd
);
867 for (p
= slaves
; p
!= NULL
; p
= p
->next
) {
868 if (p
->flags
& SLAVE_F_DEAD
)
870 FD_SET(p
->fd
, &readset
);
871 max_fd
= max(max_fd
, p
->fd
);
874 ret
= select (max_fd
+ 1,
875 &readset
, NULL
, NULL
, &to
);
880 krb5_err (context
, 1, errno
, "select");
884 old_version
= current_version
;
885 kadm5_log_get_version_fd (log_fd
, ¤t_version
);
887 if (current_version
> old_version
) {
889 "Missed a signal, updating slaves %lu to %lu",
890 (unsigned long)old_version
,
891 (unsigned long)current_version
);
892 for (p
= slaves
; p
!= NULL
; p
= p
->next
) {
893 if (p
->flags
& SLAVE_F_DEAD
)
895 send_diffs (context
, p
, log_fd
, database
, current_version
);
900 if (ret
&& FD_ISSET(signal_fd
, &readset
)) {
901 #ifndef NO_UNIX_SOCKETS
902 struct sockaddr_un peer_addr
;
904 struct sockaddr_storage peer_addr
;
906 socklen_t peer_len
= sizeof(peer_addr
);
908 if(recvfrom(signal_fd
, (void *)&vers
, sizeof(vers
), 0,
909 (struct sockaddr
*)&peer_addr
, &peer_len
) < 0) {
910 krb5_warn (context
, errno
, "recvfrom");
915 old_version
= current_version
;
916 kadm5_log_get_version_fd (log_fd
, ¤t_version
);
917 if (current_version
> old_version
) {
919 "Got a signal, updating slaves %lu to %lu",
920 (unsigned long)old_version
,
921 (unsigned long)current_version
);
922 for (p
= slaves
; p
!= NULL
; p
= p
->next
) {
923 if (p
->flags
& SLAVE_F_DEAD
)
925 send_diffs (context
, p
, log_fd
, database
, current_version
);
929 "Got a signal, but no update in log version %lu",
930 (unsigned long)current_version
);
934 for(p
= slaves
; p
!= NULL
; p
= p
->next
) {
935 if (p
->flags
& SLAVE_F_DEAD
)
937 if (ret
&& FD_ISSET(p
->fd
, &readset
)) {
940 if(process_msg (context
, p
, log_fd
, database
, current_version
))
941 slave_dead(context
, p
);
942 } else if (slave_gone_p (p
))
943 slave_dead(context
, p
);
944 else if (slave_missing_p (p
))
945 send_are_you_there (context
, p
);
948 if (ret
&& FD_ISSET(listen_fd
, &readset
)) {
949 add_slave (context
, keytab
, &slaves
, listen_fd
);
953 write_stats(context
, slaves
, current_version
);
956 if(exit_flag
== SIGINT
|| exit_flag
== SIGTERM
)
957 krb5_warnx(context
, "%s terminated", getprogname());
959 else if(exit_flag
== SIGXCPU
)
960 krb5_warnx(context
, "%s CPU time limit exceeded", getprogname());
963 krb5_warnx(context
, "%s unexpected exit reason: %ld",
964 getprogname(), (long)exit_flag
);
966 write_master_down(context
);