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>
18 #ifdef IGNORE_SOME_GCC_WARNINGS
20 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
26 #ifdef HAVE_SYS_RESOURCE_H
27 #include <sys/resource.h>
31 #define PATH_DELIM '\\'
33 #include <WINNT/afsevent.h>
34 #endif /* AFS_NT40_ENV */
36 #define PATH_DELIM '/'
39 #include <rx/rx_globals.h>
41 #include <rx/rxstat.h>
43 #include <afs/ktime.h>
44 #include <afs/afsutil.h>
45 #include <afs/fileutil.h>
46 #include <afs/audit.h>
47 #include <afs/cellconfig.h>
49 #if defined(AFS_SGI_ENV)
50 #include <afs/afs_args.h>
55 #include "bnode_internal.h"
56 #include "bosprototypes.h"
58 #define BOZO_LWP_STACKSIZE 16000
59 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
61 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
62 static PROCESS bozo_pid;
63 const char *bozo_fileName;
66 static int bozo_argc = 0;
67 static char** bozo_argv = NULL;
73 const char *DoPidFiles = NULL;
75 int DoSyslogFacility = LOG_DAEMON;
77 static afs_int32 nextRestart;
78 static afs_int32 nextDay;
80 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
83 int rxkadDisableDotCheck = 0;
85 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
86 afs_uint32 SHostAddrs[ADDRSPERSITE];
88 int bozo_isrestricted = 0;
89 int bozo_restdisable = 0;
92 bozo_insecureme(int sig)
94 signal(SIGFPE, bozo_insecureme);
95 bozo_isrestricted = 0;
103 /* check whether caller is authorized to manage RX statistics */
105 bozo_rxstat_userok(struct rx_call *call)
107 return afsconf_SuperUser(bozo_confdir, call, NULL);
111 * Return true if this name is a member of the local realm.
114 bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
116 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
117 afs_int32 islocal = 0; /* default to no */
120 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
122 bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
123 code, name, inst, cell);
128 /* restart bozo process */
133 /* exit with restart code; SCM integrator process will restart bosserver with
134 the same arguments */
135 exit(BOSEXIT_RESTART);
137 /* exec new bosserver process */
140 /* close random fd's */
141 for (i = 3; i < 64; i++) {
145 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
147 execv(bozo_argv[0], bozo_argv); /* should not return */
149 #endif /* AFS_NT40_ENV */
153 * Make directory with parents.
155 * \param[in] adir directory path to create
156 * \param[in] areqPerm permissions to set on the last component of adir
157 * \return 0 on success
160 MakeDirParents(const char *adir, int areqPerm)
166 int parent_perm = 0777; /* use umask for parent perms */
174 /* strip trailing slashes */
180 while (p != tdir && *p == PATH_DELIM) {
186 /* skip drive letter */
187 if (isalpha(p[0]) && p[1] == ':') {
191 /* skip leading slashes */
192 while (*p == PATH_DELIM) {
196 /* create parent directories with default perms */
197 p = strchr(p, PATH_DELIM);
200 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
201 if (mkdir(tdir, parent_perm) != 0) {
208 /* skip back to back slashes */
209 while (*p == PATH_DELIM) {
212 p = strchr(p, PATH_DELIM);
215 /* set required perms on the last path component */
216 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
217 if (mkdir(tdir, areqPerm) != 0) {
227 /* make sure a dir exists */
229 MakeDir(const char *adir)
233 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
236 reqPerm = GetRequiredDirPerm(adir);
239 code = MakeDirParents(adir, reqPerm);
245 /* create all the bozo dirs */
247 CreateDirs(const char *coredir)
250 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
251 strlen(AFSDIR_USR_DIRPATH)))
254 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
255 strlen(AFSDIR_USR_DIRPATH)))) {
256 if (MakeDir(AFSDIR_USR_DIRPATH))
260 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
261 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
262 if (MakeDir(AFSDIR_SERVER_AFS_DIRPATH))
265 if (MakeDir(AFSDIR_SERVER_BIN_DIRPATH))
267 if (MakeDir(AFSDIR_SERVER_ETC_DIRPATH))
269 if (MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH))
271 if (MakeDir(AFSDIR_SERVER_DB_DIRPATH))
273 if (MakeDir(AFSDIR_SERVER_LOGS_DIRPATH))
277 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
278 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
279 if (MakeDir(AFSDIR_CLIENT_VICE_DIRPATH))
282 if (MakeDir(AFSDIR_CLIENT_ETC_DIRPATH))
285 if (symlink(AFSDIR_SERVER_THISCELL_FILEPATH,
286 AFSDIR_CLIENT_THISCELL_FILEPATH))
288 if (symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
289 AFSDIR_CLIENT_CELLSERVDB_FILEPATH))
291 #endif /* AFS_NT40_ENV */
293 if (MakeDir(coredir))
299 /* strip the \\n from the end of the line, if it is present */
301 StripLine(char *abuffer)
305 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
307 return 0; /* null string, no last character to check */
308 tp--; /* aim at last character */
314 /* write one bnode's worth of entry into the file */
316 bzwrite(struct bnode *abnode, void *arock)
318 struct bztemp *at = (struct bztemp *)arock;
320 char tbuffer[BOZO_BSSIZE];
323 if (abnode->notifier)
324 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
325 abnode->name, abnode->fileGoal, abnode->notifier);
327 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
328 abnode->name, abnode->fileGoal);
330 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
336 fprintf(at->file, "parm %s\n", tbuffer);
338 fprintf(at->file, "end\n");
344 ReadBozoFile(char *aname)
347 char tbuffer[BOZO_BSSIZE];
349 char *instp, *typep, *notifier, *notp;
351 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
354 char *parms[MAXPARMS];
355 char *thisparms[MAXPARMS];
358 /* rename BozoInit to BosServer for the user */
360 /* if BozoInit exists and BosConfig doesn't, try a rename */
361 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
362 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
363 code = rk_rename(AFSDIR_SERVER_BOZINIT_FILEPATH,
364 AFSDIR_SERVER_BOZCONF_FILEPATH);
366 perror("bosconfig rename");
368 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
369 code = rk_rename(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
370 AFSDIR_SERVER_BOZCONF_FILEPATH);
372 perror("bosconfig rename");
376 /* don't do server restarts by default */
377 bozo_nextRestartKT.mask = KTIME_NEVER;
378 bozo_nextRestartKT.hour = 0;
379 bozo_nextRestartKT.min = 0;
380 bozo_nextRestartKT.day = 0;
382 /* restart processes at 5am if their binaries have changed */
383 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
384 bozo_nextDayKT.hour = 5;
385 bozo_nextDayKT.min = 0;
387 for (code = 0; code < MAXPARMS; code++)
390 aname = (char *)bozo_fileName;
391 tfile = fopen(aname, "r");
394 instp = malloc(BOZO_BSSIZE);
395 typep = malloc(BOZO_BSSIZE);
396 notp = malloc(BOZO_BSSIZE);
398 /* ok, read lines giving parms and such from the file */
399 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
401 break; /* all done */
403 if (strncmp(tbuffer, "restarttime", 11) == 0) {
405 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
406 &kthour, &ktmin, &ktsec);
411 /* otherwise we've read in the proper ktime structure; now assign
412 * it and continue processing */
413 bozo_nextRestartKT.mask = ktmask;
414 bozo_nextRestartKT.day = ktday;
415 bozo_nextRestartKT.hour = kthour;
416 bozo_nextRestartKT.min = ktmin;
417 bozo_nextRestartKT.sec = ktsec;
421 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
423 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
424 &ktday, &kthour, &ktmin, &ktsec);
429 /* otherwise we've read in the proper ktime structure; now assign
430 * it and continue processing */
431 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
432 bozo_nextDayKT.day = ktday;
433 bozo_nextDayKT.hour = kthour;
434 bozo_nextDayKT.min = ktmin;
435 bozo_nextDayKT.sec = ktsec;
439 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
440 code = sscanf(tbuffer, "restrictmode %d", &rmode);
445 if (rmode != 0 && rmode != 1) {
449 bozo_isrestricted = rmode;
453 if (strncmp("bnode", tbuffer, 5) != 0) {
459 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
464 } else if (code == 3)
467 memset(thisparms, 0, sizeof(thisparms));
469 for (i = 0; i < MAXPARMS; i++) {
470 /* now read the parms, until we see an "end" line */
471 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
477 if (!strncmp(tbuffer, "end", 3))
479 if (strncmp(tbuffer, "parm ", 5)) {
481 goto fail; /* no "parm " either */
483 if (!parms[i]) /* make sure there's space */
484 parms[i] = malloc(BOZO_BSSIZE);
485 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
486 thisparms[i] = parms[i];
489 /* ok, we have the type and parms, now create the object */
491 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
492 thisparms[2], thisparms[3], thisparms[4], notifier,
493 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
497 /* bnode created in 'temporarily shutdown' state;
498 * check to see if we are supposed to run this guy,
499 * and if so, start the process up */
501 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
503 bnode_SetStat(tb, BSTAT_SHUTDOWN);
514 for (i = 0; i < MAXPARMS; i++)
522 /* write a new bozo file */
524 WriteBozoFile(char *aname)
527 char tbuffer[AFSDIR_PATH_MAX];
532 aname = (char *)bozo_fileName;
533 strcpy(tbuffer, aname);
534 strcat(tbuffer, ".NBZ");
535 tfile = fopen(tbuffer, "w");
540 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
541 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
542 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
543 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
544 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
545 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
547 code = bnode_ApplyInstance(bzwrite, &btemp);
548 if (code || (code = ferror(tfile))) { /* something went wrong */
553 /* close the file, check for errors and snap new file into place */
554 if (fclose(tfile) == EOF) {
558 code = rk_rename(tbuffer, aname);
567 bdrestart(struct bnode *abnode, void *arock)
571 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
572 return 0; /* don't restart stopped bnodes */
574 code = bnode_RestartP(abnode);
576 /* restart the dude */
577 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
578 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
579 bnode_SetStat(abnode, BSTAT_NORMAL);
581 bnode_Release(abnode);
582 return 0; /* keep trying all bnodes */
585 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
586 /* lwp to handle system restarts */
588 BozoDaemon(void *unused)
592 /* now initialize the values */
596 now = FT_ApproxTime();
598 if (bozo_restdisable) {
599 bozo_Log("Restricted mode disabled by signal\n");
600 bozo_restdisable = 0;
603 if (bozo_newKTs) { /* need to recompute restart times */
604 bozo_newKTs = 0; /* done for a while */
605 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
606 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
609 /* see if we should do a restart */
610 if (now > nextRestart) {
611 SBOZO_ReBozo(0); /* doesn't come back */
614 /* see if we should restart a server */
616 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
618 /* call the bnode restartp function, and restart all that require it */
619 bnode_ApplyInstance(bdrestart, 0);
631 int s, sb_max, ipfragttl;
635 f = popen("/usr/sbin/no -o sb_max", "r");
636 s = fscanf(f, "sb_max = %d", &sb_max);
640 f = popen("/usr/sbin/no -o ipfragttl", "r");
641 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
651 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
659 make_pid_filename(char *ainst, char *aname)
664 if (aname && *aname) {
665 r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
666 if (r < 0 || buffer == NULL)
667 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
670 r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
671 if (r < 0 || buffer == NULL)
672 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
679 * Write a file containing the pid of the named process.
681 * @param ainst instance name
682 * @param aname sub-process name of the instance, may be null
683 * @param apid process id of the newly started process
688 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
691 char *pidfile = NULL;
694 pidfile = make_pid_filename(ainst, aname);
698 if ((fp = fopen(pidfile, "w")) == NULL) {
699 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
703 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
706 if (fclose(fp) != 0) {
714 * Clean a pid file for a process which just exited.
716 * @param ainst instance name
717 * @param aname sub-process name of the instance, may be null
722 bozo_DeletePidFile(char *ainst, char *aname)
724 char *pidfile = NULL;
725 pidfile = make_pid_filename(ainst, aname);
734 * Create the rxbind file of this bosserver.
736 * @param host bind address of this server
741 bozo_CreateRxBindFile(afs_uint32 host)
746 afs_inet_ntoa_r(host, buffer);
747 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
748 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
749 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
750 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
752 /* If listening on any interface, write the loopback interface
753 to the rxbind file to give local scripts a usable addresss. */
754 if (host == htonl(INADDR_ANY)) {
755 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
757 fprintf(fp, "%s\n", buffer);
762 /* start a process and monitor it */
764 #include "AFS_component_version_number.c"
767 main(int argc, char **argv, char **envp)
769 struct rx_service *tservice;
771 struct afsconf_dir *tdir;
774 char namebuf[AFSDIR_PATH_MAX];
776 afs_uint32 host = htonl(INADDR_ANY);
777 char *auditFileName = NULL;
778 struct rx_securityClass **securityClasses;
779 afs_int32 numClasses;
780 int DoPeerRPCStats = 0;
781 int DoProcessRPCStats = 0;
787 struct sigaction nsa;
789 /* for some reason, this permits user-mode RX to run a lot faster.
790 * we do it here in the bosserver, so we don't have to do it
791 * individually in each server.
796 * The following signal action for AIX is necessary so that in case of a
797 * crash (i.e. core is generated) we can include the user's data section
798 * in the core dump. Unfortunately, by default, only a partial core is
799 * generated which, in many cases, isn't too useful.
801 sigemptyset(&nsa.sa_mask);
802 nsa.sa_handler = SIG_DFL;
803 nsa.sa_flags = SA_FULLDUMP;
804 sigaction(SIGSEGV, &nsa, NULL);
805 sigaction(SIGABRT, &nsa, NULL);
808 signal(SIGFPE, bozo_insecureme);
811 /* Initialize winsock */
812 if (afs_winsockInit() < 0) {
813 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
814 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
819 /* Initialize dirpaths */
820 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
822 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
824 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
829 /* some path inits */
830 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
831 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
833 /* initialize the list of dirpaths that the bosserver has
834 * an interest in monitoring */
837 #if defined(AFS_SGI_ENV)
838 /* offer some protection if AFS isn't loaded */
839 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
840 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
846 /* save args for restart */
848 bozo_argv = malloc((argc+1) * sizeof(char*));
850 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
853 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
854 bozo_argv[bozo_argc] = NULL; /* null terminate list */
855 #endif /* AFS_NT40_ENV */
858 for (code = 1; code < argc; code++) {
860 bozo_argv[code] = argv[code];
861 #endif /* AFS_NT40_ENV */
862 if (strcmp(argv[code], "-noauth") == 0) {
863 /* set noauth flag */
865 } else if (strcmp(argv[code], "-log") == 0) {
866 /* set extra logging flag */
870 else if (strcmp(argv[code], "-syslog") == 0) {
871 /* set syslog logging flag */
873 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
875 DoSyslogFacility = atoi(argv[code] + 8);
876 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
877 if (strcmp((argv[code]+7), "none") == 0)
880 DoCore = (argv[code]+7);
881 } else if (strcmp(argv[code], "-nofork") == 0) {
885 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
887 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
888 DoProcessRPCStats = 1;
890 else if (strcmp(argv[code], "-restricted") == 0) {
891 bozo_isrestricted = 1;
893 else if (strcmp(argv[code], "-rxbind") == 0) {
896 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
897 rxkadDisableDotCheck = 1;
899 else if (!strcmp(argv[code], "-rxmaxmtu")) {
900 if ((code + 1) >= argc) {
901 fprintf(stderr, "missing argument for -rxmaxmtu\n");
904 rxMaxMTU = atoi(argv[++code]);
906 else if (strcmp(argv[code], "-auditlog") == 0) {
907 auditFileName = argv[++code];
909 } else if (strcmp(argv[code], "-audit-interface") == 0) {
910 char *interface = argv[++code];
912 if (osi_audit_interface(interface)) {
913 printf("Invalid audit interface '%s'\n", interface);
916 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
917 DoPidFiles = (argv[code]+10);
918 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
919 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
923 /* hack to support help flag */
926 printf("Usage: bosserver [-noauth] [-log] "
927 "[-auditlog <log path>] "
928 "[-audit-interface <file|sysvmq> (default is file)] "
929 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
930 "[-syslog[=FACILITY]] "
932 "[-enable_peer_stats] [-enable_process_stats] "
933 "[-cores=<none|path>] \n"
934 "[-pidfiles[=path]] "
935 "[-nofork] " "[-help]\n");
937 printf("Usage: bosserver [-noauth] [-log] "
938 "[-auditlog <log path>] "
939 "[-audit-interface <file|sysvmq> (default is file)] "
940 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
942 "[-enable_peer_stats] [-enable_process_stats] "
943 "[-cores=<none|path>] \n"
944 "[-pidfiles[=path]] "
953 osi_audit_file(auditFileName);
957 if (geteuid() != 0) {
958 printf("bosserver: must be run as root.\n");
965 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
966 !(S_ISFIFO(sb.st_mode)))
969 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
970 strcat(namebuf, ".old");
971 rk_rename(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
972 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
974 printf("bosserver: can't initialize log file (%s).\n",
975 AFSDIR_SERVER_BOZLOG_FILEPATH);
978 /* keep log closed normally, so can be removed */
979 fclose(bozo_logFile);
982 openlog("bosserver", LOG_PID, DoSyslogFacility);
987 * go into the background and remove our controlling tty, close open
994 printf("bosserver: warning - daemon() returned code %d\n", errno);
996 #endif /* ! AFS_NT40_ENV */
998 /* create useful dirs */
999 i = CreateDirs(DoCore);
1001 printf("bosserver: could not set up directories, code %d\n", i);
1005 /* Write current state of directory permissions to log file */
1008 /* chdir to AFS log directory */
1012 i = chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1014 printf("bosserver: could not change to %s, code %d\n",
1015 DoCore ? DoCore : AFSDIR_SERVER_LOGS_DIRPATH, errno);
1019 /* try to read the key from the config file */
1020 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1022 /* try to create local cell config file */
1023 struct afsconf_cell tcell;
1024 strcpy(tcell.name, "localcell");
1025 tcell.numServers = 1;
1026 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1028 bozo_Log("failed to get hostname, code %d\n", errno);
1031 if (tcell.hostName[0][0] == 0) {
1032 bozo_Log("host name not set, can't start\n");
1033 bozo_Log("try the 'hostname' command\n");
1036 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1038 afsconf_SetCellInfo(NULL, AFSDIR_SERVER_ETC_DIRPATH,
1042 ("could not create cell database in '%s' (code %d), quitting\n",
1043 AFSDIR_SERVER_ETC_DIRPATH, code);
1046 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1049 ("failed to open newly-created cell database, quitting\n");
1053 /* opened the cell databse */
1054 bozo_confdir = tdir;
1056 code = bnode_Init();
1058 printf("bosserver: could not init bnode package, code %d\n", code);
1062 bnode_Register("fs", &fsbnode_ops, 3);
1063 bnode_Register("dafs", &dafsbnode_ops, 4);
1064 bnode_Register("simple", &ezbnode_ops, 1);
1065 bnode_Register("cron", &cronbnode_ops, 2);
1067 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1070 getrlimit(RLIMIT_CORE, &rlp);
1074 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1075 setrlimit(RLIMIT_CORE, &rlp);
1076 getrlimit(RLIMIT_CORE, &rlp);
1077 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1081 /* Read init file, starting up programs. Also starts watcher threads. */
1082 if ((code = ReadBozoFile(0))) {
1084 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1085 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1091 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1092 AFSDIR_SERVER_NETINFO_FILEPATH) {
1094 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
1095 ADDRSPERSITE, reason,
1096 AFSDIR_SERVER_NETINFO_FILEPATH,
1097 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1099 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1102 host = SHostAddrs[0];
1104 for (i = 0; i < 10; i++) {
1106 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1108 code = rx_Init(htons(AFSCONF_NANNYPORT));
1111 bozo_Log("can't initialize rx: code=%d\n", code);
1117 bozo_Log("Bos giving up, can't initialize rx\n");
1121 /* Set some rx config */
1123 rx_enablePeerRPCStats();
1124 if (DoProcessRPCStats)
1125 rx_enableProcessRPCStats();
1127 /* Disable jumbograms */
1130 if (rxMaxMTU != -1) {
1131 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1132 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1137 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1138 /* param */ NULL , "bozo-the-clown", &bozo_pid);
1140 bozo_Log("Failed to create daemon thread\n");
1144 /* initialize audit user check */
1145 osi_audit_set_user_check(bozo_confdir, bozo_IsLocalRealmMatch);
1147 bozo_CreateRxBindFile(host); /* for local scripts */
1149 /* allow super users to manage RX statistics */
1150 rx_SetRxStatUserOk(bozo_rxstat_userok);
1152 afsconf_SetNoAuthFlag(tdir, noAuth);
1153 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1156 bozo_CreatePidFile("bosserver", NULL, getpid());
1159 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1160 "bozo", securityClasses, numClasses,
1161 BOZO_ExecuteRequest);
1162 rx_SetMinProcs(tservice, 2);
1163 rx_SetMaxProcs(tservice, 4);
1164 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1165 if (rxkadDisableDotCheck) {
1166 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1167 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1171 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1172 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1173 rx_SetMinProcs(tservice, 2);
1174 rx_SetMaxProcs(tservice, 4);
1175 rx_StartServer(1); /* donate this process */
1180 bozo_Log(const char *format, ...)
1186 va_start(ap, format);
1189 #ifndef AFS_NT40_ENV
1190 vsyslog(LOG_INFO, format, ap);
1194 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1197 /* log normally closed, so can be removed */
1199 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1200 if (bozo_logFile == NULL) {
1201 printf("bosserver: WARNING: problem with %s\n",
1202 AFSDIR_SERVER_BOZLOG_FILEPATH);
1203 printf("%s ", tdate);
1204 vprintf(format, ap);
1207 fprintf(bozo_logFile, "%s ", tdate);
1208 vfprintf(bozo_logFile, format, ap);
1210 /* close so rm BosLog works */
1211 fclose(bozo_logFile);