shod

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9f57eda3e2c4ee7d3374fde90e8c0de85567cbdc
parent 2d35ae73b14432458565d4bd886e3faec7943b99
Author: seninha <lucas@seninha.org>
Date:   Tue, 21 Jun 2022 18:00:17 -0300

add autostart script read from stdin

Diffstat:
Mshod.1 | 7+++++++
Mshod.c | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/shod.1 b/shod.1 @@ -60,6 +60,9 @@ a controller called .IR shodc (1) to control shod). .PP +.B shod +passes its standard input to the shell after initializing itself. +.PP The options are as follows: .TP .B \-c @@ -687,6 +690,10 @@ The following environment variables affect the execution of The display to start .B shod on. +.TP +.B SHELL +The shell to run with +.IR exec (3). .SH SEE ALSO .IR X (1), .IR xprompt (1), diff --git a/shod.c b/shod.c @@ -1,3 +1,5 @@ +#include <sys/wait.h> + #include <err.h> #include <limits.h> #include <locale.h> @@ -6,6 +8,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> + #include <X11/Xlib.h> #include <X11/Xatom.h> #include <X11/Xproto.h> @@ -17,6 +20,8 @@ #include <X11/extensions/Xrender.h> #include <X11/Xft/Xft.h> +#define SHELL "SHELL" +#define DEF_SHELL "sh" #define DIV 15 /* see containerplace() for details */ #define IGNOREUNMAP 6 /* number of unmap notifies to ignore while scanning existing clients */ #define NAMEMAXLEN 1024 /* maximum length of window's name */ @@ -632,6 +637,26 @@ ecalloc(size_t nmemb, size_t size) return p; } +/* call fork checking for error; exit on error */ +static pid_t +efork(void) +{ + pid_t pid; + + if ((pid = fork()) < 0) + err(1, "fork"); + return pid; +} + +/* call execlp checking for error; exit on error */ +static void +eexec(const char *cmd) +{ + if (execlp(cmd, cmd, NULL) == -1) { + err(1, "%s", cmd); + } +} + /* get color from color string */ static unsigned long ealloccolor(const char *s) @@ -6461,6 +6486,23 @@ xeventunmapnotify(XEvent *e) ewmhsetclientsstacking(); } +/* run stdin on sh */ +static void +autostart(void) +{ + pid_t pid; + char *shell; + + if ((shell = getenv(SHELL)) == NULL) + shell = DEF_SHELL; + if ((pid = efork()) == 0) { + if (efork() == 0) + eexec(shell); + exit(0); + } + waitpid(pid, NULL, 0); +} + /* destroy dummy windows */ static void cleandummywindows(void) @@ -6586,6 +6628,9 @@ main(int argc, char *argv[]) ewmhsetclientsstacking(); ewmhsetactivewindow(None); + /* run stdin on sh */ + autostart(); + /* scan windows */ scan(); mapfocuswin();