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