From 32e833f3319e279167e3c4cf50f73b5ff93e4d65 Mon Sep 17 00:00:00 2001
From: axel function on_exit --on-process %self
+ echo fish is now exiting
+end
Universal variables are stored in
the file .fishd.HOSTNAME, where HOSTNAME is the name of your
@@ -841,15 +844,28 @@ end
function --on-signal WINCH my_signal_handler + echo Got WINCH signal! +end ++ +For more information on how to define new event handlers, see the +documentation for the function +command. \section issues Common issues with fish diff --git a/event.c b/event.c index 9ea680232..7685585b1 100644 --- a/event.c +++ b/event.c @@ -273,6 +273,9 @@ static void event_fire_internal( event_t *event, array_list_t *arguments ) int i, j; string_buffer_t *b=0; array_list_t *fire=0; + + int was_subshell = is_subshell; + int was_interactive = is_interactive; /* First we free all events that have been removed @@ -344,15 +347,22 @@ static void event_fire_internal( event_t *event, array_list_t *arguments ) // debug( 1, L"Event handler fires command '%ls'", (wchar_t *)b->buff ); + /* + Event handlers are not part of the main flow of code, so + they are marked as non-interactive and as a subshell + */ is_subshell=1; - is_interactive=1; - + is_interactive=0; eval( (wchar_t *)b->buff, 0, TOP ); - is_subshell=0; - is_interactive=1; } + /* + Restore interactivity flags + */ + is_subshell = was_subshell; + is_interactive = was_interactive; + if( b ) { sb_destroy( b ); diff --git a/event.h b/event.h index d1d08aa74..43d81a8d1 100644 --- a/event.h +++ b/event.h @@ -61,6 +61,9 @@ typedef struct } param1; + /** + The name of the event handler function + */ const wchar_t *function_name; } event_t; diff --git a/init/fish_interactive.fish b/init/fish_interactive.fish index 4c639fc0d..024ae74fe 100644 --- a/init/fish_interactive.fish +++ b/init/fish_interactive.fish @@ -20,7 +20,7 @@ printf 'for instructions on how to use fish\n' # Set exit message # -function fish_on_exit -d "Commands to execute when fish exits" +function fish_on_exit -d "Commands to execute when fish exits" --on-process %self echo Good bye end diff --git a/main.c b/main.c index f9e8f3fc9..e4be0c642 100644 --- a/main.c +++ b/main.c @@ -284,11 +284,7 @@ int main( int argc, char **argv ) } } - - if( function_exists(L"fish_on_exit")) - { - eval( L"fish_on_exit", 0, TOP ); - } + proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, getpid(), res ); reader_pop_current_filename(); diff --git a/proc.c b/proc.c index 9bae4774d..fb6229da4 100644 --- a/proc.c +++ b/proc.c @@ -482,12 +482,9 @@ static void format_job_info( const job_t *j, const wchar_t *status ) fwprintf (stdout, L"\n" ); } -static void fire_process_event( const wchar_t *msg, int type, pid_t pid, int status ) +void proc_fire_event( const wchar_t *msg, int type, pid_t pid, int status ) { static event_t ev; - event_t e; - - e.function_name=0; ev.type=type; ev.param1.pid = pid; @@ -538,7 +535,7 @@ int job_reap( int interactive ) s = p->status; - fire_process_event( L"PROCESS_EXIT", EVENT_EXIT, p->pid, ( WIFSIGNALED(s)?-1:WEXITSTATUS( s )) ); + proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, p->pid, ( WIFSIGNALED(s)?-1:WEXITSTATUS( s )) ); if( WIFSIGNALED(s) ) { @@ -596,8 +593,8 @@ int job_reap( int interactive ) found=1; } } - fire_process_event( L"JOB_EXIT", EVENT_EXIT, -j->pgid, 0 ); - fire_process_event( L"JOB_EXIT", EVENT_JOB_ID, j->job_id, 0 ); + proc_fire_event( L"JOB_EXIT", EVENT_EXIT, -j->pgid, 0 ); + proc_fire_event( L"JOB_EXIT", EVENT_JOB_ID, j->job_id, 0 ); job_free(j); } diff --git a/proc.h b/proc.h index 665ffc3da..368756741 100644 --- a/proc.h +++ b/proc.h @@ -254,6 +254,11 @@ void proc_update_jiffies(); */ void proc_sanity_check(); +/** + Send of an process/job exit event notification. This function is a conveniance wrapper around event_fire(). +*/ +void proc_fire_event( const wchar_t *msg, int type, pid_t pid, int status ); + /* Initializations */ diff --git a/reader.c b/reader.c index 0f0482ce0..ec3aac449 100644 --- a/reader.c +++ b/reader.c @@ -2761,8 +2761,8 @@ wchar_t *reader_readline() break; } - - + + /* Move left*/ case R_BACKWARD_CHAR: if( data->buff_pos > 0 )