mirror of
git://git.suckless.org/slock
synced 2025-07-26 09:42:10 -07:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a70d5d2429 | ||
|
a34d8fb432 | ||
|
e8bca65d62 | ||
|
ca6f30f621 | ||
|
2fec14c567 | ||
|
5678764412 | ||
|
aecfb3f680 | ||
|
4f045545a2 | ||
|
265704d736 | ||
|
35633d4567 | ||
|
2d2a21a90a | ||
|
325581b935 | ||
|
0ff0d9f7a7 | ||
|
7a604ec1fa |
1
LICENSE
1
LICENSE
@@ -4,6 +4,7 @@ MIT/X Consortium License
|
|||||||
© 2014 Dimitris Papastamos <sin@2f30.org>
|
© 2014 Dimitris Papastamos <sin@2f30.org>
|
||||||
© 2006-2014 Anselm R Garbe <anselm@garbe.us>
|
© 2006-2014 Anselm R Garbe <anselm@garbe.us>
|
||||||
© 2014-2016 Laslo Hunhold <dev@frign.de>
|
© 2014-2016 Laslo Hunhold <dev@frign.de>
|
||||||
|
© 2016-2023 Hiltjo Posthuma <hiltjo@codemadness.org>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
57
Makefile
57
Makefile
@@ -6,56 +6,41 @@ include config.mk
|
|||||||
SRC = slock.c ${COMPATSRC}
|
SRC = slock.c ${COMPATSRC}
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
|
||||||
all: options slock
|
all: slock
|
||||||
|
|
||||||
options:
|
|
||||||
@echo slock build options:
|
|
||||||
@echo "CFLAGS = ${CFLAGS}"
|
|
||||||
@echo "LDFLAGS = ${LDFLAGS}"
|
|
||||||
@echo "CC = ${CC}"
|
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo CC $<
|
${CC} -c ${CFLAGS} $<
|
||||||
@${CC} -c ${CFLAGS} $<
|
|
||||||
|
|
||||||
${OBJ}: config.h config.mk arg.h util.h
|
${OBJ}: config.h config.mk arg.h util.h
|
||||||
|
|
||||||
config.h:
|
config.h:
|
||||||
@echo creating $@ from config.def.h
|
cp config.def.h $@
|
||||||
@cp config.def.h $@
|
|
||||||
|
|
||||||
slock: ${OBJ}
|
slock: ${OBJ}
|
||||||
@echo CC -o $@
|
${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
rm -f slock ${OBJ} slock-${VERSION}.tar.gz
|
||||||
@rm -f slock ${OBJ} slock-${VERSION}.tar.gz
|
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
@echo creating dist tarball
|
mkdir -p slock-${VERSION}
|
||||||
@mkdir -p slock-${VERSION}
|
cp -R LICENSE Makefile README slock.1 config.mk \
|
||||||
@cp -R LICENSE Makefile README slock.1 config.mk \
|
${SRC} config.def.h arg.h util.h slock-${VERSION}
|
||||||
${SRC} explicit_bzero.c config.def.h arg.h util.h slock-${VERSION}
|
tar -cf slock-${VERSION}.tar slock-${VERSION}
|
||||||
@tar -cf slock-${VERSION}.tar slock-${VERSION}
|
gzip slock-${VERSION}.tar
|
||||||
@gzip slock-${VERSION}.tar
|
rm -rf slock-${VERSION}
|
||||||
@rm -rf slock-${VERSION}
|
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
cp -f slock ${DESTDIR}${PREFIX}/bin
|
||||||
@cp -f slock ${DESTDIR}${PREFIX}/bin
|
chmod 755 ${DESTDIR}${PREFIX}/bin/slock
|
||||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/slock
|
chmod u+s ${DESTDIR}${PREFIX}/bin/slock
|
||||||
@chmod u+s ${DESTDIR}${PREFIX}/bin/slock
|
mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
sed "s/VERSION/${VERSION}/g" <slock.1 >${DESTDIR}${MANPREFIX}/man1/slock.1
|
||||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
chmod 644 ${DESTDIR}${MANPREFIX}/man1/slock.1
|
||||||
@sed "s/VERSION/${VERSION}/g" <slock.1 >${DESTDIR}${MANPREFIX}/man1/slock.1
|
|
||||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/slock.1
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
rm -f ${DESTDIR}${PREFIX}/bin/slock
|
||||||
@rm -f ${DESTDIR}${PREFIX}/bin/slock
|
rm -f ${DESTDIR}${MANPREFIX}/man1/slock.1
|
||||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
|
||||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/slock.1
|
|
||||||
|
|
||||||
.PHONY: all options clean dist install uninstall
|
.PHONY: all clean dist install uninstall
|
||||||
|
2
README
2
README
@@ -1,6 +1,6 @@
|
|||||||
slock - simple screen locker
|
slock - simple screen locker
|
||||||
============================
|
============================
|
||||||
simple screen locker utility for X.
|
simple screen locker utility for X.
|
||||||
|
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
# slock version
|
# slock version
|
||||||
VERSION = 1.4
|
VERSION = 1.5
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
@@ -27,6 +27,3 @@ COMPATSRC = explicit_bzero.c
|
|||||||
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
|
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
|
||||||
# On OpenBSD set COMPATSRC to empty
|
# On OpenBSD set COMPATSRC to empty
|
||||||
#COMPATSRC =
|
#COMPATSRC =
|
||||||
|
|
||||||
# compiler and linker
|
|
||||||
CC = cc
|
|
||||||
|
26
slock.1
26
slock.1
@@ -1,5 +1,6 @@
|
|||||||
.Dd 2016-08-23
|
.Dd October 6, 2023
|
||||||
.Dt SLOCK 1
|
.Dt SLOCK 1
|
||||||
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm slock
|
.Nm slock
|
||||||
.Nd simple X screen locker
|
.Nd simple X screen locker
|
||||||
@@ -9,31 +10,36 @@
|
|||||||
.Op Ar cmd Op Ar arg ...
|
.Op Ar cmd Op Ar arg ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
is a simple X screen locker. If provided,
|
is a simple X screen locker.
|
||||||
.Ar cmd Op Ar arg ...
|
If provided,
|
||||||
|
.Ar cmd
|
||||||
is executed after the screen has been locked.
|
is executed after the screen has been locked.
|
||||||
.Sh OPTIONS
|
.Pp
|
||||||
|
The options are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Print version information to stdout and exit.
|
Print version information to stdout and exit.
|
||||||
.El
|
.El
|
||||||
|
.Sh EXIT STATUS
|
||||||
|
.Ex -std
|
||||||
|
.Sh EXAMPLES
|
||||||
|
$
|
||||||
|
.Nm
|
||||||
|
/usr/sbin/s2ram
|
||||||
.Sh SECURITY CONSIDERATIONS
|
.Sh SECURITY CONSIDERATIONS
|
||||||
To make sure a locked screen can not be bypassed by switching VTs
|
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
|
or killing the X server with Ctrl+Alt+Backspace, it is recommended
|
||||||
to disable both in
|
to disable both in
|
||||||
.Xr xorg.conf 5
|
.Xr xorg.conf 5
|
||||||
for maximum security:
|
for maximum security:
|
||||||
.Bd -literal -offset left
|
.Bd -literal
|
||||||
Section "ServerFlags"
|
Section "ServerFlags"
|
||||||
Option "DontVTSwitch" "True"
|
Option "DontVTSwitch" "True"
|
||||||
Option "DontZap" "True"
|
Option "DontZap" "True"
|
||||||
EndSection
|
EndSection
|
||||||
.Ed
|
.Ed
|
||||||
.Sh EXAMPLES
|
|
||||||
$
|
|
||||||
.Nm
|
|
||||||
/usr/sbin/s2ram
|
|
||||||
.Sh CUSTOMIZATION
|
.Sh CUSTOMIZATION
|
||||||
.Nm
|
.Nm
|
||||||
can be customized by creating a custom config.h from config.def.h and
|
can be customized by creating a custom config.h from config.def.h and
|
||||||
(re)compiling the source code. This keeps it fast, secure and simple.
|
(re)compiling the source code.
|
||||||
|
This keeps it fast, secure and simple.
|
||||||
|
36
slock.c
36
slock.c
@@ -13,6 +13,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <spawn.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <X11/extensions/Xrandr.h>
|
#include <X11/extensions/Xrandr.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
@@ -177,7 +178,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
break;
|
break;
|
||||||
case XK_BackSpace:
|
case XK_BackSpace:
|
||||||
if (len)
|
if (len)
|
||||||
passwd[len--] = '\0';
|
passwd[--len] = '\0';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (num && !iscntrl((int)buf[0]) &&
|
if (num && !iscntrl((int)buf[0]) &&
|
||||||
@@ -201,13 +202,21 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
rre = (XRRScreenChangeNotifyEvent*)&ev;
|
rre = (XRRScreenChangeNotifyEvent*)&ev;
|
||||||
for (screen = 0; screen < nscreens; screen++) {
|
for (screen = 0; screen < nscreens; screen++) {
|
||||||
if (locks[screen]->win == rre->window) {
|
if (locks[screen]->win == rre->window) {
|
||||||
XResizeWindow(dpy, locks[screen]->win,
|
if (rre->rotation == RR_Rotate_90 ||
|
||||||
rre->width, rre->height);
|
rre->rotation == RR_Rotate_270)
|
||||||
|
XResizeWindow(dpy, locks[screen]->win,
|
||||||
|
rre->height, rre->width);
|
||||||
|
else
|
||||||
|
XResizeWindow(dpy, locks[screen]->win,
|
||||||
|
rre->width, rre->height);
|
||||||
XClearWindow(dpy, locks[screen]->win);
|
XClearWindow(dpy, locks[screen]->win);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else for (screen = 0; screen < nscreens; screen++)
|
} else {
|
||||||
XRaiseWindow(dpy, locks[screen]->win);
|
for (screen = 0; screen < nscreens; screen++)
|
||||||
|
XRaiseWindow(dpy, locks[screen]->win);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +318,7 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'v':
|
case 'v':
|
||||||
fprintf(stderr, "slock-"VERSION"\n");
|
puts("slock-"VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@@ -368,15 +377,12 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* run post-lock command */
|
/* run post-lock command */
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
switch (fork()) {
|
pid_t pid;
|
||||||
case -1:
|
extern char **environ;
|
||||||
die("slock: fork failed: %s\n", strerror(errno));
|
int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
|
||||||
case 0:
|
if (err) {
|
||||||
if (close(ConnectionNumber(dpy)) < 0)
|
die("slock: failed to execute post-lock command: %s: %s\n",
|
||||||
die("slock: close: %s\n", strerror(errno));
|
argv[0], strerror(err));
|
||||||
execvp(argv[0], argv);
|
|
||||||
fprintf(stderr, "slock: execvp %s: %s\n", argv[0], strerror(errno));
|
|
||||||
_exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user