Skip to content

Commit

Permalink
Prefix all error messages we control with "xsecurelock:" for easier g…
Browse files Browse the repository at this point in the history
…repping in ~/.xsession-errors.
  • Loading branch information
divVerent committed Feb 26, 2018
1 parent 252bfe5 commit 9a530ff
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 180 deletions.
9 changes: 6 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ bin_PROGRAMS = xsecurelock
xsecurelock_SOURCES = \
auth_child.c auth_child.h \
env_settings.c env_settings.h \
saver_child.c saver_child.h \
logging.c logging.h \
mlock_page.h \
main.c \
saver_child.c saver_child.h \
wm_properties.c wm_properties.h \
xscreensaver_api.c xscreensaver_api.h
xsecurelock_CPPFLAGS = \
Expand Down Expand Up @@ -69,9 +70,10 @@ endif
helpers_PROGRAMS = \
saver_multiplex
saver_multiplex_SOURCES = \
helpers/saver_multiplex.c \
env_settings.c env_settings.h \
helpers/monitors.c helpers/monitors.h \
helpers/saver_multiplex.c \
logging.c logging.h \
saver_child.c saver_child.h \
wm_properties.c wm_properties.h \
xscreensaver_api.c xscreensaver_api.h
Expand All @@ -85,9 +87,10 @@ if HAVE_PAM
helpers_PROGRAMS += \
auth_pam_x11
auth_pam_x11_SOURCES = \
helpers/auth_pam_x11.c \
env_settings.c env_settings.h \
helpers/auth_pam_x11.c \
helpers/monitors.c helpers/monitors.h \
logging.c logging.h \
mlock_page.h \
xscreensaver_api.c xscreensaver_api.h
auth_pam_x11_CPPFLAGS = \
Expand Down
31 changes: 15 additions & 16 deletions auth_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ limitations under the License.

#include <errno.h> // for ECHILD, EINTR, errno
#include <signal.h> // for kill, SIGTERM
#include <stdio.h> // for perror, fprintf, stderr
#include <stdlib.h> // for NULL, exit, EXIT_FAILURE, etc
#include <stdlib.h> // for NULL, exit, EXIT_FAILURE, EXIT_SUCCESS
#include <string.h> // for strlen
#include <sys/wait.h> // for waitpid, WEXITSTATUS, etc
#include <unistd.h> // for close, pid_t, ssize_t, dup2, etc
#include <sys/wait.h> // for WIFEXITED, WIFSIGNALED, waitpid, WEXIT...
#include <unistd.h> // for close, pid_t, ssize_t, dup2, execl, fork

#include "env_settings.h"
#include "xscreensaver_api.h"
#include "env_settings.h" // for GetIntSetting
#include "logging.h" // for LogErrno, Log
#include "xscreensaver_api.h" // for ExportWindowID

//! The PID of a currently running saver child, or 0 if none is running.
static pid_t auth_child_pid = 0;
Expand Down Expand Up @@ -106,7 +106,7 @@ int WatchAuthChild(Display *dpy, Window w, const char *executable,
break;
default:
// Assume the child still lives. Shouldn't ever happen.
perror("waitpid");
LogErrno("waitpid");
break;
}
} else if (pid == auth_child_pid) {
Expand All @@ -129,13 +129,12 @@ int WatchAuthChild(Display *dpy, Window w, const char *executable,
// Only report signals; "normal" exit is not worth logging as it usually
// means authentication failure anyway.
if (WIFSIGNALED(status)) {
fprintf(stderr, "Auth child killed by signal %d.\n",
WTERMSIG(status));
Log("Auth child killed by signal %d", WTERMSIG(status));
}
}
// Otherwise, it was suspended or whatever. We need to keep waiting.
} else if (pid != 0) {
fprintf(stderr, "Unexpectedly woke up for PID %d.\n", (int)pid);
Log("Unexpectedly woke up for PID %d", (int)pid);
}
// Otherwise, we're still alive.
}
Expand All @@ -144,11 +143,11 @@ int WatchAuthChild(Display *dpy, Window w, const char *executable,
// Start auth child.
int pc[2];
if (pipe(pc)) {
perror("pipe");
LogErrno("pipe");
} else {
pid_t pid = fork();
if (pid == -1) {
perror("fork");
LogErrno("fork");
} else if (pid == 0) {
// Child process.
setsid();
Expand All @@ -157,7 +156,7 @@ int WatchAuthChild(Display *dpy, Window w, const char *executable,
close(pc[0]);
close(pc[1]);
execl(executable, executable, NULL); // Flawfinder: ignore
perror("execl");
LogErrno("execl");
exit(EXIT_FAILURE);
} else {
// Parent process after successful fork.
Expand All @@ -184,12 +183,12 @@ int WatchAuthChild(Display *dpy, Window w, const char *executable,
ssize_t to_write = (ssize_t)strlen(stdinbuf); // Flawfinder: ignore
ssize_t written = write(auth_child_fd, stdinbuf, to_write);
if (written < 0) {
perror("Failed to send all data to the auth child");
LogErrno("Failed to send all data to the auth child");
} else if (written != to_write) {
fprintf(stderr, "Failed to send all data to the auth child.\n");
Log("Failed to send all data to the auth child");
}
} else {
fprintf(stderr, "No auth child. Can't send key events...\n");
Log("No auth child. Can't send key events");
}
}

Expand Down
12 changes: 7 additions & 5 deletions env_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ limitations under the License.
#include <stdio.h> // for fprintf, NULL, stderr
#include <stdlib.h> // for getenv, strtol, strtoull

#include "logging.h"

unsigned long long GetUnsignedLongLongSetting(const char* name,
unsigned long long def) {
const char* value = getenv(name); // Flawfinder: ignore
Expand All @@ -30,11 +32,11 @@ unsigned long long GetUnsignedLongLongSetting(const char* name,
errno = 0;
unsigned long long number = strtoull(value, &endptr, 0);
if (errno == ERANGE) {
fprintf(stderr, "Ignoring out-of-range value of %s: %s.", name, value);
Log("Ignoring out-of-range value of %s: %s", name, value);
return def;
}
if ((endptr != NULL && *endptr != 0)) {
fprintf(stderr, "Ignoring non-numeric value of %s: %s.", name, value);
Log("Ignoring non-numeric value of %s: %s", name, value);
return def;
}
return number;
Expand All @@ -49,11 +51,11 @@ long GetLongSetting(const char* name, long def) {
errno = 0;
long number = strtol(value, &endptr, 0);
if (errno == ERANGE) {
fprintf(stderr, "Ignoring out-of-range value of %s: %s.", name, value);
Log("Ignoring out-of-range value of %s: %s", name, value);
return def;
}
if ((endptr != NULL && *endptr != 0)) {
fprintf(stderr, "Ignoring non-numeric value of %s: %s.", name, value);
Log("Ignoring non-numeric value of %s: %s", name, value);
return def;
}
return number;
Expand All @@ -63,7 +65,7 @@ int GetIntSetting(const char* name, int def) {
long lnumber = GetLongSetting(name, def);
int number = (int)lnumber;
if (lnumber != (long)number) {
fprintf(stderr, "Ignoring out-of-range value of %s: %d.", name, number);
Log("Ignoring out-of-range value of %s: %d", name, number);
return def;
}
return number;
Expand Down
Loading

0 comments on commit 9a530ff

Please sign in to comment.