Ninja should exit with a distinct exit status if user-terminated #430

Open
rgeary1 opened this Issue Sep 26, 2012 · 4 comments

Comments

Projects
None yet
4 participants
@rgeary1
Contributor

rgeary1 commented Sep 26, 2012

If the user terminates ninja, rather than ninja terminating itself due to a build error, it should exit with a different non-zero exit status. This is useful if you have a build script wrapping ninja, which may want to terminate itself if the user exits manually.

My (hacky) patch for this is below :

From 3ce9399914fa2254dd7910912b82a083f0ddb9f3 Mon Sep 17 00:00:00 2001
From: Richard Geary <richardg.work@gmail.com>
Date: Wed, 26 Sep 2012 04:40:33 -0400
Subject: [PATCH] Exit status = 2 if user presses ctrl-c

Change-Id: I7be958e18eb2e434e78afb6e03b332281a651957

---
 src/ninja.cc |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/ninja.cc b/src/ninja.cc
index 9a7ac8b..8ee38cf 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -682,6 +682,9 @@ int RunBuild(Builder* builder, int argc, char** argv) {

   if (!builder->Build(&err)) {
     printf("ninja: build stopped: %s.\n", err.c_str());
+    if (err.find("interrupted by user") != string::npos) {
+       return 2;
+    }
     return 1;
   }

-- 
1.7.4.1
@evmar

This comment has been minimized.

Show comment Hide comment
@evmar

evmar Sep 26, 2012

Collaborator

I agree. I'll fix this in a less-hacky manner by extending the return value of Build().

Not that it matters, but some sources I see online indicate the proper exit code is 128 + the signal number.
I can confirm that behavior with at least bash:

$ sh -c 'read foo'
^C
$ echo $?
130
$ man 7 signal | grep SIGINT
       SIGINT        2       Term    Interrupt from keyboard
Collaborator

evmar commented Sep 26, 2012

I agree. I'll fix this in a less-hacky manner by extending the return value of Build().

Not that it matters, but some sources I see online indicate the proper exit code is 128 + the signal number.
I can confirm that behavior with at least bash:

$ sh -c 'read foo'
^C
$ echo $?
130
$ man 7 signal | grep SIGINT
       SIGINT        2       Term    Interrupt from keyboard
@rgeary1

This comment has been minimized.

Show comment Hide comment
@rgeary1

rgeary1 Sep 27, 2012

Contributor

Sounds good.

Contributor

rgeary1 commented Sep 27, 2012

Sounds good.

@jpsainfeld

This comment has been minimized.

Show comment Hide comment
@jpsainfeld

jpsainfeld Sep 11, 2017

Is this bug fixed now?
When I checked the top of the tree on master I see:

if (!builder.Build(&err)) {
printf("ninja: build stopped: %s.\n", err.c_str());
if (err.find("interrupted by user") != string::npos) {
return 2;
}
return 1;
}

return 0;

jpsainfeld commented Sep 11, 2017

Is this bug fixed now?
When I checked the top of the tree on master I see:

if (!builder.Build(&err)) {
printf("ninja: build stopped: %s.\n", err.c_str());
if (err.find("interrupted by user") != string::npos) {
return 2;
}
return 1;
}

return 0;

@gdm85

This comment has been minimized.

Show comment Hide comment
@gdm85

gdm85 Oct 23, 2017

I would use some standard-ish, like 130 used by bash (http://www.tldp.org/LDP/abs/html/exitcodes.html)

130 Script terminated by Control-C Ctl-C Control-C is fatal error signal 2, (130 = 128 + 2, see above)

gdm85 commented Oct 23, 2017

I would use some standard-ish, like 130 used by bash (http://www.tldp.org/LDP/abs/html/exitcodes.html)

130 Script terminated by Control-C Ctl-C Control-C is fatal error signal 2, (130 = 128 + 2, see above)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment