{
va_list ap;
+ fputs("slock: ", stderr);
va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
va_end(ap);
#ifdef __linux__
#include <fcntl.h>
-#include <linux/oom.h>
static void
dontkillme(void)
{
int fd;
- int length;
- char value[64];
fd = open("/proc/self/oom_score_adj", O_WRONLY);
- if (fd < 0 && errno == ENOENT)
+ if (fd < 0 && errno == ENOENT) {
return;
-
- /* convert OOM_SCORE_ADJ_MIN to string for writing */
- length = snprintf(value, sizeof(value), "%d\n", OOM_SCORE_ADJ_MIN);
-
- /* bail on truncation */
- if (length >= sizeof(value))
- die("buffer too small\n");
-
- if (fd < 0 || write(fd, value, length) != length || close(fd) != 0)
- die("cannot disable the out-of-memory killer for this process (make sure to suid or sgid slock)\n");
+ }
+ if (fd < 0 || write(fd, "-1000\n", (sizeof("-1000\n") - 1)) !=
+ (sizeof("-1000\n") - 1) || close(fd) != 0) {
+ die("can't tame the oom-killer. is suid or sgid set?\n");
+ }
}
#endif
errno = 0;
if (!(pw = getpwuid(getuid()))) {
if (errno)
- die("slock: getpwuid: %s\n", strerror(errno));
+ die("getpwuid: %s\n", strerror(errno));
else
- die("slock: cannot retrieve password entry\n");
+ die("cannot retrieve password entry\n");
}
rval = pw->pw_passwd;
if (rval[0] == 'x' && rval[1] == '\0') {
struct spwd *sp;
if (!(sp = getspnam(getenv("USER"))))
- die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
+ die("cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
rval = sp->sp_pwdp;
}
#endif
/* drop privileges */
if (geteuid() == 0 &&
((getegid() != pw->pw_gid && setgid(pw->pw_gid) < 0) || setuid(pw->pw_uid) < 0))
- die("slock: cannot drop privileges\n");
+ die("cannot drop privileges\n");
return rval;
}
#endif
return NULL;
}
-static void
-usage(void)
-{
- fprintf(stderr, "usage: slock [-v|POST_LOCK_CMD]\n");
- exit(1);
-}
-
int
-main(int argc, char **argv) {
+main(int argc, char **argv)
+{
#ifndef HAVE_BSD_AUTH
const char *pws;
#endif
Display *dpy;
int screen;
- if ((argc == 2) && !strcmp("-v", argv[1]))
- die("slock-%s, © 2006-2016 slock engineers\n", VERSION);
-
- if ((argc == 2) && !strcmp("-h", argv[1]))
- usage();
-
#ifdef __linux__
dontkillme();
#endif
if (!getpwuid(getuid()))
- die("slock: no passwd entry for you\n");
+ die("no passwd entry for you\n");
#ifndef HAVE_BSD_AUTH
pws = getpw();
#endif
if (!(dpy = XOpenDisplay(0)))
- die("slock: cannot open display\n");
+ die("cannot open display\n");
rr = XRRQueryExtension(dpy, &rrevbase, &rrerrbase);
/* Get the number of screens in display "dpy" and blank them all. */
nscreens = ScreenCount(dpy);
if (!(locks = malloc(sizeof(Lock*) * nscreens)))
- die("slock: malloc: %s\n", strerror(errno));
+ die("Out of memory.\n");
int nlocks = 0;
for (screen = 0; screen < nscreens; screen++) {
if ((locks[screen] = lockscreen(dpy, screen)) != NULL)
if (dpy)
close(ConnectionNumber(dpy));
execvp(argv[1], argv+1);
- die("slock: execvp %s failed: %s\n", argv[1], strerror(errno));
+ die("execvp %s failed: %s\n", argv[1], strerror(errno));
}
/* Everything is now blank. Now wait for the correct password. */