mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
small stylistic tweaks
This commit is contained in:
@ -19,7 +19,6 @@ const Command = @This();
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const internal_os = @import("os/main.zig");
|
const internal_os = @import("os/main.zig");
|
||||||
const termio = @import("termio.zig");
|
|
||||||
const windows = internal_os.windows;
|
const windows = internal_os.windows;
|
||||||
const TempDir = internal_os.TempDir;
|
const TempDir = internal_os.TempDir;
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
@ -64,7 +63,7 @@ stderr: ?File = null,
|
|||||||
/// exec process takes over, such as signal handlers, setsid, setuid, etc.
|
/// exec process takes over, such as signal handlers, setsid, setuid, etc.
|
||||||
pre_exec: ?*const PreExecFn = null,
|
pre_exec: ?*const PreExecFn = null,
|
||||||
|
|
||||||
linux_cgroup: termio.Options.LinuxCgroup = termio.Options.linux_cgroup_default,
|
linux_cgroup: LinuxCgroup = linux_cgroup_default,
|
||||||
|
|
||||||
/// If set, then the process will be created attached to this pseudo console.
|
/// If set, then the process will be created attached to this pseudo console.
|
||||||
/// `stdin`, `stdout`, and `stderr` will be ignored if set.
|
/// `stdin`, `stdout`, and `stderr` will be ignored if set.
|
||||||
@ -78,6 +77,11 @@ data: ?*anyopaque = null,
|
|||||||
/// Process ID is set after start is called.
|
/// Process ID is set after start is called.
|
||||||
pid: ?posix.pid_t = null,
|
pid: ?posix.pid_t = null,
|
||||||
|
|
||||||
|
/// LinuxCGroup type depends on our target OS
|
||||||
|
pub const LinuxCgroup = if (builtin.os.tag == .linux) ?[]const u8 else void;
|
||||||
|
pub const linux_cgroup_default = if (LinuxCgroup == void)
|
||||||
|
{} else null;
|
||||||
|
|
||||||
/// The various methods a process may exit.
|
/// The various methods a process may exit.
|
||||||
pub const Exit = if (builtin.os.tag == .windows) union(enum) {
|
pub const Exit = if (builtin.os.tag == .windows) union(enum) {
|
||||||
Exited: u32,
|
Exited: u32,
|
||||||
@ -138,8 +142,13 @@ fn startPosix(self: *Command, arena: Allocator) !void {
|
|||||||
else
|
else
|
||||||
@compileError("missing env vars");
|
@compileError("missing env vars");
|
||||||
|
|
||||||
|
// Fork. If we have a cgroup specified on Linxu then we use clone
|
||||||
const pid: posix.pid_t = switch (builtin.os.tag) {
|
const pid: posix.pid_t = switch (builtin.os.tag) {
|
||||||
.linux => if (self.linux_cgroup) |cgroup| try internal_os.cgroup.cloneInto(cgroup) else try posix.fork(),
|
.linux => if (self.linux_cgroup) |cgroup|
|
||||||
|
try internal_os.cgroup.cloneInto(cgroup)
|
||||||
|
else
|
||||||
|
try posix.fork(),
|
||||||
|
|
||||||
else => try posix.fork(),
|
else => try posix.fork(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,15 +79,14 @@ pub fn cloneInto(cgroup: []const u8) !posix.pid_t {
|
|||||||
const fd: linux.fd_t = fd: {
|
const fd: linux.fd_t = fd: {
|
||||||
const rc = linux.open(path, linux.O{ .PATH = true, .DIRECTORY = true }, 0);
|
const rc = linux.open(path, linux.O{ .PATH = true, .DIRECTORY = true }, 0);
|
||||||
switch (posix.errno(rc)) {
|
switch (posix.errno(rc)) {
|
||||||
.SUCCESS => {
|
.SUCCESS => break :fd @as(linux.fd_t, @intCast(rc)),
|
||||||
break :fd @as(linux.fd_t, @intCast(rc));
|
|
||||||
},
|
|
||||||
else => |errno| {
|
else => |errno| {
|
||||||
log.err("unable to open cgroup dir {s}: {}", .{ path, errno });
|
log.err("unable to open cgroup dir {s}: {}", .{ path, errno });
|
||||||
break :fd -1;
|
return error.CloneError;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
assert(fd >= 0);
|
||||||
|
|
||||||
const args: extern struct {
|
const args: extern struct {
|
||||||
flags: u64,
|
flags: u64,
|
||||||
@ -102,7 +101,7 @@ pub fn cloneInto(cgroup: []const u8) !posix.pid_t {
|
|||||||
set_tid_size: u64,
|
set_tid_size: u64,
|
||||||
cgroup: u64,
|
cgroup: u64,
|
||||||
} = .{
|
} = .{
|
||||||
.flags = if (fd >= 0) linux.CLONE.INTO_CGROUP else 0,
|
.flags = linux.CLONE.INTO_CGROUP,
|
||||||
.pidfd = 0,
|
.pidfd = 0,
|
||||||
.child_tid = 0,
|
.child_tid = 0,
|
||||||
.parent_tid = 0,
|
.parent_tid = 0,
|
||||||
@ -112,19 +111,17 @@ pub fn cloneInto(cgroup: []const u8) !posix.pid_t {
|
|||||||
.tls = 0,
|
.tls = 0,
|
||||||
.set_tid = 0,
|
.set_tid = 0,
|
||||||
.set_tid_size = 0,
|
.set_tid_size = 0,
|
||||||
.cgroup = if (fd >= 0) @intCast(fd) else 0,
|
.cgroup = @intCast(fd),
|
||||||
};
|
};
|
||||||
|
|
||||||
const rc = linux.syscall2(linux.SYS.clone3, @intFromPtr(&args), @sizeOf(@TypeOf(args)));
|
const rc = linux.syscall2(linux.SYS.clone3, @intFromPtr(&args), @sizeOf(@TypeOf(args)));
|
||||||
switch (posix.errno(rc)) {
|
return switch (posix.errno(rc)) {
|
||||||
.SUCCESS => {
|
.SUCCESS => @as(posix.pid_t, @intCast(rc)),
|
||||||
return @as(posix.pid_t, @intCast(rc));
|
else => |errno| err: {
|
||||||
},
|
|
||||||
else => |errno| {
|
|
||||||
log.err("unable to clone: {}", .{errno});
|
log.err("unable to clone: {}", .{errno});
|
||||||
return error.CloneError;
|
break :err error.CloneError;
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all available cgroup controllers for the given cgroup.
|
/// Returns all available cgroup controllers for the given cgroup.
|
||||||
|
@ -897,7 +897,7 @@ const Subprocess = struct {
|
|||||||
pty: ?Pty = null,
|
pty: ?Pty = null,
|
||||||
command: ?Command = null,
|
command: ?Command = null,
|
||||||
flatpak_command: ?FlatpakHostCommand = null,
|
flatpak_command: ?FlatpakHostCommand = null,
|
||||||
linux_cgroup: termio.Options.LinuxCgroup = termio.Options.linux_cgroup_default,
|
linux_cgroup: Command.LinuxCgroup = Command.linux_cgroup_default,
|
||||||
|
|
||||||
/// Initialize the subprocess. This will NOT start it, this only sets
|
/// Initialize the subprocess. This will NOT start it, this only sets
|
||||||
/// up the internal state necessary to start it later.
|
/// up the internal state necessary to start it later.
|
||||||
@ -1196,8 +1196,8 @@ const Subprocess = struct {
|
|||||||
|
|
||||||
// If we have a cgroup, then we copy that into our arena so the
|
// If we have a cgroup, then we copy that into our arena so the
|
||||||
// memory remains valid when we start.
|
// memory remains valid when we start.
|
||||||
const linux_cgroup: termio.Options.LinuxCgroup = cgroup: {
|
const linux_cgroup: Command.LinuxCgroup = cgroup: {
|
||||||
const default = termio.Options.linux_cgroup_default;
|
const default = Command.linux_cgroup_default;
|
||||||
if (comptime builtin.os.tag != .linux) break :cgroup default;
|
if (comptime builtin.os.tag != .linux) break :cgroup default;
|
||||||
const path = opts.linux_cgroup orelse break :cgroup default;
|
const path = opts.linux_cgroup orelse break :cgroup default;
|
||||||
break :cgroup try alloc.dupe(u8, path);
|
break :cgroup try alloc.dupe(u8, path);
|
||||||
|
@ -4,6 +4,7 @@ const builtin = @import("builtin");
|
|||||||
const xev = @import("xev");
|
const xev = @import("xev");
|
||||||
const apprt = @import("../apprt.zig");
|
const apprt = @import("../apprt.zig");
|
||||||
const renderer = @import("../renderer.zig");
|
const renderer = @import("../renderer.zig");
|
||||||
|
const Command = @import("../Command.zig");
|
||||||
const Config = @import("../config.zig").Config;
|
const Config = @import("../config.zig").Config;
|
||||||
const termio = @import("../termio.zig");
|
const termio = @import("../termio.zig");
|
||||||
|
|
||||||
@ -45,7 +46,4 @@ surface_mailbox: apprt.surface.Mailbox,
|
|||||||
|
|
||||||
/// The cgroup to apply to the started termio process, if able by
|
/// The cgroup to apply to the started termio process, if able by
|
||||||
/// the termio implementation. This only applies to Linux.
|
/// the termio implementation. This only applies to Linux.
|
||||||
linux_cgroup: LinuxCgroup = linux_cgroup_default,
|
linux_cgroup: Command.LinuxCgroup = Command.linux_cgroup_default,
|
||||||
|
|
||||||
pub const LinuxCgroup = if (builtin.os.tag == .linux) ?[]const u8 else void;
|
|
||||||
pub const linux_cgroup_default = if (LinuxCgroup == void) {} else null;
|
|
||||||
|
Reference in New Issue
Block a user