30 |
|
#include "statgrab.h" |
31 |
|
|
32 |
|
static sg_error error = SG_ERROR_NONE; |
33 |
+ |
#define ERROR_ARG_MAX 256 |
34 |
+ |
static char error_arg[ERROR_ARG_MAX]; |
35 |
|
|
36 |
|
void sg_set_error(sg_error code, const char *arg) { |
37 |
|
error = code; |
38 |
< |
/* FIXME do something with arg */ |
38 |
> |
strlcpy(error_arg, arg, sizeof error_arg); |
39 |
|
} |
40 |
|
|
41 |
|
sg_error sg_get_error() { |
42 |
|
return error; |
43 |
|
} |
44 |
|
|
45 |
+ |
const char *sg_get_error_arg() { |
46 |
+ |
return error_arg; |
47 |
+ |
} |
48 |
+ |
|
49 |
|
const char *sg_str_error(sg_error code) { |
50 |
|
switch (code) { |
51 |
|
case SG_ERROR_NONE: |
52 |
|
return "no error"; |
53 |
+ |
case SG_ERROR_ASPRINTF: |
54 |
+ |
return "asprintf failed"; |
55 |
+ |
case SG_ERROR_DEVSTAT_GETDEVS: |
56 |
+ |
return "devstat_getdevs failed"; |
57 |
+ |
case SG_ERROR_DEVSTAT_SELECTDEVS: |
58 |
+ |
return "devstat_selectdevs failed"; |
59 |
+ |
case SG_ERROR_ENOENT: |
60 |
+ |
return "system call received ENOENT"; |
61 |
+ |
case SG_ERROR_GETIFADDRS: |
62 |
+ |
return "getifaddress failed"; |
63 |
+ |
case SG_ERROR_GETMNTINFO: |
64 |
+ |
return "getmntinfo failed"; |
65 |
+ |
case SG_ERROR_GETPAGESIZE: |
66 |
+ |
return "getpagesize failed"; |
67 |
+ |
case SG_ERROR_KSTAT_DATA_LOOKUP: |
68 |
+ |
return "kstat_data_lookup failed"; |
69 |
+ |
case SG_ERROR_KSTAT_LOOKUP: |
70 |
+ |
return "kstat_lookup failed"; |
71 |
+ |
case SG_ERROR_KSTAT_OPEN: |
72 |
+ |
return "kstat_open failed"; |
73 |
+ |
case SG_ERROR_KSTAT_READ: |
74 |
+ |
return "kstat_read failed"; |
75 |
+ |
case SG_ERROR_KVM_GETSWAPINFO: |
76 |
+ |
return "kvm_getswapinfo failed"; |
77 |
+ |
case SG_ERROR_KVM_OPENFILES: |
78 |
+ |
return "kvm_openfiles failed"; |
79 |
+ |
case SG_ERROR_MALLOC: |
80 |
+ |
return "malloc failed"; |
81 |
+ |
case SG_ERROR_OPEN: |
82 |
+ |
return "failed to open file"; |
83 |
+ |
case SG_ERROR_OPENDIR: |
84 |
+ |
return "failed to open directory"; |
85 |
+ |
case SG_ERROR_PARSE: |
86 |
+ |
return "failed to parse input"; |
87 |
+ |
case SG_ERROR_SETEGID: |
88 |
+ |
return "setegid failed"; |
89 |
+ |
case SG_ERROR_SETEUID: |
90 |
+ |
return "seteuid failed"; |
91 |
+ |
case SG_ERROR_SETMNTENT: |
92 |
+ |
return "setmntent failed"; |
93 |
+ |
case SG_ERROR_SOCKET: |
94 |
+ |
return "socket failed"; |
95 |
+ |
case SG_ERROR_SWAPCTL: |
96 |
+ |
return "swapctl failed"; |
97 |
+ |
case SG_ERROR_SYSCONF: |
98 |
+ |
return "sysconf failed"; |
99 |
+ |
case SG_ERROR_SYSCTL: |
100 |
+ |
return "sysctl failed"; |
101 |
+ |
case SG_ERROR_SYSCTLBYNAME: |
102 |
+ |
return "sysctlbyname failed"; |
103 |
+ |
case SG_ERROR_SYSCTLNAMETOMIB: |
104 |
+ |
return "sysctlnametomib failed"; |
105 |
+ |
case SG_ERROR_UNAME: |
106 |
+ |
return "uname failed"; |
107 |
+ |
case SG_ERROR_UNSUPPORTED: |
108 |
+ |
return "unsupported function"; |
109 |
+ |
case SG_ERROR_XSW_VER_MISMATCH: |
110 |
+ |
return "XSW version mismatch"; |
111 |
|
} |
112 |
|
return "unknown error"; |
113 |
|
} |