Update README and Makefile.

This commit is contained in:
2026-09-04 17:14:35 -07:00
parent 7f2ec329c4
commit 5bace1d0e8
5 changed files with 102 additions and 161 deletions
+81 -37
View File
@@ -1,46 +1,90 @@
# slock - simple screen locker UNAME_M := $(shell uname -m)
# See LICENSE file for copyright and license details.
include config.mk ifeq ($(UNAME_M),x86_64)
ARCH := ARCHITECTURE_X64
else ifneq ($(filter $(UNAME_M),i686,i386),)
ARCH := ARCHITECTURE_X86
else ifneq ($(filter $(UNAME_M),aarch64 arm64),)
ARCH := ARCHITECTURE_ARM64
else ifneq ($(filter $(UNAME_M),armv7l armv6l),)
ARCH := ARCHITECTURE_ARM32
endif
SRC = slock.c ${COMPATSRC} UNAME_E := $(shell [ $$(printf '\01\00' | od -An -tu2) -eq 1 ] && \
OBJ = ${SRC:.c=.o} echo "little" || echo "big")
all: slock ifeq ($(UNAME_E),little)
ENDIANESS := LITTLE_ENDIAN
else ifeq ($(UNAME_E),little)
ENDIANESS := BIG_ENDIAN
endif
.c.o: UNAME_S := $(shell uname -s)
${CC} -c ${CFLAGS} $<
${OBJ}: config.h config.mk arg.h util.h ifeq ($(UNAME_S),Darwin)
OS := OS_MACOS
else ifeq ($(UNAME_S),Linux)
OS := OS_LINUX
endif
config.h: CC = gcc
cp config.def.h $@
slock: ${OBJ} ifeq ($(CC),clang)
${CC} -o $@ ${OBJ} ${LDFLAGS} COMP := COMPILER_CLANG
else ifeq ($(CC),gcc)
COMP := COMPILER_GCC
endif
# -ansi -pedantic -pedantic-errors
CFLAGS = -Wno-long-long -Wall -Wextra \
-Wincompatible-pointer-types \
-Wint-conversion -Wformat \
-Wno-strict-prototypes -Wno-missing-field-initializers \
-Wno-unused-function -Wno-unused-parameter -Wno-unused-variable \
-Wno-unused-but-set-variable \
-fno-show-column
ifeq ($(COMP),COMPILER_CLANG)
CFLAGS += -fno-caret-diagnostics
else ifeq ($(COMP),COMPILER_GCC)
CFLAGS += -fno-diagnostics-show-caret
endif
ifeq ($(OS),OS_MACOS)
FLAGS = -glldb
INCLUDE =
LIBS =
FRAMEWORKS =
else ifeq ($(OS),OS_LINUX)
FLAGS = -O3 # -ggdb -DDEBUG=1 -DINTERNAL=1
INCLUDE = -I/usr/include -I/usr/X11R6/include
LIBS = -lc -lcrypt -lX11 -lXext -lXrandr
FRAMEWORKS =
endif
EXE = slock
VERSION = "\"1.7\""
default: $(EXE)
$(EXE): $(EXE).c explicit_bzero.c
$(CC) $(CFLAGS) $(FLAGS) \
-D$(ARCH)=1 -D$(ENDIANESS)=1 -D$(OS)=1 -D$(COMP)=1 \
-DVERSION=$(VERSION) -D_DEFAULT_SOURCE -DHAVE_SHADOW_H \
$(INCLUDE) $^ $(LIBS) \
$(FRAMEWORKS) -o $@ $(ifneq $(filter $(OS), OS_MACOS OS_LINUX), \
/link /FORCE:MULTIPLE)
watch:
@ while true; do \
inotifywait -q -q -e 'modify' . && clear && make -B; \
done
perf:
perf record --call-graph dwarf ./$(EXE)
run:
@ clear; ./$(EXE)
clean: clean:
rm -f slock ${OBJ} slock-${VERSION}.tar.gz @ rm -rf $(EXE) $(EXE).dSYM
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}
tar -cf slock-${VERSION}.tar slock-${VERSION}
gzip slock-${VERSION}.tar
rm -rf slock-${VERSION}
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f slock ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/slock
chmod u+s ${DESTDIR}${PREFIX}/bin/slock
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" <slock.1 >${DESTDIR}${MANPREFIX}/man1/slock.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/slock.1
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/slock
rm -f ${DESTDIR}${MANPREFIX}/man1/slock.1
.PHONY: all clean dist install uninstall
+21 -7
View File
@@ -8,17 +8,31 @@ Requirements
In order to build slock you need the Xlib header files. In order to build slock you need the Xlib header files.
Notes
------------
As of right now, this implementation assumes that the user has no automatic
display management utilities, like mutter.
Installation Installation
------------ ------------
Edit config.mk to match your local setup (slock is installed into # make
the /usr/local namespace by default). # chmod u+s ./slock
# mv ./slock /usr/local/bin
Afterwards enter the following command to build and install slock
(if necessary as root):
make clean install
Running slock Running slock
------------- -------------
Simply invoke the 'slock' command. To get out of it, enter your password. Simply invoke the 'slock' command. To get out of it, enter your password.
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 to disable both in
xorg.conf for maximum security:
Section "ServerFlags"
Option "DontVTSwitch" "True"
Option "DontZap" "True"
EndSection
-36
View File
@@ -1,36 +0,0 @@
/* user and group to drop privileges to */
/* NOTE: Leave these empty if you want them to be determined automatically. */
static const char *user = "";
static const char *group = "";
static const int displaytimeout = 5; /* 0 to disable */
static const char *colorname[NUMCOLS] = {
[INIT] = "black", /* after initialization */
[INPUT] = "#005577", /* during input */
[FAILED] = "#CC3333", /* wrong password */
};
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
static const Passthrough passthroughs[] = {
/* Modifier Key */
{ 0, XF86XK_AudioRaiseVolume },
{ 0, XF86XK_AudioLowerVolume },
{ 0, XF86XK_AudioMute },
{ 0, XF86XK_AudioPause },
{ 0, XF86XK_AudioStop },
{ 0, XF86XK_AudioNext },
{ 0, XF86XK_AudioPrev },
{ 0, XF86XK_MonBrightnessUp },
{ 0, XF86XK_MonBrightnessDown },
};
/*static const char *dspoffcmd[] = { "xset", "dpms", "force", "off", NULL };*/
static const Key keys[] = {
/* modifier key function argument */
0
/*{ 0, XK_Escape, spawn, {.v = dspoffcmd } }*/
};
-36
View File
@@ -1,36 +0,0 @@
# slock version
VERSION = 1.7
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# includes and libs
INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
#CFLAGS = -std=c99 -pedantic -Wno-long-long -Wall -Wextra \
# -Wincompatible-pointer-types \
# -Wint-conversion -Wformat \
# -Wno-strict-prototypes -Wno-missing-field-initializers \
# -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable \
# -Wno-unused-but-set-variable \
# -fno-show-column -fno-diagnostics-show-caret -ggdb ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
COMPATSRC = explicit_bzero.c
# On OpenBSD and Darwin remove -lcrypt from LIBS
#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXext -lXrandr
# On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS
# On NetBSD add -D_NETBSD_SOURCE to CPPFLAGS
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
# On OpenBSD set COMPATSRC to empty
#COMPATSRC =
-45
View File
@@ -1,45 +0,0 @@
.Dd October 6, 2023
.Dt SLOCK 1
.Os
.Sh NAME
.Nm slock
.Nd simple X screen locker
.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
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
to disable both in
.Xr xorg.conf 5
for maximum security:
.Bd -literal
Section "ServerFlags"
Option "DontVTSwitch" "True"
Option "DontZap" "True"
EndSection
.Ed
.Sh CUSTOMIZATION
.Nm
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.