Skip to contentSkip to conversation

tools/sched_ext: fix getopt not re-parsed on restart

PATCH Applied David Carlier 2 participants 2 messages Feb 18 – Feb 21 Scheduler - sched_ext

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/sched_ext: fix getopt not re-parsed on restart

After goto restart, optind retains its advanced position from the previous getopt loop, causing getopt() to immediately return -1. This silently drops all command-line options on the restarted skeleton.

Reset optind to 1 at the restart label so options are re-parsed.

Affected schedulers: scx_simple, scx_central, scx_flatcg, scx_pair, scx_sdt, scx_cpu0.

---
 tools/sched_ext/scx_central.c | 1 +
 tools/sched_ext/scx_cpu0.c    | 1 +
 tools/sched_ext/scx_flatcg.c  | 1 +
 tools/sched_ext/scx_pair.c    | 1 +
 tools/sched_ext/scx_sdt.c     | 1 +
 tools/sched_ext/scx_simple.c  | 1 +
 6 files changed, 6 insertions(+)
tools/sched_ext/scx_central.c +1 -0
index 39f21b00a208..2a805f1d6c8f 100644
@@ -56,6 +56,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
 restart:
+	optind = 1;
 	skel = SCX_OPS_OPEN(central_ops, scx_central);
 
 	skel->rodata->central_cpu = 0;
tools/sched_ext/scx_cpu0.c +1 -0
index 1e4fa4ab8da9..a6fba9978b9c 100644
@@ -69,6 +69,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
 restart:
+	optind = 1;
 	skel = SCX_OPS_OPEN(cpu0_ops, scx_cpu0);
 
 	skel->rodata->nr_cpus = libbpf_num_possible_cpus();
tools/sched_ext/scx_flatcg.c +1 -0
index a8446509949e..d865c381589b 100644
@@ -141,6 +141,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
 restart:
+	optind = 1;
 	skel = SCX_OPS_OPEN(flatcg_ops, scx_flatcg);
 
 	skel->rodata->nr_cpus = libbpf_num_possible_cpus();
tools/sched_ext/scx_pair.c +1 -0
index 2a82d8a8a0aa..2e509391f3da 100644
@@ -53,6 +53,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
 restart:
+	optind = 1;
 	skel = SCX_OPS_OPEN(pair_ops, scx_pair);
 
 	skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus();
tools/sched_ext/scx_sdt.c +1 -0
index b0363363476d..d8ca9aa316a5 100644
@@ -51,6 +51,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
 restart:
+	optind = 1;
 	skel = SCX_OPS_OPEN(sdt_ops, scx_sdt);
 
 	while ((opt = getopt(argc, argv, "fvh")) != -1) {
tools/sched_ext/scx_simple.c +1 -0
index 06d4b13bf76b..c3b48611712b 100644
@@ -71,6 +71,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
 restart:
+	optind = 1;
 	skel = SCX_OPS_OPEN(simple_ops, scx_simple);
 
 	while ((opt = getopt(argc, argv, "fvh")) != -1) {
Signature · 1 line
2.51.0
reviewer Applied
#1 lore raw

Applied to sched_ext/for-7.0-fixes.

Thanks.
--
tejun