return 0;
}
-#ifdef HAVE_PUTENV
+#if defined HAVE_SETENV || defined HAVE_PUTENV
static int read_arg_from_pipe(int fd, char *buf, int limit)
{
char *bp = buf, *eob = buf + limit - 1;
static void set_env_str(const char *var, const char *str)
{
+#ifdef HAVE_SETENV
+ if (setenv(var, str, 1) < 0)
+ out_of_memory("set_env_str");
+#else
#ifdef HAVE_PUTENV
char *mem;
if (asprintf(&mem, "%s=%s", var, str) < 0)
out_of_memory("set_env_str");
putenv(mem);
+#else
+ (void)var;
+ (void)str;
+#endif
#endif
}
+#if defined HAVE_SETENV || defined HAVE_PUTENV
+
+static void set_envN_str(const char *var, int num, const char *str)
+{
+#ifdef HAVE_SETENV
+ char buf[128];
+ (void)snprintf(buf, sizeof buf, "%s%d", var, num);
+ if (setenv(buf, str, 1) < 0)
+ out_of_memory("set_env_str");
+#else
#ifdef HAVE_PUTENV
+ char *mem;
+ if (asprintf(&mem, "%s%d=%s", var, num, str) < 0)
+ out_of_memory("set_envN_str");
+ putenv(mem);
+#endif
+#endif
+}
+
void set_env_num(const char *var, long num)
{
+#ifdef HAVE_SETENV
+ char val[64];
+ (void)snprintf(val, sizeof val, "%ld", num);
+ if (setenv(var, val, 1) < 0)
+ out_of_memory("set_env_str");
+#else
+#ifdef HAVE_PUTENV
char *mem;
if (asprintf(&mem, "%s=%ld", var, num) < 0)
out_of_memory("set_env_num");
putenv(mem);
-}
#endif
+#endif
+}
/* Used for "early exec", "pre-xfer exec", and the "name converter" script. */
static pid_t start_pre_exec(const char *cmd, int *arg_fd_ptr, int *error_fd_ptr)
set_env_str("RSYNC_REQUEST", buf);
for (j = 0; ; j++) {
- char *p;
len = read_arg_from_pipe(arg_fd, buf, BIGPATHBUFLEN);
if (len <= 0) {
if (!len)
break;
_exit(1);
}
- if (asprintf(&p, "RSYNC_ARG%d=%s", j, buf) >= 0)
- putenv(p);
+ set_envN_str("RSYNC_ARG", j, buf);
}
dup2(arg_fd, STDIN_FILENO);
return pid;
}
+#endif
+
static void write_pre_exec_args(int write_fd, char *request, char **early_argv, char **argv, int exec_type)
{
int j = 0;
log_init(1);
-#ifdef HAVE_PUTENV
+#if defined HAVE_SETENV || defined HAVE_PUTENV
if ((*lp_early_exec(module_id) || *lp_prexfer_exec(module_id)
|| *lp_postxfer_exec(module_id) || *lp_name_converter(module_id))
&& !getenv("RSYNC_NO_XFER_EXEC")) {
#ifdef HAVE_PUTENV
if (daemon_connection)
set_env_num("RSYNC_PORT", env_port);
+#else
+ (void)env_port;
#endif
pid = do_cmd(shell_cmd, shell_machine, shell_user, remote_argv, remote_argc, &f_in, &f_out);
#endif
}
-
/**
* This routine catches signals and tries to send them to gdb.
*
return "xterm -display :0 -T Panic -n Panic -e gdb /proc/%d/exe %d";
}
-
/**
* Handle a fatal signal by launching a debugger, controlled by $RSYNC_PANIC_ACTION.
*
}
#endif
+static void unset_env_var(const char *var)
+{
+#ifdef HAVE_UNSETENV
+ unsetenv(var);
+#else
+#ifdef HAVE_PUTENV
+ char *mem;
+ if (asprintf(&mem, "%s=", var) < 0)
+ out_of_memory("unset_env_var");
+ putenv(mem);
+#else
+ (void)var;
+#endif
+#endif
+}
+
int main(int argc,char *argv[])
{
our_gid = MY_GID();
am_root = our_uid == ROOT_UID;
+ unset_env_var("DISPLAY");
+
memset(&stats, 0, sizeof(stats));
/* Even a non-daemon runs needs the default config values to be set, e.g.