summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2021-06-24 12:02:17 +0200
committerDenys Vlasenko2021-06-24 12:02:17 +0200
commit6d61eb13635ac1121762f55376989af3d6c6ebad (patch)
tree613a092df0c92f00c04a90e2b88d50b95e66367d
parent1746218beebc7e180f3eaed905277f9f46983ac4 (diff)
downloadbusybox-6d61eb13635ac1121762f55376989af3d6c6ebad.zip
busybox-6d61eb13635ac1121762f55376989af3d6c6ebad.tar.gz
taskset: use iterate_on_dir()
function old new delta iter - 27 +27 process_pid_str 854 856 +2 taskset_main 181 135 -46 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 29/-46) Total: -17 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/taskset.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/util-linux/taskset.c b/util-linux/taskset.c
index 47e9897..afe2f04 100644
--- a/util-linux/taskset.c
+++ b/util-linux/taskset.c
@@ -213,7 +213,7 @@ enum {
OPT_c = (1 << 2) * ENABLE_FEATURE_TASKSET_CPULIST,
};
-static void process_pid_str(const char *pid_str, unsigned opts, char *aff)
+static int process_pid_str(const char *pid_str, unsigned opts, char *aff)
{
ul *mask;
unsigned mask_size_in_bytes;
@@ -237,7 +237,7 @@ static void process_pid_str(const char *pid_str, unsigned opts, char *aff)
/* Either it was just "-p <pid>",
* or it was "-p <aff> <pid>" and we came here
* for the second time (see goto below) */
- return;
+ return 0;
}
current_new = "new";
}
@@ -312,6 +312,14 @@ static void process_pid_str(const char *pid_str, unsigned opts, char *aff)
aff = NULL;
goto print_aff; /* print new affinity and exit */
}
+ return 0;
+}
+
+static int FAST_FUNC iter(const char *dn UNUSED_PARAM, struct dirent *ent, void *aff)
+{
+ if (isdigit(ent->d_name[0]))
+ return process_pid_str(ent->d_name, option_mask32, aff);
+ return 0;
}
int taskset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -341,29 +349,20 @@ int taskset_main(int argc UNUSED_PARAM, char **argv)
pid_str = aff;
if (*argv) /* "-p <aff> <pid> ...rest.is.ignored..." */
- pid_str = *argv; /* NB: *argv != NULL in this case */
+ pid_str = *argv;
else
aff = NULL;
if (opts & OPT_a) {
char *dn;
- DIR *dir;
- struct dirent *ent;
+ int r;
dn = xasprintf("/proc/%s/task", pid_str);
- dir = opendir(dn);
+ r = iterate_on_dir(dn, iter, aff);
IF_FEATURE_CLEAN_UP(free(dn);)
- if (!dir) {
- goto no_threads;
- }
- while ((ent = readdir(dir)) != NULL) {
- if (isdigit(ent->d_name[0]))
- process_pid_str(ent->d_name, opts, aff);
- }
- IF_FEATURE_CLEAN_UP(closedir(dir);)
- } else {
- no_threads:
- process_pid_str(pid_str, opts, aff);
+ if (r == 0)
+ return r; /* EXIT_SUCCESS */
+ /* else: no /proc/PID/task, act as if no -a was given */
}
- return EXIT_SUCCESS;
+ return process_pid_str(pid_str, opts, aff);
}