2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
14 #include <afs/procmgmt.h>
17 #ifdef IGNORE_SOME_GCC_WARNINGS
18 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
21 #ifdef HAVE_SYS_RESOURCE_H
22 #include <sys/resource.h>
27 #include <WINNT/afsevent.h>
28 #endif /* AFS_NT40_ENV */
32 #include <rx/rx_globals.h>
34 #include <rx/rxstat.h>
36 #include <afs/ktime.h>
37 #include <afs/afsutil.h>
38 #include <afs/fileutil.h>
39 #include <afs/audit.h>
40 #include <afs/cellconfig.h>
42 #if defined(AFS_SGI_ENV)
43 #include <afs/afs_args.h>
48 #include "bosprototypes.h"
50 #define BOZO_LWP_STACKSIZE 16000
51 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
53 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
54 static PROCESS bozo_pid;
55 const char *bozo_fileName;
61 const char *DoPidFiles = NULL;
63 int DoSyslogFacility = LOG_DAEMON;
65 static afs_int32 nextRestart;
66 static afs_int32 nextDay;
68 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
71 int rxkadDisableDotCheck = 0;
73 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
74 afs_uint32 SHostAddrs[ADDRSPERSITE];
76 int bozo_isrestricted = 0;
77 int bozo_restdisable = 0;
80 bozo_insecureme(int sig)
82 signal(SIGFPE, bozo_insecureme);
83 bozo_isrestricted = 0;
91 /* check whether caller is authorized to manage RX statistics */
93 bozo_rxstat_userok(struct rx_call *call)
95 return afsconf_SuperUser(bozo_confdir, call, NULL);
98 /* restart bozo process */
103 /* exit with restart code; SCM integrator process will restart bosserver */
104 int status = BOSEXIT_RESTART;
106 /* if noauth flag is set, pass "-noauth" to new bosserver */
107 if (afsconf_GetNoAuthFlag(bozo_confdir)) {
108 status |= BOSEXIT_NOAUTH_FLAG;
110 /* if logging is on, pass "-log" to new bosserver */
112 status |= BOSEXIT_LOGGING_FLAG;
114 /* if rxbind is set, pass "-rxbind" to new bosserver */
116 status |= BOSEXIT_RXBIND_FLAG;
120 /* exec new bosserver process */
124 argv[i] = (char *)AFSDIR_SERVER_BOSVR_FILEPATH;
127 /* if noauth flag is set, pass "-noauth" to new bosserver */
128 if (afsconf_GetNoAuthFlag(bozo_confdir)) {
132 /* if logging is on, pass "-log" to new bosserver */
137 /* if rxbind is set, pass "-rxbind" to new bosserver */
143 /* if syslog logging is on, pass "-syslog" to new bosserver */
145 char *arg = (char *)malloc(40); /* enough for -syslog=# */
146 if (DoSyslogFacility != LOG_DAEMON) {
147 snprintf(arg, 40, "-syslog=%d", DoSyslogFacility);
149 strcpy(arg, "-syslog");
156 /* null-terminate argument list */
159 /* close random fd's */
160 for (i = 3; i < 64; i++) {
164 execv(argv[0], argv); /* should not return */
166 #endif /* AFS_NT40_ENV */
169 /* make sure a dir exists */
171 MakeDir(const char *adir)
175 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
178 reqPerm = GetRequiredDirPerm(adir);
182 /* underlying filesystem may not support directory protection */
185 code = mkdir(adir, reqPerm);
192 /* create all the bozo dirs */
194 CreateDirs(const char *coredir)
197 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
198 strlen(AFSDIR_USR_DIRPATH)))
201 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
202 strlen(AFSDIR_USR_DIRPATH)))) {
203 MakeDir(AFSDIR_USR_DIRPATH);
206 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
207 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
208 MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
210 MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
211 MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
212 MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
213 MakeDir(AFSDIR_SERVER_DB_DIRPATH);
214 MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
217 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
218 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
219 MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
221 MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
223 symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
224 symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
225 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
226 #endif /* AFS_NT40_ENV */
232 /* strip the \\n from the end of the line, if it is present */
234 StripLine(char *abuffer)
238 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
240 return 0; /* null string, no last character to check */
241 tp--; /* aim at last character */
247 /* write one bnode's worth of entry into the file */
249 bzwrite(struct bnode *abnode, void *arock)
251 struct bztemp *at = (struct bztemp *)arock;
253 char tbuffer[BOZO_BSSIZE];
256 if (abnode->notifier)
257 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
258 abnode->name, abnode->fileGoal, abnode->notifier);
260 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
261 abnode->name, abnode->fileGoal);
263 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
269 fprintf(at->file, "parm %s\n", tbuffer);
271 fprintf(at->file, "end\n");
277 ReadBozoFile(char *aname)
280 char tbuffer[BOZO_BSSIZE];
282 char *instp, *typep, *notifier, *notp;
284 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
287 char *parms[MAXPARMS];
288 char *thisparms[MAXPARMS];
291 /* rename BozoInit to BosServer for the user */
293 /* if BozoInit exists and BosConfig doesn't, try a rename */
294 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
295 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
297 renamefile(AFSDIR_SERVER_BOZINIT_FILEPATH,
298 AFSDIR_SERVER_BOZCONF_FILEPATH);
300 perror("bosconfig rename");
302 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
304 renamefile(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
305 AFSDIR_SERVER_BOZCONF_FILEPATH);
307 perror("bosconfig rename");
311 /* don't do server restarts by default */
312 bozo_nextRestartKT.mask = KTIME_NEVER;
313 bozo_nextRestartKT.hour = 0;
314 bozo_nextRestartKT.min = 0;
315 bozo_nextRestartKT.day = 0;
317 /* restart processes at 5am if their binaries have changed */
318 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
319 bozo_nextDayKT.hour = 5;
320 bozo_nextDayKT.min = 0;
322 for (code = 0; code < MAXPARMS; code++)
326 aname = (char *)bozo_fileName;
327 tfile = fopen(aname, "r");
330 instp = malloc(BOZO_BSSIZE);
331 typep = malloc(BOZO_BSSIZE);
332 notifier = notp = malloc(BOZO_BSSIZE);
334 /* ok, read lines giving parms and such from the file */
335 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
337 break; /* all done */
339 if (strncmp(tbuffer, "restarttime", 11) == 0) {
341 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
342 &kthour, &ktmin, &ktsec);
347 /* otherwise we've read in the proper ktime structure; now assign
348 * it and continue processing */
349 bozo_nextRestartKT.mask = ktmask;
350 bozo_nextRestartKT.day = ktday;
351 bozo_nextRestartKT.hour = kthour;
352 bozo_nextRestartKT.min = ktmin;
353 bozo_nextRestartKT.sec = ktsec;
357 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
359 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
360 &ktday, &kthour, &ktmin, &ktsec);
365 /* otherwise we've read in the proper ktime structure; now assign
366 * it and continue processing */
367 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
368 bozo_nextDayKT.day = ktday;
369 bozo_nextDayKT.hour = kthour;
370 bozo_nextDayKT.min = ktmin;
371 bozo_nextDayKT.sec = ktsec;
375 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
376 code = sscanf(tbuffer, "restrictmode %d", &rmode);
381 if (rmode != 0 && rmode != 1) {
385 bozo_isrestricted = rmode;
389 if (strncmp("bnode", tbuffer, 5) != 0) {
395 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
400 } else if (code == 3)
403 memset(thisparms, 0, sizeof(thisparms));
405 for (i = 0; i < MAXPARMS; i++) {
406 /* now read the parms, until we see an "end" line */
407 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
413 if (!strncmp(tbuffer, "end", 3))
415 if (strncmp(tbuffer, "parm ", 5)) {
417 goto fail; /* no "parm " either */
419 if (!parms[i]) /* make sure there's space */
420 parms[i] = (char *)malloc(BOZO_BSSIZE);
421 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
422 thisparms[i] = parms[i];
425 /* ok, we have the type and parms, now create the object */
427 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
428 thisparms[2], thisparms[3], thisparms[4], notifier,
429 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
433 /* bnode created in 'temporarily shutdown' state;
434 * check to see if we are supposed to run this guy,
435 * and if so, start the process up */
437 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
439 bnode_SetStat(tb, BSTAT_SHUTDOWN);
450 for (i = 0; i < MAXPARMS; i++)
458 /* write a new bozo file */
460 WriteBozoFile(char *aname)
463 char tbuffer[AFSDIR_PATH_MAX];
468 aname = (char *)bozo_fileName;
469 strcpy(tbuffer, aname);
470 strcat(tbuffer, ".NBZ");
471 tfile = fopen(tbuffer, "w");
476 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
477 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
478 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
479 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
480 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
481 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
483 code = bnode_ApplyInstance(bzwrite, &btemp);
484 if (code || (code = ferror(tfile))) { /* something went wrong */
489 /* close the file, check for errors and snap new file into place */
490 if (fclose(tfile) == EOF) {
494 code = renamefile(tbuffer, aname);
503 bdrestart(struct bnode *abnode, void *arock)
507 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
508 return 0; /* don't restart stopped bnodes */
510 code = bnode_RestartP(abnode);
512 /* restart the dude */
513 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
514 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
515 bnode_SetStat(abnode, BSTAT_NORMAL);
517 bnode_Release(abnode);
518 return 0; /* keep trying all bnodes */
521 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
522 /* lwp to handle system restarts */
524 BozoDaemon(void *unused)
528 /* now initialize the values */
532 now = FT_ApproxTime();
534 if (bozo_restdisable) {
535 bozo_Log("Restricted mode disabled by signal\n");
536 bozo_restdisable = 0;
539 if (bozo_newKTs) { /* need to recompute restart times */
540 bozo_newKTs = 0; /* done for a while */
541 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
542 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
545 /* see if we should do a restart */
546 if (now > nextRestart) {
547 SBOZO_ReBozo(0); /* doesn't come back */
550 /* see if we should restart a server */
552 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
554 /* call the bnode restartp function, and restart all that require it */
555 bnode_ApplyInstance(bdrestart, 0);
567 int s, sb_max, ipfragttl;
571 f = popen("/usr/sbin/no -o sb_max", "r");
572 s = fscanf(f, "sb_max = %d", &sb_max);
576 f = popen("/usr/sbin/no -o ipfragttl", "r");
577 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
587 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
596 * This routine causes the calling process to go into the background and
597 * to lose its controlling tty.
599 * It does not close or otherwise alter the standard file descriptors.
601 * It writes warning messages to the standard error output if certain
602 * fundamental errors occur.
604 * This routine requires
606 * #include <sys/types.h>
607 * #include <sys/stat.h>
609 * #include <unistd.h>
610 * #include <stdlib.h>
612 * and has been tested on:
628 * A process is a process group leader if its process ID
629 * (getpid()) and its process group ID (getpgrp()) are the same.
633 * To create a new session (and thereby lose our controlling
634 * terminal) we cannot be a process group leader.
636 * To guarantee we are not a process group leader, we fork and
637 * let the parent process exit.
640 if (getpid() == getpgrp()) {
645 abort(); /* leave footprints */
649 default: /* parent */
656 * By here, we are not a process group leader, so we can make a
657 * new session and become the session leader.
661 pid_t sid = setsid();
664 static char err[] = "bosserver: WARNING: setsid() failed\n";
665 write(STDERR_FILENO, err, sizeof err - 1);
670 * Once we create a new session, the current process is a
671 * session leader without a controlling tty.
673 * On some systems, the first tty device the session leader
674 * opens automatically becomes the controlling tty for the
677 * So, to guarantee we do not acquire a controlling tty, we fork
678 * and let the parent process exit. The child process is not a
679 * session leader, and so it will not acquire a controlling tty
680 * even if it should happen to open a tty device.
683 if (getpid() == getpgrp()) {
688 abort(); /* leave footprints */
692 default: /* parent */
699 * check that we no longer have a controlling tty
705 fd = open("/dev/tty", O_RDONLY);
709 "bosserver: WARNING: /dev/tty still attached\n";
711 write(STDERR_FILENO, err, sizeof err - 1);
715 #endif /* ! AFS_NT40_ENV */
719 make_pid_filename(char *ainst, char *aname)
724 length = strlen(DoPidFiles) + strlen(ainst) + 6;
725 if (aname && *aname) {
726 length += strlen(aname) + 1;
728 buffer = malloc(length * sizeof(char));
731 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
734 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
737 if (aname && *aname) {
738 snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
741 snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
748 * Write a file containing the pid of the named process.
750 * @param ainst instance name
751 * @param aname sub-process name of the instance, may be null
752 * @param apid process id of the newly started process
757 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
760 char *pidfile = NULL;
763 pidfile = make_pid_filename(ainst, aname);
767 if ((fp = fopen(pidfile, "w")) == NULL) {
768 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
772 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
775 if (fclose(fp) != 0) {
783 * Clean a pid file for a process which just exited.
785 * @param ainst instance name
786 * @param aname sub-process name of the instance, may be null
791 bozo_DeletePidFile(char *ainst, char *aname)
793 char *pidfile = NULL;
794 pidfile = make_pid_filename(ainst, aname);
802 /* start a process and monitor it */
804 #include "AFS_component_version_number.c"
807 main(int argc, char **argv, char **envp)
809 struct rx_service *tservice;
811 struct afsconf_dir *tdir;
814 char namebuf[AFSDIR_PATH_MAX];
816 afs_uint32 host = htonl(INADDR_ANY);
817 char *auditFileName = NULL;
818 struct rx_securityClass **securityClasses;
819 afs_int32 numClasses;
825 struct sigaction nsa;
827 /* for some reason, this permits user-mode RX to run a lot faster.
828 * we do it here in the bosserver, so we don't have to do it
829 * individually in each server.
834 * The following signal action for AIX is necessary so that in case of a
835 * crash (i.e. core is generated) we can include the user's data section
836 * in the core dump. Unfortunately, by default, only a partial core is
837 * generated which, in many cases, isn't too useful.
839 sigemptyset(&nsa.sa_mask);
840 nsa.sa_handler = SIG_DFL;
841 nsa.sa_flags = SA_FULLDUMP;
842 sigaction(SIGSEGV, &nsa, NULL);
843 sigaction(SIGABRT, &nsa, NULL);
846 signal(SIGFPE, bozo_insecureme);
849 /* Initialize winsock */
850 if (afs_winsockInit() < 0) {
851 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
852 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
857 /* Initialize dirpaths */
858 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
860 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
862 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
867 /* some path inits */
868 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
869 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
871 /* initialize the list of dirpaths that the bosserver has
872 * an interest in monitoring */
875 #if defined(AFS_SGI_ENV)
876 /* offer some protection if AFS isn't loaded */
877 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
878 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
884 for (code = 1; code < argc; code++) {
885 if (strcmp(argv[code], "-noauth") == 0) {
886 /* set noauth flag */
888 } else if (strcmp(argv[code], "-log") == 0) {
889 /* set extra logging flag */
893 else if (strcmp(argv[code], "-syslog") == 0) {
894 /* set syslog logging flag */
896 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
898 DoSyslogFacility = atoi(argv[code] + 8);
899 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
900 if (strcmp((argv[code]+7), "none") == 0)
903 DoCore = (argv[code]+7);
904 } else if (strcmp(argv[code], "-nofork") == 0) {
908 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
909 rx_enablePeerRPCStats();
910 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
911 rx_enableProcessRPCStats();
913 else if (strcmp(argv[code], "-restricted") == 0) {
914 bozo_isrestricted = 1;
916 else if (strcmp(argv[code], "-rxbind") == 0) {
919 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
920 rxkadDisableDotCheck = 1;
922 else if (!strcmp(argv[code], "-rxmaxmtu")) {
923 if ((code + 1) >= argc) {
924 fprintf(stderr, "missing argument for -rxmaxmtu\n");
927 rxMaxMTU = atoi(argv[++code]);
928 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
929 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
930 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
931 rxMaxMTU, RX_MIN_PACKET_SIZE,
932 RX_MAX_PACKET_DATA_SIZE);
936 else if (strcmp(argv[code], "-auditlog") == 0) {
937 auditFileName = argv[++code];
939 } else if (strcmp(argv[code], "-audit-interface") == 0) {
940 char *interface = argv[++code];
942 if (osi_audit_interface(interface)) {
943 printf("Invalid audit interface '%s'\n", interface);
946 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
947 DoPidFiles = (argv[code]+10);
948 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
949 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
953 /* hack to support help flag */
956 printf("Usage: bosserver [-noauth] [-log] "
957 "[-auditlog <log path>] "
958 "[-audit-interafce <file|sysvmq> (default is file)] "
959 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
960 "[-syslog[=FACILITY]] "
961 "[-enable_peer_stats] [-enable_process_stats] "
962 "[-cores=<none|path>] \n"
963 "[-pidfiles[=path]] "
964 "[-nofork] " "[-help]\n");
966 printf("Usage: bosserver [-noauth] [-log] "
967 "[-auditlog <log path>] "
968 "[-audit-interafce <file|sysvmq> (default is file)] "
969 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
970 "[-enable_peer_stats] [-enable_process_stats] "
971 "[-cores=<none|path>] \n"
972 "[-pidfiles[=path]] "
981 osi_audit_file(auditFileName);
985 if (geteuid() != 0) {
986 printf("bosserver: must be run as root.\n");
993 printf("bosserver: could not init bnode package, code %d\n", code);
997 bnode_Register("fs", &fsbnode_ops, 3);
998 bnode_Register("dafs", &dafsbnode_ops, 4);
999 bnode_Register("simple", &ezbnode_ops, 1);
1000 bnode_Register("cron", &cronbnode_ops, 2);
1002 /* create useful dirs */
1005 /* chdir to AFS log directory */
1009 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1012 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1016 /* go into the background and remove our controlling tty, close open
1020 #ifndef AFS_NT40_ENV
1023 #endif /* ! AFS_NT40_ENV */
1026 #ifndef AFS_NT40_ENV
1027 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1028 !(S_ISFIFO(sb.st_mode)))
1031 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1032 strcat(namebuf, ".old");
1033 renamefile(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1034 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1035 if (!bozo_logFile) {
1036 printf("bosserver: can't initialize log file (%s).\n",
1037 AFSDIR_SERVER_BOZLOG_FILEPATH);
1040 /* keep log closed normally, so can be removed */
1041 fclose(bozo_logFile);
1043 #ifndef AFS_NT40_ENV
1044 openlog("bosserver", LOG_PID, DoSyslogFacility);
1048 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1051 getrlimit(RLIMIT_CORE, &rlp);
1055 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1056 setrlimit(RLIMIT_CORE, &rlp);
1057 getrlimit(RLIMIT_CORE, &rlp);
1058 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1062 /* Write current state of directory permissions to log file */
1067 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1068 AFSDIR_SERVER_NETINFO_FILEPATH) {
1070 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1071 ADDRSPERSITE, reason,
1072 AFSDIR_SERVER_NETINFO_FILEPATH,
1073 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1075 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1078 host = SHostAddrs[0];
1081 for (i = 0; i < 10; i++) {
1083 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1085 code = rx_Init(htons(AFSCONF_NANNYPORT));
1088 bozo_Log("can't initialize rx: code=%d\n", code);
1094 bozo_Log("Bos giving up, can't initialize rx\n");
1098 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1099 /* param */ NULL , "bozo-the-clown",
1102 /* try to read the key from the config file */
1103 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1105 /* try to create local cell config file */
1106 struct afsconf_cell tcell;
1107 strcpy(tcell.name, "localcell");
1108 tcell.numServers = 1;
1109 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1111 bozo_Log("failed to get hostname, code %d\n", errno);
1114 if (tcell.hostName[0][0] == 0) {
1115 bozo_Log("host name not set, can't start\n");
1116 bozo_Log("try the 'hostname' command\n");
1119 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1121 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1125 ("could not create cell database in '%s' (code %d), quitting\n",
1126 AFSDIR_SERVER_ETC_DIRPATH, code);
1129 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1132 ("failed to open newly-created cell database, quitting\n");
1137 /* read init file, starting up programs */
1138 if ((code = ReadBozoFile(0))) {
1140 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1141 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1145 /* opened the cell databse */
1146 bozo_confdir = tdir;
1148 /* allow super users to manage RX statistics */
1149 rx_SetRxStatUserOk(bozo_rxstat_userok);
1151 afsconf_SetNoAuthFlag(tdir, noAuth);
1152 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1155 bozo_CreatePidFile("bosserver", NULL, getpid());
1158 /* Disable jumbograms */
1161 if (rxMaxMTU != -1) {
1162 rx_SetMaxMTU(rxMaxMTU);
1165 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1166 "bozo", securityClasses, numClasses,
1167 BOZO_ExecuteRequest);
1168 rx_SetMinProcs(tservice, 2);
1169 rx_SetMaxProcs(tservice, 4);
1170 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1171 if (rxkadDisableDotCheck) {
1172 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1173 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1177 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1178 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1179 rx_SetMinProcs(tservice, 2);
1180 rx_SetMaxProcs(tservice, 4);
1181 rx_StartServer(1); /* donate this process */
1186 bozo_Log(char *format, ...)
1192 va_start(ap, format);
1195 #ifndef AFS_NT40_ENV
1196 vsyslog(LOG_INFO, format, ap);
1200 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1203 /* log normally closed, so can be removed */
1205 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1206 if (bozo_logFile == NULL) {
1207 printf("bosserver: WARNING: problem with %s\n",
1208 AFSDIR_SERVER_BOZLOG_FILEPATH);
1209 printf("%s ", tdate);
1210 vprintf(format, ap);
1213 fprintf(bozo_logFile, "%s ", tdate);
1214 vfprintf(bozo_logFile, format, ap);
1216 /* close so rm BosLog works */
1217 fclose(bozo_logFile);