* Copyright (C) 1996-2001 Andrew Tridgell <tridge@samba.org>
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2008 Wayne Davison
+ * Copyright (C) 2003-2009 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
extern char *shell_cmd;
extern char *batch_name;
extern char *password_file;
+extern char *backup_dir;
extern char curr_dir[MAXPATHLEN];
+extern char backup_dir_buf[MAXPATHLEN];
extern char *basis_dir[MAX_BASIS_DIRS+1];
extern struct file_list *first_flist;
-extern struct filter_list_struct daemon_filter_list;
+extern filter_rule_list daemon_filter_list;
uid_t our_uid;
+gid_t our_gid;
int am_generator = 0;
int local_server = 0;
int daemon_over_rsh = 0;
void write_del_stats(int f)
{
- if (!INFO_GTE(STATS, 2) || protocol_version < 31)
- return;
+ if (read_batch)
+ write_int(f, NDX_DEL_STATS);
+ else
+ send_msg(MSG_DEL_STATS, "", 0, 0);
write_varint(f, stats.deleted_files - stats.deleted_dirs
- stats.deleted_symlinks - stats.deleted_devices
- stats.deleted_specials);
void read_del_stats(int f)
{
- if (!INFO_GTE(STATS, 2) || protocol_version < 31)
- return;
stats.deleted_files = read_varint(f);
stats.deleted_files += stats.deleted_dirs = read_varint(f);
stats.deleted_files += stats.deleted_symlinks = read_varint(f);
write_varlong30(f, stats.flist_buildtime, 3);
write_varlong30(f, stats.flist_xfertime, 3);
}
- write_del_stats(f);
}
return;
}
stats.flist_buildtime = read_varlong30(f, 3);
stats.flist_xfertime = read_varlong30(f, 3);
}
- if (!read_batch)
- read_del_stats(f);
} else if (write_batch) {
/* The --read-batch process is going to be a client
* receiver, so we need to give it the stats. */
write_varlong30(batch_fd, stats.flist_buildtime, 3);
write_varlong30(batch_fd, stats.flist_xfertime, 3);
}
- /* We don't write the del stats into the batch file -- they
- * come from the generator when reading the batch. */
}
}
#ifdef ICONV_CONST
setup_iconv();
#endif
- if (protect_args)
+ if (protect_args && !daemon_over_rsh)
send_protected_args(*f_out_p, args);
}
}
/* This is only called by the sender. */
-static void read_final_goodbye(int f_in)
+static void read_final_goodbye(int f_in, int f_out)
{
int i, iflags, xlen;
uchar fnamecmp_type;
if (protocol_version < 29)
i = read_int(f_in);
else {
- i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type,
- xname, &xlen);
+ i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, xname, &xlen);
+ if (protocol_version >= 31 && i == NDX_DONE) {
+ if (am_sender)
+ write_ndx(f_out, NDX_DONE);
+ else {
+ if (batch_gen_fd >= 0) {
+ while (read_int(batch_gen_fd) != NDX_DEL_STATS) {}
+ read_del_stats(batch_gen_fd);
+ }
+ send_msg(MSG_DONE, "", 0, 0);
+ }
+ i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, xname, &xlen);
+ }
}
if (i != NDX_DONE) {
io_flush(FULL_FLUSH);
handle_stats(f_out);
if (protocol_version >= 24)
- read_final_goodbye(f_in);
+ read_final_goodbye(f_in, f_out);
io_flush(FULL_FLUSH);
exit_cleanup(0);
}
exit_cleanup(RERR_IPC);
}
+ if (backup_dir) {
+ int ret = make_path(backup_dir_buf, MKP_DROP_NAME); /* drops trailing slash */
+ if (ret < 0)
+ exit_cleanup(RERR_SYNTAX);
+ if (ret)
+ rprintf(FINFO, "Created backup_dir %s\n", backup_dir_buf);
+ else if (INFO_GTE(BACKUP, 1))
+ rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
+ }
+
io_flush(NORMAL_FLUSH);
if ((pid = do_fork()) == -1) {
/* Handle any keep-alive packets from the post-processing work
* that the generator does. */
if (protocol_version >= 29) {
- int iflags, xlen;
- uchar fnamecmp_type;
- char xname[MAXPATHLEN];
-
kluge_around_eof = -1;
/* This should only get stopped via a USR2 signal. */
- read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type,
- xname, &xlen);
+ read_final_goodbye(f_in, f_out);
rprintf(FERROR, "Invalid packet at end of run [%s]\n",
who_am_i());
if (daemon_filter_list.head) {
char **dir_p;
- struct filter_list_struct *elp = &daemon_filter_list;
+ filter_rule_list *elp = &daemon_filter_list;
for (dir_p = basis_dir; *dir_p; dir_p++) {
char *dir = *dir_p;
if (write_batch && !am_server)
start_write_batch(f_out);
flist = send_file_list(f_out, argc, argv);
- set_msg_fd_in(-1);
if (DEBUG_GTE(FLIST, 3))
rprintf(FINFO,"file list sent\n");
io_flush(FULL_FLUSH);
handle_stats(-1);
if (protocol_version >= 24)
- read_final_goodbye(f_in);
+ read_final_goodbye(f_in, f_out);
if (pid != -1) {
if (DEBUG_GTE(EXIT, 2))
rprintf(FINFO,"client_run waiting on %d\n", (int) pid);
starttime = time(NULL);
our_uid = MY_UID();
+ our_gid = MY_GID();
am_root = our_uid == 0;
memset(&stats, 0, sizeof(stats));