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)) {
287 if (errno != EEXIST) {
291 if (symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
292 AFSDIR_CLIENT_CELLSERVDB_FILEPATH)) {
293 if (errno != EEXIST) {
297 #endif /* AFS_NT40_ENV */
299 if (MakeDir(coredir))
305 /* strip the \\n from the end of the line, if it is present */
307 StripLine(char *abuffer)
311 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
313 return 0; /* null string, no last character to check */
314 tp--; /* aim at last character */
320 /* write one bnode's worth of entry into the file */
322 bzwrite(struct bnode *abnode, void *arock)
324 struct bztemp *at = (struct bztemp *)arock;
326 char tbuffer[BOZO_BSSIZE];
329 if (abnode->notifier)
330 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
331 abnode->name, abnode->fileGoal, abnode->notifier);
333 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
334 abnode->name, abnode->fileGoal);
336 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
342 fprintf(at->file, "parm %s\n", tbuffer);
344 fprintf(at->file, "end\n");
350 ReadBozoFile(char *aname)
353 char tbuffer[BOZO_BSSIZE];
355 char *instp, *typep, *notifier, *notp;
357 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
360 char *parms[MAXPARMS];
361 char *thisparms[MAXPARMS];
364 /* rename BozoInit to BosServer for the user */
366 /* if BozoInit exists and BosConfig doesn't, try a rename */
367 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
368 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
369 code = rk_rename(AFSDIR_SERVER_BOZINIT_FILEPATH,
370 AFSDIR_SERVER_BOZCONF_FILEPATH);
372 perror("bosconfig rename");
374 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
375 code = rk_rename(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
376 AFSDIR_SERVER_BOZCONF_FILEPATH);
378 perror("bosconfig rename");
382 /* don't do server restarts by default */
383 bozo_nextRestartKT.mask = KTIME_NEVER;
384 bozo_nextRestartKT.hour = 0;
385 bozo_nextRestartKT.min = 0;
386 bozo_nextRestartKT.day = 0;
388 /* restart processes at 5am if their binaries have changed */
389 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
390 bozo_nextDayKT.hour = 5;
391 bozo_nextDayKT.min = 0;
393 for (code = 0; code < MAXPARMS; code++)
396 aname = (char *)bozo_fileName;
397 tfile = fopen(aname, "r");
400 instp = malloc(BOZO_BSSIZE);
401 typep = malloc(BOZO_BSSIZE);
402 notp = malloc(BOZO_BSSIZE);
404 /* ok, read lines giving parms and such from the file */
405 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
407 break; /* all done */
409 if (strncmp(tbuffer, "restarttime", 11) == 0) {
411 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
412 &kthour, &ktmin, &ktsec);
417 /* otherwise we've read in the proper ktime structure; now assign
418 * it and continue processing */
419 bozo_nextRestartKT.mask = ktmask;
420 bozo_nextRestartKT.day = ktday;
421 bozo_nextRestartKT.hour = kthour;
422 bozo_nextRestartKT.min = ktmin;
423 bozo_nextRestartKT.sec = ktsec;
427 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
429 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
430 &ktday, &kthour, &ktmin, &ktsec);
435 /* otherwise we've read in the proper ktime structure; now assign
436 * it and continue processing */
437 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
438 bozo_nextDayKT.day = ktday;
439 bozo_nextDayKT.hour = kthour;
440 bozo_nextDayKT.min = ktmin;
441 bozo_nextDayKT.sec = ktsec;
445 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
446 code = sscanf(tbuffer, "restrictmode %d", &rmode);
451 if (rmode != 0 && rmode != 1) {
455 bozo_isrestricted = rmode;
459 if (strncmp("bnode", tbuffer, 5) != 0) {
465 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
470 } else if (code == 3)
473 memset(thisparms, 0, sizeof(thisparms));
475 for (i = 0; i < MAXPARMS; i++) {
476 /* now read the parms, until we see an "end" line */
477 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
483 if (!strncmp(tbuffer, "end", 3))
485 if (strncmp(tbuffer, "parm ", 5)) {
487 goto fail; /* no "parm " either */
489 if (!parms[i]) /* make sure there's space */
490 parms[i] = malloc(BOZO_BSSIZE);
491 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
492 thisparms[i] = parms[i];
495 /* ok, we have the type and parms, now create the object */
497 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
498 thisparms[2], thisparms[3], thisparms[4], notifier,
499 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
503 /* bnode created in 'temporarily shutdown' state;
504 * check to see if we are supposed to run this guy,
505 * and if so, start the process up */
507 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
509 bnode_SetStat(tb, BSTAT_SHUTDOWN);
520 for (i = 0; i < MAXPARMS; i++)
528 /* write a new bozo file */
530 WriteBozoFile(char *aname)
533 char tbuffer[AFSDIR_PATH_MAX];
538 aname = (char *)bozo_fileName;
539 strcpy(tbuffer, aname);
540 strcat(tbuffer, ".NBZ");
541 tfile = fopen(tbuffer, "w");
546 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
547 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
548 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
549 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
550 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
551 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
553 code = bnode_ApplyInstance(bzwrite, &btemp);
554 if (code || (code = ferror(tfile))) { /* something went wrong */
559 /* close the file, check for errors and snap new file into place */
560 if (fclose(tfile) == EOF) {
564 code = rk_rename(tbuffer, aname);
573 bdrestart(struct bnode *abnode, void *arock)
577 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
578 return 0; /* don't restart stopped bnodes */
580 code = bnode_RestartP(abnode);
582 /* restart the dude */
583 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
584 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
585 bnode_SetStat(abnode, BSTAT_NORMAL);
587 bnode_Release(abnode);
588 return 0; /* keep trying all bnodes */
591 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
592 /* lwp to handle system restarts */
594 BozoDaemon(void *unused)
598 /* now initialize the values */
602 now = FT_ApproxTime();
604 if (bozo_restdisable) {
605 bozo_Log("Restricted mode disabled by signal\n");
606 bozo_restdisable = 0;
609 if (bozo_newKTs) { /* need to recompute restart times */
610 bozo_newKTs = 0; /* done for a while */
611 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
612 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
615 /* see if we should do a restart */
616 if (now > nextRestart) {
617 SBOZO_ReBozo(0); /* doesn't come back */
620 /* see if we should restart a server */
622 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
624 /* call the bnode restartp function, and restart all that require it */
625 bnode_ApplyInstance(bdrestart, 0);
637 int s, sb_max, ipfragttl;
641 f = popen("/usr/sbin/no -o sb_max", "r");
642 s = fscanf(f, "sb_max = %d", &sb_max);
646 f = popen("/usr/sbin/no -o ipfragttl", "r");
647 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
657 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
665 make_pid_filename(char *ainst, char *aname)
670 if (aname && *aname) {
671 r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
672 if (r < 0 || buffer == NULL)
673 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
676 r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
677 if (r < 0 || buffer == NULL)
678 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
685 * Write a file containing the pid of the named process.
687 * @param ainst instance name
688 * @param aname sub-process name of the instance, may be null
689 * @param apid process id of the newly started process
694 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
697 char *pidfile = NULL;
700 pidfile = make_pid_filename(ainst, aname);
704 if ((fp = fopen(pidfile, "w")) == NULL) {
705 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
709 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
712 if (fclose(fp) != 0) {
720 * Clean a pid file for a process which just exited.
722 * @param ainst instance name
723 * @param aname sub-process name of the instance, may be null
728 bozo_DeletePidFile(char *ainst, char *aname)
730 char *pidfile = NULL;
731 pidfile = make_pid_filename(ainst, aname);
740 * Create the rxbind file of this bosserver.
742 * @param host bind address of this server
747 bozo_CreateRxBindFile(afs_uint32 host)
752 afs_inet_ntoa_r(host, buffer);
753 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
754 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
755 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
756 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
758 /* If listening on any interface, write the loopback interface
759 to the rxbind file to give local scripts a usable addresss. */
760 if (host == htonl(INADDR_ANY)) {
761 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
763 fprintf(fp, "%s\n", buffer);
768 /* start a process and monitor it */
770 #include "AFS_component_version_number.c"
773 main(int argc, char **argv, char **envp)
775 struct rx_service *tservice;
777 struct afsconf_dir *tdir;
780 char namebuf[AFSDIR_PATH_MAX];
782 afs_uint32 host = htonl(INADDR_ANY);
783 char *auditFileName = NULL;
784 struct rx_securityClass **securityClasses;
785 afs_int32 numClasses;
786 int DoPeerRPCStats = 0;
787 int DoProcessRPCStats = 0;
793 struct sigaction nsa;
795 /* for some reason, this permits user-mode RX to run a lot faster.
796 * we do it here in the bosserver, so we don't have to do it
797 * individually in each server.
802 * The following signal action for AIX is necessary so that in case of a
803 * crash (i.e. core is generated) we can include the user's data section
804 * in the core dump. Unfortunately, by default, only a partial core is
805 * generated which, in many cases, isn't too useful.
807 sigemptyset(&nsa.sa_mask);
808 nsa.sa_handler = SIG_DFL;
809 nsa.sa_flags = SA_FULLDUMP;
810 sigaction(SIGSEGV, &nsa, NULL);
811 sigaction(SIGABRT, &nsa, NULL);
814 signal(SIGFPE, bozo_insecureme);
817 /* Initialize winsock */
818 if (afs_winsockInit() < 0) {
819 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
820 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
825 /* Initialize dirpaths */
826 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
828 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
830 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
835 /* some path inits */
836 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
837 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
839 /* initialize the list of dirpaths that the bosserver has
840 * an interest in monitoring */
843 #if defined(AFS_SGI_ENV)
844 /* offer some protection if AFS isn't loaded */
845 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
846 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
852 /* save args for restart */
854 bozo_argv = malloc((argc+1) * sizeof(char*));
856 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
859 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
860 bozo_argv[bozo_argc] = NULL; /* null terminate list */
861 #endif /* AFS_NT40_ENV */
864 for (code = 1; code < argc; code++) {
866 bozo_argv[code] = argv[code];
867 #endif /* AFS_NT40_ENV */
868 if (strcmp(argv[code], "-noauth") == 0) {
869 /* set noauth flag */
871 } else if (strcmp(argv[code], "-log") == 0) {
872 /* set extra logging flag */
876 else if (strcmp(argv[code], "-syslog") == 0) {
877 /* set syslog logging flag */
879 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
881 DoSyslogFacility = atoi(argv[code] + 8);
882 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
883 if (strcmp((argv[code]+7), "none") == 0)
886 DoCore = (argv[code]+7);
887 } else if (strcmp(argv[code], "-nofork") == 0) {
891 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
893 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
894 DoProcessRPCStats = 1;
896 else if (strcmp(argv[code], "-restricted") == 0) {
897 bozo_isrestricted = 1;
899 else if (strcmp(argv[code], "-rxbind") == 0) {
902 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
903 rxkadDisableDotCheck = 1;
905 else if (!strcmp(argv[code], "-rxmaxmtu")) {
906 if ((code + 1) >= argc) {
907 fprintf(stderr, "missing argument for -rxmaxmtu\n");
910 rxMaxMTU = atoi(argv[++code]);
912 else if (strcmp(argv[code], "-auditlog") == 0) {
913 auditFileName = argv[++code];
915 } else if (strcmp(argv[code], "-audit-interface") == 0) {
916 char *interface = argv[++code];
918 if (osi_audit_interface(interface)) {
919 printf("Invalid audit interface '%s'\n", interface);
922 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
923 DoPidFiles = (argv[code]+10);
924 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
925 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
929 /* hack to support help flag */
932 printf("Usage: bosserver [-noauth] [-log] "
933 "[-auditlog <log path>] "
934 "[-audit-interface <file|sysvmq> (default is file)] "
935 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
936 "[-syslog[=FACILITY]] "
938 "[-enable_peer_stats] [-enable_process_stats] "
939 "[-cores=<none|path>] \n"
940 "[-pidfiles[=path]] "
941 "[-nofork] " "[-help]\n");
943 printf("Usage: bosserver [-noauth] [-log] "
944 "[-auditlog <log path>] "
945 "[-audit-interface <file|sysvmq> (default is file)] "
946 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
948 "[-enable_peer_stats] [-enable_process_stats] "
949 "[-cores=<none|path>] \n"
950 "[-pidfiles[=path]] "
959 osi_audit_file(auditFileName);
963 if (geteuid() != 0) {
964 printf("bosserver: must be run as root.\n");
971 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
972 !(S_ISFIFO(sb.st_mode)))
975 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
976 strcat(namebuf, ".old");
977 rk_rename(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
978 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
980 printf("bosserver: can't initialize log file (%s).\n",
981 AFSDIR_SERVER_BOZLOG_FILEPATH);
984 /* keep log closed normally, so can be removed */
985 fclose(bozo_logFile);
988 openlog("bosserver", LOG_PID, DoSyslogFacility);
993 * go into the background and remove our controlling tty, close open
1000 printf("bosserver: warning - daemon() returned code %d\n", errno);
1002 #endif /* ! AFS_NT40_ENV */
1004 /* create useful dirs */
1005 i = CreateDirs(DoCore);
1007 printf("bosserver: could not set up directories, code %d\n", i);
1011 /* Write current state of directory permissions to log file */
1014 /* chdir to AFS log directory */
1018 i = chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1020 printf("bosserver: could not change to %s, code %d\n",
1021 DoCore ? DoCore : AFSDIR_SERVER_LOGS_DIRPATH, errno);
1025 /* try to read the key from the config file */
1026 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1028 /* try to create local cell config file */
1029 struct afsconf_cell tcell;
1030 strcpy(tcell.name, "localcell");
1031 tcell.numServers = 1;
1032 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1034 bozo_Log("failed to get hostname, code %d\n", errno);
1037 if (tcell.hostName[0][0] == 0) {
1038 bozo_Log("host name not set, can't start\n");
1039 bozo_Log("try the 'hostname' command\n");
1042 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1044 afsconf_SetCellInfo(NULL, AFSDIR_SERVER_ETC_DIRPATH,
1048 ("could not create cell database in '%s' (code %d), quitting\n",
1049 AFSDIR_SERVER_ETC_DIRPATH, code);
1052 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1055 ("failed to open newly-created cell database, quitting\n");
1059 /* opened the cell databse */
1060 bozo_confdir = tdir;
1062 code = bnode_Init();
1064 printf("bosserver: could not init bnode package, code %d\n", code);
1068 bnode_Register("fs", &fsbnode_ops, 3);
1069 bnode_Register("dafs", &dafsbnode_ops, 4);
1070 bnode_Register("simple", &ezbnode_ops, 1);
1071 bnode_Register("cron", &cronbnode_ops, 2);
1073 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1076 getrlimit(RLIMIT_CORE, &rlp);
1080 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1081 setrlimit(RLIMIT_CORE, &rlp);
1082 getrlimit(RLIMIT_CORE, &rlp);
1083 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1087 /* Read init file, starting up programs. Also starts watcher threads. */
1088 if ((code = ReadBozoFile(0))) {
1090 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1091 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1097 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1098 AFSDIR_SERVER_NETINFO_FILEPATH) {
1100 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
1101 ADDRSPERSITE, reason,
1102 AFSDIR_SERVER_NETINFO_FILEPATH,
1103 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1105 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1108 host = SHostAddrs[0];
1110 for (i = 0; i < 10; i++) {
1112 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1114 code = rx_Init(htons(AFSCONF_NANNYPORT));
1117 bozo_Log("can't initialize rx: code=%d\n", code);
1123 bozo_Log("Bos giving up, can't initialize rx\n");
1127 /* Set some rx config */
1129 rx_enablePeerRPCStats();
1130 if (DoProcessRPCStats)
1131 rx_enableProcessRPCStats();
1133 /* Disable jumbograms */
1136 if (rxMaxMTU != -1) {
1137 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1138 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1143 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1144 /* param */ NULL , "bozo-the-clown", &bozo_pid);
1146 bozo_Log("Failed to create daemon thread\n");
1150 /* initialize audit user check */
1151 osi_audit_set_user_check(bozo_confdir, bozo_IsLocalRealmMatch);
1153 bozo_CreateRxBindFile(host); /* for local scripts */
1155 /* allow super users to manage RX statistics */
1156 rx_SetRxStatUserOk(bozo_rxstat_userok);
1158 afsconf_SetNoAuthFlag(tdir, noAuth);
1159 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1162 bozo_CreatePidFile("bosserver", NULL, getpid());
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(const 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);