diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py index a168182e6..bf358230f 100755 --- a/misc/config_tools/launch_config/launch_cfg_gen.py +++ b/misc/config_tools/launch_config/launch_cfg_gen.py @@ -275,7 +275,7 @@ def generate_for_one_vm(board_etree, hv_scenario_etree, vm_scenario_etree, vm_id backend_device_file = eval_xpath(virtio_input_etree, "./backend_device_file[text() != '']/text()") unique_identifier = eval_xpath(virtio_input_etree, "./id[text() != '']/text()") if backend_device_file is not None and unique_identifier is not None: - script.add_virtual_device("virtio-input", options=f"{backend_device_file},id={unique_identifier}") + script.add_virtual_device("virtio-input", options=f"{backend_device_file},id:{unique_identifier}") elif backend_device_file is not None: script.add_virtual_device("virtio-input", options=backend_device_file) diff --git a/misc/config_tools/launch_config/launch_script_template.sh b/misc/config_tools/launch_config/launch_script_template.sh index b4a9ca486..61a43f98d 100644 --- a/misc/config_tools/launch_config/launch_script_template.sh +++ b/misc/config_tools/launch_config/launch_script_template.sh @@ -134,35 +134,39 @@ function add_virtual_device() { fi if [ "${kind}" = "virtio-input" ]; then - if [[ "${options}" =~ id=([a-zA-Z0-9_\-]*) ]]; then + options=$* + if [[ "${options}" =~ id:([a-zA-Z0-9_\-]*) ]]; then unique_identifier="${BASH_REMATCH[1]}" - options=${options/",id=${unique_identifier}"/''} + options=${options/",id:${unique_identifier}"/''} fi - local IFS=$'\n' - device_name_path=$(grep -r "${options%:*}" /sys/class/input/event*/device/name) - if [ -n "${device_name_path}" ]; then - for device_path in ${device_name_path}; do - if [ "${options%:*}" = "${options#*:}" ]; then - options="/dev/input/${device_path:17:6}" - break - else - phys_path=$(grep -r "${options#*:}" /sys/class/input/event*/device/phys) + if [[ "${options}" =~ (Device name: )(.*),( Device physical path: )(.*) ]]; then + device_name="${BASH_REMATCH[2]}" + phys_name="${BASH_REMATCH[4]}" + local IFS=$'\n' + device_name_paths=$(grep -r "${device_name}" /sys/class/input/event*/device/name) + phys_paths=$(grep -r "${phys_name}" /sys/class/input/event*/device/phys) + fi + + if [ -n "${device_name_paths}" ] && [ -n "${phys_paths}" ]; then + for device_path in ${device_name_paths}; do + for phys_path in ${phys_paths}; do if [ "${device_path%/device*}" = "${phys_path%/device*}" ]; then - options="/dev/input/${device_path:17:6}" - break + event_path=${device_path} + if [[ ${event_path} =~ event([0-9]+) ]]; then + event_num="${BASH_REMATCH[1]}" + options="/dev/input/event${event_num}" + break + fi fi - fi + done done - else - echo "${options%:*} device path is not found in the service vm." >> /dev/stderr - return fi if [[ ${options} =~ event([0-9]+) ]]; then echo "${options} input device path is available in the service vm." >> /dev/stderr else - echo "${options#*:} input phys path is not found in the service vm." >> /dev/stderr + echo "${options} input device path is not found in the service vm." >> /dev/stderr return fi