aboutsummaryrefslogtreecommitdiffhomepage
path: root/event.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-02 01:49:11 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-02 01:49:11 +1000
commitfeabc032f62cc2a2dd4c2626b1c6806a22d5988d (patch)
tree88773f269100dad40fff31376f81470d7f62a2cc /event.c
parent9f9f7bf95aa56f266994647b008116721f95132a (diff)
Generalize the stack tracing code, add support for showing events and command substitutions in stack traces
darcs-hash:20060201154911-ac50b-707358ea50231661c05a92b40ca109ec801081e6.gz
Diffstat (limited to 'event.c')
-rw-r--r--event.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/event.c b/event.c
index c264c351..ccbc774f 100644
--- a/event.c
+++ b/event.c
@@ -74,6 +74,7 @@ static array_list_t *killme;
*/
static array_list_t *blocked;
+static string_buffer_t *get_desc_buff=0;
/**
Tests if one event instance matches the definition of a event
@@ -186,6 +187,63 @@ static int event_is_blocked( event_t *e )
return 0;
}
+const wchar_t *event_get_desc( event_t *e )
+{
+ if( !get_desc_buff )
+ {
+ get_desc_buff=malloc(sizeof(string_buffer_t) );
+ if( !get_desc_buff )
+ die_mem();
+ sb_init( get_desc_buff );
+ }
+ else
+ {
+ sb_clear( get_desc_buff );
+ }
+
+ switch( e->type )
+ {
+
+ case EVENT_SIGNAL:
+ sb_printf( get_desc_buff, _(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ) );
+ break;
+
+ case EVENT_VARIABLE:
+ sb_printf( get_desc_buff, _(L"handler for variable '%ls'"), e->param1.variable );
+ break;
+
+ case EVENT_EXIT:
+ if( e->param1.pid > 0 )
+ {
+ sb_printf( get_desc_buff, _(L"exit handler for process %d"), e->param1.pid );
+ }
+ else
+ {
+ job_t *j = job_get_from_pid( -e->param1.pid );
+ if( j )
+ sb_printf( get_desc_buff, _(L"exit handler for job %d, '%ls'"), j->job_id, j->command );
+ else
+ sb_printf( get_desc_buff, _(L"exit handler for job with process group %d"), -e->param1.pid );
+ }
+
+ break;
+
+ case EVENT_JOB_ID:
+ {
+ job_t *j = job_get( e->param1.job_id );
+ if( j )
+ sb_printf( get_desc_buff, _(L"exit handler for job %d, '%ls'"), j->job_id, j->command );
+ else
+ sb_printf( get_desc_buff, _(L"exit handler for job with job id %d"), j->job_id );
+
+ break;
+ }
+
+ }
+
+ return (const wchar_t *)get_desc_buff->buff;
+}
+
void event_add_handler( event_t *event )
{
@@ -404,8 +462,11 @@ static void event_fire_internal( event_t *event )
they are marked as non-interactive and as a subshell
*/
is_subshell=1;
+ parser_push_block( EVENT );
+ current_block->param1.event = event;
eval( (wchar_t *)b->buff, 0, TOP );
-
+ parser_pop_block();
+
}
/*
@@ -578,6 +639,12 @@ void event_destroy()
free( killme );
killme=0;
}
+ if( get_desc_buff )
+ {
+ sb_destroy( get_desc_buff );
+ free( get_desc_buff );
+ }
+
}
void event_free( event_t *e )