mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-02-20 18:32:09 +00:00
add option to suppress debug output
This commit is contained in:
parent
e5da849c29
commit
4b9284a8d6
3 changed files with 84 additions and 31 deletions
|
@ -1,3 +1,11 @@
|
|||
2019-03-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* EcProces.h:
|
||||
* EcProces.m:
|
||||
Add KillDebugOutput option to configure a process to avoid logging
|
||||
on systems where logged information should not be available for
|
||||
security reasons. This option is not overidable from the Console.
|
||||
|
||||
2019-02-15 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* EcControl.m: If we get an alarm clear before we have reported the
|
||||
|
|
|
@ -251,6 +251,15 @@ extern NSString* cmdVersion(NSString *ver);
|
|||
* The default (EcKeepStandardError set to NO) is to merge the
|
||||
* standard error logging with the debug logging.
|
||||
* </desc>
|
||||
* <term>EcKillDebugOutput</term>
|
||||
* <desc>
|
||||
* This boolean value determines whether debug output (including anything
|
||||
* written to the standard error output if that is merged with debug)
|
||||
* should be discarded (sent to the null device).<br />
|
||||
* This setting cannot e controlled from the Console command line.<br />
|
||||
* The default (EcKillDebugOutput set to NO) is to write debug output to
|
||||
* file.
|
||||
* </desc>
|
||||
* <term>EcTransient</term>
|
||||
* <desc>
|
||||
* This boolean option is used to specify that the program
|
||||
|
|
98
EcProcess.m
98
EcProcess.m
|
@ -2009,6 +2009,31 @@ static NSString *noFiles = @"No log files to archive";
|
|||
|
||||
[EcDefaultRegistration defaultsChanged: cmdDefs];
|
||||
|
||||
/* Update debug output kill status if necessary.
|
||||
*/
|
||||
if ([cmdDefs boolForKey: @"KillDebugOutput"] != cmdKillDebug)
|
||||
{
|
||||
NSFileHandle *hdl;
|
||||
|
||||
[ecLock lock];
|
||||
hdl = [cmdLogMap objectForKey: cmdDebugName];
|
||||
if (hdl != nil)
|
||||
{
|
||||
if (cmdKillDebug == NO)
|
||||
{
|
||||
NSString *msg;
|
||||
|
||||
msg = cmdLogFormat(LT_WARNING,
|
||||
@"Logging suppressed by KillDebugOutput=YES");
|
||||
[hdl writeData: [msg dataUsingEncoding: NSUTF8StringEncoding]];
|
||||
}
|
||||
[self ecLogEnd: cmdDebugName to: nil];
|
||||
}
|
||||
[ecLock unlock];
|
||||
cmdKillDebug = (NO == cmdKillDebug ? YES : NO);
|
||||
[self cmdLogFile: cmdDebugName];
|
||||
}
|
||||
|
||||
enumerator = [cmdDebugKnown keyEnumerator];
|
||||
while (nil != (mode = [enumerator nextObject]))
|
||||
{
|
||||
|
@ -2246,54 +2271,55 @@ static NSString *noFiles = @"No log files to archive";
|
|||
hdl = [cmdLogMap objectForKey: name];
|
||||
if (nil == hdl)
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *path;
|
||||
|
||||
path = [cmdLogsDir(nil) stringByAppendingPathComponent: name];
|
||||
|
||||
/* Archive any old left-over file.
|
||||
*/
|
||||
[self _moveLog: name to: nil];
|
||||
|
||||
/*
|
||||
* Create the file if necessary, and open it for updating.
|
||||
*/
|
||||
if ([mgr isWritableFileAtPath: path] == NO
|
||||
&& [mgr createFileAtPath: path contents: nil attributes: nil] == NO)
|
||||
if (YES == cmdKillDebug && [name isEqual: cmdDebugName] == YES)
|
||||
{
|
||||
NSLog(@"File '%@' is not writable and can't be created", path);
|
||||
/* Output is killed so we don't need to create the file
|
||||
* and can simply write to /dev/null
|
||||
*/
|
||||
hdl = [NSFileHandle fileHandleWithNullDevice];
|
||||
}
|
||||
else
|
||||
{
|
||||
hdl = [NSFileHandle fileHandleForUpdatingAtPath: path];
|
||||
if (hdl == nil)
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *path;
|
||||
|
||||
path = [cmdLogsDir(nil) stringByAppendingPathComponent: name];
|
||||
|
||||
/* Create the file if necessary, and open it for updating.
|
||||
*/
|
||||
if ([mgr isWritableFileAtPath: path] == NO
|
||||
&& [mgr createFileAtPath: path contents: nil attributes: nil] == NO)
|
||||
{
|
||||
if (status != nil)
|
||||
{
|
||||
NSLog(@"%@", status);
|
||||
}
|
||||
NSLog(@"Unable to log to %@", path);
|
||||
NSLog(@"File '%@' is not writable and can't be created", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
[hdl seekToEndOfFile];
|
||||
hdl = [NSFileHandle fileHandleForUpdatingAtPath: path];
|
||||
if (hdl == nil)
|
||||
{
|
||||
if (status != nil)
|
||||
{
|
||||
NSLog(@"%@", status);
|
||||
}
|
||||
NSLog(@"Unable to log to %@", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
[hdl seekToEndOfFile];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hdl == nil)
|
||||
{
|
||||
[self ecUnLock];
|
||||
[self ecUnLock];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (YES == cmdKillDebug && [name isEqual: cmdDebugName] == YES)
|
||||
{
|
||||
const char *msg = "Logging suppressed by KillDebugOutput=YES\n";
|
||||
|
||||
[hdl writeData: [NSData dataWithBytes: msg length: strlen(msg)]];
|
||||
[hdl closeFile];
|
||||
hdl = [NSFileHandle fileHandleWithNullDevice];
|
||||
}
|
||||
|
||||
/* As a special case, if this is the default debug file
|
||||
* we must set it up to write to stderr.
|
||||
*/
|
||||
|
@ -4026,7 +4052,12 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
|
|||
if ([key isEqualToString: ecControlKey])
|
||||
{
|
||||
[self cmdPrintf: @"%@ can only be set on startup.\n", key];
|
||||
val = nil;
|
||||
return;
|
||||
}
|
||||
else if ([key isEqualToString: @"KillDebugOutput"])
|
||||
{
|
||||
[self cmdPrintf: @"%@ can not be overridden.\n", key];
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4040,7 +4071,12 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
|
|||
if ([key isEqualToString: ecControlKey])
|
||||
{
|
||||
[self cmdPrintf: @"%@ can only be set on startup.\n", key];
|
||||
val = nil;
|
||||
return;
|
||||
}
|
||||
else if ([key isEqualToString: @"KillDebugOutput"])
|
||||
{
|
||||
[self cmdPrintf: @"%@ can not be overridden.\n", key];
|
||||
return;
|
||||
}
|
||||
else if ([msg count] == 4)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue