summaryrefslogtreecommitdiffstats
path: root/src/tracefs-eprobes.c
blob: cc25f8e0ea8bcc98aa3285dc8f57f9c7383c1364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: LGPL-2.1
/*
 * Copyright (C) 2021, VMware, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
 *
 */
#include <stdlib.h>
#include <errno.h>

#include "tracefs.h"
#include "tracefs-local.h"

#define EPROBE_DEFAULT_GROUP "eprobes"

/**
 * tracefs_eprobe_alloc - Allocate new eprobe
 * @system: The system name (NULL for the default eprobes)
 * @event: The name of the event to create
 * @target_system: The system of the target event
 * @target_event: The name of the target event
 * @fetchargs: String with arguments, that will be fetched from @target_event
 *
 * Allocate an eprobe context that will be in the @system group (or eprobes if
 * @system is NULL). Have the name of @event. The new eprobe will be attached to
 * given @target_event which is in the given @target_system. The arguments
 * described in @fetchargs will fetched from the @target_event.
 *
 * The eprobe is not created in the system.
 *
 * Return a pointer to a eprobe context on success, or NULL on error.
 * The returned pointer must be freed with tracefs_dynevent_free()
 *
 */
struct tracefs_dynevent *
tracefs_eprobe_alloc(const char *system, const char *event,
		     const char *target_system, const char *target_event, const char *fetchargs)
{
	struct tracefs_dynevent *kp;
	char *target;

	if (!event || !target_system || !target_event) {
		errno = EINVAL;
		return NULL;
	}

	if (!system)
		system = EPROBE_DEFAULT_GROUP;

	if (asprintf(&target, "%s.%s", target_system, target_event) < 0)
		return NULL;

	kp = dynevent_alloc(TRACEFS_DYNEVENT_EPROBE, system, event, target, fetchargs);
	free(target);

	return kp;
}