[patch] ftpfs auto reconnect, variable misuse in command()



Another fix, allowing ftpfs to reconnect automatically when disconnected. It also fixes two 1000L bugs in command() where status was used for two different purposes and sock wasn't updated to new SUP.sock after reconnecting. No wonder Ctrl-R worked so miserably for ftp.
--
Jindrich Makovicka
Index: ftpfs.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/ftpfs.c,v
retrieving revision 1.124
diff -u -b -B -r1.124 ftpfs.c
--- ftpfs.c	14 Mar 2003 16:33:02 -0000	1.124
+++ ftpfs.c	4 May 2003 14:01:06 -0000
@@ -320,29 +320,28 @@
 {
     va_list ap;
     char *str, *fmt_str;
-    int status;
-    int sock = SUP.sock;
+    int status, cmdlen;
     
     va_start (ap, fmt);
     fmt_str = g_strdup_vprintf (fmt, ap);
     va_end (ap);
 
-    status = strlen (fmt_str);
-    str = g_realloc (fmt_str, status + 3);
-    strcpy (str + status, "\r\n");
+    cmdlen = strlen (fmt_str);
+    str = g_realloc (fmt_str, cmdlen + 3);
+    strcpy (str + cmdlen, "\r\n");
 
     if (logfile){
         if (strncmp (str, "PASS ", 5) == 0){
             fputs ("PASS <Password not logged>\r\n", logfile);
         } else
-	    fwrite (str, status + 2, 1, logfile);
+	    fwrite (str, cmdlen + 2, 1, logfile);
 
 	fflush (logfile);
     }
 
     got_sigpipe = 0;
     enable_interrupt_key ();
-    status = write (SUP.sock, str, status + 2);
+    status = write (SUP.sock, str, cmdlen + 2);
     
     if (status < 0){
 	code = 421;
@@ -353,9 +352,11 @@
 		level = 1;
 		status = reconnect (me, super);
 		level = 0;
-		if (status && write (SUP.sock, str, status + 2) > 0)
+		if (status && (write (SUP.sock, str, cmdlen + 2) > 0)) {
 		    goto ok;
 	    }
+		
+	    }
 	    got_sigpipe = 1;
 	}
 	g_free (str);
@@ -367,7 +368,7 @@
     disable_interrupt_key ();
     
     if (wait_reply)
-	return get_reply (me, sock, (wait_reply & WANT_STRING) ? reply_str : NULL, sizeof (reply_str)-1);
+	return get_reply (me, SUP.sock, (wait_reply & WANT_STRING) ? reply_str : NULL, sizeof (reply_str)-1);
     return COMPLETE;
 }
 
@@ -967,8 +968,14 @@
     struct sockaddr_in from;
     int s, j, data, fromlen = sizeof(from);
     
-    if ((s = initconn (me, super)) == -1)
+    if ((s = initconn (me, super)) == -1) {
+	/* try issuing an empty command to force reconnect  */
+	j = command (me, super, WAIT_REPLY, "NOOP");
+	if (j != COMPLETE) return -1;
+	if ((s = initconn (me, super)) == -1) {
         return -1;
+	}
+    }
     if (changetype (me, super, isbinary) == -1)
         return -1;
     if (reget > 0){


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]