関数 | |
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_struct * | cleanup_file |
static int | cleanup_fd_r |
static int | cleanup_fd_w |
static pid_t | cleanup_pid = 0 |
pid_t | cleanup_child_pid = -1 |
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.
参照先 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_child_pid・cleanup_fd_r・cleanup_fd_w・cleanup_file・cleanup_fname・cleanup_got_literal・cleanup_new_fname・cleanup_pid・close_all()・do_unlink()・FINFO・finish_transfer()・flush_write_file()・handle_partial_dir()・io_error・io_flush()・keep_partial・kill_all()・log_exit()・log_got_error・partial_dir・rprintf()・verbose・wait_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_fname・cleanup_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_fd_r・cleanup_fd_w・cleanup_file・cleanup_fname・cleanup_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 | ) |
int io_error |
int keep_partial |
int log_got_error |
char* partial_dir |
struct sigaction sigact [static] |
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.
参照元 _exit_cleanup()・cleanup_disable()・receive_data()・recv_files().
char* cleanup_fname [static] |
char* cleanup_new_fname [static] |
struct file_struct* cleanup_file [static] |
int cleanup_fd_r [static] |
int cleanup_fd_w [static] |
pid_t cleanup_pid = 0 [static] |
pid_t cleanup_child_pid = -1 |