diff options
author | Christoph Gysin <christoph.gysin@gmail.com> | 2015-11-25 23:19:08 +0200 |
---|---|---|
committer | Christoph Gysin <christoph.gysin@gmail.com> | 2015-11-25 23:19:11 +0200 |
commit | e362f871d93df7568267d9a50ff77b63f5300528 (patch) | |
tree | 629ad007a5353170bd1a6fdbdb732e8076edc2d9 /sway/config.c | |
parent | 9fb020d04c487904ef3d87a15bbdc885cca886e7 (diff) |
Call swaybg without invoking a shell
This makes escaping the arguments obsolete.
Also avoid dynamic memory allocation for the output id. It only supported ids up
to 99. Now we support up to 999, and take 4 bytes off the stack instead.
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/sway/config.c b/sway/config.c index 4955c94f..ba88a315 100644 --- a/sway/config.c +++ b/sway/config.c @@ -334,17 +334,22 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { } sway_log(L_DEBUG, "Setting background for output %d to %s", i, oc->background); - char *cmd = malloc( - strlen("swaybg ") + - (i >= 10 ? 2 : 1) + - strlen(oc->background) + 3 + - strlen(oc->background_option) + 3 + - 1); - sprintf(cmd, "swaybg %d '%s' '%s'", i, oc->background, oc->background_option); + + size_t bufsize = 4; + char output_id[bufsize]; + snprintf(output_id, bufsize, "%d", i); + output_id[bufsize-1] = 0; + + char *const cmd[] = { + "swaybg", + output_id, + oc->background, + oc->background_option, + NULL, + }; if (fork() == 0) { - execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); + execvp(cmd[0], cmd); } - free(cmd); } } |