Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

cleanup.c File Reference

Code for handling interrupted transfers. More...

Go to the source code of this file.

Functions

void _exit_cleanup (int code, const char *file, int line)
 Eventually calls exit(), passing code, therefore does not return. More...

void cleanup_disable (void)
void cleanup_set (char *fnametmp, char *fname, struct file_struct *file, struct map_struct *buf, int fd1, int fd2)
void cleanup_set_pid (int pid)

Variables

int cleanup_got_literal = 0
 Set to True once literal data has been sent across the link for the current file. More...

char * cleanup_fname
char * cleanup_new_fname
file_structcleanup_file
int cleanup_fd1
int cleanup_fd2
map_structcleanup_buf
int cleanup_pid = 0
int io_error
pid_t cleanup_child_pid = -1


Detailed Description

Code for handling interrupted transfers.

Depending on the --partial option, we may either delete the temporary file, or go ahead and overwrite the destination. This second behaviour only occurs if we've sent literal data and therefore hopefully made progress on the transfer.

Definition in file cleanup.c.


Function Documentation

void _exit_cleanup int    code,
const char *    file,
int    line
 

Eventually calls exit(), passing code, therefore does not return.

Parameters:
code  one of the RERR_* codes from errcode.h.

Definition at line 59 of file cleanup.c.

References cleanup_child_pid, cleanup_fd1, cleanup_fd2, cleanup_fname, cleanup_got_literal, cleanup_new_fname, cleanup_pid, code, do_unlink(), FINFO, finish_transfer(), io_error, io_flush(), keep_partial, kill_all(), log_exit(), log_got_error, rprintf(), unmap_file(), and waitpid().

00060 {
00061         int ocode = code;
00062         extern int keep_partial;
00063         extern int log_got_error;
00064 
00065         signal(SIGUSR1, SIG_IGN);
00066         signal(SIGUSR2, SIG_IGN);
00067 
00068         if (verbose > 3)
00069                 rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n", 
00070                         code, file, line);
00071 
00072         if (cleanup_child_pid != -1) {
00073                 int status;
00074                 if (waitpid(cleanup_child_pid, &status, WNOHANG) == cleanup_child_pid) {
00075                         status = WEXITSTATUS(status);
00076                         if (status > code) code = status;
00077                 }
00078         }
00079 
00080         if (cleanup_got_literal && cleanup_fname && keep_partial) {
00081                 char *fname = cleanup_fname;
00082                 cleanup_fname = NULL;
00083                 if (cleanup_buf) unmap_file(cleanup_buf);
00084                 if (cleanup_fd1 != -1) close(cleanup_fd1);
00085                 if (cleanup_fd2 != -1) close(cleanup_fd2);
00086                 finish_transfer(cleanup_new_fname, fname, cleanup_file);
00087         }
00088         io_flush();
00089         if (cleanup_fname)
00090                 do_unlink(cleanup_fname);
00091         if (code) {
00092                 kill_all(SIGUSR1);
00093         }
00094         if ((cleanup_pid != 0) && (cleanup_pid == (int) getpid())) {
00095                 char *pidf = lp_pid_file();
00096                 if (pidf && *pidf) {
00097                         unlink(lp_pid_file());
00098                 }
00099         }
00100 
00101         if (code == 0 && (io_error || log_got_error)) {
00102                 code = RERR_PARTIAL;
00103         }
00104 
00105         if (code) log_exit(code, file, line);
00106 
00107         if (verbose > 2)
00108                 rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): about to call exit(%d)\n", 
00109                         ocode, file, line, code);
00110 
00111         exit(code);
00112 }

void cleanup_disable void   
 

Definition at line 114 of file cleanup.c.

References cleanup_fname, and cleanup_got_literal.

Referenced by recv_files().

00115 {
00116         cleanup_fname = NULL;
00117         cleanup_got_literal = 0;
00118 }

void cleanup_set char *    fnametmp,
char *    fname,
struct file_struct   file,
struct map_struct   buf,
int    fd1,
int    fd2
 

Definition at line 121 of file cleanup.c.

References cleanup_fd1, cleanup_fd2, cleanup_fname, and cleanup_new_fname.

Referenced by recv_files().

00123 {
00124         cleanup_fname = fnametmp;
00125         cleanup_new_fname = fname;
00126         cleanup_file = file;
00127         cleanup_buf = buf;
00128         cleanup_fd1 = fd1;
00129         cleanup_fd2 = fd2;
00130 }

void cleanup_set_pid int    pid
 

Definition at line 132 of file cleanup.c.

References cleanup_pid.

Referenced by daemon_main().

00133 {
00134         cleanup_pid = pid;
00135 }


Variable Documentation

int cleanup_got_literal = 0
 

Set to True once literal data has been sent across the link for the current file.

(????)

Handling the cleanup when a transfer is interrupted is tricky when --partial is selected. We need to ensure that the partial file is kept if any real data has been transferred.

Definition at line 42 of file cleanup.c.

Referenced by _exit_cleanup(), cleanup_disable(), and receive_data().

char* cleanup_fname [static]
 

Definition at line 44 of file cleanup.c.

Referenced by _exit_cleanup(), cleanup_disable(), and cleanup_set().

char* cleanup_new_fname [static]
 

Definition at line 45 of file cleanup.c.

Referenced by _exit_cleanup(), and cleanup_set().

struct file_struct* cleanup_file [static]
 

Definition at line 46 of file cleanup.c.

int cleanup_fd1 [static]
 

Definition at line 47 of file cleanup.c.

Referenced by _exit_cleanup(), and cleanup_set().

int cleanup_fd2 [static]
 

Definition at line 47 of file cleanup.c.

Referenced by _exit_cleanup(), and cleanup_set().

struct map_struct* cleanup_buf [static]
 

Definition at line 48 of file cleanup.c.

int cleanup_pid = 0 [static]
 

Definition at line 49 of file cleanup.c.

Referenced by _exit_cleanup(), and cleanup_set_pid().

int io_error
 

Definition at line 50 of file cleanup.c.

Referenced by _exit_cleanup().

pid_t cleanup_child_pid = -1
 

Definition at line 52 of file cleanup.c.

Referenced by _exit_cleanup(), and client_run().


Generated on Tue Apr 16 12:37:37 2002 for rsync by doxygen1.2.15