Debian Codegraph @

runtime/dyninst/session_attributes.c

raw
1 // stapdyn session attribute code
2 // Copyright (C) 2013 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 #ifndef SESSION_ATTRIBUTES_C
10 #define SESSION_ATTRIBUTES_C
11
12 #include "session_attributes.h"
13
14 static struct _stp_session_attributes _stp_init_session_attributes = {
15 .log_level = 0,
16 .suppress_warnings = 0,
17 .stp_pid = 0,
18 .target = 0,
19 .tz_gmtoff = 0,
20 .tz_name = "",
21 .module_name = "",
22 .outfile_name = "",
23 };
24
25 static void stp_session_attributes_init(void)
26 {
27 *stp_session_attributes() = _stp_init_session_attributes;
28 }
29
30 static int stp_session_attribute_setter(const char *name, const char *value)
31 {
32 // Note that We start all internal variables with '@', since
33 // that can't start a "real" variable.
34
35 struct _stp_session_attributes *init = &_stp_init_session_attributes;
36
37 #define set_num(field, type) \
38 if (strcmp(name, "@" #field) == 0) { \
39 char *endp = NULL; \
40 errno = 0; \
41 init->field = strto##type(value, &endp, 0); \
42 return (endp == value || *endp != '\0') ? \
43 -EINVAL : -errno; \
44 }
45
46 #define set_string(field) \
47 if (strcmp(name, "@" #field) == 0) { \
48 size_t size = sizeof(init->field); \
49 size_t len = strlcpy(init->field, value, size); \
50 return (len < size) ? 0 : -EOVERFLOW; \
51 }
52
53 set_num(log_level, ul);
54 set_num(suppress_warnings, ul);
55 set_num(stp_pid, ul);
56 set_num(target, ul);
57 set_num(tz_gmtoff, l);
58 set_string(tz_name);
59 set_string(module_name);
60 set_string(outfile_name);
61
62 #undef set_num
63 #undef set_string
64
65 return -ENOENT;
66 }
67
68 #endif // SESSION_ATTRIBUTES_C