changeset 42:cd169e4789df

2002-10-29 Brian Masney <masneyb@gftp.org> * src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/gftp-gtk.c src/gtk/gftp-gtk.h src/gtk/menu-items.c src/gtk/misc-gtk.c src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/transfer.c - improved and simplified signal handling code
author masneyb
date Wed, 30 Oct 2002 03:34:37 +0000
parents 4bcfaf6307b5
children 36e2868ce8b7
files ChangeLog src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/gftp-gtk.c src/gtk/gftp-gtk.h src/gtk/menu-items.c src/gtk/misc-gtk.c src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/transfer.c
diffstat 10 files changed, 73 insertions(+), 127 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Oct 30 02:53:21 2002 +0000
+++ b/ChangeLog	Wed Oct 30 03:34:37 2002 +0000
@@ -1,3 +1,9 @@
+2002-10-29 Brian Masney <masneyb@gftp.org>
+	* src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/gftp-gtk.c 
+	src/gtk/gftp-gtk.h src/gtk/menu-items.c src/gtk/misc-gtk.c 
+	src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/transfer.c -
+	improved and simplified signal handling code
+
 2002-10-29 Brian Masney <masneyb@gftp.org>
 	* lib/config_file.c lib/gftp.h lib/options.h src/gtk/menu-items.c
 	src/gtk/view_dialog.c - removed tmp_directory variable. Instead use 
@@ -97,7 +103,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.20 2002/10/30 02:53:20 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.21 2002/10/30 03:34:35 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/src/gtk/chmod_dialog.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/chmod_dialog.c	Wed Oct 30 03:34:37 2002 +0000
@@ -23,12 +23,9 @@
 static void dochmod 				( GtkWidget * widget, 
 						  gftp_window_data * wdata );
 static void *do_chmod_thread 			( void * data );
-static RETSIGTYPE sig_chmodquit                 ( int signo );
-
 
 static GtkWidget *suid, *sgid, *sticky, *ur, *uw, *ux, *gr, *gw, *gx, *or, *ow,
                  *ox;
-static sigjmp_buf chmodenvir;
 static int mode; 
 
 #if !(GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2)
