@@ -947,6 +947,7 @@ static int setfile(const struct stat *fs, int fd)
947
947
static struct timeval tv [2 ];
948
948
struct stat ts ;
949
949
int gotstat , islink , fdval ;
950
+ int result ;
950
951
mode_t mode ;
951
952
rval = 0 ;
952
953
fdval = fd != -1 ;
@@ -966,8 +967,15 @@ static int setfile(const struct stat *fs, int fd)
966
967
rval = 1 ;
967
968
}
968
969
969
- if (fdval ? fstat (fd , & ts ) :
970
- (islink ? lstat (to .p_path , & ts ) : stat (to .p_path , & ts ))) {
970
+ if (fdval ) {
971
+ result = fstat (fd , & ts );
972
+ } else if (islink ) {
973
+ result = lstat (to .p_path , & ts );
974
+ } else {
975
+ result = stat (to .p_path , & ts );
976
+ }
977
+
978
+ if (result ) {
971
979
gotstat = 0 ;
972
980
} else {
973
981
gotstat = 1 ;
@@ -981,11 +989,17 @@ static int setfile(const struct stat *fs, int fd)
981
989
* the mode; current BSD behavior is to remove all setuid bits on
982
990
* chown. If chown fails, lose setuid/setgid bits.
983
991
*/
984
- if (!gotstat || fs -> st_uid != ts .st_uid || fs -> st_gid != ts .st_gid
985
- && fdval ? fchown (fd , fs -> st_uid , fs -> st_gid ) :
986
- (islink ? lchown (to .p_path , fs -> st_uid , fs -> st_gid ) :
987
- chown (to .p_path , fs -> st_uid , fs -> st_gid ))) {
988
- if (errno != EPERM ) {
992
+
993
+ if (!gotstat || fs -> st_uid != ts .st_uid || fs -> st_gid != ts .st_gid ) {
994
+ if (fdval ) {
995
+ result = fchown (fd , fs -> st_uid , fs -> st_gid );
996
+ } else if (islink ) {
997
+ result = lchown (to .p_path , fs -> st_uid , fs -> st_gid );
998
+ } else {
999
+ result = chown (to .p_path , fs -> st_uid , fs -> st_gid );
1000
+ }
1001
+
1002
+ if (result != 0 && errno != EPERM ) {
989
1003
SLOG ("chown: %s: %s" , to .p_path , strerror (errno ));
990
1004
rval = 1 ;
991
1005
}
0 commit comments