[pkg-fso-commits] [SCM] Automatic Display Manager branch, master, updated. nodm/0.3-2-25-g6b59ed6
Enrico Zini
enrico at enricozini.org
Thu Jul 23 23:44:15 UTC 2009
The following commit has been merged in the master branch:
commit ebb4698e09683edbf9791c4730ba3c22c06a7812
Author: Enrico Zini <enrico at enricozini.org>
Date: Thu Jul 23 21:09:25 2009 +0200
First attempt at vt allocation
diff --git a/debian/nodm.postinst b/debian/nodm.postinst
index c15eb76..d0e8373 100644
--- a/debian/nodm.postinst
+++ b/debian/nodm.postinst
@@ -11,7 +11,7 @@ if [ "$1" = "configure" ] ; then
# guarantee a smooth upgrade, we can safely override debconf here
# using the openmoko parameters.
db_set nodm/enabled true
- db_set nodm/x_options "vt3 -nolisten tcp"
+ db_set nodm/x_options "-nolisten tcp"
fi
# Update /etc/default/nodm
diff --git a/nodm.c b/nodm.c
index c0bc111..52c0409 100644
--- a/nodm.c
+++ b/nodm.c
@@ -69,6 +69,7 @@
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
+#include <sys/vt.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
@@ -248,6 +249,51 @@ cleanup:
return ret;
}
+/*
+ * Allocate a new vt, open it and return the file descriptor and the vt number.
+ *
+ * Searching the vt starts at the initial value of vtnum.
+ */
+int open_vt(int *vtnum)
+{
+ char vtname[15];
+ int res = -1;
+ struct vt_stat vtstat;
+ unsigned short vtmask;
+ int fd = open("/dev/console", O_WRONLY | O_NOCTTY, 0);
+ if (fd < 0)
+ {
+ fprintf (stderr, _("%s: cannot open /dev/console: %m\n"), Prog);
+ goto cleanup;
+ }
+
+ if (ioctl (fd, VT_GETSTATE, &vtstat) < 0)
+ {
+ fprintf (stderr, _("%s: VT_GETSTATE failed on /dev/console: %m\n"), Prog);
+ goto cleanup;
+ }
+
+ for (vtmask = 1 << *vtnum; vtstat.v_state & vtmask; ++*vtnum, vtmask <<= 1)
+ ;
+ if (!vtmask) {
+ fprintf (stderr, _("%s: all VTs seem to be busy\n"), Prog);
+ goto cleanup;
+ }
+
+ snprintf(vtname, 15, "/dev/tty%d", *vtnum);
+
+ res = open(vtname, O_RDWR | O_NOCTTY, 0);
+ if (res < 0) {
+ fprintf (stderr, _("%s: cannot open %s: %m\n"), Prog, vtname);
+ goto cleanup;
+ }
+
+cleanup:
+ if (fd >= 0)
+ close(fd);
+ return res;
+}
+
/* Signal handler for parent process later */
static void catch_signals (int sig)
{
@@ -461,6 +507,8 @@ static int nodm_monitor(int argc, char **argv)
char xoptions[BUFSIZ];
char* cp;
int mst;
+ int vt_fd = -1;
+ int vt_num = 3;
/* Parse command line options */
while (1)
@@ -498,15 +546,27 @@ static int nodm_monitor(int argc, char **argv)
syslog(LOG_INFO, "Starting nodm monitor");
+ if ((vt_fd = open_vt(&vt_num)) == -1)
+ {
+ fprintf (stderr, _("%s: cannot allocate a virtual terminal\n"), Prog);
+ return 1;
+ }
+
/* Read the configuration from the environment */
cp = getenv("NODM_MIN_SESSION_TIME");
mst = cp ? atoi(cp) : 60;
string_from_env(xinit, "NODM_XINIT", "/usr/bin/xinit");
string_from_env(xoptions, "NODM_X_OPTIONS", "");
+ if (xoptions[0] == 0)
+ snprintf(xoptions, BUFSIZ, "vt%d", vt_num);
+ else
+ snprintf(xoptions, BUFSIZ, "vt%d %s", vt_num, xoptions);
setenv("NODM_RUN_SESSION", "1", 1);
run_and_restart(xinit, opt_session, xoptions[0] == 0 ? NULL : xoptions, mst);
+ close(vt_fd);
+
return 0;
}
--
Automatic Display Manager
More information about the pkg-fso-commits
mailing list