Compare commits

..
4 Commits
Author SHA1 Message Date
Nikolay Edigaryev afbc2e0764 tart ip: keep waiting for the /var/db/dhcpd_leases file to appear (#254) 2022-09-22 10:24:14 -04:00
Fedor Korotkov 0229138bd5 Fixed wait delay for IP command (#250)
I initially wanted a one-second wait but made a human mistake.

Fixes #249
2022-09-19 21:44:14 +04:00
Nikolay EdigaryevandPete Goldsmith 4d08e6365e Set line-buffered output for stdout and introduce --graphics for tart run (#248)
* Set line-buffered output for stdout

* tart run: introduce --graphics

* Update Sources/tart/Commands/Run.swift

Co-authored-by: Pete Goldsmith <peter.n.goldsmith@gmail.com>

* Update Sources/tart/Commands/Run.swift

Co-authored-by: Pete Goldsmith <peter.n.goldsmith@gmail.com>

Co-authored-by: Pete Goldsmith <peter.n.goldsmith@gmail.com>
2022-09-19 21:43:37 +04:00
Nikolay Edigaryev 8cd68ea8ef Revert com.apple.vm.networking entitlement (#247) 2022-09-14 11:01:16 -04:00
5 changed files with 26 additions and 9 deletions
-2
View File
@@ -4,7 +4,5 @@
<dict> <dict>
<key>com.apple.security.virtualization</key> <key>com.apple.security.virtualization</key>
<true/> <true/>
<key>com.apple.vm.networking</key>
<true/>
</dict> </dict>
</plist> </plist>
+3 -2
View File
@@ -44,11 +44,12 @@ struct IP: AsyncParsableCommand {
let waitUntil = Calendar.current.date(byAdding: .second, value: Int(secondsToWait), to: Date.now)! let waitUntil = Calendar.current.date(byAdding: .second, value: Int(secondsToWait), to: Date.now)!
repeat { repeat {
if let ip = try Leases().resolveMACAddress(macAddress: vmMACAddress) { if let leases = try Leases(), let ip = try leases.resolveMACAddress(macAddress: vmMACAddress) {
return ip return ip
} }
try await Task.sleep(nanoseconds: 1_000_000) // wait a second
try await Task.sleep(nanoseconds: 1_000_000_000)
} while Date.now < waitUntil } while Date.now < waitUntil
return nil return nil
+9 -1
View File
@@ -19,6 +19,9 @@ struct Run: AsyncParsableCommand {
discussion: "Useful for integrating Tart VMs into other tools.\nUse `tart ip` in order to get an IP for SSHing or VNCing into the VM.")) discussion: "Useful for integrating Tart VMs into other tools.\nUse `tart ip` in order to get an IP for SSHing or VNCing into the VM."))
var noGraphics: Bool = false var noGraphics: Bool = false
@Flag(help: "Force open a UI window, even when VNC is enabled.")
var graphics: Bool = false
@Flag(help: "Boot into recovery mode") @Flag(help: "Boot into recovery mode")
var recovery: Bool = false var recovery: Bool = false
@@ -69,6 +72,10 @@ struct Run: AsyncParsableCommand {
if withSoftnet && netBridged != nil { if withSoftnet && netBridged != nil {
throw ValidationError("--with-softnet and --net-bridged are mutually exclusive") throw ValidationError("--with-softnet and --net-bridged are mutually exclusive")
} }
if graphics && noGraphics {
throw ValidationError("--graphics and --no-graphics are mutually exclusive")
}
} }
@MainActor @MainActor
@@ -129,7 +136,8 @@ struct Run: AsyncParsableCommand {
} }
sigintSrc.activate() sigintSrc.activate()
if noGraphics || vnc || vncExperimental { let useVNCWithoutGraphics = (vnc || vncExperimental) && !graphics
if noGraphics || useVNCWithoutGraphics {
dispatchMain() dispatchMain()
} else { } else {
runUI() runUI()
+11 -4
View File
@@ -19,14 +19,21 @@ enum LeasesError: Error {
class Leases { class Leases {
private let leases: [MACAddress : Lease] private let leases: [MACAddress : Lease]
convenience init() throws { convenience init?() throws {
try self.init(URL(fileURLWithPath: "/var/db/dhcpd_leases")) try self.init(URL(fileURLWithPath: "/var/db/dhcpd_leases"))
} }
convenience init(_ fromURL: URL) throws { convenience init?(_ fromURL: URL) throws {
let fileContents = try String(contentsOf: fromURL, encoding: .utf8) do {
let urlContents = try String(contentsOf: fromURL, encoding: .utf8)
try self.init(urlContents)
} catch {
if error.isFileNotFound() {
return nil
}
try self.init(fileContents) throw error
}
} }
init(_ fromString: String) throws { init(_ fromString: String) throws {
+3
View File
@@ -33,6 +33,9 @@ struct Root: AsyncParsableCommand {
} }
sigintSrc.activate() sigintSrc.activate()
// Set line-buffered output for stdout
setlinebuf(stdout)
// Parse and run command // Parse and run command
do { do {
var command = try parseAsRoot() var command = try parseAsRoot()