1 /* -*- c-file-style: "linux" -*-
3 Copyright (C) 1996-2000 by Andrew Tridgell
4 Copyright (C) Paul Mackerras 1996
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* handling the cleanup when a transfer is interrupted is tricky when
24 --partial is selected. We need to ensure that the partial file is
25 kept if any real data has been transferred */
26 int cleanup_got_literal
=0;
28 static char *cleanup_fname
;
29 static char *cleanup_new_fname
;
30 static struct file_struct
*cleanup_file
;
31 static int cleanup_fd1
, cleanup_fd2
;
32 static struct map_struct
*cleanup_buf
;
33 static int cleanup_pid
= 0;
36 pid_t cleanup_child_pid
= -1;
39 * Code is one of the RERR_* codes from errcode.h.
41 void _exit_cleanup(int code
, const char *file
, int line
)
43 extern int keep_partial
;
44 extern int log_got_error
;
46 signal(SIGUSR1
, SIG_IGN
);
47 signal(SIGUSR2
, SIG_IGN
);
49 if (cleanup_child_pid
!= -1) {
51 if (waitpid(cleanup_child_pid
, &status
, WNOHANG
) == cleanup_child_pid
) {
52 status
= WEXITSTATUS(status
);
53 if (status
> code
) code
= status
;
57 if (cleanup_got_literal
&& cleanup_fname
&& keep_partial
) {
58 char *fname
= cleanup_fname
;
60 if (cleanup_buf
) unmap_file(cleanup_buf
);
61 if (cleanup_fd1
!= -1) close(cleanup_fd1
);
62 if (cleanup_fd2
!= -1) close(cleanup_fd2
);
63 finish_transfer(cleanup_new_fname
, fname
, cleanup_file
);
67 do_unlink(cleanup_fname
);
71 if ((cleanup_pid
!= 0) && (cleanup_pid
== (int) getpid())) {
72 char *pidf
= lp_pid_file();
74 unlink(lp_pid_file());
78 if (code
== 0 && (io_error
|| log_got_error
)) {
82 if (code
) log_exit(code
, file
, line
);
87 void cleanup_disable(void)
90 cleanup_got_literal
= 0;
94 void cleanup_set(char *fnametmp
, char *fname
, struct file_struct
*file
,
95 struct map_struct
*buf
, int fd1
, int fd2
)
97 cleanup_fname
= fnametmp
;
98 cleanup_new_fname
= fname
;
105 void cleanup_set_pid(int pid
)