| 231 | #endif |
| 232 | |
| 233 | int |
| 234 | cib_connect(gboolean full) |
| 235 | { |
| 236 | int rc = pcmk_ok; |
| 237 | static gboolean need_pass = TRUE; |
| 238 | |
| 239 | CRM_CHECK(cib != NULL, return -EINVAL); |
| 240 | |
| 241 | if (getenv("CIB_passwd") != NULL) { |
| 242 | need_pass = FALSE; |
| 243 | } |
| 244 | |
| 245 | if(watch_fencing && st == NULL) { |
| 246 | st = stonith_api_new(); |
| 247 | } |
| 248 | |
| 249 | if(watch_fencing && st->state == stonith_disconnected) { |
| 250 | crm_trace("Connecting to stonith"); |
| 251 | rc = st->cmds->connect(st, crm_system_name, NULL); |
| 252 | if(rc == pcmk_ok) { |
| 253 | crm_trace("Setting up stonith callbacks"); |
| 254 | st->cmds->register_notification(st, T_STONITH_NOTIFY_FENCE, mon_st_callback); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if (cib->state != cib_connected_query && cib->state != cib_connected_command) { |
| 259 | crm_trace("Connecting to the CIB"); |
| 260 | if (as_console && need_pass && cib->variant == cib_remote) { |
| 261 | need_pass = FALSE; |
| 262 | print_as("Password:"); |
| 263 | } |
| 264 | |
| 265 | rc = cib->cmds->signon(cib, crm_system_name, cib_query); |
| 266 | |
| 267 | if (rc != pcmk_ok) { |
| 268 | return rc; |
| 269 | } |
| 270 | |
| 271 | current_cib = get_cib_copy(cib); |
| 272 | mon_refresh_display(NULL); |
| 273 | |
| 274 | if (full) { |
| 275 | if (rc == pcmk_ok) { |
| 276 | rc = cib->cmds->set_connection_dnotify(cib, mon_cib_connection_destroy); |
| 277 | if (rc == -EPROTONOSUPPORT) { |
| 278 | print_as("Notification setup failed, won't be able to reconnect after failure"); |
| 279 | if (as_console) { |
| 280 | sleep(2); |
| 281 | } |
| 282 | rc = pcmk_ok; |
| 283 | } |
| 284 | |
| 285 | } |
| 286 | |
| 287 | if (rc == pcmk_ok) { |
| 288 | cib->cmds->del_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update); |
| 289 | rc = cib->cmds->add_notify_callback(cib, T_CIB_DIFF_NOTIFY, crm_diff_update); |
| 290 | } |
no test coverage detected