Skip to contentSkip to conversation

script: Split doexec() out of doshell()

PATCH Applied Stanislav Brabec 1 participant 1 message Feb 10, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 script: Split doexec() out of doshell()

Create doshell() that will be needed by --interactive.

---
 term-utils/script.c | 46 ++++++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 20 deletions(-)
term-utils/script.c +26 -20
index 02ba596..14a44e1 100644
@@ -90,6 +90,7 @@ void getmaster(void);
 void getslave(void);
 void doinput(void);
 void dooutput(void);
+void doexec(void);
 void doshell(void);
 
 char	*shell;
@@ -508,9 +509,32 @@ dooutput(void) {
 }
 
 void
-doshell(void) {
+doexec(void) {
 	char *shname;
 
+	shname = strrchr(shell, '/');
+	if (shname)
+		shname++;
+	else
+		shname = shell;
+
+	if (access(shell, X_OK) == 0) {
+		if (cflg)
+			execl(shell, shname, "-c", cflg, NULL);
+		else
+			execl(shell, shname, "-i", NULL);
+	} else {
+		if (cflg)
+			execlp(shname, "-c", cflg, NULL);
+		else
+			execlp(shname, "-i", NULL);
+	}
+	warn(_("failed to execute %s"), shell);
+	fail();
+}
+
+void
+doshell(void) {
 	getslave();
 
 	/* close things irrelevant for this process */
@@ -528,12 +552,6 @@ doshell(void) {
 
 	master = -1;
 
-	shname = strrchr(shell, '/');
-	if (shname)
-		shname++;
-	else
-		shname = shell;
-
 	/*
 	 * When invoked from within /etc/csh.login, script spawns a csh shell
 	 * that spawns programs that cannot be killed with a SIGTERM. This is
@@ -544,19 +562,7 @@ doshell(void) {
 	 */
 	signal(SIGTERM, SIG_DFL);
 
-	if (access(shell, X_OK) == 0) {
-		if (cflg)
-			execl(shell, shname, "-c", cflg, NULL);
-		else
-			execl(shell, shname, "-i", NULL);
-	} else {
-		if (cflg)
-			execlp(shname, "-c", cflg, NULL);
-		else
-			execlp(shname, "-i", NULL);
-	}
-	warn(_("failed to execute %s"), shell);
-	fail();
+	doexec();
 }
 
 void
Signature · 13 lines
2.2.2

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                          e-mail: [email protected]
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76