cleanup.c

Code for handling interrupted transfers. [詳細]

ソースコードを見る。


関数

void close_all (void)
 Close all open sockets and files, allowing a (somewhat) graceful shutdown() of socket connections.
void _exit_cleanup (int code, const char *file, int line)
 Eventually calls exit(), passing code, therefore does not return.
void cleanup_disable (void)
void cleanup_set (char *fnametmp, char *fname, struct file_struct *file, int fd_r, int fd_w)
void cleanup_set_pid (pid_t pid)

変数

int io_error
int keep_partial
int log_got_error
char * partial_dir
static struct sigaction sigact
int cleanup_got_literal = 0
 Set to True once literal data has been sent across the link for the current file.
static char * cleanup_fname
static char * cleanup_new_fname
static struct file_structcleanup_file
static int cleanup_fd_r
static int cleanup_fd_w
static pid_t cleanup_pid = 0
pid_t cleanup_child_pid = -1

説明

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.

cleanup.c で定義されています。


関数

void close_all ( void   ) 

Close all open sockets and files, allowing a (somewhat) graceful shutdown() of socket connections.

This eliminates the abortive TCP RST sent by a Winsock-based system when the close() occurs.

cleanup.c38 行で定義されています。

参照先 do_fstat()is_a_socket().

参照元 _exit_cleanup()sigusr2_handler()start_accept_loop().

00039 {
00040 #ifdef SHUTDOWN_ALL_SOCKETS
00041         int max_fd;
00042         int fd;
00043         int ret;
00044         STRUCT_STAT st;
00045 
00046         max_fd = sysconf(_SC_OPEN_MAX) - 1;
00047         for (fd = max_fd; fd >= 0; fd--) {
00048                 if ((ret = do_fstat(fd, &st)) == 0) {
00049                         if (is_a_socket(fd))
00050                                 ret = shutdown(fd, 2);
00051                         ret = close(fd);
00052                 }
00053         }
00054 #endif
00055 }

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

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

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

cleanup.c90 行で定義されています。

参照先 cleanup_child_pidcleanup_fd_rcleanup_fd_wcleanup_filecleanup_fnamecleanup_got_literalcleanup_new_fnamecleanup_pidclose_all()do_unlink()FINFOfinish_transfer()flush_write_file()handle_partial_dir()io_errorio_flush()keep_partialkill_all()log_exit()log_got_errorpartial_dirrprintf()verbosewait_process().

00091 {
00092         int ocode = code;
00093         static int inside_cleanup = 0;
00094 
00095         if (inside_cleanup > 10) {
00096                 /* prevent the occasional infinite recursion */
00097                 return;
00098         }
00099         inside_cleanup++;
00100 
00101         SIGACTION(SIGUSR1, SIG_IGN);
00102         SIGACTION(SIGUSR2, SIG_IGN);
00103 
00104         if (verbose > 3) {
00105                 rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n",
00106                         code, file, line);
00107         }
00108 
00109         if (cleanup_child_pid != -1) {
00110                 int status;
00111                 if (wait_process(cleanup_child_pid, &status, WNOHANG)
00112                  == cleanup_child_pid) {
00113                         status = WEXITSTATUS(status);
00114                         if (status > code)
00115                                 code = status;
00116                 }
00117         }
00118 
00119         if (cleanup_got_literal && cleanup_fname && keep_partial
00120             && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
00121                 char *fname = cleanup_fname;
00122                 cleanup_fname = NULL;
00123                 if (cleanup_fd_r != -1)
00124                         close(cleanup_fd_r);
00125                 if (cleanup_fd_w != -1) {
00126                         flush_write_file(cleanup_fd_w);
00127                         close(cleanup_fd_w);
00128                 }
00129                 finish_transfer(cleanup_new_fname, fname, NULL,
00130                                 cleanup_file, 0, !partial_dir);
00131         }
00132         io_flush(FULL_FLUSH);
00133         if (cleanup_fname)
00134                 do_unlink(cleanup_fname);
00135         if (code)
00136                 kill_all(SIGUSR1);
00137         if (cleanup_pid && cleanup_pid == getpid()) {
00138                 char *pidf = lp_pid_file();
00139                 if (pidf && *pidf)
00140                         unlink(lp_pid_file());
00141         }
00142 
00143         if (code == 0) {
00144                 if (io_error & IOERR_DEL_LIMIT)
00145                         code = RERR_DEL_LIMIT;
00146                 if (io_error & IOERR_VANISHED)
00147                         code = RERR_VANISHED;
00148                 if (io_error & IOERR_GENERAL || log_got_error)
00149                         code = RERR_PARTIAL;
00150         }
00151 
00152         if (code)
00153                 log_exit(code, file, line);
00154 
00155         if (verbose > 2) {
00156                 rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): about to call exit(%d)\n",
00157                         ocode, file, line, code);
00158         }
00159 
00160         close_all();
00161         exit(code);
00162 }

