From b538a5fad096764a686a68f843f74ee36d3c7ef1 Mon Sep 17 00:00:00 2001 From: Baruch Sterin Date: Tue, 1 Feb 2011 11:13:53 -0800 Subject: 1. Replace system() with a function that responds to SIGINT. 2. Add functions to cleanup temporary files on SIGINT. 3. Fix bugs related to signal handling. --- src/base/cmd/cmd.c | 9 +++++---- src/base/cmd/cmdLoad.c | 3 ++- src/base/cmd/cmdPlugin.c | 23 ++++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src/base/cmd') diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index 47b031bc..15cbdda5 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -27,6 +27,7 @@ #include "abc.h" #include "mainInt.h" #include "cmdInt.h" +#include "utilSignal.h" ABC_NAMESPACE_IMPL_START @@ -1557,7 +1558,7 @@ int CmdCommandSis( Abc_Frame_t * pAbc, int argc, char **argv ) strcat( Command, "\"" ); // call SIS - if ( system( Command ) ) + if ( Util_SignalSystem( Command ) ) { fprintf( pErr, "The following command has returned non-zero exit status:\n" ); fprintf( pErr, "\"%s\"\n", Command ); @@ -1700,7 +1701,7 @@ int CmdCommandMvsis( Abc_Frame_t * pAbc, int argc, char **argv ) strcat( Command, "\"" ); // call MVSIS - if ( system( Command ) ) + if ( Util_SignalSystem( Command ) ) { fprintf( pErr, "The following command has returned non-zero exit status:\n" ); fprintf( pErr, "\"%s\"\n", Command ); @@ -1912,7 +1913,7 @@ int CmdCommandCapo( Abc_Frame_t * pAbc, int argc, char **argv ) } // call Capo - if ( system( Command ) ) + if ( Util_SignalSystem( Command ) ) { fprintf( pErr, "The following command has returned non-zero exit status:\n" ); fprintf( pErr, "\"%s\"\n", Command ); @@ -1964,7 +1965,7 @@ int CmdCommandCapo( Abc_Frame_t * pAbc, int argc, char **argv ) #else { sprintf( Command, "%s %s ", pProgNameGnuplot, pPlotFileName ); - if ( system( Command ) == -1 ) + if ( Util_SignalSystem( Command ) == -1 ) { fprintf( stdout, "Cannot execute \"%s\".\n", Command ); goto usage; diff --git a/src/base/cmd/cmdLoad.c b/src/base/cmd/cmdLoad.c index 7a83385c..8ff03282 100644 --- a/src/base/cmd/cmdLoad.c +++ b/src/base/cmd/cmdLoad.c @@ -22,6 +22,7 @@ #include "mainInt.h" #include "cmd.h" #include "cmdInt.h" +#include "utilSignal.h" ABC_NAMESPACE_IMPL_START @@ -72,7 +73,7 @@ int CmdCommandLoad( Abc_Frame_t * pAbc, int argc, char ** argv ) } Vec_StrPush( vCommand, 0 ); // run the command line - if ( system( Vec_StrArray(vCommand) ) ) + if ( Util_SignalSystem( Vec_StrArray(vCommand) ) ) { Abc_Print( -1, "The following command has returned non-zero exit status:\n" ); Abc_Print( -1, "\"%s\"\n", Vec_StrArray(vCommand) ); diff --git a/src/base/cmd/cmdPlugin.c b/src/base/cmd/cmdPlugin.c index 7375eb42..116687c7 100644 --- a/src/base/cmd/cmdPlugin.c +++ b/src/base/cmd/cmdPlugin.c @@ -29,6 +29,7 @@ #include "mainInt.h" #include "cmd.h" #include "cmdInt.h" +#include "utilSignal.h" ABC_NAMESPACE_IMPL_START @@ -111,8 +112,6 @@ command, then we add a new object for the new action. */ -extern int tmpFile(const char* prefix, const char* suffix, char** out_name); - //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -366,7 +365,7 @@ int Cmd_CommandAbcPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) fclose( pFile ); // create temp file - fd = tmpFile( "__abctmp_", ".aig", &pFileIn ); + fd = Util_SignalTmpFile( "__abctmp_", ".aig", &pFileIn ); if ( fd == -1 ) { Abc_Print( -1, "Cannot create a temporary file.\n" ); @@ -379,7 +378,7 @@ int Cmd_CommandAbcPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) #endif // create temp file - fd = tmpFile( "__abctmp_", ".out", &pFileOut ); + fd = Util_SignalTmpFile( "__abctmp_", ".out", &pFileOut ); if ( fd == -1 ) { ABC_FREE( pFileIn ); @@ -437,7 +436,7 @@ int Cmd_CommandAbcPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) //printf( "Running command line: %s\n", Vec_StrArray(vCommand) ); clk = clock(); - if ( system( Vec_StrArray(vCommand) ) ) + if ( Util_SignalSystem( Vec_StrArray(vCommand) ) ) { Abc_Print( -1, "The following command has returned non-zero exit status:\n" ); Abc_Print( -1, "\"%s\"\n", Vec_StrArray(vCommand) ); @@ -516,11 +515,9 @@ int Cmd_CommandAbcPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) // clean up - if ( !fLeaveFiles ) - { - remove( pFileIn ); - remove( pFileOut ); - } + Util_SignalTmpFileRemove( pFileIn, fLeaveFiles ); + Util_SignalTmpFileRemove( pFileOut, fLeaveFiles ); + ABC_FREE( pFileIn ); ABC_FREE( pFileOut ); return 0; @@ -565,7 +562,7 @@ int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) fclose( pFile ); // create temp file - fd = tmpFile( "__abctmp_", ".txt", &pTempFile ); + fd = Util_SignalTmpFile( "__abctmp_", ".txt", &pTempFile ); if ( fd == -1 ) { Abc_Print( -1, "Cannot create a temporary file.\n" ); @@ -581,7 +578,7 @@ int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) pCommandLine = ABC_ALLOC( char, 100 + strlen(pStrDirBin) + strlen(pTempFile) ); // sprintf( pCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile ); sprintf( pCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile ); - RetValue = system( pCommandLine ); + RetValue = Util_SignalSystem( pCommandLine ); if ( RetValue == -1 ) { Abc_Print( -1, "Command \"%s\" did not succeed.\n", pCommandLine ); @@ -610,7 +607,7 @@ int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) printf( "Creating command %s with binary %s\n", pBuffer, pStrDirBin ); } fclose( pFile ); - remove( pTempFile ); + Util_SignalTmpFileRemove( pTempFile, 0 ); ABC_FREE( pTempFile ); return 0; usage: -- cgit v1.2.3