Minor updates:
- JSONparseCore: - Set File mode on create - SelectableCore: - Check pipe() return value on create - Validate replacement of stdin with pipe
This commit is contained in:
@@ -105,7 +105,7 @@ bool CJSONparse::WriteToFile( const char * BasePath, const char * FilePath, cons
|
||||
}
|
||||
|
||||
// Open file
|
||||
if ((Handle = open( FilePath, O_CREAT|O_WRONLY|O_TRUNC )) < 0) {
|
||||
if ((Handle = open( FilePath, O_CREAT|O_WRONLY|O_TRUNC, 660 )) < 0) {
|
||||
Error = true;
|
||||
sprintf( ErrorText, "Could not open file" );
|
||||
return false;
|
||||
|
||||
@@ -458,6 +458,7 @@ int CSelectableCore::OpenPort( THandle * Handle )
|
||||
int CSelectableCore::OpenForkPipe( THandle * Handle )
|
||||
{
|
||||
int pipefd[2];
|
||||
int newfd;
|
||||
char * Args[50];
|
||||
int Count = 0;
|
||||
|
||||
@@ -477,8 +478,7 @@ int CSelectableCore::OpenForkPipe( THandle * Handle )
|
||||
}
|
||||
|
||||
// Create Pipe
|
||||
pipe( pipefd );
|
||||
if ((pipefd[0] == -1) || (pipefd[1] == -1))
|
||||
if ((pipe( pipefd ) == -1) || (pipefd[0] == -1) || (pipefd[1] == -1))
|
||||
{
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s: Handle '%s' - Could not open Pipe", Name, Handle->Name );
|
||||
@@ -512,15 +512,20 @@ int CSelectableCore::OpenForkPipe( THandle * Handle )
|
||||
else
|
||||
{
|
||||
// Fork success - this is child
|
||||
// Replace stdin with Read-end of pipe
|
||||
close( 0 );
|
||||
dup( pipefd[0] );
|
||||
close( pipefd[0] );
|
||||
|
||||
// Close Write-end of pipe
|
||||
close( pipefd[1] );
|
||||
|
||||
// Replace Processing image
|
||||
// Replace stdin with Read-end of pipe
|
||||
close( 0 );
|
||||
newfd = dup2( pipefd[0], 0 );
|
||||
close( pipefd[0] );
|
||||
if (newfd != 0) {
|
||||
// Replace failed, exit immediately
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s: Handle '%s' - Stdin redirect failed on forked process", Name, Handle->Name );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
// Fork : Replace Processing image
|
||||
BuildArgs( Handle->Path, Count, Args );
|
||||
// printf( "Execute params [%d]:\n", Count );
|
||||
// int i = 0;
|
||||
@@ -532,7 +537,7 @@ int CSelectableCore::OpenForkPipe( THandle * Handle )
|
||||
|
||||
// Replace failed, exit immediately
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s: Handle '%s' - Exec on forked process failed", Name, Handle->Name );
|
||||
exit(127);
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
// Add to Select Lists
|
||||
|
||||
Reference in New Issue
Block a user