Copyright (c) 2000, Andrzej Bialecki <abial@FreeBSD.org> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the d...
NAMEsysctl_add_oid sysctl_move_oid sysctl_remove_oid sysctl_remove_name - runtime sysctl tree manipulation
SYNOPSISIn sys/types.h In sys/sysctl.h Ft struct sysctl_oid * Fo sysctl_add_oid Fa struct sysctl_ctx_list *ctx Fa struct sysctl_oid_list *parent Fa int number Fa const char *name Fa int kind Fa void *arg1 Fa intmax_t arg2 Fa int (*handler) (SYSCTL_HANDLER_ARGS) Fa const char *format Fa const char *descr Fc Ft int Fo sysctl_move_oid Fa struct sysctl_oid *oidp Fa struct sysctl_oid_list *parent Fc Ft int Fo sysctl_remove_oid Fa struct sysctl_oid *oidp Fa int del Fa int recurse Fc Ft int Fo sysctl_remove_name Fa struct sysctl_oid *oidp Fa const char *name Fa int del Fa int recurse Fc
DESCRIPTIONThese functions provide the interface for creating and deleting sysctl OIDs at runtime for example during the lifetime of a module. The wrapper macros defined by sysctl(9) are recommended when creating new OIDs. Fn sysctl_add_oid should not be called directly from the code.
Dynamic OIDs of type CTLTYPE_NODE are reusable so that several code sections can create and delete them, but in reality they are allocated and freed based on their reference count. As a consequence, it is possible for two or more code sections to create partially overlapping trees that they both can use. It is not possible to create overlapping leaves, nor to create different child types with the same name and parent.
The Fn sysctl_add_oid function creates a raw OID of any type and connects it to its parent node, if any. If the OID is successfully created, the function returns a pointer to it else it returns NULL Many of the arguments for Fn sysctl_add_oid are common to the wrapper macros defined by sysctl(9).
The Fn sysctl_move_oid function reparents an existing OID. The OID is assigned a new number as if it had been created with Fa number set to OID_AUTO
The Fn sysctl_remove_oid function removes a dynamically created OID from the tree and optionally freeing its resources. It takes the following arguments:
- Fa oidp
- A pointer to the dynamic OID to be removed. If the OID is not dynamic, or the pointer is NULL the function returns Er EINVAL .
- Fa del
- If non-zero, Fn sysctl_remove_oid will try to free the OID's resources when the reference count of the OID becomes zero. However, if Fa del is set to 0, the routine will only deregister the OID from the tree, without freeing its resources. This behaviour is useful when the caller expects to rollback (possibly partially failed) deletion of many OIDs later.
- Fa recurse
- If non-zero, attempt to remove the node and all its children. If recurse is set to 0, any attempt to remove a node that contains any children will result in a Er ENOTEMPTY error. WARNING : use recursive deletion with extreme caution Normally it should not be needed if contexts are used. Contexts take care of tracking inter-dependencies between users of the tree. However, in some extreme cases it might be necessary to remove part of the subtree no matter how it was created, in order to free some other resources. Be aware, though, that this may result in a system panic(9) if other code sections continue to use removed subtrees.
The Fn sysctl_remove_name function looks up the child node matching the Fa name argument and then invokes the Fn sysctl_remove_oid function on that node, passing along the Fa del and Fa recurse arguments. If a node having the specified name does not exist an error code of Er ENOENT is returned. Else the error code from Fn sysctl_remove_oid is returned.
In most cases the programmer should use contexts, as described in sysctl_ctx_init9, to keep track of created OIDs, and to delete them later in orderly fashion.
SEE ALSOsysctl(8), sysctl(9), sysctl_ctx_free9, sysctl_ctx_init9
HISTORYThese functions first appeared in Fx 4.2 .
AUTHORSAn Andrzej Bialecki Aq Mt abial@FreeBSD.org
BUGSSharing nodes between many code sections causes interdependencies that sometimes may lock the resources. For example, if module A hooks up a subtree to an OID created by module B, module B will be unable to delete that OID. These issues are handled properly by sysctl contexts.
Many operations on the tree involve traversing linked lists. For this reason, OID creation and removal is relatively costly.