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