aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-02-08 14:27:21 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-02-08 14:27:21 +0100
commit679c30e73eda275085676f51fc77ee18c84edf21 (patch)
tree163f4f8eeb6eceb4e42e8a82cb1d53ae1f83049c /procps
parent317498f3b3335ee9b9944929ffae16f07e1ebd2d (diff)
downloadbusybox-679c30e73eda275085676f51fc77ee18c84edf21.tar.gz
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>
Diffstat (limited to 'procps')
-rw-r--r--procps/sysctl.c16
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)
static int sysctl_act_recursive(const char *path)
{
- DIR *dirp;
struct stat buf;
- struct dirent *entry;
- char *next;
int retval = 0;
- stat(path, &buf);
- if (S_ISDIR(buf.st_mode) && !(option_mask32 & FLAG_WRITE)) {
+ if (!(option_mask32 & FLAG_WRITE)
+ && stat(path, &buf) == 0
+ && S_ISDIR(buf.st_mode)
+ ) {
+ struct dirent *entry;
+ DIR *dirp;
+
dirp = opendir(path);
if (dirp == NULL)
return -1;
while ((entry = readdir(dirp)) != NULL) {
- next = concat_subpath_file(path, entry->d_name);
+ char *next = concat_subpath_file(path, entry->d_name);
if (next == NULL)
continue; /* d_name is "." or ".." */
/* if path was ".", drop "./" prefix: */
@@ -305,6 +307,8 @@ int sysctl_main(int argc UNUSED_PARAM, char **argv)
return sysctl_act_recursive(".");
}
+//TODO: if(!argv[0]) bb_show_usage() ?
+
retval = 0;
while (*argv) {
sysctl_dots_to_slashes(*argv);