* Create new sysctls at run time. * clist may point to a valid context initialized with sysctl_ctx_init(). */
| 822 | * clist may point to a valid context initialized with sysctl_ctx_init(). |
| 823 | */ |
| 824 | struct sysctl_oid * |
| 825 | sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent, |
| 826 | int number, const char *name, int kind, void *arg1, intmax_t arg2, |
| 827 | int (*handler)(SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr, |
| 828 | const char *label) |
| 829 | { |
| 830 | struct sysctl_oid *oidp; |
| 831 | |
| 832 | /* You have to hook up somewhere.. */ |
| 833 | if (parent == NULL) |
| 834 | return(NULL); |
| 835 | /* Check if the node already exists, otherwise create it */ |
| 836 | SYSCTL_WLOCK(); |
| 837 | oidp = sysctl_find_oidname(name, parent); |
| 838 | if (oidp != NULL) { |
| 839 | if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) { |
| 840 | oidp->oid_refcnt++; |
| 841 | /* Update the context */ |
| 842 | if (clist != NULL) |
| 843 | sysctl_ctx_entry_add(clist, oidp); |
| 844 | SYSCTL_WUNLOCK(); |
| 845 | return (oidp); |
| 846 | } else { |
| 847 | sysctl_warn_reuse(__func__, oidp); |
| 848 | SYSCTL_WUNLOCK(); |
| 849 | return (NULL); |
| 850 | } |
| 851 | } |
| 852 | oidp = malloc(sizeof(struct sysctl_oid), M_SYSCTLOID, M_WAITOK|M_ZERO); |
| 853 | oidp->oid_parent = parent; |
| 854 | SLIST_INIT(&oidp->oid_children); |
| 855 | oidp->oid_number = number; |
| 856 | oidp->oid_refcnt = 1; |
| 857 | oidp->oid_name = strdup(name, M_SYSCTLOID); |
| 858 | oidp->oid_handler = handler; |
| 859 | oidp->oid_kind = CTLFLAG_DYN | kind; |
| 860 | oidp->oid_arg1 = arg1; |
| 861 | oidp->oid_arg2 = arg2; |
| 862 | oidp->oid_fmt = fmt; |
| 863 | if (descr != NULL) |
| 864 | oidp->oid_descr = strdup(descr, M_SYSCTLOID); |
| 865 | if (label != NULL) |
| 866 | oidp->oid_label = strdup(label, M_SYSCTLOID); |
| 867 | /* Update the context, if used */ |
| 868 | if (clist != NULL) |
| 869 | sysctl_ctx_entry_add(clist, oidp); |
| 870 | /* Register this oid */ |
| 871 | sysctl_register_oid(oidp); |
| 872 | SYSCTL_WUNLOCK(); |
| 873 | return (oidp); |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | * Rename an existing oid. |
nothing calls this directly
no test coverage detected