Hey! Im working with inotify to check filesystem events. For some reason i want to print the name of the event. I'm calling the 'event.getName()' function and when I try to print it i got ascii chars like if like memory was freeing before printing(?
I don't know if it's a bug with my code or something else.
while (true) {
const bytes_read = linux.read(self.fd, &buffer, buffer.len);
if (bytes_read < 0) {
log.err("Failed to read from inotify file descriptor: {d}", .{bytes_read});
return error.ReadFailed;
}
var offset: usize = 0;
while (offset < bytes_read) {
const event_ptr: *const linux.inotify_event = @ptrCast(@alignCast(&buffer[offset]));
const event = event_ptr.*;
// var stat: linux.Stat = undefined;
// _ = linux.stat("./text-directory", &stat);
if (event.len > 0) {
const name: ?[:0]const u8 = event.getName();
if (name) |n| {
// Here is when the log is not working.
std.debug.print("{s}\n", .{n[0..n.len]});
}
}
if (self.config.debug_logs) log.info("Event on watch descriptor: {d}, mask: {x}, cookie: {x}, len: {d}\n", .{ event.wd, event.mask, event.cookie, event.len });
try self.process_event(event);
offset += @sizeOf(linux.inotify_event) + event.len;
}
}