Skip to content

Commit

Permalink
src/wl-restart: set WL_RESTART_COUNT on compositor restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdi265 committed Jul 19, 2024
1 parent fb079fa commit 3bc8242
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ in the [KDE wiki](https://invent.kde.org/plasma/kwin/-/wikis/Restarting).
- Restarts your compositor when it crashes
- Don't lose your session (for programs that support seamless Wayland reconnect)
- Configurable max number of crashes before giving up
- Sets `WL_RESTART_COUNT` to the current restart counter on compositor restart.

## Usage

Expand Down
4 changes: 4 additions & 0 deletions man/wl-restart.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ If the compositor exits with any other exit code, *wl-restart* increments the
restart counter and restarts the compositor if it is smaller than the maximum.
Otherwise, *wl-restart* cleans up the socket and exits as well.

When the compositor is restarted, *wl-restart* sets the environment variable
*WL_RESTART_COUNT* to the restart counter, so other scripts can react to it and
e.g. display a message or restart services that don't restart automatically.

When *wl-restart* receives a *SIGINT* or *SIGTERM* signal, it kills the
compositor with *SIGTERM* if it's currently running, cleans up the socket, and
exits.
Expand Down
11 changes: 11 additions & 0 deletions src/wl-restart.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ void run(ctx_t * ctx) {
ctx->restart_counter++;
printf("info: compositor exited with code %d, incrementing restart counter (%d)\n", status, ctx->restart_counter);
}

// format new restart count
char * restart_counter_str = NULL;
if (asprintf(&restart_counter_str, "%d", ctx->restart_counter) == -1) {
printf("error: failed to convert restart counter to string\n");
exit_fail(ctx);
}

// add restart count to environment
setenv("WL_RESTART_COUNT", restart_counter_str, true);
free(restart_counter_str);
}

printf("error: too many restarts, quitting\n");
Expand Down

0 comments on commit 3bc8242

Please sign in to comment.