Skip to content

Commit

Permalink
Merge pull request #47 from tsg/add_error_handling
Browse files Browse the repository at this point in the history
Improve error handling on darwin
  • Loading branch information
monicasarbu authored Oct 11, 2016
2 parents 2716c1f + af4c1bd commit eeb33bf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sigar_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,16 @@ func kern_procargs(pid int,
if exe != nil {
exe(string(chop(path)))
}
if err != nil {
return fmt.Errorf("Error reading the argv[0]: %v", err)
}

// skip trailing \0's
for {
c, _ := bbuf.ReadByte()
c, err := bbuf.ReadByte()
if err != nil {
return fmt.Errorf("Error skipping nils: %v", err)
}
if c != 0 {
bbuf.UnreadByte()
break // start of argv[0]
Expand All @@ -379,6 +385,9 @@ func kern_procargs(pid int,
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("Error reading args: %v", err)
}
if argv != nil {
argv(string(chop(arg)))
}
Expand All @@ -395,6 +404,9 @@ func kern_procargs(pid int,
if err == io.EOF || line[0] == 0 {
break
}
if err != nil {
return fmt.Errorf("Error reading args: %v", err)
}
pair := bytes.SplitN(chop(line), delim, 2)
env(string(pair[0]), string(pair[1]))
}
Expand Down

0 comments on commit eeb33bf

Please sign in to comment.