diff options
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r-- | src/libutil/util.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 2cfada35450a..d3446d38a6d8 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -491,3 +491,16 @@ Strings unpackStrings(const string & s) return strings; } + + +string statusToString(int status) +{ + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + if (WIFEXITED(status)) + return (format("failed with exit code %2%") % WEXITSTATUS(status)).str(); + else if (WIFSIGNALED(status)) + return (format("failed due to signal %2%") % WTERMSIG(status)).str(); + else + return "died abnormally"; + } else return "succeeded"; +} |