[complement-svn] SF.net SVN: complement: [1458] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-15 12:26:49
|
Revision: 1458 http://svn.sourceforge.net/complement/?rev=1458&view=rev Author: complement Date: 2006-12-15 04:26:46 -0800 (Fri, 15 Dec 2006) Log Message: ----------- add setting signal handler with siginfo Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/xmt.cc Added Paths: ----------- trunk/complement/explore/inquiry/shades/dump_term/ trunk/complement/explore/inquiry/shades/dump_term/Makefile trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc trunk/complement/explore/inquiry/shades/dump_term/test.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2006-12-15 08:11:12 UTC (rev 1457) +++ trunk/complement/explore/include/mt/xmt.h 2006-12-15 12:26:46 UTC (rev 1458) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 03:03:00 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 14:35:45 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -124,6 +124,8 @@ # endif #endif // SIG_PF +typedef void siginfo_handler_type( int, siginfo_t *, void * ); + } // extern "C" namespace xmt { @@ -1402,7 +1404,8 @@ __FIT_DECLSPEC void become_daemon() throw( fork_in_parent, std::runtime_error ); __FIT_DECLSPEC void block_signal( int sig ); __FIT_DECLSPEC void unblock_signal( int sig ); -__FIT_DECLSPEC void signal_handler( int sig, SIG_PF ); +__FIT_DECLSPEC int signal_handler( int sig, SIG_PF ); +__FIT_DECLSPEC int signal_handler( int sig, siginfo_handler_type ); class Thread { Property changes on: trunk/complement/explore/inquiry/shades/dump_term ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/inquiry/shades/dump_term/Makefile =================================================================== --- trunk/complement/explore/inquiry/shades/dump_term/Makefile (rev 0) +++ trunk/complement/explore/inquiry/shades/dump_term/Makefile 2006-12-15 12:26:46 UTC (rev 1458) @@ -0,0 +1,16 @@ +# -*- Makefile -*- Time-stamp: <06/12/15 13:47:56 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +INCLUDES += -I${CoMT_INCLUDE_DIR} + +release-shared : LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} +dbg-shared : LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} +stldbg-shared : LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} + +release-shared: LDLIBS = -L${CoMT_LIB_DIR} -lxmt +dbg-shared: LDLIBS = -L${CoMT_LIB_DIR} -lxmtg +stldbg-shared: LDLIBS = -L${CoMT_LIB_DIR} -lxmtstlg Added: trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc =================================================================== --- trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc (rev 0) +++ trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc 2006-12-15 12:26:46 UTC (rev 1458) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <04/01/12 15:37:40 ptr> + +PRGNAME = test +SRC_CC = test.cc Added: trunk/complement/explore/inquiry/shades/dump_term/test.cc =================================================================== --- trunk/complement/explore/inquiry/shades/dump_term/test.cc (rev 0) +++ trunk/complement/explore/inquiry/shades/dump_term/test.cc 2006-12-15 12:26:46 UTC (rev 1458) @@ -0,0 +1,77 @@ +#include <mt/xmt.h> +#include <iostream> + +using namespace std; +using namespace xmt; + +void h1( int sig ) +{ + cerr << "Signal: " << sig << endl; +} + +void h2( int sig, siginfo_t *si, void * ) +{ + cerr << "-----------------------------------------------\n" + << "my pid: " << xmt::getpid() << ", ppid: " << xmt::getppid() << "\n" + << "signal: " << sig << ", number " << si->si_signo + << " errno " << si->si_errno + << " code " << si->si_code << endl; + switch ( si->si_signo ) { + case SIGKILL: + case SIGTERM: + case SIGINT: + case SIGQUIT: + case SIGPIPE: + case SIGABRT: + case SIGALRM: + case SIGHUP: + cerr << "pid: " << si->si_pid + << "\nuid: " << si->si_uid + << endl; + break; + case SIGILL: + case SIGFPE: + case SIGSEGV: + case SIGBUS: + cerr << "Address: " << si->si_addr << endl; + break; + } +} + +class Superviser +{ + public: + ~Superviser(); +}; + +Superviser::~Superviser() +{ + cerr << "Good bye" << endl; + kill( xmt::getpid(), SIGABRT ); +} + +// Superviser s; + +int main() +{ + Condition cnd; + + cnd.set( false ); + signal_handler( SIGTERM, &h2 ); + signal_handler( SIGKILL, &h2 ); + signal_handler( SIGQUIT, &h2 ); + signal_handler( SIGINT, &h2 ); + signal_handler( SIGHUP, &h2 ); + signal_handler( SIGALRM, &h2 ); + signal_handler( SIGABRT, &h2 ); + signal_handler( SIGPIPE, &h2 ); + // signal_handler( SIGKILL, &h1 ); + // signal_handler( SIGSTOP, &h1 ); + // unblock_signal( SIGTERM ); + + cerr << "Hello, world!" << endl; + + cnd.wait(); + + return 0; +} Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-12-15 08:11:12 UTC (rev 1457) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-12-15 12:26:46 UTC (rev 1458) @@ -2,12 +2,14 @@ * time.h, time.cc: add timespec in xmt namespace, useful for conversions and inline objects; clean some code in - timespec operations. + timespec operations; * xmt.h: changes related to timespec in xmt namespace and in global namespace; now 'delay' functions family only in xmt - namespace and go away from Thread class. + namespace and go away from Thread class; + * xmt.h, xmt.cc: add setting signal handler with siginfo. + 2006-12-14 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: move 'fork' and 'become_daemon' from Thread Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2006-12-15 08:11:12 UTC (rev 1457) +++ trunk/complement/explore/lib/mt/xmt.cc 2006-12-15 12:26:46 UTC (rev 1458) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:10:57 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 14:39:47 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -695,7 +695,7 @@ } __FIT_DECLSPEC -void signal_handler( int sig, SIG_PF handler ) +int signal_handler( int sig, SIG_PF handler ) { #ifdef __unix // catch SIGPIPE here struct sigaction act; @@ -705,11 +705,30 @@ act.sa_flags = 0; // SA_RESTART; act.sa_handler = handler; - sigaction( sig, &act, 0 ); + return sigaction( sig, &act, 0 ); +#else + return -1; #endif // __unix } __FIT_DECLSPEC +int signal_handler( int sig, siginfo_handler_type handler ) +{ +#ifdef __unix // catch SIGPIPE here + struct sigaction act; + + sigemptyset( &act.sa_mask ); + sigaddset( &act.sa_mask, sig ); + + act.sa_flags = SA_SIGINFO; // SA_RESTART; + act.sa_sigaction = handler; + return sigaction( sig, &act, 0 ); +#else + return -1; +#endif // __unix +} + +__FIT_DECLSPEC void fork() throw( fork_in_parent, std::runtime_error ) { #ifdef __unix This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |