From 97afbbf0722b71ac2bcb36788ec85aa94b312be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Wed, 12 Sep 2012 00:06:55 +0200 Subject: [PATCH 1/2] added option to run X in current TTY --- README => README.md | 0 src/cdm | 48 ++++++++++++++++++++++++++++----------------- src/cdm-xlaunch | 27 +++++++++++++------------ src/profile.sh | 4 ++-- 4 files changed, 46 insertions(+), 33 deletions(-) rename README => README.md (100%) diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/src/cdm b/src/cdm index 4457118..7169566 100755 --- a/src/cdm +++ b/src/cdm @@ -132,31 +132,43 @@ case ${flaglist[$binindex]} in [Xx]) clear - # If X is already running and locktty=yes, activate it, - # otherwise increment. + # If X is already running and locktty=yes, activate it if $(yesno locktty); then - # Activate existing X session. if xdpyinfo -display ":$display.0" &> /dev/null; then chvt "$((display+xtty))" exitnormal fi + fi + + # Get the first empty display. + display=0 + while ((display < 7)); do + if dpyinfo=$(xdpyinfo -display ":$display.0" 2>&1 1>/dev/null) || + # Display is in use by another user. + [[ "$dpyinfo" == 'No protocol specified'* ]] || + # Invalid MIT cookie. + [[ "$dpyinfo" == 'Invalid MIT'* ]] + then + let display+=1 + else + break + fi + done + + # run X in current tty + if [[ $xtty == "keep" ]]; then + vt=$(tty) + vt=${vt#/dev/} + if [[ $vt != tty* ]]; then + error "error: invalid TTY" + exiterror + fi + vt=${vt#tty} else - # Get the first empty display. - display=0 - while ((display < 7)); do - if dpyinfo=$(xdpyinfo -display ":$display.0" 2>&1 1>/dev/null) || - # Display is in use by another user. - [[ "$dpyinfo" == 'No protocol specified'* ]] || - # Invalid MIT cookie. - [[ "$dpyinfo" == 'Invalid MIT'* ]] - then - let display+=1 - else - break - fi - done + vt=$((xtty+display)) fi - serverargs=":${display} $serverargs vt$((xtty+display))" + + serverargs=":${display} $serverargs vt$vt" $(yesno consolekit) && launchflags="-c -t $cktimeout" if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then diff --git a/src/cdm-xlaunch b/src/cdm-xlaunch index 5aa3714..6997a47 100755 --- a/src/cdm-xlaunch +++ b/src/cdm-xlaunch @@ -77,20 +77,21 @@ if $consolekit; then fi # Conform to POSIX and do not use `>&' here. -sh -i -c "(startx $* > /dev/null 2>&1 &)" +nohup startx $* > /dev/null 2>&1 & # If wait(1) returns with a value >128, it was interrupted by kill(1), # so registration was sucessful. -if [[ -n "$clockpid" ]]; then - if wait "$clockpid" >& /dev/null - then - kill "$dbuspid" - error "ConsoleKit registration timed out." - exit 1 - else - kill "$dbuspid" - info "ConsoleKit registration succeeded." - exit 0 - fi +if $consolekit; then + if [[ -n "$clockpid" ]]; then + if wait "$clockpid" >& /dev/null + then + kill "$dbuspid" + error "ConsoleKit registration timed out." + exit 1 + else + kill "$dbuspid" + info "ConsoleKit registration succeeded." + exit 0 + fi + fi fi - diff --git a/src/profile.sh b/src/profile.sh index dd64b9a..74fcd40 100644 --- a/src/profile.sh +++ b/src/profile.sh @@ -1,5 +1,5 @@ -if [[ "$(tty)" == /dev/tty1 ]]; then +if [[ "$(tty)" == /dev/tty* ]]; then [[ -n "$CDM_SPAWN" ]] && return - [[ -z "$DISPLAY$SSH_TTY$(pgrep xinit)" ]] && exec cdm + [[ -z "$DISPLAY$SSH_TTY" ]] && exec cdm fi From 6321427214461adb6326c52506d948e011ec898c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Wed, 12 Sep 2012 00:12:31 +0200 Subject: [PATCH 2/2] added option to run X in current TTY - entry in cdmrc --- src/cdmrc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cdmrc b/src/cdmrc index 3631ffe..1d0525c 100644 --- a/src/cdmrc +++ b/src/cdmrc @@ -39,6 +39,7 @@ countfrom=0 display=0 # Where should the first X tty be spawned? +# special value 'keep' causes to run X in current tty xtty=7 # Should cdm(1) stick to the specified display?