From 6d61110a62d2fbfd786636c7ff9137e3b685c57f Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Wed, 27 Nov 2024 15:08:54 +0800 Subject: [PATCH] fix(file): Fix file descriptor leak in `file.sync` Signed-off-by: Jianhui Zhao --- file.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/file.lua b/file.lua index 940fd1b..174a19e 100644 --- a/file.lua +++ b/file.lua @@ -2,8 +2,8 @@ -- Author: Jianhui Zhao local file = require 'eco.core.file' -local sys = require 'eco.core.sys' local time = require 'eco.time' +local sys = require 'eco.sys' local M = {} @@ -69,15 +69,13 @@ function M.flock(fd, operation, timeout) end end -function M.sync() - local pid, err = sys.exec('sync') - if not pid then +function M.sync(timeout) + local p, err = sys.exec('sync') + if not p then return nil, err end - eco.watcher(eco.CHILD, pid):wait() - - return true + return p:wait(timeout) end local inotify_methods = {}