~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH chayang] add option to provide a lock command

Ben Collerson <benc@benc.cc>
Details
Message ID
<20230307001343.66975-1-benc@benc.cc>
DKIM signature
missing
Download raw message
Patch: +21 -2
Option to launch lock command and wait for it to complete from within
chayang. Stops screen from flashing desktop between execution of chayang
and lock program.
---
 main.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 4180f69..d1fc440 100644
--- a/main.c
+++ b/main.c
@@ -5,6 +5,8 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <wayland-client.h>
#include <wayland-cursor.h>
@@ -265,8 +267,9 @@ int main(int argc, char *argv[]) {
	wl_list_init(&state.seats);

	double delay_sec = 3;
	char *command = NULL;
	while (1) {
		int opt = getopt(argc, argv, "hd:");
		int opt = getopt(argc, argv, "hc:d:");
		if (opt < 0) {
			break;
		}
@@ -281,8 +284,11 @@ int main(int argc, char *argv[]) {
				return 1;
			}
			break;
		case 'c':;
			command = optarg;
			break;
		default:
			fprintf(stderr, "usage: chayang [-d seconds]\n");
			fprintf(stderr, "usage: chayang [-d seconds] [-c command]\n");
			return opt == 'h' ? 0 : 1;
		}
	}
@@ -352,6 +358,19 @@ int main(int argc, char *argv[]) {
		ret = 2;
	}

	if (command && ret == 0) {
		int status;
		pid_t pid = fork();

		if (pid == 0)
			execl("/bin/sh", "/bin/sh", "-c", command, NULL);

		if (waitpid(pid, &status, 0) < 0 || WEXITSTATUS(status) != 0) {
			fprintf(stderr, "error running command `%s`\n", command);
			ret = 1;
		}
	}

	struct chayang_output *output_tmp;
	wl_list_for_each_safe(output, output_tmp, &state.outputs, link) {
		destroy_output(output);
-- 
2.39.2
Reply to thread Export thread (mbox)