[PATCH 1/2] erofs-utils: mount: Check the status of subprocess to avoid infinite loop

Yifan Zhao zhaoyifan28 at huawei.com
Fri Dec 12 21:17:32 AEDT 2025


In `erofsmount_nbd()`, if the child process forked therein exits
erroneously within `erofsmount_startnbd()`, the NBD device will never
become operational. Since the parent process does not check the child's
status, it will stuck in an infinite loop polling the NBD device state.

This patch ensures the parent process correctly detects this failure and
returns an error accordingly.

Signed-off-by: Yifan Zhao <zhaoyifan28 at huawei.com>
---
 mount/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/mount/main.c b/mount/main.c
index b28b8ba..758e8f8 100644
--- a/mount/main.c
+++ b/mount/main.c
@@ -8,6 +8,7 @@
 #include <signal.h>
 #include <sys/mount.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <pthread.h>
 #include <unistd.h>
 #include "erofs/config.h"
@@ -1173,6 +1174,14 @@ static int erofsmount_nbd(struct erofs_nbd_source *source,
 	while (1) {
 		err = erofs_nbd_in_service(num);
 		if (err == -ENOENT || err == -ENOTCONN) {
+			int status;
+
+			err = waitpid(pid, &status, WNOHANG);
+			if (err < 0)
+				return -errno;
+			else if (err > 0)
+				return status ? -EIO : 0;
+
 			usleep(50000);
 			continue;
 		}
-- 
2.43.0



More information about the Linux-erofs mailing list