[OpenWrt-Devel,4/7] procd: shift arguments for askfirst only once

Message ID 71d5124a90a8975fb846a55486244dd71a25507a.1546385477.git.mhei@heimpold.de
State New
Headers show
Series
  • procd: console hotplugging support
Related show

Commit Message

Michael Heimpold Jan. 1, 2019, 11:44 p.m.
In case we want to process an inittab item multiple times (e.g. in case
of hotplugging) we must not shift the arguments for askfirst multiple
times. So check whether we already did it.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
---
 inittab.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Patch

diff --git a/inittab.c b/inittab.c
index 18023f5..45118f4 100644
--- a/inittab.c
+++ b/inittab.c
@@ -165,9 +165,12 @@  static void askfirst(struct init_action *a)
 	}
 
 	a->tout.cb = respawn;
-	for (i = MAX_ARGS - 1; i >= 1; i--)
-		a->argv[i] = a->argv[i - 1];
-	a->argv[0] = ask;
+	/* shift arguments only if not yet done */
+	if (a->argv[0] != ask) {
+		for (i = MAX_ARGS - 1; i >= 1; i--)
+			a->argv[i] = a->argv[i - 1];
+		a->argv[0] = ask;
+	}
 	a->respawn = 500;
 
 	a->proc.cb = child_exit;
@@ -200,9 +203,12 @@  static void askconsole(struct init_action *a)
 	}
 
 	a->tout.cb = respawn;
-	for (i = MAX_ARGS - 1; i >= 1; i--)
-		a->argv[i] = a->argv[i - 1];
-	a->argv[0] = ask;
+	/* shift arguments only if not yet done */
+	if (a->argv[0] != ask) {
+		for (i = MAX_ARGS - 1; i >= 1; i--)
+			a->argv[i] = a->argv[i - 1];
+		a->argv[0] = ask;
+	}
 	a->respawn = 500;
 
 	a->proc.cb = child_exit;