From bdf6192509ca79baacda8ddf79112647bd3c0791 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Fri, 14 May 2010 16:03:32 -0400 Subject: [PATCH] bosserver force corefiles override system resource limits so we get corefiles Change-Id: I50f228d709090c8275bed2fc2958653c43a0a026 Change-Id: I5b5e8c6a5e02ed0b28610949eb81f6345357969e Reviewed-on: http://gerrit.openafs.org/1959 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear --- acinclude.m4 | 4 ++-- doc/man-pages/pod8/bosserver.pod | 6 +++++ src/bozo/bnode.c | 38 +++++++++++++++++++----------- src/bozo/bosserver.c | 40 +++++++++++++++++++++++++++++--- 4 files changed, 70 insertions(+), 18 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index d2cb0f58e..bf538fb88 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1222,7 +1222,7 @@ AC_CHECK_HEADERS(stdlib.h string.h unistd.h fcntl.h sys/time.h sys/file.h grp.h) AC_CHECK_HEADERS(netinet/in.h netdb.h sys/fcntl.h sys/mnttab.h sys/mntent.h) AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h sys/fstyp.h) AC_CHECK_HEADERS(sys/mount.h strings.h termios.h signal.h sys/pag.h) -AC_CHECK_HEADERS(windows.h direct.h sys/ipc.h) +AC_CHECK_HEADERS(windows.h direct.h sys/ipc.h sys/resource.h) AC_CHECK_HEADERS(security/pam_modules.h ucontext.h regex.h sys/statvfs.h sys/statfs.h sys/bitypes.h) AC_CHECK_HEADERS(linux/errqueue.h,,,[#include ]) AC_CHECK_HEADERS(et/com_err.h) @@ -1264,7 +1264,7 @@ else fi AC_SUBST(BUILD_LOGIN) -AC_CHECK_FUNCS(snprintf strlcat strlcpy flock) +AC_CHECK_FUNCS(snprintf strlcat strlcpy flock getrlimit) AC_CHECK_FUNCS(setprogname getprogname sigaction mkstemp vsnprintf strerror strcasestr) AC_CHECK_FUNCS(setvbuf vsyslog getcwd) AC_CHECK_FUNCS(regcomp regexec regerror) diff --git a/doc/man-pages/pod8/bosserver.pod b/doc/man-pages/pod8/bosserver.pod index 8c7181df8..5c8a2f47b 100644 --- a/doc/man-pages/pod8/bosserver.pod +++ b/doc/man-pages/pod8/bosserver.pod @@ -10,6 +10,7 @@ bosserver - Initializes the BOS Server B [B<-noauth>] [B<-log>] [B<-enable_peer_stats>] S<<< [B<-auditlog> >] >>> [B<-audit-interface> (file | sysvmq)] [B<-enable_process_stats>] [B<-allow-dotted-principals>] + [B<-cores=>(none|>)] [B<-restricted>] [B<-help>] =for html @@ -117,6 +118,11 @@ Records in the F file the names of all users who successfully issue a privileged B command (one that requires being listed in the F file). +=item B<-cores=>none|> + +The argument none turns off core file generation. Otherwise, the +argument is a path where core files will be stored. + =item B<-auditlog> > Turns on audit logging, and sets the path for the audit log. The audit diff --git a/src/bozo/bnode.c b/src/bozo/bnode.c index 38ad7c27b..7596cadd3 100644 --- a/src/bozo/bnode.c +++ b/src/bozo/bnode.c @@ -57,6 +57,7 @@ static struct bnode_stats { int weirdPids; } bnode_stats; +extern const char *DoCore; #ifndef AFS_NT40_ENV extern char **environ; /* env structure */ #endif @@ -86,7 +87,12 @@ RememberProcName(register struct bnode_proc *ap) int bnode_CoreName(register struct bnode *abnode, char *acoreName, char *abuffer) { - strcpy(abuffer, AFSDIR_SERVER_CORELOG_FILEPATH); + if (DoCore) { + strcpy(abuffer, DoCore); + strcat(abuffer, "/"); + strcat(abuffer, AFSDIR_CORE_FILE); + } else + strcpy(abuffer, AFSDIR_SERVER_CORELOG_FILEPATH); if (acoreName) { strcat(abuffer, acoreName); strcat(abuffer, "."); @@ -102,7 +108,7 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc { char tbuffer[256]; struct stat tstat; - register afs_int32 code; + register afs_int32 code = 0; char *corefile = NULL; #ifdef BOZO_SAVE_CORES struct timeval Start; @@ -112,14 +118,23 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc /* Linux always appends the PID to core dumps from threaded processes, so * we have to scan the directory to find core files under another name. */ - code = stat(AFSDIR_SERVER_CORELOG_FILEPATH, &tstat); + if (DoCore) { + strcpy(tbuffer, DoCore); + strcat(tbuffer, "/"); + strcat(tbuffer, AFSDIR_CORE_FILE); + } else + code = stat(AFSDIR_SERVER_CORELOG_FILEPATH, &tstat); if (code) { DIR *logdir; struct dirent *file; size_t length; unsigned long pid; + const char *coredir = AFSDIR_LOGS_DIR; + + if (DoCore) + coredir = DoCore; - logdir = opendir(AFSDIR_LOGS_DIR); + logdir = opendir(coredir); if (logdir == NULL) return; while ((file = readdir(logdir)) != NULL) { @@ -127,19 +142,20 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc continue; pid = atol(file->d_name + 5); if (pid == aproc->pid) { - length = strlen(AFSDIR_LOGS_DIR) + strlen(file->d_name) + 2; + length = strlen(coredir) + strlen(file->d_name) + 2; corefile = malloc(length); if (corefile == NULL) { closedir(logdir); return; } - snprintf(corefile, length, "%s/%s", AFSDIR_LOGS_DIR, - file->d_name); + snprintf(corefile, length, "%s/%s", coredir, file->d_name); code = 0; break; } } closedir(logdir); + } else { + corefile = strdup(tbuffer); } if (code) return; @@ -153,12 +169,8 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc TimeFields->tm_hour, TimeFields->tm_min, TimeFields->tm_sec); strcpy(tbuffer, FileName); #endif - if (corefile == NULL) - code = renamefile(AFSDIR_SERVER_CORELOG_FILEPATH, tbuffer); - else { - code = renamefile(corefile, tbuffer); - free(corefile); - } + code = renamefile(corefile, tbuffer); + free(corefile); } int diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index 52b9088f9..6a62302ba 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -23,6 +23,12 @@ #include #include #include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif #ifdef AFS_NT40_ENV #include #include @@ -61,6 +67,7 @@ static PROCESS bozo_pid; const char *bozo_fileName; FILE *bozo_logFile; +const char *DoCore; int DoLogging = 0; int DoSyslog = 0; #ifndef AFS_NT40_ENV @@ -186,7 +193,7 @@ MakeDir(const char *adir) /* create all the bozo dirs */ static int -CreateDirs(void) +CreateDirs(const char *coredir) { if ((!strncmp (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH, @@ -219,6 +226,8 @@ CreateDirs(void) symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH, AFSDIR_CLIENT_CELLSERVDB_FILEPATH); #endif /* AFS_NT40_ENV */ + if (coredir) + MakeDir(coredir); return 0; } @@ -772,6 +781,7 @@ main(int argc, char **argv, char **envp) /* some path inits */ bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH; + DoCore = AFSDIR_SERVER_LOGS_DIRPATH; /* initialize the list of dirpaths that the bosserver has * an interest in monitoring */ @@ -801,6 +811,11 @@ main(int argc, char **argv, char **envp) } else if (strncmp(argv[code], "-syslog=", 8) == 0) { DoSyslog = 1; DoSyslogFacility = atoi(argv[code] + 8); + } else if (strncmp(argv[code], "-cores=", 7) == 0) { + if (strcmp((argv[code]+7), "none") == 0) + DoCore = 0; + else + DoCore = (argv[code]+7); } else if (strcmp(argv[code], "-nofork") == 0) { nofork = 1; } @@ -855,6 +870,7 @@ main(int argc, char **argv, char **envp) "[-rxmaxmtu ] [-rxbind] [-allow-dotted-principals]" "[-syslog[=FACILITY]] " "[-enable_peer_stats] [-enable_process_stats] " + "[-cores=] \n" "[-nofork] " "[-help]\n"); #else printf("Usage: bosserver [-noauth] [-log] " @@ -862,6 +878,7 @@ main(int argc, char **argv, char **envp) "[-audit-interafce (default is file)] " "[-rxmaxmtu ] [-rxbind] [-allow-dotted-principals]" "[-enable_peer_stats] [-enable_process_stats] " + "[-cores=] \n" "[-help]\n"); #endif fflush(stdout); @@ -892,10 +909,13 @@ main(int argc, char **argv, char **envp) bnode_Register("cron", &cronbnode_ops, 2); /* create useful dirs */ - CreateDirs(); + CreateDirs(DoCore); /* chdir to AFS log directory */ - chdir(AFSDIR_SERVER_LOGS_DIRPATH); + if (DoCore) + chdir(DoCore); + else + chdir(AFSDIR_SERVER_LOGS_DIRPATH); #if 0 fputs(AFS_GOVERNMENT_MESSAGE, stdout); @@ -934,6 +954,20 @@ main(int argc, char **argv, char **envp) #endif } +#if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT) + { + struct rlimit rlp; + getrlimit(RLIMIT_CORE, &rlp); + if (!DoCore) + rlp.rlim_cur = 0; + else + rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY; + setrlimit(RLIMIT_CORE, &rlp); + getrlimit(RLIMIT_CORE, &rlp); + bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max); + } +#endif + /* Write current state of directory permissions to log file */ DirAccessOK(); -- 2.39.5