| 163 | } |
| 164 | |
| 165 | bool |
| 166 | RemapPluginInfo::initInstance(int argc, char **argv, void **ih, std::string &error) |
| 167 | { |
| 168 | TSReturnCode res = TS_SUCCESS; |
| 169 | bool result = true; |
| 170 | |
| 171 | PluginDbg(_dbg_ctl(), "started initializing instance of plugin '%s'", _configPath.c_str()); |
| 172 | |
| 173 | /* A buffer to get the error from the plugin instance init function, be defensive here. */ |
| 174 | char tmpbuf[2048]; |
| 175 | ink_zero(tmpbuf); |
| 176 | |
| 177 | if (new_instance_cb) { |
| 178 | #if defined(freebsd) || defined(darwin) |
| 179 | optreset = 1; |
| 180 | #endif |
| 181 | #if defined(__GLIBC__) |
| 182 | optind = 0; |
| 183 | #else |
| 184 | optind = 1; |
| 185 | #endif |
| 186 | opterr = 0; |
| 187 | optarg = nullptr; |
| 188 | |
| 189 | setPluginContext(); |
| 190 | |
| 191 | res = new_instance_cb(argc, argv, ih, tmpbuf, sizeof(tmpbuf) - 1); |
| 192 | |
| 193 | resetPluginContext(); |
| 194 | |
| 195 | if (TS_SUCCESS != res) { |
| 196 | error.assign("failed to create instance for plugin ") |
| 197 | .append(_configPath.string()) |
| 198 | .append(": ") |
| 199 | .append(tmpbuf[0] ? tmpbuf : "Unknown plugin error"); |
| 200 | result = false; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | PluginDbg(_dbg_ctl(), "finished initializing instance of plugin '%s'", _configPath.c_str()); |
| 205 | |
| 206 | return result; |
| 207 | } |
| 208 | |
| 209 | void |
| 210 | RemapPluginInfo::doneInstance(void *ih) |