#include <limits.h>
#include <ctype.h>
+#include <pthread.h>
+
#include <ftw.h>
#ifdef HAVE_SECURITY_PAM_APPL_H
const struct pam_conv *pam_conversation,
pam_handle_t **pamh)
{
+ pwrap_init();
+
PWRAP_LOG(PWRAP_LOG_TRACE,
"pam_start service=%s, user=%s",
service_name,
* CONSTRUCTOR
***************************/
+/*
+ * Handler executed before fork(2) processing starts.
+ */
+static void pwrap_thread_prepare(void)
+{
+}
+
+/*
+ * Handler that is executed in the parent process after fork(2) processing
+ * completes.
+ */
+static void pwrap_thread_parent(void)
+{
+}
+
+/*
+ * Handler that is executed in the child process after fork(2) processing
+ * completes.
+ */
+static void pwrap_thread_child(void)
+{
+ pwrap.initialised = false;
+}
+
void pwrap_constructor(void)
{
+ /*
+ * If we hold a lock and the application forks, then the child
+ * is not able to unlock the mutex and we are in a deadlock.
+ * This should prevent such deadlocks.
+ */
+ pthread_atfork(&pwrap_thread_prepare,
+ &pwrap_thread_parent,
+ &pwrap_thread_child);
+
/*
* Here is safe place to call pwrap_init() and initialize data
* for main process.