diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 1997-02-02 10:16:59 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 1997-02-02 10:16:59 +0000 |
commit | 6089dd6563f4aaba17c0a82aeb009f182744acfd (patch) | |
tree | 60f8c5713ac0b29fbc1908ccba51a6829109af39 | |
parent | c9a729c4b02933dfe9d4a4ab40587419a09d96da (diff) |
Remember errno if fchown() fails so we get correct warnings
Only warn about not being able to restore user/group owner if not -f
-rw-r--r-- | bin/mv/mv.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 6155f2957ce..d2bc283cb85 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mv.c,v 1.5 1996/12/14 12:18:05 mickey Exp $ */ +/* $OpenBSD: mv.c,v 1.6 1997/02/02 10:16:58 tholo Exp $ */ /* $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: mv.c,v 1.5 1996/12/14 12:18:05 mickey Exp $"; +static char rcsid[] = "$OpenBSD: mv.c,v 1.6 1997/02/02 10:16:58 tholo Exp $"; #endif #endif /* not lint */ @@ -238,7 +238,7 @@ fastcopy(from, to, sbp) static u_int blen; static char *bp; register int nread, from_fd, to_fd; - int badchown = 0; + int badchown = 0, serrno; if ((from_fd = open(from, O_RDONLY, 0)) < 0) { warn("%s", from); @@ -250,8 +250,10 @@ fastcopy(from, to, sbp) return (1); } - if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) + if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) { + serrno = errno; badchown = 1; + } (void) fchmod(to_fd, sbp->st_mode & ~(S_ISUID|S_ISGID)); if (!blen && !(bp = malloc(blen = sbp->st_blksize))) { @@ -274,11 +276,12 @@ err: if (unlink(to)) (void)close(from_fd); if (badchown) { + errno = serrno; if ((sbp->st_mode & (S_ISUID|S_ISGID))) { warn("%s: set owner/group; not setting setuid/setgid", to); sbp->st_mode &= ~(S_ISUID|S_ISGID); - } else + } else if (!fflg) warn("%s: set owner/group", to); } if (fchmod(to_fd, sbp->st_mode)) |