diff options
author | Ron Yorston <rmy@pobox.com> | 2014-10-06 12:50:22 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-10-06 12:50:22 +0100 |
commit | b04d11dcbadda2620743a1dd923938f2f3043a38 (patch) | |
tree | 971afe425a81304b79e44122e220c7a69efe2616 /coreutils | |
parent | 124bbf02948b7ac0babb4ead04acd1559db182d3 (diff) | |
parent | 760d035699c4a878f9109544c1d35ea0d5f6b76c (diff) | |
download | busybox-w32-b04d11dcbadda2620743a1dd923938f2f3043a38.tar.gz busybox-w32-b04d11dcbadda2620743a1dd923938f2f3043a38.tar.bz2 busybox-w32-b04d11dcbadda2620743a1dd923938f2f3043a38.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/df.c | 36 | ||||
-rw-r--r-- | coreutils/install.c | 37 | ||||
-rw-r--r-- | coreutils/test.c | 69 |
3 files changed, 85 insertions, 57 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index 5e9a8670f..d79c11a6c 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -25,6 +25,7 @@ | |||
25 | //usage:#define df_trivial_usage | 25 | //usage:#define df_trivial_usage |
26 | //usage: "[-Pk" | 26 | //usage: "[-Pk" |
27 | //usage: IF_FEATURE_HUMAN_READABLE("mh") | 27 | //usage: IF_FEATURE_HUMAN_READABLE("mh") |
28 | //usage: "T" | ||
28 | //usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE") | 29 | //usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE") |
29 | //usage: "] [FILESYSTEM]..." | 30 | //usage: "] [FILESYSTEM]..." |
30 | //usage:#define df_full_usage "\n\n" | 31 | //usage:#define df_full_usage "\n\n" |
@@ -35,6 +36,7 @@ | |||
35 | //usage: "\n -m 1M-byte blocks" | 36 | //usage: "\n -m 1M-byte blocks" |
36 | //usage: "\n -h Human readable (e.g. 1K 243M 2G)" | 37 | //usage: "\n -h Human readable (e.g. 1K 243M 2G)" |
37 | //usage: ) | 38 | //usage: ) |
39 | //usage: "\n -T Print filesystem type" | ||
38 | //usage: IF_FEATURE_DF_FANCY( | 40 | //usage: IF_FEATURE_DF_FANCY( |
39 | //usage: "\n -a Show all filesystems" | 41 | //usage: "\n -a Show all filesystems" |
40 | //usage: "\n -i Inodes" | 42 | //usage: "\n -i Inodes" |
@@ -83,11 +85,12 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
83 | enum { | 85 | enum { |
84 | OPT_KILO = (1 << 0), | 86 | OPT_KILO = (1 << 0), |
85 | OPT_POSIX = (1 << 1), | 87 | OPT_POSIX = (1 << 1), |
86 | OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY, | 88 | OPT_FSTYPE = (1 << 2), |
87 | OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY, | 89 | OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY, |
88 | OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY, | 90 | OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY, |
89 | OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, | 91 | OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY, |
90 | OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, | 92 | OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, |
93 | OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, | ||
91 | }; | 94 | }; |
92 | const char *disp_units_hdr = NULL; | 95 | const char *disp_units_hdr = NULL; |
93 | char *chp; | 96 | char *chp; |
@@ -99,7 +102,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
99 | #elif ENABLE_FEATURE_HUMAN_READABLE | 102 | #elif ENABLE_FEATURE_HUMAN_READABLE |
100 | opt_complementary = "k-m:m-k"; | 103 | opt_complementary = "k-m:m-k"; |
101 | #endif | 104 | #endif |
102 | opt = getopt32(argv, "kP" | 105 | opt = getopt32(argv, "kPT" |
103 | IF_FEATURE_DF_FANCY("aiB:") | 106 | IF_FEATURE_DF_FANCY("aiB:") |
104 | IF_FEATURE_HUMAN_READABLE("hm") | 107 | IF_FEATURE_HUMAN_READABLE("hm") |
105 | IF_FEATURE_DF_FANCY(, &chp)); | 108 | IF_FEATURE_DF_FANCY(, &chp)); |
@@ -134,8 +137,11 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
134 | disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr); | 137 | disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr); |
135 | #endif | 138 | #endif |
136 | } | 139 | } |
137 | printf("Filesystem %-15sUsed Available %s Mounted on\n", | 140 | |
138 | disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%"); | 141 | printf("Filesystem %s%-15sUsed Available %s Mounted on\n", |
142 | (opt & OPT_FSTYPE) ? "Type " : "", | ||
143 | disp_units_hdr, | ||
144 | (opt & OPT_POSIX) ? "Capacity" : "Use%"); | ||
139 | 145 | ||
140 | mount_table = NULL; | 146 | mount_table = NULL; |
141 | argv += optind; | 147 | argv += optind; |
@@ -148,6 +154,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
148 | while (1) { | 154 | while (1) { |
149 | const char *device; | 155 | const char *device; |
150 | const char *mount_point; | 156 | const char *mount_point; |
157 | const char *fs_type; | ||
151 | 158 | ||
152 | if (mount_table) { | 159 | if (mount_table) { |
153 | mount_entry = getmntent(mount_table); | 160 | mount_entry = getmntent(mount_table); |
@@ -170,6 +177,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
170 | 177 | ||
171 | device = mount_entry->mnt_fsname; | 178 | device = mount_entry->mnt_fsname; |
172 | mount_point = mount_entry->mnt_dir; | 179 | mount_point = mount_entry->mnt_dir; |
180 | fs_type = mount_entry->mnt_type; | ||
173 | 181 | ||
174 | if (statfs(mount_point, &s) != 0) { | 182 | if (statfs(mount_point, &s) != 0) { |
175 | bb_simple_perror_msg(mount_point); | 183 | bb_simple_perror_msg(mount_point); |
@@ -218,10 +226,22 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
218 | printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, ""); | 226 | printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, ""); |
219 | } | 227 | } |
220 | free(uni_dev); | 228 | free(uni_dev); |
229 | if (opt & OPT_FSTYPE) { | ||
230 | char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type); | ||
231 | if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX)) | ||
232 | printf(" %s\n%31s", uni_type, ""); | ||
233 | else | ||
234 | printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, ""); | ||
235 | free(uni_type); | ||
236 | } | ||
221 | } | 237 | } |
222 | #else | 238 | #else |
223 | if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX)) | 239 | if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX)) |
224 | printf("\n%-20s", ""); | 240 | printf("\n%-20s", ""); |
241 | if (opt & OPT_FSTYPE) { | ||
242 | if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX)) | ||
243 | printf("\n%-30s", ""); | ||
244 | } | ||
225 | #endif | 245 | #endif |
226 | 246 | ||
227 | #if ENABLE_FEATURE_HUMAN_READABLE | 247 | #if ENABLE_FEATURE_HUMAN_READABLE |
diff --git a/coreutils/install.c b/coreutils/install.c index 6c88ae11c..73f9c70d5 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
@@ -8,7 +8,7 @@ | |||
8 | 8 | ||
9 | /* -v, -b, -c are ignored */ | 9 | /* -v, -b, -c are ignored */ |
10 | //usage:#define install_trivial_usage | 10 | //usage:#define install_trivial_usage |
11 | //usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST" | 11 | //usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST" |
12 | //usage:#define install_full_usage "\n\n" | 12 | //usage:#define install_full_usage "\n\n" |
13 | //usage: "Copy files and set attributes\n" | 13 | //usage: "Copy files and set attributes\n" |
14 | //usage: "\n -c Just copy (default)" | 14 | //usage: "\n -c Just copy (default)" |
@@ -19,6 +19,7 @@ | |||
19 | //usage: "\n -o USER Set ownership" | 19 | //usage: "\n -o USER Set ownership" |
20 | //usage: "\n -g GRP Set group ownership" | 20 | //usage: "\n -g GRP Set group ownership" |
21 | //usage: "\n -m MODE Set permissions" | 21 | //usage: "\n -m MODE Set permissions" |
22 | //usage: "\n -t DIR Install to DIR" | ||
22 | //usage: IF_SELINUX( | 23 | //usage: IF_SELINUX( |
23 | //usage: "\n -Z Set security context" | 24 | //usage: "\n -Z Set security context" |
24 | //usage: ) | 25 | //usage: ) |
@@ -37,6 +38,7 @@ static const char install_longopts[] ALIGN1 = | |||
37 | "group\0" Required_argument "g" | 38 | "group\0" Required_argument "g" |
38 | "mode\0" Required_argument "m" | 39 | "mode\0" Required_argument "m" |
39 | "owner\0" Required_argument "o" | 40 | "owner\0" Required_argument "o" |
41 | "target-directory\0" Required_argument "t" | ||
40 | /* autofs build insists of using -b --suffix=.orig */ | 42 | /* autofs build insists of using -b --suffix=.orig */ |
41 | /* TODO? (short option for --suffix is -S) */ | 43 | /* TODO? (short option for --suffix is -S) */ |
42 | #if ENABLE_SELINUX | 44 | #if ENABLE_SELINUX |
@@ -95,9 +97,8 @@ int install_main(int argc, char **argv) | |||
95 | int mkdir_flags = FILEUTILS_RECUR; | 97 | int mkdir_flags = FILEUTILS_RECUR; |
96 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; | 98 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; |
97 | int opts; | 99 | int opts; |
98 | int min_args = 1; | ||
99 | int ret = EXIT_SUCCESS; | 100 | int ret = EXIT_SUCCESS; |
100 | int isdir = 0; | 101 | int isdir; |
101 | #if ENABLE_SELINUX | 102 | #if ENABLE_SELINUX |
102 | security_context_t scontext; | 103 | security_context_t scontext; |
103 | bool use_default_selinux_context = 1; | 104 | bool use_default_selinux_context = 1; |
@@ -113,20 +114,22 @@ int install_main(int argc, char **argv) | |||
113 | OPT_GROUP = 1 << 7, | 114 | OPT_GROUP = 1 << 7, |
114 | OPT_MODE = 1 << 8, | 115 | OPT_MODE = 1 << 8, |
115 | OPT_OWNER = 1 << 9, | 116 | OPT_OWNER = 1 << 9, |
117 | OPT_TARGET = 1 << 10, | ||
116 | #if ENABLE_SELINUX | 118 | #if ENABLE_SELINUX |
117 | OPT_SET_SECURITY_CONTEXT = 1 << 10, | 119 | OPT_SET_SECURITY_CONTEXT = 1 << 11, |
118 | OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11, | 120 | OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12, |
119 | #endif | 121 | #endif |
120 | }; | 122 | }; |
121 | 123 | ||
122 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS | 124 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS |
123 | applet_long_options = install_longopts; | 125 | applet_long_options = install_longopts; |
124 | #endif | 126 | #endif |
125 | opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); | 127 | opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); |
126 | /* -c exists for backwards compatibility, it's needed */ | 128 | /* -c exists for backwards compatibility, it's needed */ |
127 | /* -b is ignored ("make a backup of each existing destination file") */ | 129 | /* -b is ignored ("make a backup of each existing destination file") */ |
128 | opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"), | 130 | opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), |
129 | &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext)); | 131 | &gid_str, &mode_str, &uid_str, &last |
132 | IF_SELINUX(, &scontext)); | ||
130 | argc -= optind; | 133 | argc -= optind; |
131 | argv += optind; | 134 | argv += optind; |
132 | 135 | ||
@@ -160,20 +163,23 @@ int install_main(int argc, char **argv) | |||
160 | uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); | 163 | uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); |
161 | gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); | 164 | gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); |
162 | 165 | ||
163 | last = argv[argc - 1]; | 166 | /* If -t DIR is in use, then isdir=true, last="DIR" */ |
164 | if (!(opts & OPT_DIRECTORY)) { | 167 | isdir = (opts & OPT_TARGET); |
165 | argv[argc - 1] = NULL; | 168 | if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) { |
166 | min_args++; | 169 | /* Neither -t DIR nor -d is in use */ |
167 | 170 | argc--; | |
171 | last = argv[argc]; | ||
172 | argv[argc] = NULL; | ||
168 | /* coreutils install resolves link in this case, don't use lstat */ | 173 | /* coreutils install resolves link in this case, don't use lstat */ |
169 | isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); | 174 | isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); |
170 | } | 175 | } |
171 | 176 | ||
172 | if (argc < min_args) | 177 | if (argc < 1) |
173 | bb_show_usage(); | 178 | bb_show_usage(); |
174 | 179 | ||
175 | while ((arg = *argv++) != NULL) { | 180 | while ((arg = *argv++) != NULL) { |
176 | char *dest = last; | 181 | char *dest; |
182 | |||
177 | if (opts & OPT_DIRECTORY) { | 183 | if (opts & OPT_DIRECTORY) { |
178 | dest = arg; | 184 | dest = arg; |
179 | /* GNU coreutils 6.9 does not set uid:gid | 185 | /* GNU coreutils 6.9 does not set uid:gid |
@@ -184,6 +190,7 @@ int install_main(int argc, char **argv) | |||
184 | goto next; | 190 | goto next; |
185 | } | 191 | } |
186 | } else { | 192 | } else { |
193 | dest = last; | ||
187 | if (opts & OPT_MKDIR_LEADING) { | 194 | if (opts & OPT_MKDIR_LEADING) { |
188 | char *ddir = xstrdup(dest); | 195 | char *ddir = xstrdup(dest); |
189 | bb_make_directory(dirname(ddir), 0755, mkdir_flags); | 196 | bb_make_directory(dirname(ddir), 0755, mkdir_flags); |
diff --git a/coreutils/test.c b/coreutils/test.c index ba1dbaa2f..6b16ffeb1 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
@@ -845,7 +845,6 @@ int test_main(int argc, char **argv) | |||
845 | { | 845 | { |
846 | int res; | 846 | int res; |
847 | const char *arg0; | 847 | const char *arg0; |
848 | // bool negate = 0; | ||
849 | 848 | ||
850 | arg0 = bb_basename(argv[0]); | 849 | arg0 = bb_basename(argv[0]); |
851 | if (arg0[0] == '[') { | 850 | if (arg0[0] == '[') { |
@@ -863,6 +862,7 @@ int test_main(int argc, char **argv) | |||
863 | } | 862 | } |
864 | argv[argc] = NULL; | 863 | argv[argc] = NULL; |
865 | } | 864 | } |
865 | /* argc is unused after this point */ | ||
866 | 866 | ||
867 | /* We must do DEINIT_S() prior to returning */ | 867 | /* We must do DEINIT_S() prior to returning */ |
868 | INIT_S(); | 868 | INIT_S(); |
@@ -881,43 +881,45 @@ int test_main(int argc, char **argv) | |||
881 | */ | 881 | */ |
882 | /*ngroups = 0; - done by INIT_S() */ | 882 | /*ngroups = 0; - done by INIT_S() */ |
883 | 883 | ||
884 | //argc--; | ||
885 | argv++; | 884 | argv++; |
885 | args = argv; | ||
886 | 886 | ||
887 | /* Implement special cases from POSIX.2, section 4.62.4 */ | 887 | /* Implement special cases from POSIX.2, section 4.62.4. |
888 | if (!argv[0]) { /* "test" */ | 888 | * Testcase: "test '(' = '('" |
889 | res = 1; | 889 | * The general parser would misinterpret '(' as group start. |
890 | goto ret; | 890 | */ |
891 | } | 891 | if (1) { |
892 | #if 0 | 892 | int negate = 0; |
893 | // Now it's fixed in the parser and should not be needed | 893 | again: |
894 | if (LONE_CHAR(argv[0], '!') && argv[1]) { | 894 | if (!argv[0]) { |
895 | negate = 1; | 895 | /* "test" */ |
896 | //argc--; | 896 | res = 1; |
897 | argv++; | 897 | goto ret_special; |
898 | } | 898 | } |
899 | if (!argv[1]) { /* "test [!] arg" */ | 899 | if (!argv[1]) { |
900 | res = (*argv[0] == '\0'); | 900 | /* "test [!] arg" */ |
901 | goto ret; | 901 | res = (argv[0][0] == '\0'); |
902 | } | 902 | goto ret_special; |
903 | if (argv[2] && !argv[3]) { | 903 | } |
904 | check_operator(argv[1]); | 904 | if (argv[2] && !argv[3]) { |
905 | if (last_operator->op_type == BINOP) { | 905 | check_operator(argv[1]); |
906 | /* "test [!] arg1 <binary_op> arg2" */ | 906 | if (last_operator->op_type == BINOP) { |
907 | args = argv; | 907 | /* "test [!] arg1 <binary_op> arg2" */ |
908 | res = (binop() == 0); | 908 | args = argv; |
909 | goto ret; | 909 | res = (binop() == 0); |
910 | ret_special: | ||
911 | /* If there was leading "!" op... */ | ||
912 | res ^= negate; | ||
913 | goto ret; | ||
914 | } | ||
915 | } | ||
916 | if (LONE_CHAR(argv[0], '!')) { | ||
917 | argv++; | ||
918 | negate ^= 1; | ||
919 | goto again; | ||
910 | } | 920 | } |
911 | } | 921 | } |
912 | 922 | ||
913 | /* Some complex expression. Undo '!' removal */ | ||
914 | if (negate) { | ||
915 | negate = 0; | ||
916 | //argc++; | ||
917 | argv--; | ||
918 | } | ||
919 | #endif | ||
920 | args = argv; | ||
921 | res = !oexpr(check_operator(*args)); | 923 | res = !oexpr(check_operator(*args)); |
922 | 924 | ||
923 | if (*args != NULL && *++args != NULL) { | 925 | if (*args != NULL && *++args != NULL) { |
@@ -930,6 +932,5 @@ int test_main(int argc, char **argv) | |||
930 | } | 932 | } |
931 | ret: | 933 | ret: |
932 | DEINIT_S(); | 934 | DEINIT_S(); |
933 | // return negate ? !res : res; | ||
934 | return res; | 935 | return res; |
935 | } | 936 | } |