On Sat, Nov 03, 2018 at 09:01:33PM +0100, Klemens Nanni wrote:
> Closing stdin makes sense, but I still want to see error messages from
> the program I'm running.  Since arbitrary progams can be run, keep both
> stdout and stderr open so users get a chance to actually notice program
> failure or maybe even use output for good.
> 
> In a common setup where xidle(1) is started from ~/.xsession, I'd expect
> errors to pop up in ~/.xsession-errors.
This, plus closely related changes:

We should never execute the program unless a new session was
created so that the child process does not share the same controlling
terminal.

Also, use execvp(3) to search PATH so users don't have to provide full
paths any longer. Not sure why this wasn't done in the first place.

Termination information from wait(2) is not used and irrelevant at this
point, so zap `status'.

OK?

Index: xidle.1
===================================================================
RCS file: /cvs/xenocara/app/xidle/xidle.1,v
retrieving revision 1.5
diff -u -p -r1.5 xidle.1
--- xidle.1     6 Sep 2018 07:21:34 -0000       1.5
+++ xidle.1     11 Nov 2018 16:36:10 -0000
@@ -72,8 +72,7 @@ respectively.
 If no position is specified,
 the default is northwest.
 .It Fl program Ar path
-Specify the full pathname of the program to run on any of the
-aforementioned events.
+Specify the program to run on any of the aforementioned events.
 Arguments to the program may also be specified, separated by whitespace.
 If
 .Fl program
Index: xidle.c
===================================================================
RCS file: /cvs/xenocara/app/xidle/xidle.c,v
retrieving revision 1.8
diff -u -p -r1.8 xidle.c
--- xidle.c     11 Nov 2018 16:10:37 -0000      1.8
+++ xidle.c     11 Nov 2018 16:36:10 -0000
@@ -94,7 +94,7 @@ static XrmOptionDescRec opts[] = {
 
 extern char *__progname;
 
-void   action(struct xinfo *, char **);
+void   action(struct xinfo *, char *const []);
 void   close_x(struct xinfo *);
 Bool   getres(XrmValue *, const XrmDatabase, const char *, const char *);
 void    init_x(struct xinfo *, int, int, int);
@@ -180,19 +180,18 @@ close_x(struct xinfo *xi)
 
 
 void
-action(struct xinfo *xi, char **args)
+action(struct xinfo *xi, char *const args[])
 {
-       int dumb;
-
        switch (fork()) {
        case -1:
                err(1, "fork");
        case 0:
-               setsid();
-               execv(*args, args);
-               exit(1);
+               if (setsid() == -1)
+                       err(1, "setsid");
+               execvp(args[0], args);
+               err(1, "execvp");
        default:
-               wait(&dumb);
+               wait(NULL);
                XSync(xi->dpy, True);
                break;
        }
@@ -356,8 +355,6 @@ main(int argc, char **argv)
        if (fd < 0)
                err(1, _PATH_DEVNULL);
        dup2(fd, STDIN_FILENO);
-       dup2(fd, STDOUT_FILENO);
-       dup2(fd, STDERR_FILENO);
        if (fd > 2)
                close(fd);
 

Reply via email to