X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=ioncore%2Fexec.c;h=9da70032c12d2a4d7ccf74ff806994d87eb309a9;hb=bab1a29cb81b48fe5f1f79349db31363e52143c1;hp=10c8267781eb70113e92d50cbae1304d14eec068;hpb=8366314611bf30a0f31d25bf5f5023186fa87692;p=ion3.git diff --git a/ioncore/exec.c b/ioncore/exec.c index 10c8267..9da7003 100644 --- a/ioncore/exec.c +++ b/ioncore/exec.c @@ -1,12 +1,9 @@ /* * ion/ioncore/exec.c * - * Copyright (c) Tuomo Valkonen 1999-2006. + * Copyright (c) Tuomo Valkonen 1999-2009. * - * Ion is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. + * See the included file LICENSE for details. */ #include @@ -28,10 +25,12 @@ /*{{{ Exec */ -void ioncore_setup_environ(int xscr) +void ioncore_setup_display(int xscr) { char *tmp, *ptr; char *display; + + /* Set up $DISPLAY */ display=XDisplayName(ioncore_g.display); @@ -54,7 +53,7 @@ void ioncore_setup_environ(int xscr) snprintf(tmp+strlen(tmp), 11, ".%u", (unsigned)xscr); putenv(tmp); - + /* No need to free it, we'll execve soon */ /*free(tmp);*/ @@ -62,25 +61,15 @@ void ioncore_setup_environ(int xscr) } -typedef struct{ - WRootWin *rw; - const char *wd; -} ExecP; - - -static void setup_exec(void *p_) +void ioncore_setup_environ(const WExecP *p) { - ExecP *p=(ExecP*)p_; - - close(ioncore_g.conn); - - ioncore_g.dpy=NULL; + /* Set up $DISPLAY */ -#ifndef CF_NO_SETPGID - setpgid(0, 0); -#endif + ioncore_setup_display(p->target!=NULL + ? region_rootwin_of(p->target)->xscr + : -1); - ioncore_setup_environ(p->rw==NULL ? -1 : p->rw->xscr); + /* Set up working directory */ if(p->wd!=NULL){ if(chdir(p->wd)!=0) @@ -89,13 +78,29 @@ static void setup_exec(void *p_) } +WHook *ioncore_exec_environ_hook=NULL; + + +static void setup_exec(void *execp) +{ + hook_call_p(ioncore_exec_environ_hook, execp, NULL); + +#ifndef CF_NO_SETPGID + setpgid(0, 0); +#endif + + ioncore_g.dpy=NULL; +} + + EXTL_EXPORT -int ioncore_do_exec_rw(WRootWin *rw, const char *cmd, const char *wd, +int ioncore_do_exec_on(WRegion *reg, const char *cmd, const char *wd, ExtlFn errh) { - ExecP p; + WExecP p; - p.rw=rw; + p.target=reg; + p.cmd=cmd; p.wd=wd; return mainloop_popen_bgread(cmd, setup_exec, (void*)&p, @@ -113,23 +118,28 @@ EXTL_SAFE EXTL_EXPORT int ioncore_exec(const char *cmd) { - return ioncore_do_exec_rw(NULL, cmd, NULL, extl_fn_none()); + return ioncore_do_exec_on(NULL, cmd, NULL, extl_fn_none()); } /*EXTL_DOC - * Run \var{cmd} with a read pipe connected to its stdout. - * When data is received through the pipe, \var{handler} is called - * with that data. + * Run \var{cmd} in directory \var{wd} with a read pipe connected to its + * stdout and stderr. + * When data is received through one of these pipes, \var{h} or \var{errh} + * is called with that data. When the pipe is closed, the handler is called + * with \code{nil} argument. The PID of the new process is returned, or + * -1 on error. */ EXTL_SAFE EXTL_EXPORT -int ioncore_popen_bgread(const char *cmd, ExtlFn h, ExtlFn errh) +int ioncore_popen_bgread(const char *cmd, ExtlFn h, ExtlFn errh, + const char *wd) { - ExecP p; + WExecP p; - p.rw=NULL; - p.wd=NULL; + p.target=NULL; + p.wd=wd; + p.cmd=cmd; return mainloop_popen_bgread(cmd, setup_exec, (void*)&p, h, errh); } @@ -196,7 +206,7 @@ void ioncore_do_restart() ioncore_deinit(); if(other!=NULL){ if(ioncore_g.display!=NULL) - ioncore_setup_environ(-1); + ioncore_setup_display(-1); mainloop_do_exec(other); warn_err_obj(other); }