Linux console tools development discussion
 help / color / mirror / Atom feed
* [kbd] Return code of openvt command
@ 2015-07-30  3:09 ToBeReplaced
  2015-07-30 17:33 ` [kbd] [PATCH] openvt -w: Return exit status from child Felix Janda
  0 siblings, 1 reply; 3+ messages in thread
From: ToBeReplaced @ 2015-07-30  3:09 UTC (permalink / raw)
  To: kbd

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?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [kbd] [PATCH] openvt -w: Return exit status from child
  2015-07-30  3:09 [kbd] Return code of openvt command ToBeReplaced
@ 2015-07-30 17:33 ` Felix Janda
  2015-08-09  8:46   ` [kbd] [PATCHv2] " Felix Janda
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Janda @ 2015-07-30 17:33 UTC (permalink / raw)
  To: Linux console tools development discussion

---
ToBeReplaced wrote:
> 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.

> 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.

> 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(-)

diff --git a/src/openvt.c b/src/openvt.c
index 1ba8912..1a36a69 100644
--- a/src/openvt.c
+++ b/src/openvt.c
@@ -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;
-- 
2.3.6



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [kbd] [PATCHv2] openvt -w: Return exit status from child
  2015-07-30 17:33 ` [kbd] [PATCH] openvt -w: Return exit status from child Felix Janda
@ 2015-08-09  8:46   ` Felix Janda
  0 siblings, 0 replies; 3+ messages in thread
From: Felix Janda @ 2015-08-09  8:46 UTC (permalink / raw)
  To: Linux console tools development discussion

Return 128+signum when child exited because of a signal.
---
 src/openvt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/openvt.c b/src/openvt.c
index 1ba8912..4386584 100644
--- a/src/openvt.c
+++ b/src/openvt.c
@@ -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;
-- 
2.4.6



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-09  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-30  3:09 [kbd] Return code of openvt command ToBeReplaced
2015-07-30 17:33 ` [kbd] [PATCH] openvt -w: Return exit status from child Felix Janda
2015-08-09  8:46   ` [kbd] [PATCHv2] " Felix Janda

Linux console tools development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/kbd/0 kbd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kbd kbd/ http://lore.altlinux.org/kbd \
		kbd@lists.altlinux.org kbd@lists.altlinux.ru kbd@lists.altlinux.com
	public-inbox-index kbd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.kbd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git