summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dwl.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/dwl.c b/dwl.c
index 73d3c00..95850d6 100644
--- a/dwl.c
+++ b/dwl.c
@@ -8,6 +8,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
@@ -322,7 +323,7 @@ static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
static void requestmonstate(struct wl_listener *listener, void *data);
static void resize(Client *c, struct wlr_box geo, int interact);
-static void run(char *startup_cmd);
+static void run(char *startup_cmd, uid_t uid);
static void setcursor(struct wl_listener *listener, void *data);
static void setcursorshape(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating);
@@ -2188,7 +2189,7 @@ resize(Client *c, struct wlr_box geo, int interact)
}
void
-run(char *startup_cmd)
+run(char *startup_cmd, uid_t uid)
{
/* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(dpy);
@@ -2201,6 +2202,11 @@ run(char *startup_cmd)
if (!wlr_backend_start(backend))
die("startup: backend_start");
+ /* In case the option is passed, drop priviledges to desired uid */
+ if (uid > 0)
+ setuid(uid);
+
+
/* Now that the socket exists and the backend is started, run the startup command */
if (startup_cmd) {
int piperw[2];
@@ -3172,10 +3178,13 @@ int
main(int argc, char *argv[])
{
char *startup_cmd = NULL;
+ uid_t uid = 0;
int c;
- while ((c = getopt(argc, argv, "s:hdv")) != -1) {
- if (c == 's')
+ while ((c = getopt(argc, argv, "u:s:hdv")) != -1) {
+ if (c == 'u')
+ uid = atoi(optarg);
+ else if (c == 's')
startup_cmd = optarg;
else if (c == 'd')
log_level = WLR_DEBUG;
@@ -3191,10 +3200,10 @@ main(int argc, char *argv[])
if (!getenv("XDG_RUNTIME_DIR"))
die("XDG_RUNTIME_DIR must be set");
setup();
- run(startup_cmd);
+ run(startup_cmd, uid);
cleanup();
return EXIT_SUCCESS;
usage:
- die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
+ die("Usage: %s [-v] [-u uid] [-d] [-s startup command]", argv[0]);
}