@@ -304,9 +301,8 @@
 
   if (wdata->request->use_threads)
     {
-      sj = sigsetjmp (chmodenvir, 1);
-      signal (SIGINT, sig_chmodquit);
-      signal (SIGALRM, sig_chmodquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -339,21 +335,10 @@
     }
 
   if (wdata->request->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   wdata->request->user_data = NULL;
   wdata->request->stopable = 0;
   return ((void *) success);
 }
 
-
-static RETSIGTYPE
-sig_chmodquit (int signo)
-{
-  signal (signo, sig_chmodquit);
-  siglongjmp (chmodenvir, signo == SIGINT ? 1 : 2);
-}
-
--- a/src/gtk/delete_dialog.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/delete_dialog.c	Wed Oct 30 03:34:37 2002 +0000
@@ -27,9 +27,6 @@
 static void delete_purge_cache 			( gpointer key, 
 						  gpointer value, 
 						  gpointer user_data );
-static RETSIGTYPE sig_delquit                 	( int signo );
-
-static sigjmp_buf delenvir;
 
 void
 delete_dialog (gpointer data)
@@ -196,9 +193,8 @@
 
   if (transfer->fromreq->use_threads)
     {
-      sj = sigsetjmp (delenvir, 1);
-      signal (SIGINT, sig_delquit);
-      signal (SIGALRM, sig_delquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -249,10 +245,7 @@
   transfer->fromreq->stopable = 0;
 
   if (transfer->fromreq->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   return (NULL);
 }
@@ -272,11 +265,3 @@
   g_free (key);
 }
 
-
-static RETSIGTYPE
-sig_delquit (int signo)
-{
-  signal (signo, sig_delquit);
-  siglongjmp (delenvir, signo == SIGINT ? 1 : 2);
-}
-
--- a/src/gtk/gftp-gtk.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/gftp-gtk.c	Wed Oct 30 03:34:37 2002 +0000
@@ -74,6 +74,9 @@
 pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
 gftp_graphic * gftp_icon;
 int gftp_is_started = 0;
+sigjmp_buf jmp_environment;
+volatile int use_jmp_environment = 0;
+
 
 int
 main (int argc, char **argv)
@@ -92,9 +95,12 @@
   g_thread_init (NULL);
   gtk_set_locale ();
   gtk_init (&argc, &argv);
+
   signal (SIGCHLD, sig_child);
   signal (SIGPIPE, SIG_IGN);
-  signal (SIGALRM, SIG_IGN);
+  signal (SIGALRM, signal_handler);
+  signal (SIGINT, signal_handler);
+
   graphic_hash_table = g_hash_table_new (string_hash_function, string_hash_compare);
   gftp_read_config_file (argv, 1);
   if (gftp_parse_command_line (&argc, &argv) != 0)
--- a/src/gtk/gftp-gtk.h	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/gftp-gtk.h	Wed Oct 30 03:34:37 2002 +0000
@@ -149,6 +149,8 @@
 extern pthread_mutex_t transfer_mutex, log_mutex;
 extern gftp_graphic * gftp_icon;
 extern int gftp_is_started;
+extern sigjmp_buf jmp_environment;
+extern volatile int use_jmp_environment;
 
 /* bookmarks.c */
 void run_bookmark 				( gpointer data );
@@ -332,6 +334,8 @@
 
 void display_cached_logs			( void );
 
+RETSIGTYPE signal_handler			(int signo);
+
 /* mkdir_dialog.c */
 void mkdir_dialog 				( gpointer data );
 
--- a/src/gtk/menu-items.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/menu-items.c	Wed Oct 30 03:34:37 2002 +0000
@@ -23,8 +23,6 @@
 static int do_change_dir			( gftp_window_data * wdata,
 						  char * directory );
 static void *do_change_dir_thread 		( void * data );
-static RETSIGTYPE sig_chdirquit                 ( int signo );
-static sigjmp_buf chdirenvir;
 
 void
 change_setting (gftp_window_data * wdata, int menuitem, GtkWidget * checkmenu)
@@ -554,9 +552,8 @@
 
   if (wdata->request->use_threads)
     {
-      sj = sigsetjmp (chdirenvir, 1);
-      signal (SIGINT, sig_chdirquit);
-      signal (SIGALRM, sig_chdirquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -578,10 +575,7 @@
     }
 
   if (wdata->request->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   wdata->request->user_data = NULL;
   wdata->request->stopable = 0;
@@ -589,14 +583,6 @@
 }
 
 
-static RETSIGTYPE
-sig_chdirquit (int signo)
-{
-  signal (signo, sig_chdirquit);
-  siglongjmp (chdirenvir, signo == SIGINT ? 1 : 2);
-}
-
-
 void 
 clearlog (gpointer data)
 {
--- a/src/gtk/misc-gtk.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/misc-gtk.c	Wed Oct 30 03:34:37 2002 +0000
@@ -1221,6 +1221,17 @@
   pthread_mutex_unlock (&log_mutex);
 }
 
+
+RETSIGTYPE 
+signal_handler (int signo)
+{
+  signal (signo, signal_handler);
+
+  if (use_jmp_environment)
+    siglongjmp (jmp_environment, signo == SIGINT ? 1 : 2);
+}
+
+
 #if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR)
 
 static pthread_mutex_t netfunclock = PTHREAD_MUTEX_INITIALIZER;
--- a/src/gtk/mkdir_dialog.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/mkdir_dialog.c	Wed Oct 30 03:34:37 2002 +0000
@@ -21,15 +21,6 @@
 static const char cvsid[] = "$Id$";
 
 static const char *edttext;
-static sigjmp_buf mkdirenvir;
-
-
-static RETSIGTYPE
-sig_mkdirquit (int signo)
-{
-  signal (signo, sig_mkdirquit);
-  siglongjmp (mkdirenvir, signo == SIGINT ? 1 : 2);
-}
 
 
 static void *
@@ -43,9 +34,8 @@
 
   if (wdata->request->use_threads)
     {
-      sj = sigsetjmp (mkdirenvir, 1);
-      signal (SIGINT, sig_mkdirquit);
-      signal (SIGALRM, sig_mkdirquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -67,10 +57,7 @@
     }
 
   if (wdata->request->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   wdata->request->user_data = NULL;
   wdata->request->stopable = 0;
--- a/src/gtk/rename_dialog.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/rename_dialog.c	Wed Oct 30 03:34:37 2002 +0000
@@ -20,19 +20,10 @@
 #include "gftp-gtk.h"
 static const char cvsid[] = "$Id$";
 
-static sigjmp_buf renenvir;
 static const char *edttext;
 static gftp_file * curfle;
 
 
-static RETSIGTYPE
-sig_renquit (int signo)
-{
-  signal (signo, sig_renquit);
-  siglongjmp (renenvir, signo == SIGINT ? 1 : 2);
-}
-
-
 static void *
 do_rename_thread (void * data)
 {
@@ -44,9 +35,8 @@
 
   if (wdata->request->use_threads)
     { 
-      sj = sigsetjmp (renenvir, 1);
-      signal (SIGINT, sig_renquit);
-      signal (SIGALRM, sig_renquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -68,10 +58,7 @@
     }
 
   if (wdata->request->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   wdata->request->user_data = NULL;
   wdata->request->stopable = 0;
--- a/src/gtk/transfer.c	Wed Oct 30 02:53:21 2002 +0000
+++ b/src/gtk/transfer.c	Wed Oct 30 03:34:37 2002 +0000
@@ -59,9 +59,7 @@
 						  gint handler );
 static mode_t parse_attribs 			( char *attribs );
 static void remove_file 			( char *filename );
-static RETSIGTYPE sig_connquit			( int signo );
 
-static sigjmp_buf connenvir;
 static GtkWidget * dialog;
 
 int
@@ -136,9 +134,8 @@
   
   if (request->use_threads)
     {
-      sj = sigsetjmp (connenvir, 1);
-      signal (SIGINT, sig_connquit);
-      signal (SIGALRM, sig_connquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -149,10 +146,8 @@
       if (gftp_list_files (request) != 0 || !GFTP_IS_CONNECTED (request))
         {
           if (request->use_threads)
-            {
-              signal (SIGINT, SIG_DFL);
-              signal (SIGALRM, SIG_IGN);
-            }
+            use_jmp_environment = 0;
+
           request->user_data = NULL;
           request->stopable = 0;
           if (request->wakeup_main_thread[1] > 0)
@@ -182,10 +177,8 @@
       if (!GFTP_IS_CONNECTED (request))
         {
           if (request->use_threads)
-            {
-              signal (SIGINT, SIG_DFL);
-              signal (SIGALRM, SIG_IGN);
-            }
+            use_jmp_environment = 0;
+
           request->user_data = NULL;
           request->stopable = 0;
           if (request->wakeup_main_thread[1] > 0)
@@ -212,10 +205,8 @@
 
   request->user_data = NULL;
   if (request->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 1;
+
   request->stopable = 0;
   if (request->wakeup_main_thread[1] > 0)
     write (request->wakeup_main_thread[1], " ", 1);
@@ -338,9 +329,8 @@
   conn_num = 0;
   if (request->use_threads)
     {
-      sj = sigsetjmp (connenvir, 1);
-      signal (SIGINT, sig_connquit);
-      signal (SIGALRM, sig_connquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -373,10 +363,7 @@
     }
 
   if (request->use_threads)
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   request->user_data = NULL;
   request->stopable = 0;
@@ -526,9 +513,8 @@
   if (transfer->fromreq->use_threads || 
       (transfer->toreq && transfer->toreq->use_threads))
     {
-      sj = sigsetjmp (connenvir, 1);
-      signal (SIGINT, sig_connquit);
-      signal (SIGALRM, sig_connquit);
+      sj = sigsetjmp (jmp_environment, 1);
+      use_jmp_environment = 1;
     }
   else
     sj = 0;
@@ -548,10 +534,7 @@
 
   if (transfer->fromreq->use_threads || 
       (transfer->toreq && transfer->toreq->use_threads))
-    {
-      signal (SIGINT, SIG_DFL);
-      signal (SIGALRM, SIG_IGN);
-    }
+    use_jmp_environment = 0;
 
   transfer->fromreq->user_data = NULL;
   if (transfer->toreq)
@@ -797,6 +780,8 @@
       if (transfer->cancel && !transfer->skip_file)
         break;
       transfer->cancel = 0;
+      transfer->fromreq->cancel = 0;
+      transfer->toreq->cancel = 0;
     }
   transfer->done = 1; 
   transfer->fromreq->user_data = NULL;
@@ -1081,7 +1066,11 @@
 
   pthread_mutex_lock (tdata->structmutex);
   if (tdata->started)
-    tdata->cancel = 1;
+    {
+      tdata->cancel = 1;
+      tdata->fromreq->cancel = 1;
+      tdata->toreq->cancel = 1;
+    }
   else
     tdata->done = 1;
 
@@ -1383,6 +1372,8 @@
   if (transdata->transfer->started)
     {
       transdata->transfer->cancel = 1;
+      transdata->transfer->fromreq->cancel = 1;
+      transdata->transfer->toreq->cancel = 1;
       transdata->transfer->skip_file = 0;
     }
   else
@@ -1418,6 +1409,8 @@
       if (transdata->transfer->started)
         {
           transdata->transfer->cancel = 1;
+          transdata->transfer->fromreq->cancel = 1;
+          transdata->transfer->toreq->cancel = 1;
           transdata->transfer->skip_file = 1;
         }
 
@@ -1467,6 +1460,8 @@
       transdata->curfle == transdata->transfer->curfle)
     {
       transdata->transfer->cancel = 1;
+      transdata->transfer->fromreq->cancel = 1;
+      transdata->transfer->toreq->cancel = 1;
       transdata->transfer->skip_file = 1;
     }
   else if (transdata->curfle != transdata->transfer->curfle &&
@@ -2145,6 +2140,8 @@
                   tdata->next_file = 1;
                   tdata->skip_file = 0;
                   tdata->cancel = 0;
+                  tdata->fromreq->cancel = 0;
+                  tdata->toreq->cancel = 0;
                 }
               else
                 {
@@ -2272,11 +2269,3 @@
              g_strerror (errno));
 }
 
-
-static RETSIGTYPE
-sig_connquit (int signo)
-{
-  signal (signo, sig_connquit);
-  siglongjmp (connenvir, signo == SIGINT ? 1 : 2);
-}
-