diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-16 21:49:02 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-16 21:49:02 +0000 |
| commit | d6817f5d8bc1deda64ff3230301a75cf7019fda2 (patch) | |
| tree | 1f145bead535a3f34cb91cee8d27e4ca8fd4ee64 /coreutils | |
| parent | 83cea0ef049d5aa50dfd431d5f8f6564cd93ce77 (diff) | |
| download | busybox-w32-d6817f5d8bc1deda64ff3230301a75cf7019fda2.tar.gz busybox-w32-d6817f5d8bc1deda64ff3230301a75cf7019fda2.tar.bz2 busybox-w32-d6817f5d8bc1deda64ff3230301a75cf7019fda2.zip | |
install: do not chown intermediate directories with install -d; shrink
(by Natanael Copa)
function old new delta
.rodata 171528 171511 -17
install_main 841 697 -144
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-161) Total: -161 bytes
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/install.c | 75 |
1 files changed, 28 insertions, 47 deletions
diff --git a/coreutils/install.c b/coreutils/install.c index 0b5eda0ac..c5d7a0cc5 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
| @@ -76,8 +76,9 @@ int install_main(int argc, char **argv) | |||
| 76 | const char *mode_str; | 76 | const char *mode_str; |
| 77 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; | 77 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; |
| 78 | int flags; | 78 | int flags; |
| 79 | int min_args = 1; | ||
| 79 | int ret = EXIT_SUCCESS; | 80 | int ret = EXIT_SUCCESS; |
| 80 | int isdir; | 81 | int isdir = 0; |
| 81 | #if ENABLE_SELINUX | 82 | #if ENABLE_SELINUX |
| 82 | security_context_t scontext; | 83 | security_context_t scontext; |
| 83 | bool use_default_selinux_context = 1; | 84 | bool use_default_selinux_context = 1; |
| @@ -133,58 +134,38 @@ int install_main(int argc, char **argv) | |||
| 133 | bb_parse_mode(mode_str, &mode); | 134 | bb_parse_mode(mode_str, &mode); |
| 134 | uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); | 135 | uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); |
| 135 | gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); | 136 | gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); |
| 136 | if (flags & (OPT_OWNER|OPT_GROUP)) | 137 | |
| 137 | umask(0); | 138 | last = argv[argc - 1]; |
| 138 | 139 | if (!(flags & OPT_DIRECTORY)) { | |
| 139 | /* Create directories | 140 | argv[argc - 1] = NULL; |
| 140 | * don't use bb_make_directory() as it can't change uid or gid | 141 | min_args++; |
| 141 | * perhaps bb_make_directory() should be improved. | 142 | |
| 142 | */ | 143 | /* coreutils install resolves link in this case, don't use lstat */ |
| 143 | if (flags & OPT_DIRECTORY) { | 144 | isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); |
| 144 | while ((arg = *argv++) != NULL) { | ||
| 145 | char *slash = arg; | ||
| 146 | while (1) { | ||
| 147 | slash = strchr(slash + 1, '/'); | ||
| 148 | if (slash) | ||
| 149 | *slash = '\0'; | ||
| 150 | if (mkdir(arg, mode | 0111) == -1) { | ||
| 151 | if (errno != EEXIST) { | ||
| 152 | bb_perror_msg("cannot create %s", arg); | ||
| 153 | ret = EXIT_FAILURE; | ||
| 154 | break; | ||
| 155 | } | ||
| 156 | } /* dir was created, chown? */ | ||
| 157 | else if ((flags & (OPT_OWNER|OPT_GROUP)) | ||
| 158 | && lchown(arg, uid, gid) == -1 | ||
| 159 | ) { | ||
| 160 | bb_perror_msg("cannot change ownership of %s", arg); | ||
| 161 | ret = EXIT_FAILURE; | ||
| 162 | break; | ||
| 163 | } | ||
| 164 | if (!slash) | ||
| 165 | break; | ||
| 166 | *slash = '/'; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | return ret; | ||
| 170 | } | 145 | } |
| 171 | 146 | ||
| 172 | if (argc < 2) | 147 | if (argc < min_args) |
| 173 | bb_show_usage(); | 148 | bb_show_usage(); |
| 174 | 149 | ||
| 175 | last = argv[argc - 1]; | ||
| 176 | argv[argc - 1] = NULL; | ||
| 177 | /* coreutils install resolves link in this case, don't use lstat */ | ||
| 178 | isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); | ||
| 179 | |||
| 180 | while ((arg = *argv++) != NULL) { | 150 | while ((arg = *argv++) != NULL) { |
| 181 | char *dest = last; | 151 | char *dest = last; |
| 182 | if (isdir) | 152 | if (flags & OPT_DIRECTORY) { |
| 183 | dest = concat_path_file(last, basename(arg)); | 153 | dest = arg; |
| 184 | if (copy_file(arg, dest, copy_flags)) { | 154 | /* GNU coreutils 6.9 does not set uid:gid |
| 185 | /* copy is not made */ | 155 | * on intermediate created directories |
| 186 | ret = EXIT_FAILURE; | 156 | * (only on last one) */ |
| 187 | goto next; | 157 | if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) { |
| 158 | ret = EXIT_FAILURE; | ||
| 159 | goto next; | ||
| 160 | } | ||
| 161 | } else { | ||
| 162 | if (isdir) | ||
| 163 | dest = concat_path_file(last, basename(arg)); | ||
| 164 | if (copy_file(arg, dest, copy_flags)) { | ||
| 165 | /* copy is not made */ | ||
| 166 | ret = EXIT_FAILURE; | ||
| 167 | goto next; | ||
| 168 | } | ||
| 188 | } | 169 | } |
| 189 | 170 | ||
| 190 | /* Set the file mode */ | 171 | /* Set the file mode */ |
