From: Matthew Dillon Date: Mon, 10 Sep 2012 21:03:30 +0000 (-0700) Subject: hammer - Fix core dump during remote termination of mirror-stream X-Git-Tag: v3.2.0~179 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/db7dd3cf4078fb77bfc05075918ad190f74b707b?hp=c758a2a9e21d4958066e8d957f54e8955b74972c hammer - Fix core dump during remote termination of mirror-stream * Fix issue where remote-end hammer can core trying to fprintf() an error message if a mirror-stream connection is lost unexpectedly. --- diff --git a/sbin/hammer/cmd_mirror.c b/sbin/hammer/cmd_mirror.c index eacc76ab06..f3644799ba 100644 --- a/sbin/hammer/cmd_mirror.c +++ b/sbin/hammer/cmd_mirror.c @@ -860,7 +860,8 @@ again: mrec->head.rec_size != sizeof(mrec->sync)) { fprintf(stderr, "Mirror-write %s: Did not get termination " "sync record, or rec_size is wrong rt=%d\n", - filesystem, mrec->head.type); + filesystem, + (mrec ? mrec->head.type : -1)); exit(1); } diff --git a/test/fastbulk/fastbulk.c b/test/fastbulk/fastbulk.c index 60ffc6a72c..174dc490d8 100644 --- a/test/fastbulk/fastbulk.c +++ b/test/fastbulk/fastbulk.c @@ -48,15 +48,20 @@ * Only one attempt is made to build any given package, no matter how many * other packages depend on it. */ +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include #include -#include -#include -#include struct item; @@ -369,6 +374,7 @@ addBuild(struct item *item) static void runBuilds(const char *bpath) { + struct rlimit rlm; struct item *item; char *logpath; FILE *fp; @@ -405,6 +411,10 @@ runBuilds(const char *bpath) if (chdir(item->rpath) < 0) _exit(99); + /* + * Connect log file up, disconnect tty (in case a + * 'patch' command tries to ask for help). + */ fd = open(logpath, O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd != 1) dup2(fd, 1); @@ -418,6 +428,53 @@ runBuilds(const char *bpath) close(fd); } + /* + * Set resource limits: + * + * ~2 hours cpu - prevent runaways from stalling + * the build. + * + * ~2GB file size - prevent endless growing log files. + * + * ~5GB footprint - prevent processes w/ out of + * control memory usage. + * + * ~0 core - No core dumps cluttering + * directories, please. + */ + if (getrlimit(RLIMIT_CPU, &rlm) == 0 && + rlm.rlim_cur > 2 * 60 * 60) { + rlm.rlim_cur = 2 * 60 * 60; + setrlimit(RLIMIT_CPU, &rlm); + } + if (getrlimit(RLIMIT_FSIZE, &rlm) == 0 && + rlm.rlim_cur > 2LL * 1024 * 1024 * 1024) { + rlm.rlim_cur = 2LL * 1024 * 1024 * 1024; + setrlimit(RLIMIT_FSIZE, &rlm); + } + if (getrlimit(RLIMIT_AS, &rlm) == 0 && + rlm.rlim_cur > 5LL * 1024 * 1024 * 1024) { + rlm.rlim_cur = 5LL * 1024 * 1024 * 1024; + setrlimit(RLIMIT_AS, &rlm); + } + if (getrlimit(RLIMIT_CORE, &rlm) == 0 && + rlm.rlim_cur > 0) { + rlm.rlim_cur = 0; + setrlimit(RLIMIT_CORE, &rlm); + } + + /* + * Disconnect tty so utilities which try to ask + * for help (like patch) or Y/N answers on /dev/tty + * do not stall. + */ + fd = open("/dev/tty", O_RDWR); + if (fd >= 0) { + ioctl(fd, TIOCNOTTY, 0); + close(fd); + } + setsid(); + /* * we tack a 'clean' on to the repackage to clean * the work directory on success. If a failure