mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-04-26 00:59:24 -04:00
patch from Alberto Accomazzi <aaccomazzi@cfa.harvard.edu> to add
different exit codes for different conditions.
This commit is contained in:
@@ -56,7 +56,7 @@ int start_socket_client(char *host, char *path, int argc, char *argv[])
|
||||
|
||||
fd = open_socket_out(host, rsync_port);
|
||||
if (fd == -1) {
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SOCKETIO);
|
||||
}
|
||||
|
||||
server_options(sargs,&sargc);
|
||||
@@ -311,7 +311,7 @@ static int rsync_module(int fd, int i)
|
||||
|
||||
if (!ret) {
|
||||
rprintf(FERROR,"Error parsing options (unsupported option?) - aborting\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
start_server(fd, fd, argc, argp);
|
||||
@@ -343,7 +343,7 @@ static int start_daemon(int fd)
|
||||
extern int remote_version;
|
||||
|
||||
if (!lp_load(config_file, 0)) {
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
set_socket_options(fd,"SO_KEEPALIVE");
|
||||
@@ -433,7 +433,7 @@ int daemon_main(void)
|
||||
|
||||
if (!lp_load(config_file, 1)) {
|
||||
fprintf(stderr,"failed to load config file %s\n", config_file);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
log_open();
|
||||
@@ -447,7 +447,7 @@ int daemon_main(void)
|
||||
if ((f = fopen(lp_pid_file(), "w")) == NULL) {
|
||||
cleanup_set_pid(0);
|
||||
fprintf(stderr,"failed to create pid file %s\n", pid_file);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
}
|
||||
fprintf(f, "%d\n", pid);
|
||||
fclose(f);
|
||||
|
||||
2
compat.c
2
compat.c
@@ -54,7 +54,7 @@ void setup_protocol(int f_out,int f_in)
|
||||
remote_version > MAX_PROTOCOL_VERSION) {
|
||||
rprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
|
||||
rprintf(FERROR,"(see the rsync man page for an explanation)\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_PROTOCOL);
|
||||
}
|
||||
|
||||
if (verbose > 2)
|
||||
|
||||
18
errcode.h
Normal file
18
errcode.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/* error codes returned by rsync */
|
||||
|
||||
#define RERR_SYNTAX 1 /* syntax or usage error */
|
||||
#define RERR_PROTOCOL 2 /* protocol incompatibility */
|
||||
#define RERR_FILESELECT 3 /* errors selecting input/output files, dirs */
|
||||
#define RERR_NOSUPPORT 4 /* requested action not supported */
|
||||
|
||||
#define RERR_SOCKETIO 10 /* error in socket IO */
|
||||
#define RERR_FILEIO 11 /* error in file IO */
|
||||
#define RERR_STREAMIO 12 /* error in rsync protocol data stream */
|
||||
#define RERR_MESSAGEIO 13 /* errors with program diagnostics */
|
||||
#define RERR_IPC 14 /* error in IPC code */
|
||||
|
||||
#define RERR_SIGNAL 20 /* status returned when sent SIGUSR1, SIGINT */
|
||||
#define RERR_WAITCHILD 21 /* some error returned by waitpid() */
|
||||
#define RERR_MALLOC 22 /* error allocating core memory buffers */
|
||||
|
||||
#define RERR_TIMEOUT 30 /* timeout in data send/receive */
|
||||
@@ -221,7 +221,7 @@ struct exclude_struct **make_exclude_list(char *fname,
|
||||
if (!f) {
|
||||
if (fatal) {
|
||||
rprintf(FERROR,"%s : %s\n",fname,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ void send_exclude_list(int f)
|
||||
if (exclude_list[i]->include) {
|
||||
if (remote_version < 19) {
|
||||
rprintf(FERROR,"remote rsync does not support include syntax - aborting\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_NOSUPPORT);
|
||||
}
|
||||
write_int(f,l+2);
|
||||
write_buf(f,"+ ",2);
|
||||
|
||||
4
fileio.c
4
fileio.c
@@ -136,7 +136,7 @@ char *map_ptr(struct map_struct *map,OFF_T offset,int len)
|
||||
}
|
||||
if (munmap(map->map, map->p_len) != 0) {
|
||||
rprintf(FERROR,"munmap failed : %s\n", strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_MALLOC);
|
||||
}
|
||||
|
||||
/* align the mmap region on a nice boundary back a bit from
|
||||
@@ -186,7 +186,7 @@ char *map_ptr(struct map_struct *map,OFF_T offset,int len)
|
||||
|
||||
if (do_lseek(map->fd,offset,SEEK_SET) != offset) {
|
||||
rprintf(FERROR,"lseek failed in map_ptr\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
}
|
||||
|
||||
if ((nread=read(map->fd,map->p,len)) != len) {
|
||||
|
||||
2
flist.c
2
flist.c
@@ -686,7 +686,7 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
|
||||
if (pop_dir(olddir) != 0) {
|
||||
rprintf(FERROR,"pop_dir %s : %s\n",
|
||||
dir,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
io.c
18
io.c
@@ -60,7 +60,7 @@ static void check_timeout(void)
|
||||
if (last_io && io_timeout && (t-last_io) >= io_timeout) {
|
||||
rprintf(FERROR,"io timeout after %d second - exiting\n",
|
||||
(int)(t-last_io));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ static int read_timeout(int fd, char *buf, int len)
|
||||
if (eof_error) {
|
||||
rprintf(FERROR,"unexpected EOF in read_timeout\n");
|
||||
}
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
rprintf(FERROR,"read error: %s\n", strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -181,13 +181,13 @@ static int read_unbuffered(int fd, char *buf, int len)
|
||||
|
||||
if (tag != FERROR && tag != FINFO) {
|
||||
rprintf(FERROR,"unexpected tag %d\n", tag);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
if (remaining > sizeof(line)-1) {
|
||||
rprintf(FERROR,"multiplexing overflow %d\n\n",
|
||||
remaining);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
read_loop(fd, line, remaining);
|
||||
@@ -292,7 +292,7 @@ int64 read_longint(int f)
|
||||
|
||||
#ifdef NO_INT64
|
||||
rprintf(FERROR,"Integer overflow - attempted 64 bit offset\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_UNSUPPORTED);
|
||||
#else
|
||||
if (remote_version >= 16) {
|
||||
readfd(f,b,8);
|
||||
@@ -386,7 +386,7 @@ static void writefd_unbuffered(int fd,char *buf,int len)
|
||||
|
||||
if (ret <= 0) {
|
||||
rprintf(FERROR,"erroring writing %d bytes - exiting\n", len);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
blocked = 0;
|
||||
@@ -541,7 +541,7 @@ void io_printf(int fd, const char *format, ...)
|
||||
len = vslprintf(buf, sizeof(buf)-1, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (len < 0) exit_cleanup(1);
|
||||
if (len < 0) exit_cleanup(RERR_STREAMIO);
|
||||
|
||||
write_sbuf(fd, buf);
|
||||
}
|
||||
@@ -563,7 +563,7 @@ void io_start_multiplex_in(int fd)
|
||||
io_flush();
|
||||
if (read_buffer_len) {
|
||||
fprintf(stderr,"ERROR: data in read buffer at mplx start\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
io_multiplexing_in = 1;
|
||||
|
||||
@@ -358,7 +358,7 @@ static void string_set(char **s, char *v)
|
||||
return;
|
||||
}
|
||||
*s = strdup(v);
|
||||
if (!*s) exit_cleanup(1);
|
||||
if (!*s) exit_cleanup(RERR_MALLOC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
14
log.c
14
log.c
@@ -93,9 +93,9 @@ void log_open(void)
|
||||
len = vslprintf(buf, sizeof(buf)-1, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (len < 0) exit_cleanup(1);
|
||||
if (len < 0) exit_cleanup(RERR_MESSAGEIO);
|
||||
|
||||
if (len > sizeof(buf)-1) exit_cleanup(1);
|
||||
if (len > sizeof(buf)-1) exit_cleanup(RERR_MESSAGEIO);
|
||||
|
||||
buf[len] = 0;
|
||||
|
||||
@@ -134,9 +134,9 @@ void log_open(void)
|
||||
f = stdout;
|
||||
}
|
||||
|
||||
if (!f) exit_cleanup(1);
|
||||
if (!f) exit_cleanup(RERR_MESSAGEIO);
|
||||
|
||||
if (fwrite(buf, len, 1, f) != 1) exit_cleanup(1);
|
||||
if (fwrite(buf, len, 1, f) != 1) exit_cleanup(RERR_MESSAGEIO);
|
||||
|
||||
if (buf[len-1] == '\r' || buf[len-1] == '\n') fflush(f);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ void rflush(int fd)
|
||||
f = stdout;
|
||||
}
|
||||
|
||||
if (!f) exit_cleanup(1);
|
||||
if (!f) exit_cleanup(RERR_MESSAGEIO);
|
||||
fflush(f);
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ static void log_formatted(int fd,
|
||||
if ((l-1) + ((int)(s - &buf[0])) > sizeof(buf)) {
|
||||
rprintf(FERROR,"buffer overflow expanding %%%c - exiting\n",
|
||||
p[0]);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_MESSAGEIO);
|
||||
}
|
||||
|
||||
if (l != 2) {
|
||||
@@ -304,7 +304,7 @@ void log_exit(int code)
|
||||
(double)stats.total_read,
|
||||
(double)stats.total_size);
|
||||
} else {
|
||||
rprintf(FLOG,"transfer interrupted\n");
|
||||
rprintf(FLOG,"transfer interrupted (code %d)\n", code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
main.c
32
main.c
@@ -178,13 +178,13 @@ static char *get_local_name(struct file_list *flist,char *name)
|
||||
if (!push_dir(name, 0)) {
|
||||
rprintf(FERROR,"push_dir %s : %s (1)\n",
|
||||
name,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
if (flist->count > 1) {
|
||||
rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ static char *get_local_name(struct file_list *flist,char *name)
|
||||
|
||||
if (do_mkdir(name,0777 & ~orig_umask) != 0) {
|
||||
rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
} else {
|
||||
if (verbose > 0)
|
||||
rprintf(FINFO,"created directory %s\n",name);
|
||||
@@ -206,7 +206,7 @@ static char *get_local_name(struct file_list *flist,char *name)
|
||||
if (!push_dir(name, 0)) {
|
||||
rprintf(FERROR,"push_dir %s : %s (2)\n",
|
||||
name,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -228,7 +228,7 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
|
||||
|
||||
if (!relative_paths && !push_dir(dir, 0)) {
|
||||
rprintf(FERROR,"push_dir %s: %s (3)\n",dir,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -275,7 +275,7 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
|
||||
|
||||
if (pipe(recv_pipe) < 0) {
|
||||
rprintf(FERROR,"pipe failed in do_recv\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SOCKETIO);
|
||||
}
|
||||
|
||||
io_flush();
|
||||
@@ -330,7 +330,7 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
|
||||
if (!am_daemon && !push_dir(dir, 0)) {
|
||||
rprintf(FERROR,"push_dir %s : %s (4)\n",
|
||||
dir,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
|
||||
flist = recv_file_list(f_in);
|
||||
if (!flist || flist->count == 0) {
|
||||
rprintf(FERROR,"server_recv: nothing to do\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILESELECT);
|
||||
}
|
||||
|
||||
if (argc > 0) {
|
||||
@@ -489,7 +489,7 @@ static int start_client(int argc, char *argv[])
|
||||
|
||||
if (argc < 1) {
|
||||
usage(FERROR);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
am_sender = 0;
|
||||
@@ -511,7 +511,7 @@ static int start_client(int argc, char *argv[])
|
||||
|
||||
if (argc < 2) {
|
||||
usage(FERROR);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
if (local_server) {
|
||||
@@ -544,7 +544,7 @@ static int start_client(int argc, char *argv[])
|
||||
|
||||
if (!am_sender && argc > 1) {
|
||||
usage(FERROR);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
pid = do_cmd(shell_cmd,shell_machine,shell_user,shell_path,&f_in,&f_out);
|
||||
@@ -559,7 +559,7 @@ static int start_client(int argc, char *argv[])
|
||||
|
||||
|
||||
static RETSIGTYPE sigusr1_handler(int val) {
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SIGNAL);
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
@@ -579,7 +579,7 @@ int main(int argc,char *argv[])
|
||||
|
||||
if (argc < 2) {
|
||||
usage(FERROR);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
/* we set a 0 umask so that correct file permissions can be
|
||||
@@ -587,7 +587,7 @@ int main(int argc,char *argv[])
|
||||
orig_umask = (int)umask(0);
|
||||
|
||||
if (!parse_arguments(argc, argv)) {
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
@@ -606,7 +606,7 @@ int main(int argc,char *argv[])
|
||||
|
||||
if (argc < 1) {
|
||||
usage(FERROR);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
|
||||
if (dry_run)
|
||||
@@ -615,7 +615,7 @@ int main(int argc,char *argv[])
|
||||
#ifndef SUPPORT_LINKS
|
||||
if (!am_server && preserve_links) {
|
||||
rprintf(FERROR,"ERROR: symbolic links not supported\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_UNSUPPORTED);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ int parse_arguments(int argc, char *argv[])
|
||||
case OPT_SENDER:
|
||||
if (!am_server) {
|
||||
usage(FERROR);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SYNTAX);
|
||||
}
|
||||
am_sender = 1;
|
||||
break;
|
||||
|
||||
@@ -223,7 +223,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
|
||||
|
||||
if (fd != -1 && write_file(fd,data,i) != i) {
|
||||
rprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
}
|
||||
offset += i;
|
||||
continue;
|
||||
@@ -249,7 +249,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
|
||||
if (fd != -1 && write_file(fd,map,len) != len) {
|
||||
rprintf(FERROR,"write failed on %s : %s\n",
|
||||
fname,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
}
|
||||
offset += len;
|
||||
}
|
||||
@@ -259,7 +259,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
|
||||
if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
|
||||
rprintf(FERROR,"write failed on %s : %s\n",
|
||||
fname,strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_FILEIO);
|
||||
}
|
||||
|
||||
sum_end(file_sum1);
|
||||
@@ -322,7 +322,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
|
||||
if (i < 0 || i >= flist->count) {
|
||||
rprintf(FERROR,"Invalid file index %d in recv_files (count=%d)\n",
|
||||
i, flist->count);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_PROTOCOL);
|
||||
}
|
||||
|
||||
file = flist->files[i];
|
||||
|
||||
2
rsync.c
2
rsync.c
@@ -188,7 +188,7 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
|
||||
|
||||
void sig_int(void)
|
||||
{
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SIGNAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
2
rsync.h
2
rsync.h
@@ -63,6 +63,8 @@
|
||||
#define FINFO 2
|
||||
#define FLOG 3
|
||||
|
||||
#include "errcode.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if HAVE_REMSH
|
||||
|
||||
2
sender.c
2
sender.c
@@ -118,7 +118,7 @@ void send_files(struct file_list *flist,int f_out,int f_in)
|
||||
if (i < 0 || i >= flist->count) {
|
||||
rprintf(FERROR,"Invalid file index %d (count=%d)\n",
|
||||
i, flist->count);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_PROTOCOL);
|
||||
}
|
||||
|
||||
file = flist->files[i];
|
||||
|
||||
8
socket.c
8
socket.c
@@ -125,12 +125,12 @@ void start_accept_loop(int port, int (*fn)(int ))
|
||||
/* open an incoming socket */
|
||||
s = open_socket_in(SOCK_STREAM, port);
|
||||
if (s == -1)
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SOCKETIO);
|
||||
|
||||
/* ready to listen */
|
||||
if (listen(s, 5) == -1) {
|
||||
close(s);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SOCKETIO);
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ char *client_addr(int fd)
|
||||
initialised = 1;
|
||||
|
||||
if (getpeername(fd, &sa, &length)) {
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SOCKETIO);
|
||||
}
|
||||
|
||||
strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf)-1);
|
||||
@@ -356,7 +356,7 @@ char *client_name(int fd)
|
||||
strcpy(name_buf,def);
|
||||
|
||||
if (getpeername(fd, &sa, &length)) {
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_SOCKETIO);
|
||||
}
|
||||
|
||||
/* Look up the remote host name. */
|
||||
|
||||
16
token.c
16
token.c
@@ -108,7 +108,7 @@ send_deflated_token(int f, int token,
|
||||
Z_DEFLATED, -15, 8,
|
||||
Z_DEFAULT_STRATEGY) != Z_OK) {
|
||||
rprintf(FERROR, "compression init failed\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
if ((obuf = malloc(MAX_DATA_COUNT+2)) == NULL)
|
||||
out_of_memory("send_deflated_token");
|
||||
@@ -178,7 +178,7 @@ send_deflated_token(int f, int token,
|
||||
r = deflate(&tx_strm, flush);
|
||||
if (r != Z_OK) {
|
||||
rprintf(FERROR, "deflate returned %d\n", r);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
if (nb == 0 || tx_strm.avail_out == 0) {
|
||||
n = MAX_DATA_COUNT - tx_strm.avail_out;
|
||||
@@ -215,7 +215,7 @@ send_deflated_token(int f, int token,
|
||||
if (r != Z_OK || tx_strm.avail_in != 0) {
|
||||
rprintf(FERROR, "deflate on token returned %d (%d bytes left)\n",
|
||||
r, tx_strm.avail_in);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,7 +250,7 @@ recv_deflated_token(int f, char **data)
|
||||
rx_strm.zfree = NULL;
|
||||
if (inflateInit2(&rx_strm, -15) != Z_OK) {
|
||||
rprintf(FERROR, "inflate init failed\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
if ((cbuf = malloc(MAX_DATA_COUNT)) == NULL
|
||||
|| (dbuf = malloc(CHUNK_SIZE)) == NULL)
|
||||
@@ -293,7 +293,7 @@ recv_deflated_token(int f, char **data)
|
||||
if (r != Z_OK && r != Z_BUF_ERROR) {
|
||||
rprintf(FERROR, "inflate flush returned %d (%d bytes)\n",
|
||||
r, n);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
if (n != 0 && r != Z_BUF_ERROR) {
|
||||
/* have to return some more data and
|
||||
@@ -308,7 +308,7 @@ recv_deflated_token(int f, char **data)
|
||||
*/
|
||||
if (!inflateSyncPoint(&rx_strm)) {
|
||||
rprintf(FERROR, "decompressor lost sync!\n");
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
rx_strm.avail_in = 4;
|
||||
rx_strm.next_in = (Bytef *)cbuf;
|
||||
@@ -343,7 +343,7 @@ recv_deflated_token(int f, char **data)
|
||||
n = CHUNK_SIZE - rx_strm.avail_out;
|
||||
if (r != Z_OK) {
|
||||
rprintf(FERROR, "inflate returned %d (%d bytes)\n", r, n);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
if (rx_strm.avail_in == 0)
|
||||
recv_state = r_inflated;
|
||||
@@ -399,7 +399,7 @@ static void see_deflate_token(char *buf, int len)
|
||||
r = inflate(&rx_strm, Z_SYNC_FLUSH);
|
||||
if (r != Z_OK) {
|
||||
rprintf(FERROR, "inflate (token) returned %d\n", r);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
} while (len || rx_strm.avail_out == 0);
|
||||
}
|
||||
|
||||
22
util.c
22
util.c
@@ -61,14 +61,14 @@ int piped_child(char **command,int *f_in,int *f_out)
|
||||
if (pipe(to_child_pipe) < 0 ||
|
||||
pipe(from_child_pipe) < 0) {
|
||||
rprintf(FERROR,"pipe: %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
|
||||
pid = do_fork();
|
||||
if (pid < 0) {
|
||||
rprintf(FERROR,"fork: %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
if (pid == 0)
|
||||
@@ -79,7 +79,7 @@ int piped_child(char **command,int *f_in,int *f_out)
|
||||
close(from_child_pipe[0]) < 0 ||
|
||||
dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
|
||||
rprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]);
|
||||
if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]);
|
||||
@@ -87,13 +87,13 @@ int piped_child(char **command,int *f_in,int *f_out)
|
||||
execvp(command[0], command);
|
||||
rprintf(FERROR,"Failed to exec %s : %s\n",
|
||||
command[0],strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
if (close(from_child_pipe[1]) < 0 ||
|
||||
close(to_child_pipe[0]) < 0) {
|
||||
rprintf(FERROR,"Failed to close : %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
*f_in = from_child_pipe[0];
|
||||
@@ -114,14 +114,14 @@ int local_child(int argc, char **argv,int *f_in,int *f_out)
|
||||
if (pipe(to_child_pipe) < 0 ||
|
||||
pipe(from_child_pipe) < 0) {
|
||||
rprintf(FERROR,"pipe: %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
|
||||
pid = do_fork();
|
||||
if (pid < 0) {
|
||||
rprintf(FERROR,"fork: %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
@@ -136,7 +136,7 @@ int local_child(int argc, char **argv,int *f_in,int *f_out)
|
||||
close(from_child_pipe[0]) < 0 ||
|
||||
dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
|
||||
rprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]);
|
||||
if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]);
|
||||
@@ -146,7 +146,7 @@ int local_child(int argc, char **argv,int *f_in,int *f_out)
|
||||
if (close(from_child_pipe[1]) < 0 ||
|
||||
close(to_child_pipe[0]) < 0) {
|
||||
rprintf(FERROR,"Failed to close : %s\n",strerror(errno));
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_IPC);
|
||||
}
|
||||
|
||||
*f_in = from_child_pipe[0];
|
||||
@@ -160,13 +160,13 @@ int local_child(int argc, char **argv,int *f_in,int *f_out)
|
||||
void out_of_memory(char *str)
|
||||
{
|
||||
rprintf(FERROR,"ERROR: out of memory in %s\n",str);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_MALLOC);
|
||||
}
|
||||
|
||||
void overflow(char *str)
|
||||
{
|
||||
rprintf(FERROR,"ERROR: buffer overflow in %s\n",str);
|
||||
exit_cleanup(1);
|
||||
exit_cleanup(RERR_MALLOC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user