From 04f4fc996f6cd13f3f995165f2df622a2aed7cd3 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 30 Apr 2013 08:13:45 +0000 Subject: [PATCH] allow unlimited core dump size git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36589 72102866-910b-0410-8b05-ffd578937521 --- EcProcess.h | 5 +++-- EcProcess.m | 59 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/EcProcess.h b/EcProcess.h index 89f0e0a..d07dcc8 100644 --- a/EcProcess.h +++ b/EcProcess.h @@ -54,8 +54,9 @@ Specifies the maximum size (in MB) for any core-dump of the process.
- If this is negative, the default size of 1GB is used.
- If this is zero (or no value is set) then no limit is set. + If this is not set, the default size of 1GB is used.
+ If this is negative, the size is unlimited.
+ If this is zero then no core dumping is performed.
EcDebug- diff --git a/EcProcess.m b/EcProcess.m index cc2ce7c..a887c7b 100644 --- a/EcProcess.m +++ b/EcProcess.m @@ -448,7 +448,7 @@ static NSMutableArray *noNetConfig = nil; static NSMutableDictionary *servers = nil; -static int coreSize = 0; +static int coreSize = -2; // Not yet set static NSString *hostName = nil; static NSString * @@ -1097,10 +1097,18 @@ static NSString *noFiles = @"No log files to archive"; } } - i = (int)[cmdDefs integerForKey: @"CoreSize"]; - if (i < 0) + str = [cmdDefs stringForKey: @"CoreSize"]; + if (nil == str) { - i = 1024; // 1 GB default + i = 1024; // 1 GB default + } + else + { + i = [str intValue]; + if (i < 0) + { + i = -1; // unlimited + } } if (i != coreSize) { @@ -1108,29 +1116,46 @@ static NSString *noFiles = @"No log files to archive"; rlim_t want; coreSize = i; - want = i * 1024 * 1024; - if (i > 0) + if (coreSize < 0) { - if (getrlimit(RLIMIT_CORE, &rlim) < 0) + want = RLIM_INFINITY; + } + else + { + want = i * 1024 * 1024; + } + if (getrlimit(RLIMIT_CORE, &rlim) < 0) + { + NSLog(@"Unable to get core file size limit: %d", errno); + } + else + { + if (RLIM_INFINITY != rlim.rlim_max && rlim.rlim_max < want) { - NSLog(@"Unable to get core file size limit: %d", errno); + NSLog(@"Hard limit for core file size (%dMB)" + @" less than requested (%dMB)", + (int)(rlim.rlim_max/(1024*1024)), coreSize); } else { - if (rlim.rlim_max < want) + rlim.rlim_cur = want; + if (setrlimit(RLIMIT_CORE, &rlim) < 0) { - NSLog(@"Hard limit for core file size (%dMB)" - @" less than requested (%dMB)", - (int)(rlim.rlim_max/(1024*1024)), coreSize); - } - else - { - rlim.rlim_cur = want; - if (setrlimit(RLIMIT_CORE, &rlim) < 0) + if (coreSize > 0) { NSLog(@"Unable to set core file size limit to %uMB" @", errno: %d", coreSize, errno); } + else if (coreSize < 0) + { + NSLog(@"Unable to set core file size unlimited" + @", errno: %d", errno); + } + else + { + NSLog(@"Unable to set core dumps disabled" + @", errno: %d", errno); + } } } }