summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Clements <aclements@csail.mit.edu>2009-07-15 09:58:42 -0700
committerAustin Clements <aclements@csail.mit.edu>2009-07-15 09:58:42 -0700
commitdb06429efde1dae3c3aa370243c0212a97041c06 (patch)
tree7ddf6464d0c97b4866800963b3f2c7c8f9705ca4 /src
parent1946834c95044862ed592bece05c1af1d5be11b1 (diff)
downloadgolang-db06429efde1dae3c3aa370243c0212a97041c06.tar.gz
Pretty printer for os.Waitmsg
R=rsc APPROVED=rsc DELTA=49 (49 added, 0 deleted, 0 changed) OCL=31568 CL=31671
Diffstat (limited to 'src')
-rw-r--r--src/pkg/os/exec.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/pkg/os/exec.go b/src/pkg/os/exec.go
index 9ae81c0d5..ceb52999b 100644
--- a/src/pkg/os/exec.go
+++ b/src/pkg/os/exec.go
@@ -98,6 +98,55 @@ func Wait(pid int, options int) (w *Waitmsg, err Error) {
return w, nil;
}
+// Convert i to decimal string.
+func itod(i int) string {
+ if i == 0 {
+ return "0"
+ }
+
+ u := uint64(i);
+ if i < 0 {
+ u = -u;
+ }
+
+ // Assemble decimal in reverse order.
+ var b [32]byte;
+ bp := len(b);
+ for ; u > 0; u /= 10 {
+ bp--;
+ b[bp] = byte(u%10) + '0'
+ }
+
+ if i < 0 {
+ bp--;
+ b[bp] = '-'
+ }
+
+ return string(b[bp:len(b)])
+}
+
+func (w Waitmsg) String() string {
+ // TODO(austin) Use signal names when possible?
+ res := "";
+ switch {
+ case w.Exited():
+ res = "exit status " + itod(w.ExitStatus());
+ case w.Signaled():
+ res = "signal " + itod(w.Signal());
+ case w.Stopped():
+ res = "stop signal " + itod(w.StopSignal());
+ if w.StopSignal() == syscall.SIGTRAP && w.TrapCause() != 0 {
+ res += " (trap " + itod(w.TrapCause()) + ")";
+ }
+ case w.Continued():
+ res = "continued";
+ }
+ if w.CoreDump() {
+ res += " (core dumped)"
+ }
+ return res;
+}
+
// Getpid returns the process id of the caller.
func Getpid() int {
p, r2, e := syscall.Syscall(syscall.SYS_GETPID, 0, 0, 0);