For the foreseeable future, everything I run is in degbug mode.
I need to call Process() multiple times to stop and start a binary with updated arguments. Apple say Process() can only be called once - which I translate to mean one instance at a time. I'd been calling it from another place without the waitUntilExit().
So, I guess the Trace/breakpoint trap was my fault and I need to find a way of getting a Process() to return when launching a background process. Any ideas?
Resorting to bash scripts just feels wrong, so is there a way to do all this natively in Swift?
@ea7kir This just means that your program crashed because of a fatal error in Swift. Likely that is ! on a nil value, an integer overflow, a fatalError or something else of that kind.
The easiest way to debug what's going is on to either use lldb path/to/your/binary and in lldb type run to run the program and once it crashed, you can look at what's going on, for example with bt which gives you a backtrace.
If you're on macOS, you should also find a crash report that you can look into with Console.app under Crash Reports (left side) name something like yourapp_DATE_TIME....
@lukasa I think I've found a solution. Repeatably executing process = Process() not only solves the problem, it also eliminates the need to call the killall script.
class LongmyndController {
private let startLongmyndPath = "/home/pirec/startLongmynd.sh"
private let fifoPath = "/home/pirec/longmynd/longmynd_main_status"
private var fd: Int32
private var process: Process
private var _longmyndIsRunning: Bool
init() {
self.fd = -1
self.process = Process()
self._longmyndIsRunning = false
}
var longmyndIsRunning: Bool { get { return _longmyndIsRunning } }
func configure(with params: [String]) {
// MARK: stop and start longmynd
process = Process()
Task {
process.executableURL = URL(fileURLWithPath: startLongmyndPath)
process.arguments = params
do {
try process.run()
_longmyndIsRunning = true
} catch {
_longmyndIsRunning = false
logError("LongmyndController.\(#function) : failed to start longmynd")
}
// MARK: open FIFO - once only and keep it open
if _longmyndIsRunning && fd < 0 {
fd = open(fifoPath, O_RDONLY)
if fd < 0 {
logError("LongmyndController.\(#function) : failed to open FIFO")
}
}
}
}
// other functions follow
}
I ran this in a loop for over an hour without a hiccup, but do you think this dirty solution will cause problems further down the line?
@johannesweiss Debuggers? I've never found the patience to learn one. Trial & error with lots of print statements has always seemed easier, but thank you for your suggestion.