return -1;
}
+static int lv_connect(void) {
+ if (conn == NULL) {
+ /* `conn_string == NULL' is acceptable. */
+ conn = virConnectOpenReadOnly(conn_string);
+ if (conn == NULL) {
+ c_complain(LOG_ERR, &conn_complain,
+ PLUGIN_NAME " plugin: Unable to connect: "
+ "virConnectOpenReadOnly failed.");
+ return -1;
+ }
+ }
+ c_release(LOG_NOTICE, &conn_complain,
+ PLUGIN_NAME " plugin: Connection established.");
+ return 0;
+}
+
static int lv_read(user_data_t *ud) {
time_t t;
struct lv_read_instance *inst = NULL;
inst = ud->data;
state = &inst->read_state;
- if (inst->id == 0 && conn == NULL) {
- /* `conn_string == NULL' is acceptable. */
- conn = virConnectOpenReadOnly(conn_string);
- if (conn == NULL) {
- c_complain(LOG_ERR, &conn_complain,
- PLUGIN_NAME " plugin: Unable to connect: "
- "virConnectOpenReadOnly failed.");
+ if (inst->id == 0) {
+ if (lv_connect() < 0)
return -1;
- }
}
- c_release(LOG_NOTICE, &conn_complain,
- PLUGIN_NAME " plugin: Connection established.");
time(&t);
if (virInitialize() != 0)
return -1;
+ lv_connect();
+
DEBUG(PLUGIN_NAME " plugin: starting %i instances", nr_instances);
for (int i = 0; i < nr_instances; ++i)