Fixed failing hunks.
[rsync/rsync-patches.git] / pre-post-exec.diff
CommitLineData
1955c4a2
WD
1A crude attempt to add two new daemon module options:
2
3 pre-exec = COMMAND
4 post-exec = COMMAND
5
6The pre-exec command runs prior to the chroot() (if enabled) as the daemon user.
7
8The post-exec command runs inside any chroot() as the module user.
9
10You'll want to run "make proto" after applying this patch.
11
5b36b3cc
WD
12--- orig/cleanup.c 2005-03-05 18:58:38
13+++ cleanup.c 2005-06-10 21:32:40
14@@ -21,9 +21,13 @@
1955c4a2
WD
15
16 #include "rsync.h"
17
18+extern int am_daemon;
5b36b3cc
WD
19+extern int am_sender;
20+extern int am_generator;
1955c4a2
WD
21 extern int io_error;
22 extern int keep_partial;
23 extern int log_got_error;
24+extern int module_id;
25 extern char *partial_dir;
26
27 /**
5b36b3cc 28@@ -152,6 +156,16 @@ void _exit_cleanup(int code, const char
1955c4a2
WD
29 ocode, safe_fname(file), line, code);
30 }
31
5b36b3cc 32+ if (am_daemon && (am_sender || am_generator)) {
1955c4a2
WD
33+ char *p = lp_post_exec(module_id);
34+ if (p && *p) {
35+ char *arg;
36+ if (asprintf(&arg, "RSYNC_EXIT_STATUS=%d", code) == 0)
37+ putenv(arg); /* XXX Need configure support? */
38+ system(p); /* XXX Check for errors */
39+ }
40+ }
41+
42 close_all();
43 exit(code);
44 }
5b36b3cc
WD
45--- orig/clientserver.c 2005-06-10 21:33:27
46+++ clientserver.c 2005-06-10 21:25:25
1955c4a2
WD
47@@ -347,6 +347,10 @@ static int rsync_module(int f_in, int f_
48
49 log_init();
50
51+ p = lp_pre_exec(i);
52+ if (p && *p)
53+ system(p); /* XXX Check for errors */
54+
55 if (use_chroot) {
56 /*
57 * XXX: The 'use chroot' flag is a fairly reliable
5b36b3cc
WD
58--- orig/loadparm.c 2005-06-10 21:33:28
59+++ loadparm.c 2005-06-10 21:25:25
1955c4a2
WD
60@@ -140,6 +140,8 @@ typedef struct
61 char *log_format;
62 char *refuse_options;
63 char *dont_compress;
64+ char *pre_exec;
65+ char *post_exec;
66 int timeout;
67 int max_connections;
68 int max_verbosity;
69@@ -175,6 +177,8 @@ static service sDefault =
70 "%o %h [%a] %m (%u) %f %l", /* log format */
71 NULL, /* refuse options */
72 "*.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz", /* dont compress */
73+ NULL, /* pre_exec */
74+ NULL, /* post_exec */
75 0, /* timeout */
76 0, /* max connections */
77 1, /* max verbosity */
78@@ -298,6 +302,8 @@ static struct parm_struct parm_table[] =
79 {"log format", P_STRING, P_LOCAL, &sDefault.log_format, NULL, 0},
80 {"refuse options", P_STRING, P_LOCAL, &sDefault.refuse_options,NULL, 0},
81 {"dont compress", P_STRING, P_LOCAL, &sDefault.dont_compress,NULL, 0},
82+ {"pre-exec", P_STRING, P_LOCAL, &sDefault.pre_exec, NULL, 0},
83+ {"post-exec", P_STRING, P_LOCAL, &sDefault.post_exec, NULL, 0},
84 {NULL, P_BOOL, P_NONE, NULL, NULL, 0}
85 };
86
87@@ -379,6 +385,8 @@ FN_LOCAL_STRING(lp_include_from, include
88 FN_LOCAL_STRING(lp_log_format, log_format)
89 FN_LOCAL_STRING(lp_refuse_options, refuse_options)
90 FN_LOCAL_STRING(lp_dont_compress, dont_compress)
91+FN_LOCAL_STRING(lp_pre_exec, pre_exec)
92+FN_LOCAL_STRING(lp_post_exec, post_exec)
93 FN_LOCAL_INTEGER(lp_timeout, timeout)
94 FN_LOCAL_INTEGER(lp_max_connections, max_connections)
95 FN_LOCAL_INTEGER(lp_max_verbosity, max_verbosity)