1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3 * Copyright (C) 2021, VMware, Tzvetomir Stoyanov <[email protected]>
4 *
5 */
6 #include <stdlib.h>
7 #include <errno.h>
8
9 #include "tracefs.h"
10 #include "tracefs-local.h"
11
12 #define EPROBE_DEFAULT_GROUP "eprobes"
13
14 /**
15 * tracefs_eprobe_alloc - Allocate new eprobe
16 * @system: The system name (NULL for the default eprobes)
17 * @event: The name of the event to create
18 * @target_system: The system of the target event
19 * @target_event: The name of the target event
20 * @fetchargs: String with arguments, that will be fetched from @target_event
21 *
22 * Allocate an eprobe context that will be in the @system group (or eprobes if
23 * @system is NULL). Have the name of @event. The new eprobe will be attached to
24 * given @target_event which is in the given @target_system. The arguments
25 * described in @fetchargs will fetched from the @target_event.
26 *
27 * The eprobe is not created in the system.
28 *
29 * Return a pointer to a eprobe context on success, or NULL on error.
30 * The returned pointer must be freed with tracefs_dynevent_free()
31 *
32 */
33 struct tracefs_dynevent *
tracefs_eprobe_alloc(const char * system,const char * event,const char * target_system,const char * target_event,const char * fetchargs)34 tracefs_eprobe_alloc(const char *system, const char *event,
35 const char *target_system, const char *target_event, const char *fetchargs)
36 {
37 struct tracefs_dynevent *kp;
38 char *target;
39
40 if (!event || !target_system || !target_event) {
41 errno = EINVAL;
42 return NULL;
43 }
44
45 if (!system)
46 system = EPROBE_DEFAULT_GROUP;
47
48 if (asprintf(&target, "%s.%s", target_system, target_event) < 0)
49 return NULL;
50
51 kp = dynevent_alloc(TRACEFS_DYNEVENT_EPROBE, system, event, target, fetchargs);
52 free(target);
53
54 return kp;
55 }
56
57