aboutsummaryrefslogtreecommitdiff
path: root/slock.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2024-02-26 21:07:08 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2024-02-26 21:07:08 -0800
commit1aebdfb9b77d5f71a5aa9faa13beab1f382cf30c (patch)
treec74ce246d59f0d076dfe3e8f5422a5b0e364cbf1 /slock.c
parent4c565d2020230ad3fdf603fde32b9892e56c16e1 (diff)
downloadslock-1aebdfb9b77d5f71a5aa9faa13beab1f382cf30c.tar.gz
slock-1aebdfb9b77d5f71a5aa9faa13beab1f382cf30c.tar.xz
add option allowing process to be killed by user who started it
Diffstat (limited to 'slock.c')
-rw-r--r--slock.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/slock.c b/slock.c
index 0036c10..edd4440 100644
--- a/slock.c
+++ b/slock.c
@@ -301,7 +301,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
static void
usage(void)
{
- die("usage: slock [-f [-p]] [-v] [cmd [arg ...]]\n");
+ die("usage: slock [-k] [-f [-p]] [-v] [cmd [arg ...]]\n");
}
int
@@ -315,13 +315,17 @@ main(int argc, char **argv) {
const char *hash;
Display *dpy;
int s, nlocks, nscreens;
- int opt_fork, opt_pid;
+ int opt_killable, opt_fork, opt_pid;
pid_t pid;
+ opt_killable = 0;
opt_fork = 0;
opt_pid = 0;
ARGBEGIN {
+ case 'k':
+ opt_killable = 1;
+ break;
case 'f':
opt_fork = 1;
break;
@@ -365,10 +369,17 @@ main(int argc, char **argv) {
/* drop privileges */
if (setgroups(0, NULL) < 0)
die("slock: setgroups: %s\n", strerror(errno));
- if (setgid(dgid) < 0)
- die("slock: setgid: %s\n", strerror(errno));
- if (setuid(duid) < 0)
- die("slock: setuid: %s\n", strerror(errno));
+ if (opt_killable) {
+ if (setregid(-1, dgid) < 0)
+ die("slock: setregid: %s\n", strerror(errno));
+ if (setreuid(-1, duid) < 0)
+ die("slock: setreuid: %s\n", strerror(errno));
+ } else {
+ if (setgid(dgid) < 0)
+ die("slock: setgid: %s\n", strerror(errno));
+ if (setuid(duid) < 0)
+ die("slock: setuid: %s\n", strerror(errno));
+ }
/* check for Xrandr support */
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);