mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-25 04:37:42 +00:00
tstest/tailmac: add support for mounting host directories in the guest (#13957)
updates tailscale/corp#24197 tailmac run now supports the --share option which will allow you to specify a directory on the host which can be mounted in the guest using mount_virtiofs vmshare <path>. Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
This commit is contained in:
@@ -95,6 +95,7 @@ extension Tailmac {
|
||||
extension Tailmac {
|
||||
struct Run: ParsableCommand {
|
||||
@Option(help: "The vm identifier") var id: String
|
||||
@Option(help: "Optional share directory") var share: String?
|
||||
@Flag(help: "Tail the TailMac log output instead of returning immediatly") var tail
|
||||
|
||||
mutating func run() {
|
||||
@@ -115,7 +116,12 @@ extension Tailmac {
|
||||
fatalError("Could not find Host.app at \(appPath). This must be co-located with the tailmac utility")
|
||||
}
|
||||
|
||||
process.arguments = ["run", "--id", id]
|
||||
var args = ["run", "--id", id]
|
||||
if let share {
|
||||
args.append("--share")
|
||||
args.append(share)
|
||||
}
|
||||
process.arguments = args
|
||||
|
||||
do {
|
||||
process.standardOutput = stdOutPipe
|
||||
@@ -124,26 +130,18 @@ extension Tailmac {
|
||||
fatalError("Unable to launch the vm process")
|
||||
}
|
||||
|
||||
// This doesn't print until we exit which is not ideal, but at least we
|
||||
// get the output
|
||||
if tail != 0 {
|
||||
// (jonathan)TODO: How do we get the process output in real time?
|
||||
// The child process only seems to flush to stdout on completion
|
||||
let outHandle = stdOutPipe.fileHandleForReading
|
||||
|
||||
let queue = OperationQueue()
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name.NSFileHandleDataAvailable,
|
||||
object: outHandle, queue: queue)
|
||||
{
|
||||
notification -> Void in
|
||||
let data = outHandle.availableData
|
||||
outHandle.readabilityHandler = { handle in
|
||||
let data = handle.availableData
|
||||
if data.count > 0 {
|
||||
if let str = String(data: data, encoding: String.Encoding.utf8) {
|
||||
print(str)
|
||||
}
|
||||
}
|
||||
outHandle.waitForDataInBackgroundAndNotify()
|
||||
}
|
||||
outHandle.waitForDataInBackgroundAndNotify()
|
||||
process.waitUntilExit()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user