| 1387 | } |
| 1388 | |
| 1389 | static int |
| 1390 | ng_con_part2(node_p node, item_p item, hook_p hook) |
| 1391 | { |
| 1392 | hook_p peer; |
| 1393 | int error = 0; |
| 1394 | |
| 1395 | /* |
| 1396 | * When we run, we know that the node 'node' is locked for us. |
| 1397 | * Our caller has a reference on the hook. |
| 1398 | * Our caller has a reference on the node. |
| 1399 | * (In this case our caller is ng_apply_item() ). |
| 1400 | * The peer hook has a reference on the hook. |
| 1401 | * our node pointer points to the 'dead' node. |
| 1402 | * First check the hook name is unique. |
| 1403 | * Should not happen because we checked before queueing this. |
| 1404 | */ |
| 1405 | if (ng_findhook(node, NG_HOOK_NAME(hook)) != NULL) { |
| 1406 | TRAP_ERROR(); |
| 1407 | ng_destroy_hook(hook); /* should destroy peer too */ |
| 1408 | printf("failed in ng_con_part2()\n"); |
| 1409 | ERROUT(EEXIST); |
| 1410 | } |
| 1411 | /* |
| 1412 | * Check if the node type code has something to say about it |
| 1413 | * If it fails, the unref of the hook will also unref the attached node, |
| 1414 | * however since that node is 'ng_deadnode' this will do nothing. |
| 1415 | * The peer hook will also be destroyed. |
| 1416 | */ |
| 1417 | if (node->nd_type->newhook != NULL) { |
| 1418 | if ((error = (*node->nd_type->newhook)(node, hook, |
| 1419 | hook->hk_name))) { |
| 1420 | ng_destroy_hook(hook); /* should destroy peer too */ |
| 1421 | printf("failed in ng_con_part2()\n"); |
| 1422 | ERROUT(error); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | /* |
| 1427 | * The 'type' agrees so far, so go ahead and link it in. |
| 1428 | * We'll ask again later when we actually connect the hooks. |
| 1429 | */ |
| 1430 | hook->hk_node = node; /* just overwrite ng_deadnode */ |
| 1431 | NG_NODE_REF(node); /* each hook counts as a reference */ |
| 1432 | LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); |
| 1433 | node->nd_numhooks++; |
| 1434 | NG_HOOK_REF(hook); /* one for the node */ |
| 1435 | |
| 1436 | /* |
| 1437 | * We now have a symmetrical situation, where both hooks have been |
| 1438 | * linked to their nodes, the newhook methods have been called |
| 1439 | * And the references are all correct. The hooks are still marked |
| 1440 | * as invalid, as we have not called the 'connect' methods |
| 1441 | * yet. |
| 1442 | * We can call the local one immediately as we have the |
| 1443 | * node locked, but we need to queue the remote one. |
| 1444 | */ |
| 1445 | if (hook->hk_node->nd_type->connect) { |
| 1446 | if ((error = (*hook->hk_node->nd_type->connect) (hook))) { |
nothing calls this directly
no test coverage detected