Skip to contentSkip to conversation

Return code of openvt command

kbd Superseded ToBeReplaced 2 participants 3 messages Jul 30, 2015 – Aug 9, 2015

lore
Share & tools
lore
#0 lore raw

On openvt from kbd 2.0.2, openvt -c 1 -fw /bin/false exits with return code 0 instead of 1.

There's a bug report from 2003 and a claim that it was resolved as of kbd 1.14.1: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=190386

I'm not sure if this is a bug or desired behavior.

How can I get the return code of the command passed to openvt?

#1 lore raw

PATCH 1/1 openvt -w: Return exit status from child

---

Quoted 2 lines · ToBeReplaced

On openvt from kbd 2.0.2, openvt -c 1 -fw /bin/false exits with return code 0 instead of 1.

Can confirm on current git.

Quoted 2 lines

There's a bug report from 2003 and a claim that it was resolved as of kbd 1.14.1: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=190386

The relevant commit is e37c78afc7fcee6d8edaa506b99d9081249adb7d. Maybe it got broken since. Possibly it never worked at all.

Quoted 3 lines

I'm not sure if this is a bug or desired behavior.

How can I get the return code of the command passed to openvt?

Try this patch.

---
 src/openvt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
src/openvt.c +1 -2
index 1ba8912..1a36a69 100644
@@ -386,7 +386,6 @@ main(int argc, char *argv[])
 	if (do_wait) {
 		int retval = 0; /* actual value returned form process */
 
-		wait(NULL);
 		waitpid(pid, &retval, 0);
 
 		if (show) {	/* Switch back... */
@@ -403,7 +402,7 @@ main(int argc, char *argv[])
 
 		/* if all our stuff went right, we want to return the exit code of the command we ran
 		   super vital for scripting loops etc */
-		return(retval);
+		return WEXITSTATUS(retval);
 	}
 
 	return EXIT_SUCCESS;
Signature · 1 line
2.3.6
#2 lore raw

PATCH v2 1/1 openvt -w: Return exit status from child

Return 128+signum when child exited because of a signal.

---
 src/openvt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/openvt.c +4 -2
index 1ba8912..4386584 100644
@@ -386,7 +386,6 @@ main(int argc, char *argv[])
 	if (do_wait) {
 		int retval = 0; /* actual value returned form process */
 
-		wait(NULL);
 		waitpid(pid, &retval, 0);
 
 		if (show) {	/* Switch back... */
@@ -403,7 +402,10 @@ main(int argc, char *argv[])
 
 		/* if all our stuff went right, we want to return the exit code of the command we ran
 		   super vital for scripting loops etc */
-		return(retval);
+		if (WIFEXITED(retval))
+			return WEXITSTATUS(retval);
+		else
+			return 128 + WTERMSIG(retval);
 	}
 
 	return EXIT_SUCCESS;
Signature · 1 line
2.4.6