void cleanup_disable ( void   ) 

cleanup.c164 行で定義されています。

参照先 cleanup_fnamecleanup_got_literal.

参照元 recv_files().

00165 {
00166         cleanup_fname = NULL;
00167         cleanup_got_literal = 0;
00168 }

void cleanup_set ( char *  fnametmp,
char *  fname,
struct file_struct file,
int  fd_r,
int  fd_w 
)

cleanup.c171 行で定義されています。

参照先 cleanup_fd_rcleanup_fd_wcleanup_filecleanup_fnamecleanup_new_fname.

参照元 recv_files().

00173 {
00174         cleanup_fname = fname ? fnametmp : NULL;
00175         cleanup_new_fname = fname;
00176         cleanup_file = file;
00177         cleanup_fd_r = fd_r;
00178         cleanup_fd_w = fd_w;
00179 }

void cleanup_set_pid ( pid_t  pid  ) 

cleanup.c181 行で定義されています。

参照先 cleanup_pid.

参照元 daemon_main().

00182 {
00183         cleanup_pid = pid;
00184 }


変数

int io_error

flist.c72 行で定義されています。

参照元 _exit_cleanup()delete_in_dir()generate_files()make_file()recv_file_list()send_directory()send_file_list()send_files()send_if_directory().

int keep_partial

options.c98 行で定義されています。

参照元 _exit_cleanup()parse_arguments()recv_files()server_options().

int log_got_error

log.c61 行で定義されています。

参照元 _exit_cleanup()rwrite()sigusr2_handler().

char* partial_dir

options.c146 行で定義されています。

参照元 _exit_cleanup()handle_partial_dir()parse_arguments()partial_dir_fname()recv_files()recv_generator().

struct sigaction sigact [static]

cleanup.c30 行で定義されています。

参照元 main()start_accept_loop()start_daemon().

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.

cleanup.c75 行で定義されています。

参照元 _exit_cleanup()cleanup_disable()receive_data()recv_files().

char* cleanup_fname [static]

cleanup.c77 行で定義されています。

参照元 _exit_cleanup()cleanup_disable()cleanup_set().

char* cleanup_new_fname [static]

cleanup.c78 行で定義されています。

参照元 _exit_cleanup()cleanup_set().

struct file_struct* cleanup_file [static]

cleanup.c79 行で定義されています。

参照元 _exit_cleanup()cleanup_set().

int cleanup_fd_r [static]

cleanup.c80 行で定義されています。

参照元 _exit_cleanup()cleanup_set().

int cleanup_fd_w [static]

cleanup.c80 行で定義されています。

参照元 _exit_cleanup()cleanup_set().

pid_t cleanup_pid = 0 [static]

cleanup.c81 行で定義されています。

参照元 _exit_cleanup()cleanup_set_pid().

pid_t cleanup_child_pid = -1

cleanup.c83 行で定義されています。

参照元 _exit_cleanup()client_run().


rsyncに対してSat Dec 5 19:45:43 2009に生成されました。  doxygen 1.4.7