[1/5] fown: Dont fail if owner is a dead pid

Submitted by Cyrill Gorcunov on Dec. 7, 2018, 12:29 p.m.

Details

Message ID 20181207122948.26683-2-gorcunov@gmail.com
State New
Series "fown: Handle dead pids and O_PATH"
Headers show

Commit Message

Cyrill Gorcunov Dec. 7, 2018, 12:29 p.m.
A pid owner may already have exited when we're dumping a file,
thus on restore we will not find the pid and should simply
ignore it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/files.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index 3e0c8c4592dd..b12258ad2654 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -741,8 +741,19 @@  int restore_fown(int fd, FownEntry *fown)
 	owner.pid = fown->pid;
 
 	if (fcntl(fd, F_SETOWN_EX, &owner)) {
-		pr_perror("Can't setup %d file owner pid", fd);
-		return -1;
+		if (errno == ESRCH) {
+			/*
+			 * The pid obtained at the dump may no longer
+			 * exist, because the tasks with it has already
+			 * exited. Just ignore it.
+			 */
+			pr_debug("fown: No owner type %d pid %d found on file %d, skipping\n",
+				 owner.type, owner.pid, fd);
+		} else {
+			pr_perror("fown: Can't setup %d file owner type %d pid %d",
+				  fd, owner.type, owner.pid);
+			return -1;
+		}
 	}
 
 	if (setresuid(uids[0], uids[1], uids[2])) {