Changeset 1730 in kBuild for trunk/src/kmk/kmkbuiltin/install.c
- Timestamp:
- Sep 5, 2008 4:24:19 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/install.c
r1710 r1730 125 125 static mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 126 126 static const char *suffix = BACKUP_SUFFIX; 127 static int ignore_perm_errors; 127 128 128 129 static struct option long_options[] = … … 130 131 { "help", no_argument, 0, 261 }, 131 132 { "version", no_argument, 0, 262 }, 133 { "ignore-perm-errors", no_argument, 0, 263 }, 134 { "no-ignore-perm-errors", no_argument, 0, 264 }, 132 135 { 0, 0, 0, 0 }, 133 136 }; … … 149 152 150 153 int 151 kmk_builtin_install(int argc, char *argv[], char ** envp)154 kmk_builtin_install(int argc, char *argv[], char ** envp) 152 155 { 153 156 struct stat from_sb, to_sb; … … 158 161 char *flags; 159 162 const char *group, *owner, *to_name; 163 (void)envp; 160 164 161 165 /* reinitialize globals */ … … 165 169 uid = 0; 166 170 dobackup = docompare = dodir = dopreserve = dostrip = nommap = safecopy = verbose = 0; 171 ignore_perm_errors = geteuid() != 0; 167 172 168 173 /* reset getopt and set progname. */ … … 235 240 case 262: 236 241 return kbuild_version(argv[0]); 242 case 263: 243 ignore_perm_errors = 1; 244 break; 245 case 264: 246 ignore_perm_errors = 0; 247 break; 237 248 case '?': 238 249 default: … … 614 625 (uid != (uid_t)-1 && uid != to_sb.st_uid)) 615 626 if (fchown(to_fd, uid, gid) == -1) { 616 serrno = errno; 617 (void)unlink(to_name); 618 errno = serrno; 619 rc = err(EX_OSERR,"%s: chown/chgrp", to_name); 620 goto l_done; 627 if (errno == EPERM && ignore_perm_errors) { 628 warn("%s: ignoring chown uid=%d gid=%d failure", to_name, (int)uid, (int)gid); 629 } else { 630 serrno = errno; 631 (void)unlink(to_name); 632 errno = serrno; 633 rc = err(EX_OSERR,"%s: chown/chgrp", to_name); 634 goto l_done; 635 } 621 636 } 622 637 … … 624 639 if (fchmod(to_fd, mode)) { 625 640 serrno = errno; 626 (void)unlink(to_name); 627 errno = serrno; 628 rc = err(EX_OSERR, "%s: chmod", to_name); 629 goto l_done; 641 if (serrno == EPERM && ignore_perm_errors) { 642 fchmod(to_fd, mode & (ALLPERMS & ~0007000)); 643 errno = errno; 644 warn("%s: ignoring chmod 0%o failure", to_name, (int)(mode & ALLPERMS)); 645 } else { 646 serrno = errno; 647 (void)unlink(to_name); 648 errno = serrno; 649 rc = err(EX_OSERR, "%s: chmod", to_name); 650 goto l_done; 651 } 630 652 } 631 653 … … 843 865 } 844 866 #else 845 (void)p; 867 (void)p; (void)size; 846 868 #endif 847 869 if (!done_copy) { … … 949 971 usage(FILE *pf) 950 972 { 951 fprintf( stderr,952 "usage: %s [-bCcpSsv] [- B suffix] [-f flags] [-g group] [-m mode]\n"953 " [-o owner] file1 file2\n"954 " or: %s [-bCcpSsv] [- B suffix] [-f flags] [-g group] [-m mode]\n"955 " [-o owner] file1 ... fileN directory\n"973 fprintf(pf, 974 "usage: %s [-bCcpSsv] [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n" 975 " [-g group] [-m mode] [-o owner] file1 file2\n" 976 " or: %s [-bCcpSsv] [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n" 977 " [-g group] [-m mode] [-o owner] file1 ... fileN directory\n" 956 978 " or: %s -d [-v] [-g group] [-m mode] [-o owner] directory ...\n" 957 979 " or: %s --help\n"
Note:
See TracChangeset
for help on using the changeset viewer.