feat: improve error messages

This commit is contained in:
MusiKid 2022-01-21 13:00:00 +01:00 committed by musikid
parent bd0d35427d
commit 7490705f8f
No known key found for this signature in database
GPG key ID: 7567D43648C6E2F4

View file

@ -1,9 +1,9 @@
#include <cerrno> #include <cerrno>
#include <csignal> #include <csignal>
#include <cstdlib> #include <cstdlib>
#include <glob.h>
#include <ostream> #include <ostream>
#include <glob.h>
#include <pthread.h> #include <pthread.h>
#include <spawn.h> #include <spawn.h>
#include <sys/signalfd.h> #include <sys/signalfd.h>
@ -65,25 +65,31 @@ int howdy_error(int status, function<int(int, const char *)> conv_function) {
break; break;
// Status 11 means we exceded the maximum retry count // Status 11 means we exceded the maximum retry count
case 11: case 11:
syslog(LOG_INFO, "Failure, timeout reached"); syslog(LOG_ERR, "Failure, timeout reached");
break; break;
// Status 12 means we aborted // Status 12 means we aborted
case 12: case 12:
syslog(LOG_INFO, "Failure, general abort"); syslog(LOG_ERR, "Failure, general abort");
break; break;
// Status 13 means the image was too dark // Status 13 means the image was too dark
case 13: case 13:
conv_function(PAM_ERROR_MSG, conv_function(PAM_ERROR_MSG,
dgettext("pam", "Face detection image too dark")); dgettext("pam", "Face detection image too dark"));
syslog(LOG_INFO, "Failure, image too dark"); syslog(LOG_ERR, "Failure, image too dark");
break; break;
// Otherwise, we can't describe what happened but it wasn't successful // Otherwise, we can't describe what happened but it wasn't successful
default: default:
conv_function( conv_function(
PAM_ERROR_MSG, PAM_ERROR_MSG,
string(dgettext("pam", "Unknown error: ") + status).c_str()); string(dgettext("pam", "Unknown error: ") + status).c_str());
syslog(LOG_INFO, "Failure, unknown error %d", status); syslog(LOG_ERR, "Failure, unknown error %d", status);
} }
} else {
// We get the signal
status = WIFSIGNALED(status);
syslog(LOG_ERR, "Child killed by signal %s (%d)", strsignal(status),
status);
} }
// As this function is only called for error status codes, signal an error to // As this function is only called for error status codes, signal an error to
@ -255,7 +261,8 @@ int identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
// Start the python subprocess // Start the python subprocess
if (posix_spawnp(&child_pid, "/usr/bin/python3", &file_actions, nullptr, if (posix_spawnp(&child_pid, "/usr/bin/python3", &file_actions, nullptr,
(char *const *)args, nullptr) < 0) { (char *const *)args, nullptr) < 0) {
syslog(LOG_ERR, "Can't spawn the howdy process: %s", strerror(errno)); syslog(LOG_ERR, "Can't spawn the howdy process: %s (%d)", strerror(errno),
errno);
return PAM_SYSTEM_ERR; return PAM_SYSTEM_ERR;
} }