Cosmos Nicolaou | 87c0a55 | 2014-12-02 23:05:49 -0800 | [diff] [blame] | 1 | package platform |
Cosmos Nicolaou | 39a00e0 | 2014-08-14 11:04:14 -0700 | [diff] [blame] | 2 | |
| 3 | // #include <sys/utsname.h> |
| 4 | // #include <errno.h> |
| 5 | import "C" |
| 6 | |
| 7 | import ( |
| 8 | "fmt" |
| 9 | |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame^] | 10 | "v.io/core/veyron2" |
Cosmos Nicolaou | 39a00e0 | 2014-08-14 11:04:14 -0700 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | // Platform returns the description of the Platform this process is running on. |
| 14 | // A default value for veyron2.Platform is provided even if an error is |
| 15 | // returned; nil is never returned for the first return result. |
| 16 | func Platform() (*veyron2.Platform, error) { |
| 17 | var t C.struct_utsname |
| 18 | if r, err := C.uname(&t); r != 0 { |
| 19 | return &veyron2.Platform{}, fmt.Errorf("uname failed: errno %d", err) |
| 20 | } |
| 21 | d := &veyron2.Platform{ |
| 22 | Vendor: "google", |
| 23 | Model: "generic", |
| 24 | System: C.GoString(&t.sysname[0]), |
| 25 | Version: C.GoString(&t.version[0]), |
| 26 | Release: C.GoString(&t.release[0]), |
| 27 | Machine: C.GoString(&t.machine[0]), |
| 28 | Node: C.GoString(&t.nodename[0]), |
| 29 | } |
Cosmos Nicolaou | 39a00e0 | 2014-08-14 11:04:14 -0700 | [diff] [blame] | 30 | return d, nil |
| 31 | } |