[pkg-fso-commits] [SCM] Automatic Display Manager branch, master, updated. debian/0.1-52-g76526e2
Enrico Zini
enrico at enricozini.org
Mon Feb 23 18:02:46 UTC 2009
The following commit has been merged in the master branch:
commit afc5624c8c02adaf7f9b4ffe2dfbd331b89b9a72
Author: Enrico Zini <enrico at enricozini.org>
Date: Mon Feb 2 19:06:07 2009 +0000
Moved restart logic to C
diff --git a/Makefile b/Makefile
index a75521e..e25eb4c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-pam-helper: pam-helper.c
+nodm: nodm.c
gcc -o $@ $< -lpam -lpam_misc -Wall
clean:
- rm pam-helper
+ rm -f nodm
diff --git a/debian/defaults/nodm b/debian/defaults/nodm
index 64322c1..cf599ef 100644
--- a/debian/defaults/nodm
+++ b/debian/defaults/nodm
@@ -1,18 +1,20 @@
# nodm configuration
+# Set NODM_ENABLED to something different than 'no' to enable nodm
+NODM_ENABLED=no
+
# User to autologin for
-# Note: if NODM_USER is not set to any value, nodm will not start
-# NODM_USER=root
+NODM_USER=root
# xinit program
-# NODM_XINIT=/usr/bin/xinit
+NODM_XINIT=/usr/bin/xinit
# X session
-# NODM_XSESSION=/etc/X11/Xsession
+NODM_XSESSION=/etc/X11/Xsession
# Options for the X server
-# NODM_X_OPTIONS="vt7 -nolisten tcp"
+NODM_X_OPTIONS="vt7 -nolisten tcp"
-# If an X session will run for less than this time in seconds, it will be
-# considered an X configuration error and the session will not be restarted
-# NODM_MIN_SESSION_TIME=10
+# If an X session will run for less than this time in seconds, nodm will wait an
+# increasing bit of time before restarting the session.
+NODM_MIN_SESSION_TIME=60
diff --git a/debian/nodm.init b/debian/nodm.init
index ec88dbe..c09e73f 100644
--- a/debian/nodm.init
+++ b/debian/nodm.init
@@ -18,14 +18,20 @@ NAME=nodm
PIDDIR=/var/run/
PIDFILE=${PIDDIR}/${NAME}.pid
+NODM_ENABLED=no
+NODM_XINIT=/usr/bin/xinit
+NODM_XSESSION=/etc/X11/Xsession
+NODM_X_OPTIONS="vt7 -nolisten tcp"
+NODM_USER=root
+NODM_MIN_SESSION_TIME=60
+
if [ -f /etc/defaults/$NAME ]
then
. /etc/defaults/$NAME
- NODM_XINIT=${NODM_XINIT:-"/usr/bin/xinit"}
- NODM_XSESSION=${NODM_XSESSION:-"/etc/X11/Xsession"}
- export NODM_XINIT NODM_XSESSION NODM_X_OPTIONS NODM_USER NODM_MIN_SESSION_TIME
fi
+export NODM_XINIT NODM_XSESSION NODM_X_OPTIONS NODM_USER NODM_MIN_SESSION_TIME
+
# If you change the user to a non-root user, make sure you
# set allowed_users=anybody in /etc/X11/Xwrapper.config
@@ -42,9 +48,9 @@ fi
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
- if [ -z "$NODM_USER" ]
+ if [ "$NODM_ENABLED" == "no" ]
then
- log_warning_msg "Not starting $NAME because NODM_USER has not been set in /etc/defaults/$NAME"
+ log_warning_msg "Not starting $NAME because NODM_ENABLED is 'no' in /etc/defaults/$NAME"
else
start-stop-daemon --start --oknodo --pidfile ${PIDFILE} --make-pidfile --background --exec /usr/sbin/nodm
fi
diff --git a/debian/nodm.install b/debian/nodm.install
index 874ab4a..a1b86ee 100644
--- a/debian/nodm.install
+++ b/debian/nodm.install
@@ -1,3 +1,2 @@
nodm /usr/sbin/
-pam-helper /usr/lib/nodm/
debian/defaults/nodm /etc/defaults/
diff --git a/nodm b/nodm
deleted file mode 100755
index 5c25f7c..0000000
--- a/nodm
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh -ue
-
-# Configuration values are taken from the environment, and if they are missing
-# default values are used
-NODM_XINIT=${NODM_XINIT:-"/usr/bin/xinit"}
-NODM_XSESSION=${NODM_XSESSION:-"/etc/X11/Xsession"}
-NODM_X_OPTIONS=${NODM_X_OPTIONS:-"vt7 -nolisten tcp"}
-NODM_USER=${NODM_USER:-"root"}
-NODM_MIN_SESSION_TIME=${NODM_MIN_SESSION_TIME:-"10"}
-
-# Run an X session, returning success if it lasted at least
-# $NODM_MIN_SESSION_TIME
-run()
-{
- start=`date +%s`
- /usr/lib/nodm/pam-helper
- end=`date +%s`
- if [ `expr $end - $start` -ge $NODM_MIN_SESSION_TIME ]
- then
- return 0
- else
- return 1
- fi
-}
-
-while :
-do
- if ! run
- then
- exit 1
- fi
-done
-
-exit 0
diff --git a/pam-helper.c b/nodm.c
similarity index 91%
rename from pam-helper.c
rename to nodm.c
index af5c75c..79b6509 100644
--- a/pam-helper.c
+++ b/nodm.c
@@ -53,11 +53,13 @@
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <syslog.h>
+#include <time.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
@@ -190,12 +192,10 @@ static void catch_signals (int sig)
* have been applied. Some work was needed to get it integrated into
* su.c from shadow.
*/
-static void run_shell ()
+static int run_shell (int* status)
{
int child;
sigset_t ourset;
- int status;
- int ret;
char* argv0 = getenv("NODM_XINIT");
if (argv0 == NULL)
argv0 = "/usr/bin/xinit";
@@ -203,6 +203,15 @@ static void run_shell ()
child = fork ();
if (child == 0) { /* child shell */
/*
+ * This is a workaround for Linux libc bug/feature (?) - the
+ * /dev/log file descriptor is open without the close-on-exec flag
+ * and used to be passed to the new shell. There is "fcntl(LogFile,
+ * F_SETFD, 1)" in libc/misc/syslog.c, but it is commented out (at
+ * least in 5.4.33). Why? --marekm
+ */
+ closelog ();
+
+ /*
* PAM_DATA_SILENT is not supported by some modules, and
* there is no strong need to clean up the process space's
* memory since we will either call exec or exit.
@@ -221,7 +230,7 @@ static void run_shell ()
(void) fprintf (stderr, "%s: Cannot fork user shell\n", Prog);
syslog (LOG_WARNING, "Cannot execute %s", argv0);
closelog ();
- exit (1);
+ return 1;
}
/* parent only */
sigfillset (&ourset);
@@ -252,42 +261,56 @@ static void run_shell ()
do {
int pid;
- pid = waitpid (-1, &status, WUNTRACED);
+ pid = waitpid (-1, status, WUNTRACED);
- if (WIFSTOPPED (status)) {
+ if (WIFSTOPPED (*status)) {
kill (getpid (), SIGSTOP);
/* once we get here, we must have resumed */
kill (pid, SIGCONT);
}
- } while (WIFSTOPPED (status));
+ } while (WIFSTOPPED (*status));
}
if (caught) {
fprintf (stderr, "\nSession terminated, killing shell...");
kill (child, SIGTERM);
- }
-
- ret = pam_close_session (pamh, 0);
- if (ret != PAM_SUCCESS) {
- syslog (LOG_ERR, "pam_close_session: %s",
- pam_strerror (pamh, ret));
- fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
- pam_end (pamh, ret);
- exit (1);
- }
-
- ret = pam_end (pamh, PAM_SUCCESS);
-
- if (caught) {
sleep (2);
kill (child, SIGKILL);
fprintf (stderr, " ...killed.\n");
- exit (-1);
+ return -1;
}
- exit (WIFEXITED (status)
- ? WEXITSTATUS (status)
- : WTERMSIG (status) + 128);
+ return 0;
+}
+
+void run_session()
+{
+ int restart_count = 0;
+ char* s_mst = getenv("NODM_MIN_SESSION_TIME");
+ int mst = s_mst ? atoi(s_mst) : 60;
+
+ while (1)
+ {
+ /* Run the shell */
+ time_t begin = time(NULL);
+ time_t end;
+ int status;
+ if (run_shell(&status))
+ return;
+ end = time(NULL);
+
+ /* Check if the session was too short */
+ if (end - begin > mst)
+ {
+ if (restart_count < 6)
+ ++restart_count;
+ }
+ else
+ restart_count = 0;
+
+ /* Sleep a bit if the session was too short */
+ sleep(1 << restart_count);
+ }
}
/*
@@ -455,17 +478,19 @@ int main (int argc, char **argv)
setenv ("USER", pwent.pw_name, 1);
setenv ("LOGNAME", pwent.pw_name, 1);
- /*
- * This is a workaround for Linux libc bug/feature (?) - the
- * /dev/log file descriptor is open without the close-on-exec flag
- * and used to be passed to the new shell. There is "fcntl(LogFile,
- * F_SETFD, 1)" in libc/misc/syslog.c, but it is commented out (at
- * least in 5.4.33). Why? --marekm
- */
- closelog ();
+ run_session();
- run_shell();
+ ret = pam_close_session (pamh, 0);
+ if (ret != PAM_SUCCESS) {
+ syslog (LOG_ERR, "pam_close_session: %s",
+ pam_strerror (pamh, ret));
+ fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
+ pam_end (pamh, ret);
+ return 1;
+ }
+
+ ret = pam_end (pamh, PAM_SUCCESS);
- /* NOT REACHED */
- exit (1);
+ closelog ();
+ return 0;
}
--
Automatic Display Manager
More information about the pkg-fso-commits
mailing list