Skip to content

Commit

Permalink
Lock: use an optional type for ready_fd
Browse files Browse the repository at this point in the history
There's no bug this fixes or behavior change, the intention is just to
make this code harder to silently break in the future.
  • Loading branch information
ifreund committed Apr 15, 2024
1 parent d859e5b commit 4d8f4e1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Lock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const Color = enum {

pub const Options = struct {
fork_on_lock: bool,
ready_fd: os.fd_t = -1,
ready_fd: ?os.fd_t = null,
ignore_empty_password: bool,
init_color: u24 = 0x002b36,
input_color: u24 = 0x6c71c4,
Expand Down Expand Up @@ -61,7 +61,7 @@ state: enum {
color: Color = .init,

fork_on_lock: bool,
ready_fd: os.fd_t,
ready_fd: ?os.fd_t,
ignore_empty_password: bool,

pollfds: [2]os.pollfd,
Expand Down Expand Up @@ -361,14 +361,14 @@ fn session_lock_listener(_: *ext.SessionLockV1, event: ext.SessionLockV1.Event,
.locked => {
assert(lock.state == .locking);
lock.state = .locked;
if (lock.ready_fd >= 0) {
const file = std.fs.File{ .handle = lock.ready_fd };
if (lock.ready_fd) |ready_fd| {
const file = std.fs.File{ .handle = ready_fd };
file.writeAll("\n") catch |err| {
log.err("failed to send readiness notification: {s}", .{@errorName(err)});
os.exit(1);
};
file.close();
lock.ready_fd = -1;
lock.ready_fd = null;
}
if (lock.fork_on_lock) {
fork_to_background();
Expand Down

0 comments on commit 4d8f4e1

Please sign in to comment.