new error handling system
authorAndrew Tridgell <tridge@samba.org>
Thu, 22 Mar 2001 07:36:51 +0000 (07:36 +0000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 22 Mar 2001 07:36:51 +0000 (07:36 +0000)
we now give a non-0 exit code if *any* of the files we have been asked
to transfer fail to transfer

cleanup.c
clientserver.c
compat.c
io.c
log.c
main.c

index bd562ae..4b9cad3 100644 (file)
--- a/cleanup.c
+++ b/cleanup.c
@@ -40,6 +40,7 @@ extern int io_error;
 void _exit_cleanup(int code, const char *file, int line)
 {
        extern int keep_partial;
 void _exit_cleanup(int code, const char *file, int line)
 {
        extern int keep_partial;
+       extern int log_got_error;
 
        if (code == 0 && io_error) code = RERR_FILEIO;
 
 
        if (code == 0 && io_error) code = RERR_FILEIO;
 
@@ -69,6 +70,12 @@ void _exit_cleanup(int code, const char *file, int line)
 
        if (code) log_exit(code, file, line);
 
 
        if (code) log_exit(code, file, line);
 
+       if (code == 0) {
+               if (log_got_error) {
+                       code = RERR_FILEIO;
+               }
+       }
+
        exit(code);
 }
 
        exit(code);
 }
 
index 1bb0633..3d8b0a1 100644 (file)
@@ -63,7 +63,7 @@ int start_socket_client(char *host, char *path, int argc, char *argv[])
         }
         
        if (*path == '/') {
         }
         
        if (*path == '/') {
-               rprintf(FERROR,"ERROR: The remote path must start with a module name\n");
+               rprintf(FERROR,"ERROR: The remote path must start with a module name not a /\n");
                return -1;
        }
 
                return -1;
        }
 
index ee9e052..305c827 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -55,10 +55,6 @@ void setup_protocol(int f_out,int f_in)
                exit_cleanup(RERR_PROTOCOL);
        }       
        
                exit_cleanup(RERR_PROTOCOL);
        }       
        
-       if (verbose > 2)
-               rprintf(FINFO, "local_version=%d remote_version=%d\n",
-                       PROTOCOL_VERSION, remote_version);
-       
        if (remote_version >= 12) {
                if (am_server) {
                        checksum_seed = time(NULL);
        if (remote_version >= 12) {
                if (am_server) {
                        checksum_seed = time(NULL);
diff --git a/io.c b/io.c
index 649bd75..1069a2e 100644 (file)
--- a/io.c
+++ b/io.c
@@ -490,18 +490,6 @@ void io_end_buffering(int fd)
        }
 }
 
        }
 }
 
-/* some OSes have a bug where an exit causes the pending writes on
-   a socket to be flushed. Do an explicit shutdown to try to prevent this */
-void io_shutdown(void)
-{
-       err_list_push();
-       if (multiplex_out_fd != -1) close(multiplex_out_fd);
-       if (io_error_fd != -1) close(io_error_fd);
-       multiplex_out_fd = -1;
-       io_error_fd = -1;
-}
-
-
 static void writefd(int fd,char *buf,int len)
 {
        stats.total_written += len;
 static void writefd(int fd,char *buf,int len)
 {
        stats.total_written += len;
diff --git a/log.c b/log.c
index a826b18..492948b 100644 (file)
--- a/log.c
+++ b/log.c
@@ -31,6 +31,7 @@ static char *logfname;
 static FILE *logfile;
 static int log_error_fd = -1;
 
 static FILE *logfile;
 static int log_error_fd = -1;
 
+int log_got_error=0;
 
 struct {
         int code;
 
 struct {
         int code;
@@ -107,6 +108,8 @@ void err_list_push(void)
        while (err_list_head) {
                struct err_list *el = err_list_head;
                int n = write(log_error_fd, el->buf+el->written, el->len - el->written);
        while (err_list_head) {
                struct err_list *el = err_list_head;
                int n = write(log_error_fd, el->buf+el->written, el->len - el->written);
+               /* don't check for an error if the best way of handling the error is
+                  to ignore it */
                if (n == -1) break;
                if (n > 0) {
                        el->written += n;
                if (n == -1) break;
                if (n > 0) {
                        el->written += n;
@@ -250,6 +253,7 @@ void rwrite(enum logcode code, char *buf, int len)
        }
 
        if (code == FERROR) {
        }
 
        if (code == FERROR) {
+               log_got_error = 1;
                f = stderr;
        } 
 
                f = stderr;
        } 
 
diff --git a/main.c b/main.c
index 86a1a55..dae6e79 100644 (file)
--- a/main.c
+++ b/main.c
@@ -553,7 +553,7 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
                wait_process(pid, &status);
        }
        
                wait_process(pid, &status);
        }
        
-       return status | status2;
+       return MAX(status, status2);
 }
 
 static char *find_colon(char *s)
 }
 
 static char *find_colon(char *s)
@@ -699,6 +699,8 @@ static RETSIGTYPE sigusr1_handler(int val) {
 }
 
 static RETSIGTYPE sigusr2_handler(int val) {
 }
 
 static RETSIGTYPE sigusr2_handler(int val) {
+       extern int log_got_error;
+       if (log_got_error) _exit(RERR_FILEIO);
        _exit(0);
 }
 
        _exit(0);
 }
 
@@ -709,6 +711,7 @@ int main(int argc,char *argv[])
        extern int dry_run;
        extern int am_daemon;
        extern int am_server;
        extern int dry_run;
        extern int am_daemon;
        extern int am_server;
+       int ret;
 
        signal(SIGUSR1, sigusr1_handler);
        signal(SIGUSR2, sigusr2_handler);
 
        signal(SIGUSR1, sigusr1_handler);
        signal(SIGUSR2, sigusr2_handler);
@@ -734,7 +737,6 @@ int main(int argc,char *argv[])
                exit_cleanup(RERR_SYNTAX);
        }
 
                exit_cleanup(RERR_SYNTAX);
        }
 
-       signal(SIGCHLD,SIG_IGN);
        signal(SIGINT,SIGNAL_CAST sig_int);
        signal(SIGPIPE,SIGNAL_CAST sig_int);
        signal(SIGHUP,SIGNAL_CAST sig_int);
        signal(SIGINT,SIGNAL_CAST sig_int);
        signal(SIGPIPE,SIGNAL_CAST sig_int);
        signal(SIGHUP,SIGNAL_CAST sig_int);
@@ -771,6 +773,8 @@ int main(int argc,char *argv[])
                start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
        }
 
                start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
        }
 
-       return start_client(argc, argv);
+       ret = start_client(argc, argv);
+       exit_cleanup(ret);
+       return ret;
 }
 
 }