exec command if it's not exit

This commit is contained in:
emersion 2017-10-02 18:21:39 +02:00
parent c686699817
commit eb0b315c6c
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 9 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_pointer.h> #include <wlr/types/wlr_pointer.h>
@ -25,6 +26,14 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
struct roots_server *server = keyboard->input->server; struct roots_server *server = keyboard->input->server;
if (strcmp(command, "exit") == 0) { if (strcmp(command, "exit") == 0) {
wl_display_terminate(server->wl_display); wl_display_terminate(server->wl_display);
} else {
pid_t pid = fork();
if (pid < 0) {
wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
return;
} else if (pid == 0) {
execl("/bin/sh", "/bin/sh", "-c", command, (void *)NULL);
}
} }
} }