diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-02-08 14:27:21 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-02-08 14:27:21 +0100 |
commit | 679c30e73eda275085676f51fc77ee18c84edf21 (patch) | |
tree | 163f4f8eeb6eceb4e42e8a82cb1d53ae1f83049c | |
parent | 317498f3b3335ee9b9944929ffae16f07e1ebd2d (diff) | |
download | busybox-w32-679c30e73eda275085676f51fc77ee18c84edf21.tar.gz busybox-w32-679c30e73eda275085676f51fc77ee18c84edf21.tar.bz2 busybox-w32-679c30e73eda275085676f51fc77ee18c84edf21.zip |
sysctl: avoid stat() on every item if in -w mode
function old new delta
sysctl_act_recursive 163 167 +4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/sysctl.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c index 42de374d2..2ef19c1be 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c | |||
@@ -205,19 +205,21 @@ static int sysctl_act_on_setting(char *setting) | |||
205 | 205 | ||
206 | static int sysctl_act_recursive(const char *path) | 206 | static int sysctl_act_recursive(const char *path) |
207 | { | 207 | { |
208 | DIR *dirp; | ||
209 | struct stat buf; | 208 | struct stat buf; |
210 | struct dirent *entry; | ||
211 | char *next; | ||
212 | int retval = 0; | 209 | int retval = 0; |
213 | 210 | ||
214 | stat(path, &buf); | 211 | if (!(option_mask32 & FLAG_WRITE) |
215 | if (S_ISDIR(buf.st_mode) && !(option_mask32 & FLAG_WRITE)) { | 212 | && stat(path, &buf) == 0 |
213 | && S_ISDIR(buf.st_mode) | ||
214 | ) { | ||
215 | struct dirent *entry; | ||
216 | DIR *dirp; | ||
217 | |||
216 | dirp = opendir(path); | 218 | dirp = opendir(path); |
217 | if (dirp == NULL) | 219 | if (dirp == NULL) |
218 | return -1; | 220 | return -1; |
219 | while ((entry = readdir(dirp)) != NULL) { | 221 | while ((entry = readdir(dirp)) != NULL) { |
220 | next = concat_subpath_file(path, entry->d_name); | 222 | char *next = concat_subpath_file(path, entry->d_name); |
221 | if (next == NULL) | 223 | if (next == NULL) |
222 | continue; /* d_name is "." or ".." */ | 224 | continue; /* d_name is "." or ".." */ |
223 | /* if path was ".", drop "./" prefix: */ | 225 | /* if path was ".", drop "./" prefix: */ |
@@ -305,6 +307,8 @@ int sysctl_main(int argc UNUSED_PARAM, char **argv) | |||
305 | return sysctl_act_recursive("."); | 307 | return sysctl_act_recursive("."); |
306 | } | 308 | } |
307 | 309 | ||
310 | //TODO: if(!argv[0]) bb_show_usage() ? | ||
311 | |||
308 | retval = 0; | 312 | retval = 0; |
309 | while (*argv) { | 313 | while (*argv) { |
310 | sysctl_dots_to_slashes(*argv); | 314 | sysctl_dots_to_slashes(*argv); |