bosserver force corefiles
authorDerrick Brashear <shadow@dementia.org>
Fri, 14 May 2010 20:03:32 +0000 (16:03 -0400)
committerDerrick Brashear <shadow@dementia.org>
Fri, 2 Jul 2010 16:35:36 +0000 (09:35 -0700)
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 <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

acinclude.m4
doc/man-pages/pod8/bosserver.pod
src/bozo/bnode.c
src/bozo/bosserver.c

index d2cb0f5..bf538fb 100644 (file)
@@ -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 <linux/types.h>])
 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)
index 8c7181d..5c8a2f4 100644 (file)
@@ -10,6 +10,7 @@ bosserver - Initializes the BOS Server
 B<bosserver> [B<-noauth>] [B<-log>] [B<-enable_peer_stats>]
     S<<< [B<-auditlog> <I<log path>>] >>> [B<-audit-interface> (file | sysvmq)]
     [B<-enable_process_stats>] [B<-allow-dotted-principals>]
+    [B<-cores=>(none|<I<path>>)]
     [B<-restricted>] [B<-help>]
 
 =for html
@@ -117,6 +118,11 @@ Records in the F</usr/afs/logs/BosLog> file the names of all users who
 successfully issue a privileged B<bos> command (one that requires being
 listed in the F</usr/afs/etc/UserList> file).
 
+=item B<-cores=>none|<I<path>>
+
+The argument none turns off core file generation. Otherwise, the
+argument is a path where core files will be stored.
+
 =item B<-auditlog> <I<log path>>
 
 Turns on audit logging, and sets the path for the audit log.  The audit
index 38ad7c2..7596cad 100644 (file)
@@ -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
index 52b9088..6a62302 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
 #include <direct.h>
@@ -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 <bytes>] [-rxbind] [-allow-dotted-principals]"
                   "[-syslog[=FACILITY]] "
                   "[-enable_peer_stats] [-enable_process_stats] "
+                  "[-cores=<none|path>] \n"
                   "[-nofork] " "[-help]\n");
 #else
            printf("Usage: bosserver [-noauth] [-log] "
@@ -862,6 +878,7 @@ main(int argc, char **argv, char **envp)
                   "[-audit-interafce <file|sysvmq> (default is file)] "
                   "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
                   "[-enable_peer_stats] [-enable_process_stats] "
+                  "[-cores=<none|path>] \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();