[PATCH] pidfiles: check if arg, path is empty string

Leesoo Ahn yisooan at fedoraproject.org
Wed Apr 15 05:03:42 UTC 2020


Although open() syscall returns -1 with an empty string and
is like error handling behavior, checking if the arg is empty
string at the early stage is much better. Hence, we do not
need to pay the overhead of calling the syscall at all.

Signed-off-by: Leesoo Ahn <yisooan at fedoraproject.org>
---
 libbb/pidfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libbb/pidfile.c b/libbb/pidfile.c
index a6a282562..51432133d 100644
--- a/libbb/pidfile.c
+++ b/libbb/pidfile.c
@@ -20,7 +20,7 @@ void FAST_FUNC write_pidfile(const char *path)
 	char buf[sizeof(int)*3 + 2];
 	struct stat sb;
 
-	if (!path)
+	if (!path || *path == '\0')
 		return;
 	/* we will overwrite stale pidfile */
 	pid_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666);
-- 
2.24.1



More information about the busybox mailing list