diff options
Diffstat (limited to 'tools/perf/util/target.c')
-rw-r--r-- | tools/perf/util/target.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index 065528b7563e..3c778a07b7cc 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c | |||
@@ -13,9 +13,9 @@ | |||
13 | #include <string.h> | 13 | #include <string.h> |
14 | 14 | ||
15 | 15 | ||
16 | enum perf_target_errno perf_target__validate(struct perf_target *target) | 16 | enum target_errno target__validate(struct target *target) |
17 | { | 17 | { |
18 | enum perf_target_errno ret = PERF_ERRNO_TARGET__SUCCESS; | 18 | enum target_errno ret = TARGET_ERRNO__SUCCESS; |
19 | 19 | ||
20 | if (target->pid) | 20 | if (target->pid) |
21 | target->tid = target->pid; | 21 | target->tid = target->pid; |
@@ -23,42 +23,42 @@ enum perf_target_errno perf_target__validate(struct perf_target *target) | |||
23 | /* CPU and PID are mutually exclusive */ | 23 | /* CPU and PID are mutually exclusive */ |
24 | if (target->tid && target->cpu_list) { | 24 | if (target->tid && target->cpu_list) { |
25 | target->cpu_list = NULL; | 25 | target->cpu_list = NULL; |
26 | if (ret == PERF_ERRNO_TARGET__SUCCESS) | 26 | if (ret == TARGET_ERRNO__SUCCESS) |
27 | ret = PERF_ERRNO_TARGET__PID_OVERRIDE_CPU; | 27 | ret = TARGET_ERRNO__PID_OVERRIDE_CPU; |
28 | } | 28 | } |
29 | 29 | ||
30 | /* UID and PID are mutually exclusive */ | 30 | /* UID and PID are mutually exclusive */ |
31 | if (target->tid && target->uid_str) { | 31 | if (target->tid && target->uid_str) { |
32 | target->uid_str = NULL; | 32 | target->uid_str = NULL; |
33 | if (ret == PERF_ERRNO_TARGET__SUCCESS) | 33 | if (ret == TARGET_ERRNO__SUCCESS) |
34 | ret = PERF_ERRNO_TARGET__PID_OVERRIDE_UID; | 34 | ret = TARGET_ERRNO__PID_OVERRIDE_UID; |
35 | } | 35 | } |
36 | 36 | ||
37 | /* UID and CPU are mutually exclusive */ | 37 | /* UID and CPU are mutually exclusive */ |
38 | if (target->uid_str && target->cpu_list) { | 38 | if (target->uid_str && target->cpu_list) { |
39 | target->cpu_list = NULL; | 39 | target->cpu_list = NULL; |
40 | if (ret == PERF_ERRNO_TARGET__SUCCESS) | 40 | if (ret == TARGET_ERRNO__SUCCESS) |
41 | ret = PERF_ERRNO_TARGET__UID_OVERRIDE_CPU; | 41 | ret = TARGET_ERRNO__UID_OVERRIDE_CPU; |
42 | } | 42 | } |
43 | 43 | ||
44 | /* PID and SYSTEM are mutually exclusive */ | 44 | /* PID and SYSTEM are mutually exclusive */ |
45 | if (target->tid && target->system_wide) { | 45 | if (target->tid && target->system_wide) { |
46 | target->system_wide = false; | 46 | target->system_wide = false; |
47 | if (ret == PERF_ERRNO_TARGET__SUCCESS) | 47 | if (ret == TARGET_ERRNO__SUCCESS) |
48 | ret = PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM; | 48 | ret = TARGET_ERRNO__PID_OVERRIDE_SYSTEM; |
49 | } | 49 | } |
50 | 50 | ||
51 | /* UID and SYSTEM are mutually exclusive */ | 51 | /* UID and SYSTEM are mutually exclusive */ |
52 | if (target->uid_str && target->system_wide) { | 52 | if (target->uid_str && target->system_wide) { |
53 | target->system_wide = false; | 53 | target->system_wide = false; |
54 | if (ret == PERF_ERRNO_TARGET__SUCCESS) | 54 | if (ret == TARGET_ERRNO__SUCCESS) |
55 | ret = PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM; | 55 | ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM; |
56 | } | 56 | } |
57 | 57 | ||
58 | return ret; | 58 | return ret; |
59 | } | 59 | } |
60 | 60 | ||
61 | enum perf_target_errno perf_target__parse_uid(struct perf_target *target) | 61 | enum target_errno target__parse_uid(struct target *target) |
62 | { | 62 | { |
63 | struct passwd pwd, *result; | 63 | struct passwd pwd, *result; |
64 | char buf[1024]; | 64 | char buf[1024]; |
@@ -66,7 +66,7 @@ enum perf_target_errno perf_target__parse_uid(struct perf_target *target) | |||
66 | 66 | ||
67 | target->uid = UINT_MAX; | 67 | target->uid = UINT_MAX; |
68 | if (str == NULL) | 68 | if (str == NULL) |
69 | return PERF_ERRNO_TARGET__SUCCESS; | 69 | return TARGET_ERRNO__SUCCESS; |
70 | 70 | ||
71 | /* Try user name first */ | 71 | /* Try user name first */ |
72 | getpwnam_r(str, &pwd, buf, sizeof(buf), &result); | 72 | getpwnam_r(str, &pwd, buf, sizeof(buf), &result); |
@@ -79,22 +79,22 @@ enum perf_target_errno perf_target__parse_uid(struct perf_target *target) | |||
79 | int uid = strtol(str, &endptr, 10); | 79 | int uid = strtol(str, &endptr, 10); |
80 | 80 | ||
81 | if (*endptr != '\0') | 81 | if (*endptr != '\0') |
82 | return PERF_ERRNO_TARGET__INVALID_UID; | 82 | return TARGET_ERRNO__INVALID_UID; |
83 | 83 | ||
84 | getpwuid_r(uid, &pwd, buf, sizeof(buf), &result); | 84 | getpwuid_r(uid, &pwd, buf, sizeof(buf), &result); |
85 | 85 | ||
86 | if (result == NULL) | 86 | if (result == NULL) |
87 | return PERF_ERRNO_TARGET__USER_NOT_FOUND; | 87 | return TARGET_ERRNO__USER_NOT_FOUND; |
88 | } | 88 | } |
89 | 89 | ||
90 | target->uid = result->pw_uid; | 90 | target->uid = result->pw_uid; |
91 | return PERF_ERRNO_TARGET__SUCCESS; | 91 | return TARGET_ERRNO__SUCCESS; |
92 | } | 92 | } |
93 | 93 | ||
94 | /* | 94 | /* |
95 | * This must have a same ordering as the enum perf_target_errno. | 95 | * This must have a same ordering as the enum target_errno. |
96 | */ | 96 | */ |
97 | static const char *perf_target__error_str[] = { | 97 | static const char *target__error_str[] = { |
98 | "PID/TID switch overriding CPU", | 98 | "PID/TID switch overriding CPU", |
99 | "PID/TID switch overriding UID", | 99 | "PID/TID switch overriding UID", |
100 | "UID switch overriding CPU", | 100 | "UID switch overriding CPU", |
@@ -104,7 +104,7 @@ static const char *perf_target__error_str[] = { | |||
104 | "Problems obtaining information for user %s", | 104 | "Problems obtaining information for user %s", |
105 | }; | 105 | }; |
106 | 106 | ||
107 | int perf_target__strerror(struct perf_target *target, int errnum, | 107 | int target__strerror(struct target *target, int errnum, |
108 | char *buf, size_t buflen) | 108 | char *buf, size_t buflen) |
109 | { | 109 | { |
110 | int idx; | 110 | int idx; |
@@ -124,21 +124,19 @@ int perf_target__strerror(struct perf_target *target, int errnum, | |||
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | 126 | ||
127 | if (errnum < __PERF_ERRNO_TARGET__START || | 127 | if (errnum < __TARGET_ERRNO__START || errnum >= __TARGET_ERRNO__END) |
128 | errnum >= __PERF_ERRNO_TARGET__END) | ||
129 | return -1; | 128 | return -1; |
130 | 129 | ||
131 | idx = errnum - __PERF_ERRNO_TARGET__START; | 130 | idx = errnum - __TARGET_ERRNO__START; |
132 | msg = perf_target__error_str[idx]; | 131 | msg = target__error_str[idx]; |
133 | 132 | ||
134 | switch (errnum) { | 133 | switch (errnum) { |
135 | case PERF_ERRNO_TARGET__PID_OVERRIDE_CPU | 134 | case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM: |
136 | ... PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM: | ||
137 | snprintf(buf, buflen, "%s", msg); | 135 | snprintf(buf, buflen, "%s", msg); |
138 | break; | 136 | break; |
139 | 137 | ||
140 | case PERF_ERRNO_TARGET__INVALID_UID: | 138 | case TARGET_ERRNO__INVALID_UID: |
141 | case PERF_ERRNO_TARGET__USER_NOT_FOUND: | 139 | case TARGET_ERRNO__USER_NOT_FOUND: |
142 | snprintf(buf, buflen, msg, target->uid_str); | 140 | snprintf(buf, buflen, msg, target->uid_str); |
143 | break; | 141 | break; |
144 | 142 | ||