Skip to content

Commit

Permalink
Add ability to wait for command to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyfan committed Jan 13, 2019
1 parent 161bc3c commit a1e49da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct swayidle_state {
struct wl_event_loop *event_loop;
struct wl_list timeout_cmds; // struct swayidle_timeout_cmd *
char *lock_cmd;
bool wait;
} state;

struct swayidle_timeout_cmd {
Expand Down Expand Up @@ -83,7 +84,9 @@ static void cmd_exec(char *param) {
swayidle_log(LOG_DEBUG, "Cmd exec %s", param);
pid_t pid = fork();
if (pid == 0) {
pid = fork();
if (!state.wait) {
pid = fork();
}
if (pid == 0) {
char *const cmd[] = { "sh", "-c", param, NULL, };
execvp(cmd[0], cmd);
Expand Down Expand Up @@ -357,16 +360,20 @@ static int parse_sleep(int argc, char **argv) {

static int parse_args(int argc, char *argv[]) {
int c;
while ((c = getopt(argc, argv, "hd")) != -1) {
while ((c = getopt(argc, argv, "hdw")) != -1) {
switch (c) {
case 'd':
verbosity = LOG_DEBUG;
break;
case 'w':
state.wait = true;
break;
case 'h':
case '?':
printf("Usage: %s [OPTIONS]\n", argv[0]);
printf(" -d\tdebug\n");
printf(" -h\tthis help menu\n");
printf(" -d\tdebug\n");
printf(" -w\wait for command to finish\n");
return 1;
default:
return 1;
Expand Down
10 changes: 10 additions & 0 deletions swayidle.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ swayidle - Idle manager for Wayland
*-d*
Enable debug output.

*-w*
Wait for command to finish executing before continuing, helpful for ensuring
that a *before-sleep* command has finished before the system goes to sleep.

Note: using this option causes swayidle to block until the command finishes.

# DESCRIPTION

swayidle listens for idle activity on your Wayland compositor and executes tasks
Expand All @@ -36,6 +42,10 @@ Sending SIGUSR1 to swayidle will immediately enter idle state.
If built with systemd support, executes _command_ before systemd puts the
computer to sleep.

Note: this only delays sleeping up to the limit set in *logind.conf(5)* by
the option InhibitDelayMaxSec. A command that has not finished by then will
continue running after resuming from sleep.

All commands are executed in a shell.

# EXAMPLE
Expand Down

0 comments on commit a1e49da

Please sign in to comment.