Commit ff81e809 authored by Andrew Tridgell's avatar Andrew Tridgell

new error handling system

we now give a non-0 exit code if *any* of the files we have been asked
to transfer fail to transfer
parent fd2dd2aa
......@@ -40,6 +40,7 @@ extern int io_error;
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;
......@@ -69,6 +70,12 @@ void _exit_cleanup(int code, const char *file, int line)
if (code) log_exit(code, file, line);
if (code == 0) {
if (log_got_error) {
code = RERR_FILEIO;
}
}
exit(code);
}
......
......@@ -63,7 +63,7 @@ int start_socket_client(char *host, char *path, int argc, char *argv[])
}
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;
}
......
......@@ -55,10 +55,6 @@ void setup_protocol(int f_out,int f_in)
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);
......
......@@ -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;
......
......@@ -31,6 +31,7 @@ static char *logfname;
static FILE *logfile;
static int log_error_fd = -1;
int log_got_error=0;
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);
/* 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;
......@@ -250,6 +253,7 @@ void rwrite(enum logcode code, char *buf, int len)
}
if (code == FERROR) {
log_got_error = 1;
f = stderr;
}
......
......@@ -553,7 +553,7 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
wait_process(pid, &status);
}
return status | status2;
return MAX(status, status2);
}
static char *find_colon(char *s)
......@@ -699,6 +699,8 @@ static RETSIGTYPE sigusr1_handler(int val) {
}
static RETSIGTYPE sigusr2_handler(int val) {
extern int log_got_error;
if (log_got_error) _exit(RERR_FILEIO);
_exit(0);
}
......@@ -709,6 +711,7 @@ int main(int argc,char *argv[])
extern int dry_run;
extern int am_daemon;
extern int am_server;
int ret;
signal(SIGUSR1, sigusr1_handler);
signal(SIGUSR2, sigusr2_handler);
......@@ -734,7 +737,6 @@ int main(int argc,char *argv[])
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);
......@@ -771,6 +773,8 @@ int main(int argc,char *argv[])
start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
}
return start_client(argc, argv);
ret = start_client(argc, argv);
exit_cleanup(ret);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment