summaryrefslogtreecommitdiff
path: root/server/main.c
diff options
context:
space:
mode:
authorGravatar Greg Hudson <ghudson@mit.edu>1997-09-14 17:50:06 +0000
committerGravatar Greg Hudson <ghudson@mit.edu>1997-09-14 17:50:06 +0000
commitac16f380e349fa39ec7e26bccb5456cb300006a5 (patch)
treec07ca88af97b4f6b77d28a2dc723d2e4621ed302 /server/main.c
parentd33e482744fad80d95cdd89ed380c5b8401e49bf (diff)
Pull in sources from zephyr locker. See /mit/zephyr/repository for
detailed change information.
Diffstat (limited to 'server/main.c')
-rw-r--r--server/main.c946
1 files changed, 431 insertions, 515 deletions
diff --git a/server/main.c b/server/main.c
index 3420d06..9978bbd 100644
--- a/server/main.c
+++ b/server/main.c
@@ -12,10 +12,13 @@
*/
#include <zephyr/mit-copyright.h>
+#include "zserver.h"
+#include <sys/socket.h>
+#include <sys/resource.h>
#ifndef lint
#ifndef SABER
-static char rcsid_main_c[] =
+static const char rcsid_main_c[] =
"$Id$";
#endif
#endif
@@ -47,91 +50,58 @@ static char rcsid_main_c[] =
(if the client has not acknowledged a packet after a given timeout).
*/
-#include "zserver.h"
-/* which includes
- zephyr/zephyr.h
- <errno.h>
- <sys/types.h>
- <netinet/in.h>
- <sys/time.h>
- <stdio.h>
- <sys/file.h>
- <syslog.h>
- <strings.h>
- <signal.h>
- timer.h
- zsrv_err.h
- */
-
-#include <netdb.h>
-#include <sys/socket.h>
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/resource.h>
-#include <sys/wait.h>
-#ifdef POSIX
-#include <termios.h>
-#endif
-
-#ifdef POSIX
-#define SIGNAL_RETURN_TYPE void
-#define SIG_RETURN return
-#else
-#define SIGNAL_RETURN_TYPE int
-#define SIG_RETURN return(0)
-#endif
-
-#if !defined(__SABER__) && (defined (vax) || defined (ibm032))
-#define MONCONTROL moncontrol
-#else
-#define MONCONTROL (void)
-#endif
-
#define EVER (;;) /* don't stop looping */
-#ifdef __STDC__
-# define P(s) s
-#else
-# define P(s) ()
-#endif
-
-static int do_net_setup P((void)), initialize P((void));
-static void usage P((void)), do_reset P((void));
-static SIGNAL_RETURN_TYPE bye P((int)),
- dbug_on P((int)), dbug_off P((int)),
- sig_dump_db P((int)), sig_dump_strings P((int)),
- reset P((int)), reap P((int));
-static void read_from_dump P((char *dumpfile));
-static void dump_db P((void)), dump_strings P((void));
+static int do_net_setup __P((void));
+static int initialize __P((void));
+static void usage __P((void));
+static void do_reset __P((void));
+static RETSIGTYPE bye __P((int));
+static RETSIGTYPE dbug_on __P((int));
+static RETSIGTYPE dbug_off __P((int));
+static RETSIGTYPE sig_dump_db __P((int));
+static RETSIGTYPE sig_dump_strings __P((int));
+static RETSIGTYPE reset __P((int));
+static RETSIGTYPE reap __P((int));
+static void read_from_dump __P((char *dumpfile));
+static void dump_db __P((void));
+static void dump_strings __P((void));
#ifndef DEBUG
-static void detach P((void));
+static void detach __P((void));
#endif
-extern void perror P((Zconst char *));
-
-#undef P
-
static short doreset = 0; /* if it becomes 1, perform
reset functions */
+int nfds; /* max file descriptor for select() */
int srv_socket; /* dgram socket for clients
and other servers */
int bdump_socket = -1; /* brain dump socket fd
(closed most of the time) */
fd_set interesting; /* the file descrips we are listening
to right now */
-int nfildes; /* number to look at in select() */
-struct sockaddr_in sock_sin; /* address of the socket */
-struct timeval nexthost_tv; /* time till next timeout for select */
+struct sockaddr_in srv_addr; /* address of the socket */
-ZNotAcked_t *nacklist; /* list of packets waiting for ack's */
+Unacked *nacklist = NULL; /* list of packets waiting for ack's */
-u_short hm_port; /* the port # of the host manager */
+unsigned short hm_port; /* host manager receiver port */
+unsigned short hm_srv_port; /* host manager server sending port */
char *programname; /* set to the basename of argv[0] */
char myname[MAXHOSTNAMELEN]; /* my host name */
+#ifndef ZEPHYR_USES_HESIOD
+char list_file[128];
+#endif
+#ifdef ZEPHYR_USES_KERBEROS
+char srvtab_file[128];
+char my_realm[REALM_SZ];
+static char tkt_file[128];
+#endif
+char acl_dir[128];
+char subs_file[128];
+
int zdebug;
#ifdef DEBUG_MALLOC
int dump_malloc_stats = 0;
@@ -147,259 +117,247 @@ static int dump_db_flag = 0;
static int dump_strings_flag = 0;
u_long npackets; /* number of packets processed */
-long uptime; /* when we started operations */
+time_t uptime; /* when we started operations */
static int nofork;
struct in_addr my_addr;
-char *bdump_version = "1.1";
+char *bdump_version = "1.2";
int
main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char **argv;
{
- int nfound; /* #fildes ready on select */
- fd_set readable;
- struct timeval *tvp;
- int init_from_dump = 0;
- char *dumpfile;
-#ifdef POSIX
- struct sigaction action;
-#endif
-
-
- int optchar; /* option processing */
- extern char *optarg;
- extern int optind;
-
- /* set name */
- if (programname = strrchr(argv[0],'/'))
- programname++;
- else programname = argv[0];
-
- /* process arguments */
-
- while ((optchar = getopt(argc, argv, "dsnv:f:")) != EOF) {
- switch(optchar) {
- case 'd':
- zdebug = 1;
- break;
+ int nfound; /* #fildes ready on select */
+ fd_set readable;
+ struct timeval tv;
+ int init_from_dump = 0;
+ char *dumpfile;
+#ifdef _POSIX_VERSION
+ struct sigaction action;
+#endif
+ int optchar; /* option processing */
+ extern char *optarg;
+ extern int optind;
+
+#ifndef ZEPHYR_USES_HESIOD
+ sprintf(list_file, "%s/%s", CONFDIR, SERVER_LIST_FILE);
+#endif
+#ifdef ZEPHYR_USES_KERBEROS
+ sprintf(srvtab_file, "%s/%s", CONFDIR, ZEPHYR_SRVTAB);
+ sprintf(tkt_file, "%s/%s", CONFDIR, ZEPHYR_TKFILE);
+#endif
+ sprintf(acl_dir, "%s/%s", CONFDIR, ZEPHYR_ACL_DIR);
+ sprintf(subs_file, "%s/%s", CONFDIR, DEFAULT_SUBS_FILE);
+
+ /* set name */
+ programname = strrchr(argv[0],'/');
+ programname = (programname) ? programname + 1 : argv[0];
+
+ /* process arguments */
+ while ((optchar = getopt(argc, argv, "dsnv:f:k:")) != EOF) {
+ switch(optchar) {
+ case 'd':
+ zdebug = 1;
+ break;
#ifdef DEBUG
- case 's':
- zalone = 1;
- break;
-#endif
- case 'n':
- nofork = 1;
- break;
- case 'v':
- bdump_version = optarg;
- break;
- case 'f':
- init_from_dump = 0;
- dumpfile = optarg;
- break;
- case '?':
- default:
- usage();
- /*NOTREACHED*/
- }
+ case 's':
+ zalone = 1;
+ break;
+#endif
+ case 'n':
+ nofork = 1;
+ break;
+ case 'k':
+#ifdef ZEPHYR_USES_KERBEROS
+ strncpy(my_realm, optarg, REALM_SZ);
+#endif
+ break;
+ case 'v':
+ bdump_version = optarg;
+ break;
+ case 'f':
+ init_from_dump = 0;
+ dumpfile = optarg;
+ break;
+ case '?':
+ default:
+ usage();
+ /*NOTREACHED*/
}
+ }
-#ifdef KERBEROS
- /* if there is no readable srvtab and we are not standalone, there
- is no possible way we can succeed, so we exit */
+#ifdef ZEPHYR_USES_KERBEROS
+ /* if there is no readable srvtab and we are not standalone, there
+ is no possible way we can succeed, so we exit */
- if (access(ZEPHYR_SRVTAB, R_OK)
+ if (access(srvtab_file, R_OK)
#ifdef DEBUG
- && !zalone
+ && !zalone
#endif /* DEBUG */
- ) {
- fprintf(stderr, "NO ZEPHYR SRVTAB (%s) available; exiting\n",
- ZEPHYR_SRVTAB);
- exit(1);
+ ) {
+ fprintf(stderr, "NO ZEPHYR SRVTAB (%s) available; exiting\n",
+ srvtab_file);
+ exit(1);
+ }
+ /* Use local realm if not specified on command line. */
+ if (!*my_realm) {
+ if (krb_get_lrealm(my_realm, 1) != KSUCCESS) {
+ fputs("Couldn't get local Kerberos realm; exiting.\n", stderr);
+ exit(1);
}
-#endif /* KERBEROS */
+ }
+#endif /* ZEPHYR_USES_KERBEROS */
#ifndef DEBUG
- if (!nofork)
- detach();
+ if (!nofork)
+ detach();
#endif /* DEBUG */
- /* open log */
- OPENLOG(programname, LOG_PID, LOG_LOCAL6);
+ /* open log */
+ OPENLOG(programname, LOG_PID, LOG_LOCAL6);
#if defined (DEBUG) && 0
- if (zalone)
- syslog(LOG_DEBUG, "standalone operation");
+ if (zalone)
+ syslog(LOG_DEBUG, "standalone operation");
#endif
#if 0
- if (zdebug)
- syslog(LOG_DEBUG, "debugging on");
+ if (zdebug)
+ syslog(LOG_DEBUG, "debugging on");
#endif
- /* set up sockets & my_addr and myname,
- find other servers and set up server table, initialize queues
- for retransmits, initialize error tables,
- set up restricted classes */
-
- /* Initialize t_local for other uses */
- (void) gettimeofday(&t_local, (struct timezone *)0);
+ /* set up sockets & my_addr and myname,
+ find other servers and set up server table, initialize queues
+ for retransmits, initialize error tables,
+ set up restricted classes */
- if (initialize())
- exit(1);
+ /* Initialize t_local for other uses */
+ gettimeofday(&t_local, NULL);
- if (init_from_dump)
- read_from_dump(dumpfile);
+ if (initialize())
+ exit(1);
- /* Seed random number set. */
- srandom (getpid () ^ time (0));
+ if (init_from_dump)
+ read_from_dump(dumpfile);
-#ifndef __SABER__
- /* chdir to somewhere where a core dump will survive */
- if (chdir("/usr/tmp") != 0)
- syslog(LOG_ERR,"chdir failed (%m) (execution continuing)");
+ /* Seed random number set. */
+ srandom(getpid() ^ time(0));
-#if 0
- /*
- * Many systems don't implement setpriority() as is done under BSD,
- * and the kernel scheduler will appropriately swap in the processes
- * that are needed.
- */
- if (setpriority(PRIO_PROCESS, getpid(), -10))
- syslog(LOG_ERR,"setpriority failed (%m)");
-#endif
-#endif
+ /* chdir to somewhere where a core dump will survive */
+ if (chdir(TEMP_DIRECTORY) != 0)
+ syslog(LOG_ERR, "chdir failed (%m) (execution continuing)");
- FD_ZERO(&interesting);
- FD_SET(srv_socket, &interesting);
+ FD_ZERO(&interesting);
+ FD_SET(srv_socket, &interesting);
- nfildes = srv_socket + 1;
+ nfds = srv_socket + 1;
-#ifdef POSIX
- action.sa_flags = 0;
- sigemptyset(&action.sa_mask);
+#ifdef _POSIX_VERSION
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
- action.sa_handler = bye;
- sigaction(SIGINT, &action, NULL);
- sigaction(SIGTERM, &action, NULL);
+ action.sa_handler = bye;
+ sigaction(SIGINT, &action, NULL);
+ sigaction(SIGTERM, &action, NULL);
- action.sa_handler = dbug_on;
- sigaction(SIGUSR1, &action, NULL);
+ action.sa_handler = dbug_on;
+ sigaction(SIGUSR1, &action, NULL);
- action.sa_handler = dbug_off;
- sigaction(SIGUSR2, &action, NULL);
+ action.sa_handler = dbug_off;
+ sigaction(SIGUSR2, &action, NULL);
- action.sa_handler = reap;
- sigaction(SIGCHLD, &action, NULL);
+ action.sa_handler = reap;
+ sigaction(SIGCHLD, &action, NULL);
- action.sa_handler = sig_dump_db;
- sigaction(SIGFPE, &action, NULL);
- sigaction(SIGXCPU, &action, NULL);
+ action.sa_handler = sig_dump_db;
+ sigaction(SIGFPE, &action, NULL);
#ifdef SIGEMT
- action.sa_handler = sig_dump_strings;
- sigaction(SIGEMT, &action, NULL);
+ action.sa_handler = sig_dump_strings;
+ sigaction(SIGEMT, &action, NULL);
#endif
- action.sa_handler = reset;
- sigaction(SIGHUP, &action, NULL);
+ action.sa_handler = reset;
+ sigaction(SIGHUP, &action, NULL);
#else /* !posix */
- (void) signal(SIGINT, bye);
- (void) signal(SIGTERM, bye);
- (void) signal(SIGUSR1, dbug_on);
- (void) signal(SIGUSR2, dbug_off);
- (void) signal(SIGCHLD, reap);
- (void) signal(SIGFPE, sig_dump_db);
- (void) signal(SIGXCPU, sig_dump_db);
+ signal(SIGINT, bye);
+ signal(SIGTERM, bye);
+ signal(SIGUSR1, dbug_on);
+ signal(SIGUSR2, dbug_off);
+ signal(SIGCHLD, reap);
+ signal(SIGFPE, sig_dump_db);
#ifdef SIGEMT
- (void) signal(SIGEMT, sig_dump_strings);
+ signal(SIGEMT, sig_dump_strings);
#endif
- (void) signal(SIGHUP, reset);
-#endif /* POSIX */
+ signal(SIGHUP, reset);
+#endif /* _POSIX_VERSION */
- syslog(LOG_NOTICE, "Ready for action");
+ syslog(LOG_NOTICE, "Ready for action");
- /* Reinitialize t_local now that initialization is done. */
- (void) gettimeofday(&t_local, (struct timezone *)0);
- /* GO! */
- uptime = NOW;
+ /* Reinitialize t_local now that initialization is done. */
+ gettimeofday(&t_local, NULL);
+ uptime = NOW;
+#ifdef ZEPHYR_USES_KERBEROS
+ timer_set_rel(SWEEP_INTERVAL, sweep_ticket_hash_table, NULL);
+#endif
#ifdef DEBUG_MALLOC
- malloc_inuse(&m_size);
-#endif
- for EVER {
- if (doreset)
- do_reset();
-
- if (dump_db_flag)
- dump_db();
- if (dump_strings_flag)
- dump_strings();
-
- nexthost_tv.tv_usec = 0;
- tvp = &nexthost_tv;
-
- if (nexttimo != 0L) {
- nexthost_tv.tv_sec = nexttimo - NOW;
- if (nexthost_tv.tv_sec <= 0) {
- /* timeout has passed! */
- /* so we process one timeout, then pop to
- select, polling for input. This way we get
- work done even if swamped with many
- timeouts */
- /* this will reset nexttimo */
- (void) timer_process();
- nexthost_tv.tv_sec = 0;
- }
- } else { /* no timeouts to process */
- nexthost_tv.tv_sec = 15;
- }
- readable = interesting;
- if (msgs_queued()) {
- /* when there is input in the queue, we
- artificially set up to pick up the input */
- nfound = 1;
- FD_ZERO(&readable);
- } else
- nfound = select(nfildes, &readable, (fd_set *) 0,
- (fd_set *) 0, tvp);
-
- /* Initialize t_local for other uses */
- (void) gettimeofday(&t_local, (struct timezone *)0);
+ malloc_inuse(&m_size);
+#endif
+ for EVER {
+ if (doreset)
+ do_reset();
+
+ if (dump_db_flag)
+ dump_db();
+ if (dump_strings_flag)
+ dump_strings();
+
+ readable = interesting;
+ if (msgs_queued()) {
+ /* when there is input in the queue, we
+ artificially set up to pick up the input */
+ nfound = 1;
+ FD_ZERO(&readable);
+ } else {
+ nfound = select(nfds, &readable, NULL, NULL, timer_timeout(&tv));
+ }
+
+ /* Initialize t_local for other uses */
+ gettimeofday(&t_local, (struct timezone *)0);
- /* don't flame about EINTR, since a SIGUSR1 or SIGUSR2
- can generate it by interrupting the select */
- if (nfound < 0) {
- if (errno != EINTR)
- syslog(LOG_WARNING, "select error: %m");
+ /* don't flame about EINTR, since a SIGUSR1 or SIGUSR2
+ can generate it by interrupting the select */
+ if (nfound < 0) {
+ if (errno != EINTR)
+ syslog(LOG_WARNING, "select error: %m");
#ifdef DEBUG_MALLOC
- if (dump_malloc_stats) {
- unsigned long foo,histid2;
- dump_malloc_stats = 0;
- foo = malloc_inuse(&histid2);
- printf("Total inuse: %d\n",foo);
- malloc_list(2,m_size,histid2);
- }
-#endif
- continue;
- }
- if (nfound == 0)
- /* either we timed out or we were just
- polling for input. Either way we want to continue
- the loop, and process the next timeout */
- continue;
- else {
- if ((bdump_socket >= 0) &&
- FD_ISSET(bdump_socket,&readable))
- bdump_send();
- else if (msgs_queued() ||
- FD_ISSET(srv_socket, &readable)) {
- handle_packet();
- } else
- syslog(LOG_ERR, "select weird?!?!");
- }
+ if (dump_malloc_stats) {
+ unsigned long foo,histid2;
+
+ dump_malloc_stats = 0;
+ foo = malloc_inuse(&histid2);
+ printf("Total inuse: %d\n",foo);
+ malloc_list(2,m_size,histid2);
+ }
+#endif
+ continue;
+ }
+
+ if (nfound == 0) {
+ /* either we timed out or we were just
+ polling for input. Either way we want to continue
+ the loop, and process the next timeout */
+ continue;
+ } else {
+ if (bdump_socket >= 0 && FD_ISSET(bdump_socket,&readable))
+ bdump_send();
+ else if (msgs_queued() || FD_ISSET(srv_socket, &readable))
+ handle_packet();
+ else
+ syslog(LOG_ERR, "select weird?!?!");
}
+ }
}
/* Initialize net stuff.
@@ -412,49 +370,35 @@ main(argc, argv)
static int
initialize()
{
- if (do_net_setup())
- return(1);
+ if (do_net_setup())
+ return(1);
- server_init();
+ server_init();
-#if 0
- if (!(nacklist = (ZNotAcked_t *) xmalloc(sizeof(ZNotAcked_t)))) {
- /* unrecoverable */
- syslog(LOG_CRIT, "nacklist malloc");
- abort();
- }
-#else
- {
- static ZNotAcked_t not_acked_head;
- nacklist = &not_acked_head;
- }
+#ifdef ZEPHYR_USES_KERBEROS
+ krb_set_tkt_string(tkt_file);
#endif
- (void) memset((caddr_t) nacklist, 0, sizeof(ZNotAcked_t));
- nacklist->q_forw = nacklist->q_back = nacklist;
-
- nexttimo = 1L; /* trigger the timers when we hit
- the FOR loop */
+ realm_init();
- (void) ZInitialize(); /* set up the library */
- (void) init_zsrv_err_tbl(); /* set up err table */
+ ZSetServerState(1);
+ ZInitialize(); /* set up the library */
+ init_zsrv_err_tbl(); /* set up err table */
- (void) ZSetServerState(1);
- (void) ZSetFD(srv_socket); /* set up the socket as the
- input fildes */
+ ZSetFD(srv_socket); /* set up the socket as the input fildes */
- /* set up default strings */
+ /* set up default strings */
- class_control = make_zstring(ZEPHYR_CTL_CLASS, 1);
- class_admin = make_zstring(ZEPHYR_ADMIN_CLASS, 1);
- class_hm = make_zstring(HM_CTL_CLASS, 1);
- class_ulogin = make_zstring(LOGIN_CLASS, 1);
- class_ulocate = make_zstring(LOCATE_CLASS, 1);
- wildcard_instance = make_zstring(WILDCARD_INSTANCE, 1);
- empty = make_zstring("", 0);
+ class_control = make_string(ZEPHYR_CTL_CLASS, 1);
+ class_admin = make_string(ZEPHYR_ADMIN_CLASS, 1);
+ class_hm = make_string(HM_CTL_CLASS, 1);
+ class_ulogin = make_string(LOGIN_CLASS, 1);
+ class_ulocate = make_string(LOCATE_CLASS, 1);
+ wildcard_instance = make_string(WILDCARD_INSTANCE, 1);
+ empty = make_string("", 0);
- /* restrict certain classes */
- access_init();
- return(0);
+ /* restrict certain classes */
+ access_init();
+ return 0;
}
/*
@@ -464,62 +408,59 @@ initialize()
static int
do_net_setup()
{
- struct servent *sp;
- struct hostent *hp;
- char hostname[MAXHOSTNAMELEN+1];
- int flags;
-
- if (gethostname(hostname, MAXHOSTNAMELEN+1)) {
- syslog(LOG_ERR, "no hostname: %m");
- return(1);
- }
- if (!(hp = gethostbyname(hostname))) {
- syslog(LOG_ERR, "no gethostbyname repsonse");
- (void) strncpy(myname, hostname, MAXHOSTNAMELEN);
- return(1);
- }
- (void) strncpy(myname, hp->h_name, MAXHOSTNAMELEN);
- (void) memcpy((caddr_t) &my_addr, (caddr_t) hp->h_addr,
- sizeof(hp->h_addr));
-
- (void) setservent(1); /* keep file/connection open */
-
- if (!(sp = getservbyname(SERVER_SVCNAME, "udp"))) {
- syslog(LOG_ERR, "%s/udp unknown",SERVER_SVCNAME);
- return(1);
- }
- (void) memset((caddr_t) &sock_sin, 0, sizeof(sock_sin));
- sock_sin.sin_port = sp->s_port;
-
- if (!(sp = getservbyname(HM_SVCNAME, "udp"))) {
- syslog(LOG_ERR, "%s/udp unknown", HM_SVCNAME);
- return(1);
- }
- hm_port = sp->s_port;
+ struct servent *sp;
+ struct hostent *hp;
+ char hostname[MAXHOSTNAMELEN+1];
+ int flags;
+
+ if (gethostname(hostname, MAXHOSTNAMELEN + 1)) {
+ syslog(LOG_ERR, "no hostname: %m");
+ return 1;
+ }
+ hp = gethostbyname(hostname);
+ if (!hp) {
+ syslog(LOG_ERR, "no gethostbyname repsonse");
+ strncpy(myname, hostname, MAXHOSTNAMELEN);
+ return 1;
+ }
+ strncpy(myname, hp->h_name, MAXHOSTNAMELEN);
+ memcpy(&my_addr, hp->h_addr, sizeof(hp->h_addr));
- (void) endservent();
+ setservent(1); /* keep file/connection open */
+
+ memset(&srv_addr, 0, sizeof(srv_addr));
+ srv_addr.sin_family = AF_INET;
+ sp = getservbyname(SERVER_SVCNAME, "udp");
+ srv_addr.sin_port = (sp) ? sp->s_port : SERVER_SVC_FALLBACK;
+
+ sp = getservbyname(HM_SVCNAME, "udp");
+ hm_port = (sp) ? sp->s_port : HM_SVC_FALLBACK;
- if ((srv_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "client_sock failed: %m");
- return(1);
- }
- if (bind(srv_socket, (struct sockaddr *) &sock_sin,
- sizeof(sock_sin)) < 0) {
- syslog(LOG_ERR, "client bind failed: %m");
- return(1);
- }
+ sp = getservbyname(HM_SRV_SVCNAME, "udp");
+ hm_srv_port = (sp) ? sp->s_port : HM_SRV_SVC_FALLBACK;
+
+ srv_socket = socket(AF_INET, SOCK_DGRAM, 0);
+ if (srv_socket < 0) {
+ syslog(LOG_ERR, "client_sock failed: %m");
+ return 1;
+ }
+ if (bind(srv_socket, (struct sockaddr *) &srv_addr,
+ sizeof(srv_addr)) < 0) {
+ syslog(LOG_ERR, "client bind failed: %m");
+ return 1;
+ }
- /* set not-blocking */
-#ifdef POSIX
- flags = fcntl(srv_socket, F_GETFL);
- flags |= O_NONBLOCK;
- (void) fcntl(srv_socket, F_SETFL, flags);
+ /* set not-blocking */
+#ifdef _POSIX_VERSION
+ flags = fcntl(srv_socket, F_GETFL);
+ flags |= O_NONBLOCK;
+ fcntl(srv_socket, F_SETFL, flags);
#else
- flags = 1;
- (void) ioctl(srv_socket, FIONBIO, (caddr_t) &flags);
+ flags = 1;
+ ioctl(srv_socket, FIONBIO, &flags);
#endif
- return(0);
+ return 0;
}
@@ -531,186 +472,160 @@ static void
usage()
{
#ifdef DEBUG
- fprintf(stderr,"Usage: %s [-d] [-s] [-n] [-f dumpfile]\n",programname);
+ fprintf(stderr, "Usage: %s [-d] [-s] [-n] [-k realm] [-f dumpfile]\n",
+ programname);
#else
- fprintf(stderr,"Usage: %s [-d] [-n] [-f dumpfile]\n",programname);
+ fprintf(stderr, "Usage: %s [-d] [-n] [-k realm] [-f dumpfile]\n",
+ programname);
#endif /* DEBUG */
exit(2);
}
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-bye(int sig)
-#else
+int
+packets_waiting()
+{
+ fd_set readable, initial;
+ struct timeval tv;
+
+ if (msgs_queued())
+ return 1;
+ FD_ZERO(&initial);
+ FD_SET(srv_socket, &initial);
+ readable = initial;
+ tv.tv_sec = tv.tv_usec = 0;
+ return (select(srv_socket + 1, &readable, NULL, NULL, &tv) > 0);
+}
+
+static RETSIGTYPE
bye(sig)
- int sig;
-#endif
+ int sig;
{
- server_shutdown(); /* tell other servers */
- hostm_shutdown(); /* tell our hosts */
-#ifdef KERBEROS
- (void) dest_tkt();
+ server_shutdown(); /* tell other servers */
+ hostm_shutdown(); /* tell our hosts */
+#ifdef ZEPHYR_USES_KERBEROS
+ dest_tkt();
#endif
- syslog(LOG_NOTICE, "goodbye (sig %d)",sig);
- exit(0);
- /*NOTREACHED*/
+ syslog(LOG_NOTICE, "goodbye (sig %d)", sig);
+ exit(0);
}
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-dbug_on(int sig)
-#else
+static RETSIGTYPE
dbug_on(sig)
- int sig;
-#endif
+ int sig;
{
- syslog(LOG_DEBUG, "debugging turned on");
+ syslog(LOG_DEBUG, "debugging turned on");
#ifdef DEBUG_MALLOC
- dump_malloc_stats = 1;
+ dump_malloc_stats = 1;
#endif
- zdebug = 1;
- SIG_RETURN;
+ zdebug = 1;
}
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-dbug_off(int sig)
-#else
+static RETSIGTYPE
dbug_off(sig)
- int sig;
-#endif
+ int sig;
{
- syslog(LOG_DEBUG, "debugging turned off");
+ syslog(LOG_DEBUG, "debugging turned off");
#ifdef DEBUG_MALLOC
- malloc_inuse(&m_size);
+ malloc_inuse(&m_size);
#endif
- zdebug = 0;
- SIG_RETURN;
+ zdebug = 0;
}
int fork_for_dump = 0;
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-sig_dump_strings (int sig)
-#else
+static RETSIGTYPE
sig_dump_strings(sig)
- int sig;
-#endif
+ int sig;
{
- dump_strings_flag = 1;
- SIG_RETURN;
+ dump_strings_flag = 1;
}
static void dump_strings()
{
+ char filename[128];
+
FILE *fp;
int oerrno = errno;
- fp = fopen ("/usr/tmp/zephyr.strings", "w");
+
+ sprintf(filename, "%szephyr.strings", TEMP_DIRECTORY);
+ fp = fopen (filename, "w");
if (!fp) {
- syslog (LOG_ERR, "can't open strings dump file: %m");
+ syslog(LOG_ERR, "can't open strings dump file: %m");
errno = oerrno;
dump_strings_flag = 0;
return;
}
- syslog (LOG_INFO, "dumping strings to disk");
- print_zstring_table(fp);
- if (fclose (fp) == EOF)
- syslog (LOG_ERR, "error writing strings dump file");
+ syslog(LOG_INFO, "dumping strings to disk");
+ print_string_table(fp);
+ if (fclose(fp) == EOF)
+ syslog(LOG_ERR, "error writing strings dump file");
else
- syslog (LOG_INFO, "dump done");
+ syslog(LOG_INFO, "dump done");
oerrno = errno;
dump_strings_flag = 0;
return;
}
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-sig_dump_db(int sig)
-#else
+static RETSIGTYPE
sig_dump_db(sig)
- int sig;
-#endif
+ int sig;
{
- dump_db_flag = 1;
- SIG_RETURN;
+ dump_db_flag = 1;
}
static void dump_db()
{
- /* dump the in-core database to human-readable form on disk */
- FILE *fp;
- int oerrno = errno;
- int pid;
+ /* dump the in-core database to human-readable form on disk */
+ FILE *fp;
+ int oerrno = errno;
+ int pid;
+ char filename[128];
-#ifdef __SABER__
- pid = -1;
-#else
- if (fork_for_dump) {
- MONCONTROL (0);
- pid = fork ();
- MONCONTROL (1);
- }
- else
- pid = -1;
-#endif
- if (pid > 0)
- {
- dump_db_flag = 0;
- return;
- }
- if ((fp = fopen("/usr/tmp/zephyr.db", "w")) == (FILE *)0) {
- syslog(LOG_ERR, "can't open dump database");
- errno = oerrno;
- dump_db_flag = 0;
- return;
- }
- syslog(LOG_INFO, "dumping to disk");
- server_dump_servers(fp);
- uloc_dump_locs(fp);
- hostm_dump_hosts(fp);
- class_dump_subs(fp);
- syslog(LOG_INFO, "dump done");
- if (fclose(fp) == EOF) {
- syslog(LOG_ERR, "can't close dump db");
- }
- if (pid == 0)
- exit (0);
+ pid = (fork_for_dump) ? fork() : -1;
+ if (pid > 0) {
+ dump_db_flag = 0;
+ return;
+ }
+ sprintf(filename, "%szephyr.db", TEMP_DIRECTORY);
+ fp = fopen(filename, "w");
+ if (!fp) {
+ syslog(LOG_ERR, "can't open dump database");
errno = oerrno;
dump_db_flag = 0;
return;
+ }
+ syslog(LOG_INFO, "dumping to disk");
+ server_dump_servers(fp);
+ uloc_dump_locs(fp);
+ client_dump_clients(fp);
+ triplet_dump_subs(fp);
+ realm_dump_realms(fp);
+ syslog(LOG_INFO, "dump done");
+ if (fclose(fp) == EOF)
+ syslog(LOG_ERR, "can't close dump db");
+ if (pid == 0)
+ exit(0);
+ errno = oerrno;
+ dump_db_flag = 0;
}
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-reset(int sig)
-#else
+static RETSIGTYPE
reset(sig)
- int sig;
-#endif
+ int sig;
{
#if 1
- zdbug((LOG_DEBUG,"reset()"));
+ zdbug((LOG_DEBUG,"reset()"));
#endif
- doreset = 1;
- SIG_RETURN;
+ doreset = 1;
}
-#ifdef __GNUG__
-#define wait WaitStatus
-#endif
-
-static SIGNAL_RETURN_TYPE
-#ifdef __STDC__
-reap(int sig)
-#else
+static RETSIGTYPE
reap(sig)
- int sig;
-#endif
+ int sig;
{
int oerrno = errno;
-#ifdef POSIX
+#ifdef _POSIX_VERSION
int waitb;
while (waitpid(-1, &waitb, WNOHANG) == 0) ;
#else
@@ -719,40 +634,39 @@ reap(sig)
#endif
errno = oerrno;
- SIG_RETURN;
}
static void
do_reset()
{
- int oerrno = errno;
-#ifdef POSIX
- sigset_t mask, omask;
+ int oerrno = errno;
+#ifdef _POSIX_VERSION
+ sigset_t mask, omask;
#else
- int omask;
+ int omask;
#endif
#if 0
- zdbug((LOG_DEBUG,"do_reset()"));
+ zdbug((LOG_DEBUG,"do_reset()"));
#endif
-#ifdef POSIX
- sigemptyset(&mask);
- sigaddset(&mask, SIGHUP);
- sigprocmask(SIG_BLOCK, &mask, &omask);
+#ifdef _POSIX_VERSION
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGHUP);
+ sigprocmask(SIG_BLOCK, &mask, &omask);
#else
- omask = sigblock(sigmask(SIGHUP));
+ omask = sigblock(sigmask(SIGHUP));
#endif
- /* reset various things in the server's state */
- subscr_reset();
- server_reset();
- access_reinit();
- syslog (LOG_INFO, "restart completed");
- doreset = 0;
- errno = oerrno;
-#ifdef POSIX
- sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
+ /* reset various things in the server's state */
+ subscr_reset();
+ server_reset();
+ access_reinit();
+ syslog(LOG_INFO, "restart completed");
+ doreset = 0;
+ errno = oerrno;
+#ifdef _POSIX_VERSION
+ sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
#else
- sigsetmask(omask);
+ sigsetmask(omask);
#endif
}
@@ -764,40 +678,42 @@ do_reset()
static void
detach()
{
- /* detach from terminal and fork. */
- register int i;
- register long size;
+ /* detach from terminal and fork. */
+ int i;
+ long size;
-#ifdef POSIX
- size = sysconf(_SC_OPEN_MAX);
+#ifdef _POSIX_VERSION
+ size = sysconf(_SC_OPEN_MAX);
#else
- size = getdtablesize();
-#endif
- /* profiling seems to get confused by fork() */
- MONCONTROL (0);
- i = fork ();
- MONCONTROL (1);
- if (i) {
- if (i < 0)
- perror("fork");
- exit(0);
- }
+ size = getdtablesize();
+#endif
+ /* profiling seems to get confused by fork() */
+ i = fork ();
+ if (i) {
+ if (i < 0)
+ perror("fork");
+ exit(0);
+ }
- for (i = 0; i < size; i++) {
- (void) close(i);
- }
- i = open("/dev/tty", O_RDWR, 666);
- (void) ioctl(i, TIOCNOTTY, (caddr_t) 0);
- (void) close(i);
-#ifdef POSIX
- (void) setsid();
+ for (i = 0; i < size; i++)
+ close(i);
+
+ i = open("/dev/tty", O_RDWR, 666);
+#ifdef TIOCNOTTY /* Only necessary on old systems. */
+ ioctl(i, TIOCNOTTY, NULL);
#endif
-}
+ close(i);
+#ifdef _POSIX_VERSION
+ setsid();
#endif
+}
+#endif /* not DEBUG */
static void
read_from_dump(dumpfile)
- char *dumpfile;
+ char *dumpfile;
{
- return;
+ /* Not yet implemented. */
+ return;
}
+