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