FreeBSD/sys/kern/subr_bus.c
/*
 * Common routine that tries to make sending messages as easy as possible.
 * We allocate memory for the data, copy strings into that, but do not
 * free it unless there's an error.  The dequeue part of the driver should
 * free the data.  We don't send data when the device is disabled.  We do
 * send data, even when we have no listeners, because we wish to avoid
 * races relating to startup and restart of listening applications.
 *
 * devaddq is designed to string together the type of event, with the
 * object of that event, plus the plug and play info and location info
 * for that event.  This is likely most useful for devices, but less
 * useful for other consumers of this interface.  Those should use
 * the devctl_queue_data() interface instead.
 */
Common routine that tries to make sending messages as easy as possible.
We allocate memory for the data, copy strings into that, but do not
free it unless there's an error.  The dequeue part of the driver should
free the data.  We don't send data when the device is disabled.  We do
send data, even when we have no listeners, because we wish to avoid
races relating to startup and restart of listening applications.

devaddq is designed to string together the type of event, with the
object of that event, plus the plug and play info and location info
for that event.  This is likely most useful for devices, but less
useful for other consumers of this interface.  Those should use
the devctl_queue_data() interface instead.
Common routine that tries to make sending messages as easy as possible . We allocate memory for the data copy strings into that but do not free it unless there ' s an error . The dequeue part of the driver should free the data . We don ' t send data when the device is disabled . We do send data even when we have no listeners because we wish to avoid races relating to startup and restart of listening applications . devaddq is designed to string together the type of event with the object of that event plus the plug and play info and location info for that event . This is likely most useful for devices but less useful for other consumers of this interface . Those should use the devctl_queue_data () interface instead .
static void
devaddq(const char *type, const char *what, device_t dev)
{
	char *data = NULL;
	char *loc = NULL;
	char *pnp = NULL;
	const char *parstr;
	if (!devctl_queue_length)
		return;
	data = malloc(1024, M_BUS, M_NOWAIT);
	if (data == NULL)
		goto bad;
	loc = malloc(1024, M_BUS, M_NOWAIT);
	if (loc == NULL)
		goto bad;
	*loc = '\0';
	bus_child_location_str(dev, loc, 1024);
	pnp = malloc(1024, M_BUS, M_NOWAIT);
	if (pnp == NULL)
		goto bad;
	*pnp = '\0';
	bus_child_pnpinfo_str(dev, pnp, 1024);
	if (device_get_parent(dev) == NULL)
		parstr = ".";	
	else
		parstr = device_get_nameunit(device_get_parent(dev));
	snprintf(data, 1024, "%s%s at %s %s on %s\n", type, what, loc, pnp,
	  parstr);
	free(loc, M_BUS);
	free(pnp, M_BUS);
	devctl_queue_data(data);
	return;
bad:
	free(pnp, M_BUS);
	free(loc, M_BUS);
	free(data, M_BUS);
	return;
}
static void devaddq ( const char * type , const char * what , device_t dev ) { char * data = NULL ; char * loc = NULL ; char * pnp = NULL ; const char * parstr ; if ( ! devctl_queue_length ) return ; data = malloc ( 1024 , M_BUS , M_NOWAIT ) ; if ( data == NULL ) goto bad ; loc = malloc ( 1024 , M_BUS , M_NOWAIT ) ; if ( loc == NULL ) goto bad ; * loc = ' \0 ' ; bus_child_location_str ( dev , loc , 1024 ) ; pnp = malloc ( 1024 , M_BUS , M_NOWAIT ) ; if ( pnp == NULL ) goto bad ; * pnp = ' \0 ' ; bus_child_pnpinfo_str ( dev , pnp , 1024 ) ; if ( device_get_parent ( dev ) == NULL ) parstr = " " ; else parstr = device_get_nameunit ( device_get_parent ( dev ) ) ; snprintf ( data , 1024 , " \n " , type , what , loc , pnp , parstr ) ; free ( loc , M_BUS ) ; free ( pnp , M_BUS ) ; devctl_queue_data ( data ) ; return ; bad : free ( pnp , M_BUS ) ; free ( loc , M_BUS ) ; free ( data , M_BUS ) ; return ; }
Common routine that tries to make sending messages as easy as possible.
Common routine that tries to make sending messages as easy as possible .
/* Rare race, but lost races safely discard */ /* get the bus specific location of this device */ /* Get the bus specific pnp info of this device */ /* Get the parent of this device, or / if high enough in the tree. */ /* Or '/' ? */ /* String it all together. */