[hackers] [slock] remove support for running post lock command || Hiltjo Posthuma
commit 65cb721c9eb7b5d80267378790dee93e9db0223c
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Sat Sep 5 12:20:57 2026 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Sat Sep 5 12:57:54 2026 +0200
remove support for running post lock command
This command was used for example to suspend-to-ram (man page example).
On Linux running this command inherits OOM killer immunity. This could be
abused by an other local user on the same machine (abusing resources).
To keep the use-case for suspend-to-ram an user could write a wrapper script
for it, outside the scope of slock.
Simplify argument handling, because the post-lock command parameter is removed.
Reported by: Acts1631 <acts1631kjv_AT_proton.me>
diff --git a/Makefile b/Makefile
index 6d74b21..c41e57e 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -11,7 +11,7 @@ all: slock
.c.o:
${CC} -c ${CFLAGS} $<
-${OBJ}: config.h config.mk arg.h util.h
+${OBJ}: config.h config.mk util.h
config.h:
cp config.def.h $_AT_
_AT_@ -25,7 +25,7 @@ clean:
dist: clean
mkdir -p slock-${VERSION}
cp -R LICENSE Makefile README slock.1 config.mk \
- ${SRC} config.def.h arg.h util.h slock-${VERSION}
+ ${SRC} config.def.h util.h slock-${VERSION}
tar -cf slock-${VERSION}.tar slock-${VERSION}
gzip slock-${VERSION}.tar
rm -rf slock-${VERSION}
diff --git a/arg.h b/arg.h
deleted file mode 100644
index 0b23c53..0000000
--- a/arg.h
+++ /dev/null
_AT_@ -1,65 +0,0 @@
-/*
- * Copy me if you can.
- * by 20h
- */
-
-#ifndef ARG_H__
-#define ARG_H__
-
-extern char *argv0;
-
-/* use main(int argc, char *argv[]) */
-#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
- argv[0] && argv[0][0] == '-'\
- && argv[0][1];\
- argc--, argv++) {\
- char argc_;\
- char **argv_;\
- int brk_;\
- if (argv[0][1] == '-' && argv[0][2] == '\0') {\
- argv++;\
- argc--;\
- break;\
- }\
- for (brk_ = 0, argv[0]++, argv_ = argv;\
- argv[0][0] && !brk_;\
- argv[0]++) {\
- if (argv_ != argv)\
- break;\
- argc_ = argv[0][0];\
- switch (argc_)
-
-/* Handles obsolete -NUM syntax */
-#define ARGNUM case '0':\
- case '1':\
- case '2':\
- case '3':\
- case '4':\
- case '5':\
- case '6':\
- case '7':\
- case '8':\
- case '9'
-
-#define ARGEND }\
- }
-
-#define ARGC() argc_
-
-#define ARGNUMF() (brk_ = 1, estrtonum(argv[0], 0, INT_MAX))
-
-#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
- ((x), abort(), (char *)0) :\
- (brk_ = 1, (argv[0][1] != '\0')?\
- (&argv[0][1]) :\
- (argc--, argv++, argv[0])))
-
-#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
- (char *)0 :\
- (brk_ = 1, (argv[0][1] != '\0')?\
- (&argv[0][1]) :\
- (argc--, argv++, argv[0])))
-
-#define LNGARG() &argv[0][0]
-
-#endif
diff --git a/slock.1 b/slock.1
index 40c15e1..e485992 100644
--- a/slock.1
+++ b/slock.1
_AT_@ -1,4 +1,4 @@
-.Dd October 6, 2023
+.Dd September 5, 2026
.Dt SLOCK 1
.Os
.Sh NAME
_AT_@ -7,14 +7,9 @@
.Sh SYNOPSIS
.Nm
.Op Fl v
-.Op Ar cmd Op Ar arg ...
.Sh DESCRIPTION
.Nm
is a simple X screen locker.
-If provided,
-.Ar cmd
-is executed after the screen has been locked.
-.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl v
_AT_@ -22,10 +17,6 @@ Print version information to stdout and exit.
.El
.Sh EXIT STATUS
.Ex -std
-.Sh EXAMPLES
-$
-.Nm
-/usr/sbin/s2ram
.Sh SECURITY CONSIDERATIONS
To make sure a locked screen can not be bypassed by switching VTs
or killing the X server with Ctrl+Alt+Backspace, it is recommended
diff --git a/slock.c b/slock.c
index 3cede0f..9c587e1 100644
--- a/slock.c
+++ b/slock.c
_AT_@ -13,14 +13,12 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <spawn.h>
#include <sys/types.h>
#include <X11/extensions/Xrandr.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include "arg.h"
#include "util.h"
char *argv0;
_AT_@ -304,7 +302,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
static void
usage(void)
{
- die("usage: slock [-v] [cmd [arg ...]]\n");
+ die("usage: slock [-v]\n");
}
int
_AT_@ -319,13 +317,12 @@ main(int argc, char **argv) {
Display *dpy;
int s, nlocks, nscreens;
- ARGBEGIN {
- case 'v':
+ if (argc > 1 && !strcmp(argv[1], "-v")) {
puts("slock-"VERSION);
return 0;
- default:
+ } else if (argc > 1) {
usage();
- } ARGEND
+ }
/* validate drop-user and -group */
errno = 0;
_AT_@ -378,17 +375,6 @@ main(int argc, char **argv) {
if (nlocks != nscreens)
return 1;
- /* run post-lock command */
- if (argc > 0) {
- pid_t pid;
- extern char **environ;
- int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
- if (err) {
- die("slock: failed to execute post-lock command: %s: %s\n",
- argv[0], strerror(err));
- }
- }
-
/* everything is now blank. Wait for the correct password */
readpw(dpy, &rr, locks, nscreens, hash);
Received on Sat Sep 05 2026 - 13:00:59 CEST
This archive was generated by hypermail 2.3.0
: Sat Sep 05 2026 - 13:12:36 CEST