Skip to content

Commit fb1ce99

Browse files
committed
pass in the path to zpool as an argument
1 parent b28476b commit fb1ce99

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Sources/zfs-pool-importer/main.swift

+18-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ formatter.timeStyle = .long
1111

1212
let stdout = FileHandle.standardOutput
1313

14-
stdout.print("+zfs-pool-importer")
14+
let command = ProcessInfo.processInfo.arguments.first?.split(separator: "/").last ?? "zfs_pool_importer"
15+
let arguments = ProcessInfo.processInfo.arguments.dropFirst()
16+
let sbin = arguments.first.flatMap {
17+
arg in // elementary (and inflexible) parsing of a single possible command line option
18+
var dir = ObjCBool(false)
19+
guard arg.hasPrefix("--sbindir"),
20+
let rawPath = arg.split(separator: "=").last.map(String.init),
21+
FileManager.default.fileExists(atPath: rawPath, isDirectory: &dir),
22+
dir.boolValue == true
23+
else { return nil }
24+
return URL(fileURLWithPath: rawPath, isDirectory: true).path.appending("/")
25+
} ?? "/usr/local/zfs/bin/"
26+
27+
let zpool = sbin + "zpool"
28+
29+
stdout.print("+\(command)")
1530
stdout.print(formatter.string(from: Date()))
1631

1732
formatter.dateStyle = .none
@@ -42,8 +57,7 @@ stdout.print("\(invariantDisksCookie) was\(found ? "" : "n't") found in \(String
4257
Thread.sleep(forTimeInterval: 10)
4358
stdout.print("\(formatter.string(from: Date())): running zpool import -a")
4459

45-
let code = launch(command: "/usr/local/zfs/bin/zpool",
46-
arguments: ["import", "-a", "-d", "/var/run/disk/by-id"])
60+
let code = launch(command: zpool, arguments: ["import", "-a", "-d", "/var/run/disk/by-id"])
4761

4862
stdout.print("\(formatter.string(from: Date())): zpool import returned with exit code \(code)")
4963

@@ -62,6 +76,6 @@ catch {
6276
formatter.dateStyle = .medium
6377
formatter.timeStyle = .long
6478
stdout.print(formatter.string(from: Date()))
65-
stdout.print("-zfs-pool-importer")
79+
stdout.print("-\(command)")
6680

6781
exit(code)

org.openzfsonosx.zfs-pool-importer.plist

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<key>ProgramArguments</key>
88
<array>
99
<string>/usr/local/zfs/libexec/zfs/launchd.d/zfs-pool-importer</string>
10+
<string>--sbindir=/usr/local/zfs/bin/</string>
1011
</array>
1112
<key>RunAtLoad</key>
1213
<true/>

0 commit comments

Comments
 (0)