- add_exclude_line(p);
-
- log_init();
-
- if (use_chroot) {
- /* TODO: If we're not running as root, then we'll get
- * an error here. I wonder if we should perhaps just
- * log a warning here, and continue anyhow using the
- * push_dir feature? -- mbp 2001-08-31 */
- if (chroot(lp_path(i))) {
- rsyserr(FERROR, errno, "chroot %s failed", lp_path(i));
- io_printf(fd,"@ERROR: chroot failed\n");
- return -1;
+ parse_rule(&server_filter_list, p, MATCHFLG_WORD_SPLIT,
+ XFLG_ABS_IF_SLASH | XFLG_OLD_PREFIXES);
+
+ log_init(1);
+
+#ifdef HAVE_PUTENV
+ if (*lp_prexfer_exec(i) || *lp_postxfer_exec(i)) {
+ char *modname, *modpath, *hostaddr, *hostname, *username;
+ int status;
+ if (asprintf(&modname, "RSYNC_MODULE_NAME=%s", name) < 0
+ || asprintf(&modpath, "RSYNC_MODULE_PATH=%s", module_dir) < 0
+ || asprintf(&hostaddr, "RSYNC_HOST_ADDR=%s", addr) < 0
+ || asprintf(&hostname, "RSYNC_HOST_NAME=%s", host) < 0
+ || asprintf(&username, "RSYNC_USER_NAME=%s", auth_user) < 0)
+ out_of_memory("rsync_module");
+ putenv(modname);
+ putenv(modpath);
+ putenv(hostaddr);
+ putenv(hostname);
+ putenv(username);
+ umask(orig_umask);
+ /* For post-xfer exec, fork a new process to run the rsync
+ * daemon while this process waits for the exit status and
+ * runs the indicated command at that point. */
+ if (*lp_postxfer_exec(i)) {
+ pid_t pid = fork();
+ if (pid < 0) {
+ rsyserr(FLOG, errno, "fork failed");
+ io_printf(f_out, "@ERROR: fork failed\n");
+ return -1;
+ }
+ if (pid) {
+ if (asprintf(&p, "RSYNC_PID=%ld", (long)pid) > 0)
+ putenv(p);
+ if (wait_process(pid, &status, 0) < 0)
+ status = -1;
+ if (asprintf(&p, "RSYNC_RAW_STATUS=%d", status) > 0)
+ putenv(p);
+ if (WIFEXITED(status))
+ status = WEXITSTATUS(status);
+ else
+ status = -1;
+ if (asprintf(&p, "RSYNC_EXIT_STATUS=%d", status) > 0)
+ putenv(p);
+ system(lp_postxfer_exec(i));
+ _exit(status);
+ }