Skip to content

Commit 0eb534a

Browse files
author
mfe
committed
Handle signals in sam tools #220
1 parent 0f5a28c commit 0eb534a

File tree

10 files changed

+29
-0
lines changed

10 files changed

+29
-0
lines changed

applications/sam/src/sam/check/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ void checkSequence( Graph::Node& read, Graph::Node& stat, Graph& graph, const sp
115115

116116
int main( int argc, char** argv )
117117
{
118+
signal(SIGINT, signal_callback_handler);
119+
118120
using namespace tuttle::common;
119121
using namespace sam;
120122

applications/sam/src/sam/common/mvcp.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void copy_sequence( const sp::Sequence& s, const bfs::path& d, const sp::Time of
121121

122122
int sammvcp(int argc, char** argv)
123123
{
124+
signal(SIGINT, signal_callback_handler);
125+
124126
using namespace tuttle::common;
125127
using namespace sam;
126128

applications/sam/src/sam/common/utility.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
#include <boost/algorithm/string/predicate.hpp>
55

66
#include <string>
7+
#include <iostream>
8+
#include <tuttle/common/utils/global.hpp>
9+
#include <csignal>
710

811
bool string_to_boolean( const std::string& str )
912
{
1013
return ( str == "1" || boost::iequals(str, "y") || boost::iequals(str, "yes") || boost::iequals(str, "true") );
1114
}
1215

16+
void signal_callback_handler( int signum )
17+
{
18+
std::ostringstream os;
19+
os << "Signal "<< strsignal(signum) << "(" << signum << ") was caught.\nTerminate sam.";
20+
TUTTLE_LOG_WARNING(os.str());
21+
exit(signum);
22+
}
23+
1324
#endif

applications/sam/src/sam/diff/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ void displayHelp(bpo::options_description &desc)
299299

300300
int main( int argc, char** argv )
301301
{
302+
signal(SIGINT, signal_callback_handler);
303+
302304
using namespace tuttle::common;
303305
using namespace sam;
304306

applications/sam/src/sam/do/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ bool isContextSupported( const ttl::Graph::Node* node , const std::string& conte
249249

250250
int main( int argc, char** argv )
251251
{
252+
signal(SIGINT, signal_callback_handler);
253+
252254
using namespace tuttle::common;
253255
using namespace sam;
254256
using namespace sam::samdo;

applications/sam/src/sam/info/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ void dumpImageProperties( boost::ptr_vector<sp::FileObject>& listing )
183183

184184
int main( int argc, char** argv )
185185
{
186+
signal(SIGINT, signal_callback_handler);
187+
186188
using namespace tuttle::common;
187189
using namespace sam;
188190

applications/sam/src/sam/ls/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void coutVec( const boost::ptr_vector<T>& v )
4949

5050
int main( int argc, char** argv )
5151
{
52+
signal(SIGINT, signal_callback_handler);
53+
5254
using namespace tuttle::common;
5355
using namespace sam;
5456

applications/sam/src/sam/plugins/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ std::string getDefaultValues(const tth::ofx::property::OfxhProperty& prop)
4545

4646
void printProperties( const tth::ofx::property::OfxhSet properties, std::string context="" )
4747
{
48+
signal(SIGINT, signal_callback_handler);
49+
4850
using namespace tuttle::common;
4951
boost::shared_ptr<Color> color( Color::get() );
5052
if( context.size() == 0 )

applications/sam/src/sam/rm/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ void removeFiles( std::vector<boost::filesystem::path> &listing )
136136

137137
int main( int argc, char** argv )
138138
{
139+
signal(SIGINT, signal_callback_handler);
140+
139141
using namespace tuttle::common;
140142
using namespace sam;
141143

applications/sam/src/sam/sam/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ std::vector<bfs::path> retrieveAllSamCommands(const std::vector<bfs::path>& dirs
9999

100100
int main( int argc, char** argv )
101101
{
102+
signal(SIGINT, signal_callback_handler);
103+
102104
using namespace tuttle::common;
103105
using namespace sam;
104106

0 commit comments

Comments
 (0)