Module Name:    src
Committed By:   wiz
Date:           Mon Jul 29 09:33:21 UTC 2019

Modified Files:
        src/usr.sbin/user: user.c

Log Message:
Fix warning in userdel -r.

If the 'rm -rf' works, then the home directory does not exist any more,
and rmdir() on it will return an error (ENOENT). Catch and ignore it.

Avoids:

# useradd -m foo
# userdel -r foo
userdel: Unable to remove all files in `/home/foo': No such file or directory


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/usr.sbin/user/user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/user/user.c
diff -u src/usr.sbin/user/user.c:1.132 src/usr.sbin/user/user.c:1.133
--- src/usr.sbin/user/user.c:1.132	Sun Jun 10 07:52:05 2018
+++ src/usr.sbin/user/user.c	Mon Jul 29 09:33:21 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.132 2018/06/10 07:52:05 zafer Exp $ */
+/* $NetBSD: user.c,v 1.133 2019/07/29 09:33:21 wiz Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.132 2018/06/10 07:52:05 zafer Exp $");
+__RCSID("$NetBSD: user.c,v 1.133 2019/07/29 09:33:21 wiz Exp $");
 #endif
 
 #include <sys/types.h>
@@ -300,7 +300,7 @@ removehomedir(struct passwd *pwp)
 	(void)asystem("%s -rf %s > /dev/null 2>&1 || true", _PATH_RM,
 		      pwp->pw_dir);
 	(void)seteuid(0);
-	if (rmdir(pwp->pw_dir) < 0) {
+	if (rmdir(pwp->pw_dir) < 0 && errno != ENOENT) {
 		warn("Unable to remove all files in `%s'", pwp->pw_dir);
 		return 0;
 	}

Reply via email to