| ... | @@ -332,7 +332,7 @@ pub const File = struct { | ... | @@ -332,7 +332,7 @@ pub const File = struct { |
| 332 | .coff, .elf, .macho, .plan9 => { | 332 | .coff, .elf, .macho, .plan9 => { |
| 333 | if (base.file != null) return; | 333 | if (base.file != null) return; |
| 334 | const emit = base.options.emit orelse return; | 334 | const emit = base.options.emit orelse return; |
| 335 | if (base.child_pid != null) { | 335 | if (base.child_pid) |pid| { |
| 336 | // If we try to open the output file in write mode while it is running, | 336 | // If we try to open the output file in write mode while it is running, |
| 337 | // it will return ETXTBSY. So instead, we copy the file, atomically rename it | 337 | // it will return ETXTBSY. So instead, we copy the file, atomically rename it |
| 338 | // over top of the exe path, and then proceed normally. This changes the inode, | 338 | // over top of the exe path, and then proceed normally. This changes the inode, |
| ... | @@ -342,6 +342,11 @@ pub const File = struct { | ... | @@ -342,6 +342,11 @@ pub const File = struct { |
| 342 | }); | 342 | }); |
| 343 | try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{}); | 343 | try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{}); |
| 344 | try emit.directory.handle.rename(tmp_sub_path, emit.sub_path); | 344 | try emit.directory.handle.rename(tmp_sub_path, emit.sub_path); |
| | 345 | |
| | 346 | switch (std.os.errno(std.os.linux.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0, 0))) { |
| | 347 | .SUCCESS => {}, |
| | 348 | else => |errno| log.warn("ptrace failure: {s}", .{@tagName(errno)}), |
| | 349 | } |
| 345 | } | 350 | } |
| 346 | base.file = try emit.directory.handle.createFile(emit.sub_path, .{ | 351 | base.file = try emit.directory.handle.createFile(emit.sub_path, .{ |
| 347 | .truncate = false, | 352 | .truncate = false, |
| ... | @@ -393,6 +398,13 @@ pub const File = struct { | ... | @@ -393,6 +398,13 @@ pub const File = struct { |
| 393 | } | 398 | } |
| 394 | f.close(); | 399 | f.close(); |
| 395 | base.file = null; | 400 | base.file = null; |
| | 401 | |
| | 402 | if (base.child_pid) |pid| { |
| | 403 | switch (std.os.errno(std.os.linux.ptrace(std.os.linux.PTRACE.DETACH, pid, 0, 0, 0))) { |
| | 404 | .SUCCESS => {}, |
| | 405 | else => |errno| log.warn("ptrace failure: {s}", .{@tagName(errno)}), |
| | 406 | } |
| | 407 | } |
| 396 | }, | 408 | }, |
| 397 | .c, .wasm, .spirv => {}, | 409 | .c, .wasm, .spirv => {}, |
| 398 | } | 410 | } |