commit: fa6f5e88ada3f53f9eb64f80e0cd6547a0133bea
parent 1f05b9a1a093accaee5ff20433d86876125c4671
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 3 Dec 2020 12:43:41 -0800
st: Don't wait for process to exit when plumbing
Diffstat:
2 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/pkg/st/patch/0003-Add-support-for-plumbing-via-right-click.patch b/pkg/st/patch/0003-Add-support-for-plumbing-via-right-click.patch
@@ -1,12 +1,12 @@
-From 6e99154fe219e4fdb7bf6fd441863adb3c2e005b Mon Sep 17 00:00:00 2001
+From 278e0375c56b7a8abca4807163158e6811b01125 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Wed, 2 Dec 2020 17:54:35 -0800
Subject: [PATCH] Add support for plumbing via right click
---
config.def.h | 5 ++++
- st.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++---
- 2 files changed, 68 insertions(+), 3 deletions(-)
+ st.c | 74 +++++++++++++++++++++++++++++++++++++++++++---------
+ 2 files changed, 67 insertions(+), 12 deletions(-)
diff --git a/config.def.h b/config.def.h
index 49ca50b..a63d2be 100644
@@ -22,7 +22,7 @@ index 49ca50b..a63d2be 100644
+ */
+static char *plumb_cmd[] = {"plumb", NULL, NULL};
diff --git a/st.c b/st.c
-index caa5aa0..b4e9616 100644
+index caa5aa0..e27ee51 100644
--- a/st.c
+++ b/st.c
@@ -44,6 +44,9 @@ char *argv0;
@@ -74,7 +74,7 @@ index caa5aa0..b4e9616 100644
void
selinit(void)
{
-@@ -1165,6 +1186,37 @@ wlsetsel(char *str, uint32_t serial)
+@@ -1165,6 +1186,29 @@ wlsetsel(char *str, uint32_t serial)
wl_data_device_set_selection(wl.datadev, sel.source, serial);
}
@@ -89,30 +89,45 @@ index caa5aa0..b4e9616 100644
+plumb(char *sel)
+{
+ char cwd[PATH_MAX];
-+ pid_t pid;
+
+ if (!sel || subprocwd(cwd, sizeof(cwd)) != 0)
+ return;
+ plumb_cmd[plumbsel] = sel;
+
-+ pid = fork();
-+ switch (pid) {
-+ case -1:
-+ break;
-+ case 0:
-+ if (chdir(cwd) != 0)
-+ exit(1);
-+ execvp(plumb_cmd[0], plumb_cmd);
++ if (fork() == 0) {
++ if (chdir(cwd) == 0)
++ execvp(plumb_cmd[0], plumb_cmd);
+ _exit(1);
-+ default:
-+ waitpid(pid, NULL, 0);
+ }
+}
+
void
die(const char *errstr, ...)
{
-@@ -4223,16 +4275,23 @@ ptrbutton(void * data, struct wl_pointer * pointer, uint32_t serial,
+@@ -1227,15 +1271,13 @@ sigchld(int a)
+ int stat;
+ pid_t p;
+
+- if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
+- die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
+-
+- if (pid != p)
+- return;
+-
+- if (!WIFEXITED(stat) || WEXITSTATUS(stat))
+- die("child finished with error '%d'\n", stat);
+- exit(0);
++ while ((p = waitpid(-1, &stat, WNOHANG)) == 0) {
++ if (pid == p) {
++ if (!WIFEXITED(stat) || WEXITSTATUS(stat))
++ die("child finished with error '%d'\n", stat);
++ exit(0);
++ }
++ }
+ }
+
+
+@@ -4223,16 +4265,23 @@ ptrbutton(void * data, struct wl_pointer * pointer, uint32_t serial,
switch (state) {
case WL_POINTER_BUTTON_STATE_RELEASED:
@@ -139,7 +154,7 @@ index caa5aa0..b4e9616 100644
}
break;
-@@ -4556,6 +4615,7 @@ main(int argc, char *argv[])
+@@ -4556,6 +4605,7 @@ main(int argc, char *argv[])
} ARGEND;
run:
diff --git a/pkg/st/ver b/pkg/st/ver
@@ -1 +1 @@
-c63a87cd93 r2
+c63a87cd93 r3