Go to main content

man pages section 3: Extended Library Functions, Volume 2

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

dtrace_provider_modules (3DTRACE)

Name

dtrace_provider_modules - Retrieve the list of DTrace provider modules

Synopsis

     cc [ flag... ] file... -ldtrace [ library... ]
     #include <dtrace.h>

     int dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods,
	int nmods)

Description

The dtrace_provider_modules() function retrieves the list of kernel modules functioning as DTrace providers. The function writes at most nmods module names into the array, mods.

Return Values

On successful completion, the dtrace_provider_modules() function returns the number of DTrace provider modules. Otherwise the function returns -1, and sets an error number to indicate the error. The error number can be retrieved with the dtrace_errno(3DTRACE)) function.

Errors

The dtrace_provider_modules() function will fail if:

EINVAL

The dtp or the mods argument is NULL.

Examples

Example 1 Printing List of Loaded Kernel Modules

The following example shows how the dtrace_provider_modules() function prints the list of loaded kernel modules functioning as DTrace providers:

      #include <dtrace.h>
      #include <stdio.h>
      #include <stdlib.h>
	
	static dtrace_hdl_t *g_dtp;
	
	static void
	fatal(const char *fmt, ...)
	{
	        va_list ap;
	
	        va_start(ap, fmt);
	        (void) vfprintf(stderr, fmt, ap);
	
	        if (fmt[strlen(fmt) - 1] != '\n')
	                (void) fprintf(stderr, ": %s\n",
	                    dtrace_errmsg(g_dtp, dtrace_errno(g_dtp)));
	
	        exit(EXIT_FAILURE);
	}
	
	int
	main(int argc, char **argv)
	{
	        int err, i;
	        const char *mods[20];
	        int nmods;
	
	        if ((g_dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL)
	                fatal("cannot open dtrace library: %s\n",
	                    dtrace_errmsg(NULL, err));
	
	        if ((nmods = dtrace_provider_modules(g_dtp, mods,
	            sizeof (mods) / sizeof (char *))) < 0)
	                fatal("dtrace_provider_modules()");
	
	        printf("nmods == %d\n", nmods);
	
	        for (i = 0; i < nmods; i++)
	                printf("Module: %s\n", mods[i]);
	
	        dtrace_close(g_dtp);
	
	        return (0);
	}

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Architecture
All
Availability
system/dtrace
Interface Stability
Committed
MT-Level
Safe

See Also

libdtrace(3LIB), dtrace_errno(3DTRACE)