Commit 0019865c authored by Eliot Courtney's avatar Eliot Courtney Committed by Commit Bot

Check version of mojo bootstrap from lacros socket.

This also fixes a bug where sometimes fds are not received and
lacros can't start.

Bug: 1139796
Test: Can run lacros on chromeos via this script
Change-Id: I33f5fae07b377fb7848dc444be7fcb4f8d4a3f46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2483749Reviewed-by: default avatarYuke Liao <liaoyuke@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Eliot Courtney <edcourtney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819196}
parent fa602938
......@@ -3,7 +3,8 @@
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Helps launch lacros-chrome with mojo connection established on Linux.
"""Helps launch lacros-chrome with mojo connection established on Linux
or Chrome OS. Use on Chrome OS is for dev purposes.
The main use case is to be able to launch lacros-chrome in a debugger.
......@@ -47,12 +48,15 @@ def _ReceiveFD(sock):
# This function is borrowed from with modifications:
# https://docs.python.org/3/library/socket.html#socket.socket.recvmsg
fds = array.array("i") # Array of ints
_, ancdata, _, _ = sock.recvmsg(0, socket.CMSG_LEN(fds.itemsize))
# Along with the file descriptor, ash-chrome also sends the version in the
# regular data.
version, ancdata, _, _ = sock.recvmsg(1, socket.CMSG_LEN(fds.itemsize))
for cmsg_level, cmsg_type, cmsg_data in ancdata:
if cmsg_level == socket.SOL_SOCKET and cmsg_type == socket.SCM_RIGHTS:
assert len(cmsg_data) == fds.itemsize, 'Expecting exactly 1 FD'
fds.frombytes(cmsg_data[:fds.itemsize])
assert version == b'\x00', 'Expecting version code to be 0'
assert len(list(fds)) == 1, 'Expecting exactly 1 FD'
return os.fdopen(list(fds)[0])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment