* Locate the path to a given oid. Returns the length of the resulting path, * or -1 if the oid was not found. nodes must have room for CTL_MAXNAME * elements and be NULL initialized. */
| 347 | * elements and be NULL initialized. |
| 348 | */ |
| 349 | static int |
| 350 | sysctl_search_oid(struct sysctl_oid **nodes, struct sysctl_oid *needle) |
| 351 | { |
| 352 | int indx; |
| 353 | |
| 354 | SYSCTL_ASSERT_LOCKED(); |
| 355 | indx = 0; |
| 356 | while (indx < CTL_MAXNAME && indx >= 0) { |
| 357 | if (nodes[indx] == NULL && indx == 0) |
| 358 | nodes[indx] = SLIST_FIRST(&sysctl__children); |
| 359 | else if (nodes[indx] == NULL) |
| 360 | nodes[indx] = SLIST_FIRST(&nodes[indx - 1]->oid_children); |
| 361 | else |
| 362 | nodes[indx] = SLIST_NEXT(nodes[indx], oid_link); |
| 363 | |
| 364 | if (nodes[indx] == needle) |
| 365 | return (indx + 1); |
| 366 | |
| 367 | if (nodes[indx] == NULL) { |
| 368 | indx--; |
| 369 | continue; |
| 370 | } |
| 371 | |
| 372 | if ((nodes[indx]->oid_kind & CTLTYPE) == CTLTYPE_NODE) { |
| 373 | indx++; |
| 374 | continue; |
| 375 | } |
| 376 | } |
| 377 | return (-1); |
| 378 | } |
| 379 | |
| 380 | static void |
| 381 | sysctl_warn_reuse(const char *func, struct sysctl_oid *leaf) |