Fix Windows build: no fork for kdc
This commit is contained in:
@@ -829,6 +829,7 @@ handle_tcp(krb5_context context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_FORK
|
||||||
static void
|
static void
|
||||||
handle_islive(int fd)
|
handle_islive(int fd)
|
||||||
{
|
{
|
||||||
@@ -839,6 +840,7 @@ handle_islive(int fd)
|
|||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
exit_flag = -1;
|
exit_flag = -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
krb5_boolean
|
krb5_boolean
|
||||||
realloc_descrs(struct descr **d, unsigned int *ndescr)
|
realloc_descrs(struct descr **d, unsigned int *ndescr)
|
||||||
@@ -891,12 +893,14 @@ loop(krb5_context context, krb5_kdc_configuration *config,
|
|||||||
struct timeval tmout;
|
struct timeval tmout;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
int min_free = -1;
|
int min_free = -1;
|
||||||
int max_fd;
|
int max_fd = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(islive, &fds);
|
if (islive > -1) {
|
||||||
max_fd = islive;
|
FD_SET(islive, &fds);
|
||||||
|
max_fd = islive;
|
||||||
|
}
|
||||||
for (i = 0; i < ndescr; i++) {
|
for (i = 0; i < ndescr; i++) {
|
||||||
if (!rk_IS_BAD_SOCKET(d[i].s)) {
|
if (!rk_IS_BAD_SOCKET(d[i].s)) {
|
||||||
if (d[i].type == SOCK_STREAM &&
|
if (d[i].type == SOCK_STREAM &&
|
||||||
@@ -929,8 +933,10 @@ loop(krb5_context context, krb5_kdc_configuration *config,
|
|||||||
krb5_warn(context, rk_SOCK_ERRNO, "select");
|
krb5_warn(context, rk_SOCK_ERRNO, "select");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (FD_ISSET(islive, &fds))
|
#ifdef HAVE_FORK
|
||||||
|
if (islive > -1 && FD_ISSET(islive, &fds))
|
||||||
handle_islive(islive);
|
handle_islive(islive);
|
||||||
|
#endif
|
||||||
for (i = 0; i < ndescr; i++)
|
for (i = 0; i < ndescr; i++)
|
||||||
if (!rk_IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
|
if (!rk_IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
|
||||||
min_free = next_min_free(context, &d, &ndescr);
|
min_free = next_min_free(context, &d, &ndescr);
|
||||||
@@ -945,8 +951,8 @@ loop(krb5_context context, krb5_kdc_configuration *config,
|
|||||||
|
|
||||||
switch (exit_flag) {
|
switch (exit_flag) {
|
||||||
case -1:
|
case -1:
|
||||||
kdc_log(context, config, 0, "sub-KDC exiting because Master KDC "
|
kdc_log(context, config, 0,
|
||||||
"exited.");
|
"KDC worker process exiting because Master KDC exited.");
|
||||||
break;
|
break;
|
||||||
#ifdef SIGXCPU
|
#ifdef SIGXCPU
|
||||||
case SIGXCPU:
|
case SIGXCPU:
|
||||||
@@ -979,6 +985,7 @@ bonjour_kid(krb5_context context, krb5_kdc_configuration *config, int islive)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_FORK
|
||||||
static void
|
static void
|
||||||
kill_kids(pid_t *pids, int max_kids, int sig)
|
kill_kids(pid_t *pids, int max_kids, int sig)
|
||||||
{
|
{
|
||||||
@@ -998,7 +1005,6 @@ reap_kid(krb5_context context, krb5_kdc_configuration *config,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
pid = waitpid(-1, &status, options);
|
pid = waitpid(-1, &status, options);
|
||||||
|
|
||||||
if (pid < 1)
|
if (pid < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -1012,7 +1018,7 @@ reap_kid(krb5_context context, krb5_kdc_configuration *config,
|
|||||||
|
|
||||||
/* XXXrcd: should likely log exit code and the like */
|
/* XXXrcd: should likely log exit code and the like */
|
||||||
kdc_log(context, config, 0, "sub-KDC reaped: %d", pid);
|
kdc_log(context, config, 0, "sub-KDC reaped: %d", pid);
|
||||||
pids[i] = 0;
|
pids[i] = (pid_t)-1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1041,6 +1047,7 @@ select_sleep(int microseconds)
|
|||||||
tv.tv_usec = microseconds % 1000000;
|
tv.tv_usec = microseconds % 1000000;
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
start_kdc(krb5_context context,
|
start_kdc(krb5_context context,
|
||||||
@@ -1051,12 +1058,15 @@ start_kdc(krb5_context context,
|
|||||||
struct descr *d;
|
struct descr *d;
|
||||||
unsigned int ndescr;
|
unsigned int ndescr;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
#ifdef HAVE_FORK
|
||||||
pid_t *pids;
|
pid_t *pids;
|
||||||
int max_kdcs = config->num_kdc_processes;
|
int max_kdcs = config->num_kdc_processes;
|
||||||
int num_kdcs = 0;
|
int num_kdcs = 0;
|
||||||
int i;
|
int i;
|
||||||
int islive[2];
|
int islive[2];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_FORK
|
||||||
#ifdef _SC_NPROCESSORS_ONLN
|
#ifdef _SC_NPROCESSORS_ONLN
|
||||||
if (max_kdcs == -1)
|
if (max_kdcs == -1)
|
||||||
max_kdcs = sysconf(_SC_NPROCESSORS_ONLN);
|
max_kdcs = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
@@ -1065,10 +1075,6 @@ start_kdc(krb5_context context,
|
|||||||
if (max_kdcs == -1)
|
if (max_kdcs == -1)
|
||||||
max_kdcs = 1;
|
max_kdcs = 1;
|
||||||
|
|
||||||
ndescr = init_sockets(context, config, &d);
|
|
||||||
if(ndescr <= 0)
|
|
||||||
krb5_errx(context, 1, "No sockets!");
|
|
||||||
|
|
||||||
pids = malloc(max_kdcs * sizeof(*pids));
|
pids = malloc(max_kdcs * sizeof(*pids));
|
||||||
if (!pids)
|
if (!pids)
|
||||||
krb5_err(context, 1, errno, "malloc");
|
krb5_err(context, 1, errno, "malloc");
|
||||||
@@ -1083,17 +1089,30 @@ start_kdc(krb5_context context,
|
|||||||
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, islive) == -1)
|
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, islive) == -1)
|
||||||
krb5_errx(context, 1, "socketpair");
|
krb5_errx(context, 1, "socketpair");
|
||||||
socket_set_nonblocking(islive[1], 1);
|
socket_set_nonblocking(islive[1], 1);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
bonjour_kid(context, config, islive[1]);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ndescr = init_sockets(context, config, &d);
|
||||||
|
if(ndescr <= 0)
|
||||||
|
krb5_errx(context, 1, "No sockets!");
|
||||||
|
|
||||||
|
#ifdef HAVE_FORK
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
bonjour_kid(context, config, islive[1]); /* fork()s */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
kdc_log(context, config, 0, "Master KDC started pid=%d", getpid());
|
kdc_log(context, config, 0, "Master KDC started pid=%d", getpid());
|
||||||
|
#else
|
||||||
|
kdc_log(context, config, 0, "KDC started pid=%d", getpid());
|
||||||
|
#endif
|
||||||
|
|
||||||
roken_detach_finish(NULL, daemon_child);
|
roken_detach_finish(NULL, daemon_child);
|
||||||
|
|
||||||
tv1.tv_sec = 0;
|
tv1.tv_sec = 0;
|
||||||
tv1.tv_usec = 0;
|
tv1.tv_usec = 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_FORK
|
||||||
while (exit_flag == 0) {
|
while (exit_flag == 0) {
|
||||||
|
|
||||||
/* Slow down the creation of KDCs... */
|
/* Slow down the creation of KDCs... */
|
||||||
@@ -1124,6 +1143,8 @@ start_kdc(krb5_context context,
|
|||||||
exit(0);
|
exit(0);
|
||||||
case -1:
|
case -1:
|
||||||
/* XXXrcd: hmmm, do something useful?? */
|
/* XXXrcd: hmmm, do something useful?? */
|
||||||
|
kdc_log(context, config, 0,
|
||||||
|
"KDC master process could not fork worker process");
|
||||||
sleep(10);
|
sleep(10);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1172,6 +1193,10 @@ start_kdc(krb5_context context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
kdc_log(context, config, 0, "master KDC exiting", pid);
|
kdc_log(context, config, 0, "master KDC exiting", pid);
|
||||||
|
#else
|
||||||
|
loop(context, config, d, ndescr, -1);
|
||||||
|
kdc_log(context, config, 0, "KDC exiting", pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
free (d);
|
free (d);
|
||||||
}
|
}
|
||||||
|
@@ -47,7 +47,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
@@ -145,8 +145,10 @@ main(int argc, char **argv)
|
|||||||
sigaction(SIGXCPU, &sa, NULL);
|
sigaction(SIGXCPU, &sa, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SIGCHLD
|
||||||
sa.sa_handler = sigchld;
|
sa.sa_handler = sigchld;
|
||||||
sigaction(SIGCHLD, &sa, NULL);
|
sigaction(SIGCHLD, &sa, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
sa.sa_handler = SIG_IGN;
|
sa.sa_handler = SIG_IGN;
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
@@ -156,7 +158,9 @@ main(int argc, char **argv)
|
|||||||
#else
|
#else
|
||||||
signal(SIGINT, sigterm);
|
signal(SIGINT, sigterm);
|
||||||
signal(SIGTERM, sigterm);
|
signal(SIGTERM, sigterm);
|
||||||
|
#ifdef SIGCHLD
|
||||||
signal(SIGCHLD, sigchld);
|
signal(SIGCHLD, sigchld);
|
||||||
|
#endif
|
||||||
#ifdef SIGXCPU
|
#ifdef SIGXCPU
|
||||||
signal(SIGXCPU, sigterm);
|
signal(SIGXCPU, sigterm);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user