VirtualBox

Changeset 43832 in vbox for trunk/src/VBox/Installer/linux


Ignore:
Timestamp:
Nov 7, 2012 2:37:42 PM (12 years ago)
Author:
vboxsync
Message:

Installer/linux: HeadlessXOrg clean-up.

Location:
trunk/src/VBox/Installer/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/VBoxHeadlessXOrg.sh

    r43797 r43832  
    6969rendering.  We only support X.Org Server at the moment.  Starting the X servers
    7070is managed by dropping one or more files xorg.conf.<n> into a configuration
    71 directory (by default ${DEFAULT_CONFIGURATION_FOLDER} - this can be overridden
     71directory, by default ${DEFAULT_CONFIGURATION_FOLDER}, but this can be overridden
    7272in the configuration file (see below).  We will attempt to start an X server
    7373process for each configuration file using display number <n>.
     
    7676
    7777  -c|--conf-file)        Specify an alternative locations for the configuration
    78                          file.  The default location is \"${CONFIGURATION_FILE}\".
     78                         file.  The default location is "${CONFIGURATION_FILE}".
    7979
    8080  --help|--usage         Print this text.
     
    119119
    120120  HEADLESS_X_ORG_SERVER_COMMAND
    121     The default X server start-up command, containing the variables "${screen}"
    122     for the screen number, "${conf_file}" for the configuration file path and
    123     ${log_file} for the log file.  The variables must be quoted for expansion
    124     at evaluation time, e.g.
    125       HEADLESS_X_ORG_SERVER_COMMAND="Xorg :\${screen} [...] > \"\${log_file}\"
     121    The default X server start-up command.  It will be passed three parameters
     122    - in order, the screen number to use, the path of the X.Org configuration
     123    file to use and the path of the X server log file to create.
    126124
    127125  HEADLESS_X_ORG_SERVER_POST_COMMAND
     
    129127    default this stores the service configuration information to VirtualBox
    130128    extra data for each of the users in the list \${HEADLESS_X_ORG_USERS}.
    131 
    132   HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE
    133     The default X server log file name, containing the variable "\${screen}" for
    134     the screen number.  The variable must be quoted for expansion at evaluation
    135     time, e.g.
    136       HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="Xorg.\${screen}.log"
     129    It will be passed a single parameter which is a space-separated list of the
     130    X server screen numbers.
    137131EOF
    138132}
     
    144138HEADLESS_X_ORG_RUN_FOLDER="/var/run/${SERVICE_NAME}"
    145139HEADLESS_X_ORG_CHECK_PREREQUISITES="udevadm settle || ! udevadm -V"
     140HEADLESS_X_ORG_USERS=""
     141
    146142X_AUTH_FILE="${HEADLESS_X_ORG_RUN_FOLDER}/xauth"
    147 HEADLESS_X_ORG_SERVER_PRE_COMMAND="echo > \"${X_AUTH_FILE}\"; xauth -f \"${X_AUTH_FILE}\" add :0 . \"\$(dd if=/dev/urandom count=1 bs=16 2>/dev/null | od -An -x)\"; for i in ${HEADLESS_X_ORG_USERS}; do cp \"${X_AUTH_FILE}\" \"${X_AUTH_FILE}.${i}\"; chown \"${i}\" \"${X_AUTH_FILE}.${i}\"; done"
    148 HEADLESS_X_ORG_SERVER_COMMAND="Xorg :\${screen} -auth \"${HEADLESS_X_ORG_RUN_FOLDER}/xauth\" -config \"\${conf_file}\" -logverbose 0 -logfile /dev/null -verbose 7 > \"\${log_file}\" 2>&1"
    149 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="Xorg.\${screen}.log"
     143default_pre_command()
     144{
     145  echo > "${X_AUTH_FILE}"
     146  key="$(dd if=/dev/urandom count=1 bs=16 2>/dev/null | od -An -x)"
     147  xauth -f "${X_AUTH_FILE}" add :0 . "${key}"
     148  for i in ${HEADLESS_X_ORG_USERS}; do
     149    cp "${X_AUTH_FILE}" "${X_AUTH_FILE}.${i}"
     150    chown "${i}" "${X_AUTH_FILE}.${i}"
     151  done
     152}
     153HEADLESS_X_ORG_SERVER_PRE_COMMAND="default_pre_command"
     154
     155default_command()
     156{
     157  auth="${HEADLESS_X_ORG_RUN_FOLDER}/xauth"
     158  # screen=$1
     159  # conf_file=$2
     160  # log_file=$3
     161  Xorg :"${1}" -auth "${auth}" -config "${2}" -logverbose 0 -logfile /dev/null -verbose 7 > "${3}" 2>&1
     162}
     163HEADLESS_X_ORG_SERVER_COMMAND="default_command"
     164
     165default_post_command()
     166{
     167  # screens=$1
     168  for i in ${HEADLESS_X_ORG_USERS}; do
     169    su ${i} -c "VBoxManage setextradata global HeadlessXServer/Screens \"${1}\""
     170    su ${i} -c "VBoxManage setextradata global HeadlessXServer/AuthFile \"${HEADLESS_X_ORG_RUN_FOLDER}/xauth\""
     171  done
     172}
     173HEADLESS_X_ORG_SERVER_POST_COMMAND="default_post_command"
    150174
    151175## The function definition at the start of every non-trivial shell script!
     
    248272
    249273X_SERVER_PIDS=""
     274X_SERVER_SCREENS=""
    250275trap "kill \${X_SERVER_PIDS} 2>/dev/null" ${EXIT_SIGNALS}
    251276space=""  # Hack to put spaces between the pids but not before or after.
     
    258283  [ 0 -le "${screen}" ] 2>/dev/null ||
    259284    abort "Badly formed file name \"${conf_file}\".\n"
    260   log_file="${HEADLESS_X_ORG_LOG_FOLDER}/$(eval echo "${HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE}")"
    261   eval "${HEADLESS_X_ORG_SERVER_COMMAND}" "&"
     285  log_file="${HEADLESS_X_ORG_LOG_FOLDER}/Xorg.${screen}.log"
     286  eval "${HEADLESS_X_ORG_SERVER_COMMAND} \"\${screen}\" \"\${conf_file}\" \"\${log_file}\"" "&"
    262287  X_SERVER_PIDS="${X_SERVER_PIDS}${space}$!"
     288  X_SERVER_SCREENS="${X_SERVER_SCREENS}${space}${screen}"
    263289  space=" "
    264290done
    265291
    266292# Do any post-start work.
    267 eval "${HEADLESS_X_ORG_SERVER_POST_COMMAND}"
     293eval "${HEADLESS_X_ORG_SERVER_POST_COMMAND} \"${X_SERVER_SCREENS}\""
    268294
    269295wait
  • trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh

    r43797 r43832  
    6969HEADLESS_X_ORG_CHECK_PREREQUISITES=
    7070HEADLESS_X_ORG_SERVER_PRE_COMMAND=
    71 HEADLESS_X_ORG_SERVER_COMMAND="echo \\\${screen} \\\${conf_file} \\\${log_file}"
    72 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}"
     71HEADLESS_X_ORG_SERVER_COMMAND="echo"
    7372EOF
    7473
     
    9594# Create a temporary directory for configuration and logging.
    9695for i in 0 1 2 3 4 5 6 7 8 9; do
    97   TEST_FOLDER="/tmp/${TEST_NAME}${i}"
     96  TEST_FOLDER="/tmp/${TEST_NAME} ${i}"  # Space in the name to test quoting.
    9897  mkdir -m 0700 "${TEST_FOLDER}" 2>/dev/null && break
    9998done
     
    105104mkdir -p "${XORG_FOLDER}"
    106105
    107 # Simple start-up test.
     106###############################################################################
     107# Simple start-up test.                                                       #
     108###############################################################################
    108109print_line "simple start-up test"
    109110create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     
    118119    LOG_FOLDER="${TEST_FOLDER}/log"
    119120    LOG="${LOG_FOLDER}/log"
    120     if grep -q "2 ${XORG_FOLDER}/xorg.conf.2 ${LOG_FOLDER}/log.2" "${LOG}" &&
    121       grep -q "4 ${XORG_FOLDER}/xorg.conf.4 ${LOG_FOLDER}/log.4" "${LOG}"; then
     121    if grep -q "2 ${XORG_FOLDER}/xorg.conf.2 ${LOG_FOLDER}/Xorg.2.log" "${LOG}" &&
     122      grep -q "4 ${XORG_FOLDER}/xorg.conf.4 ${LOG_FOLDER}/Xorg.4.log" "${LOG}"; then
    122123      printf "SUCCESS.\n"
    123124    else
     
    135136rm "${XORG_FOLDER}"/xorg.conf.*
    136137
    137 # No configuration files.
     138###############################################################################
     139# No configuration files.                                                     #
     140###############################################################################
    138141print_line "no configuration files"
    139142
     
    154157expect_exit "${PID}" 5 test_should_fail
    155158
    156 # Bad configuration files.
     159###############################################################################
     160# Bad configuration files.                                                    #
     161###############################################################################
    157162print_line "bad configuration files"
    158163touch "${XORG_FOLDER}/xorg.conf.2"
     
    164169rm "${XORG_FOLDER}/"xorg.conf.*
    165170
     171###############################################################################
     172# Long running server command.                                                #
     173###############################################################################
     174
    166175# Set up a configuration file for a long-running command.
    167176create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
    168177cat >> "${TEST_FOLDER}/conf" << EOF
    169 HEADLESS_X_ORG_SERVER_COMMAND="\"${TEST_NAME_FULL}\" --test-sleep \\\${screen}"
    170 EOF
    171 
    172 # Long running server command.
     178HEADLESS_X_ORG_SERVER_COMMAND="\"${TEST_NAME_FULL}\" --test-sleep"
     179EOF
     180
    173181print_line "long running server command (sleeps)"
    174182touch "${XORG_FOLDER}/xorg.conf.1"
     
    208216rm "${XORG_FOLDER}/"xorg.conf.*
    209217
     218###############################################################################
     219# Pre-requisite test.                                                         #
     220###############################################################################
     221
    210222# Set up a configuration file with a pre-requisite.
    211223create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     
    214226EOF
    215227
    216 # Pre-requisite test.
    217228print_line "configuration file with pre-requisite (sleeps)"
    218229touch "${XORG_FOLDER}/xorg.conf.2"
     
    231242rm -r "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run"
    232243
     244###############################################################################
     245# Pre-command test.                                                           #
     246###############################################################################
     247
    233248# Set up our pre-command test configuration file.
    234249create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     250
    235251cat >> "${TEST_FOLDER}/conf" << EOF
     252test_pre_command_server_command()
     253{
     254  cp "${TEST_FOLDER}/run/pre" "${TEST_FOLDER}/run/pre2"
     255}
    236256HEADLESS_X_ORG_SERVER_PRE_COMMAND="touch \"${TEST_FOLDER}/run/pre\""
    237 HEADLESS_X_ORG_SERVER_COMMAND="cp \"${TEST_FOLDER}/run/pre\" \"${TEST_FOLDER}/run/pre2\""
    238 EOF
    239 
    240 # Pre-command test.
     257HEADLESS_X_ORG_SERVER_COMMAND="test_pre_command_server_command"
     258EOF
     259
    241260print_line "pre-command test"
    242261touch "${XORG_FOLDER}/xorg.conf.2"
     
    266285rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}"/run/pre*
    267286
     287###############################################################################
     288# Post-command test.                                                          #
     289###############################################################################
     290
    268291# Set up our post-command test configuration file.
    269292create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
    270293cat >> "${TEST_FOLDER}/conf" << EOF
    271 HEADLESS_X_ORG_SERVER_COMMAND="rm -f \"${TEST_FOLDER}/run/post\""
    272 HEADLESS_X_ORG_SERVER_POST_COMMAND="touch \"${TEST_FOLDER}/run/post\""
    273 EOF
    274 
    275 # Post-command test.
     294test_post_command_post_command()
     295{
     296  echo "\${1}" > "${TEST_FOLDER}/run/post"
     297}
     298HEADLESS_X_ORG_SERVER_POST_COMMAND="test_post_command_post_command"
     299EOF
     300
    276301print_line "post-command test"
    277302touch "${XORG_FOLDER}/xorg.conf.2"
     
    285310    LOG_FOLDER="${TEST_FOLDER}/log"
    286311    LOG="${LOG_FOLDER}/log"
    287     if [ -e "${TEST_FOLDER}/run/post" ]; then
     312    if grep -q "2 4" "${TEST_FOLDER}/run/post"; then
    288313      printf "SUCCESS.\n"
    289314    else
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette