13
13
#include <string.h>
16
enum perf_target_errno perf_target__validate(struct perf_target *target)
16
enum target_errno target__validate(struct target *target)
18
enum perf_target_errno ret = PERF_ERRNO_TARGET__SUCCESS;
18
enum target_errno ret = TARGET_ERRNO__SUCCESS;
21
21
target->tid = target->pid;
23
23
/* CPU and PID are mutually exclusive */
24
24
if (target->tid && target->cpu_list) {
25
25
target->cpu_list = NULL;
26
if (ret == PERF_ERRNO_TARGET__SUCCESS)
27
ret = PERF_ERRNO_TARGET__PID_OVERRIDE_CPU;
26
if (ret == TARGET_ERRNO__SUCCESS)
27
ret = TARGET_ERRNO__PID_OVERRIDE_CPU;
30
30
/* UID and PID are mutually exclusive */
31
31
if (target->tid && target->uid_str) {
32
32
target->uid_str = NULL;
33
if (ret == PERF_ERRNO_TARGET__SUCCESS)
34
ret = PERF_ERRNO_TARGET__PID_OVERRIDE_UID;
33
if (ret == TARGET_ERRNO__SUCCESS)
34
ret = TARGET_ERRNO__PID_OVERRIDE_UID;
37
37
/* UID and CPU are mutually exclusive */
38
38
if (target->uid_str && target->cpu_list) {
39
39
target->cpu_list = NULL;
40
if (ret == PERF_ERRNO_TARGET__SUCCESS)
41
ret = PERF_ERRNO_TARGET__UID_OVERRIDE_CPU;
40
if (ret == TARGET_ERRNO__SUCCESS)
41
ret = TARGET_ERRNO__UID_OVERRIDE_CPU;
44
44
/* PID and SYSTEM are mutually exclusive */
45
45
if (target->tid && target->system_wide) {
46
46
target->system_wide = false;
47
if (ret == PERF_ERRNO_TARGET__SUCCESS)
48
ret = PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM;
47
if (ret == TARGET_ERRNO__SUCCESS)
48
ret = TARGET_ERRNO__PID_OVERRIDE_SYSTEM;
51
51
/* UID and SYSTEM are mutually exclusive */
52
52
if (target->uid_str && target->system_wide) {
53
53
target->system_wide = false;
54
if (ret == PERF_ERRNO_TARGET__SUCCESS)
55
ret = PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM;
54
if (ret == TARGET_ERRNO__SUCCESS)
55
ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
61
enum perf_target_errno perf_target__parse_uid(struct perf_target *target)
61
enum target_errno target__parse_uid(struct target *target)
63
63
struct passwd pwd, *result;
67
67
target->uid = UINT_MAX;
69
return PERF_ERRNO_TARGET__SUCCESS;
69
return TARGET_ERRNO__SUCCESS;
71
71
/* Try user name first */
72
72
getpwnam_r(str, &pwd, buf, sizeof(buf), &result);
79
79
int uid = strtol(str, &endptr, 10);
81
81
if (*endptr != '\0')
82
return PERF_ERRNO_TARGET__INVALID_UID;
82
return TARGET_ERRNO__INVALID_UID;
84
84
getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
86
86
if (result == NULL)
87
return PERF_ERRNO_TARGET__USER_NOT_FOUND;
87
return TARGET_ERRNO__USER_NOT_FOUND;
90
90
target->uid = result->pw_uid;
91
return PERF_ERRNO_TARGET__SUCCESS;
91
return TARGET_ERRNO__SUCCESS;
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.
97
static const char *perf_target__error_str[] = {
97
static const char *target__error_str[] = {
98
98
"PID/TID switch overriding CPU",
99
99
"PID/TID switch overriding UID",
100
100
"UID switch overriding CPU",
104
104
"Problems obtaining information for user %s",
107
int perf_target__strerror(struct perf_target *target, int errnum,
107
int target__strerror(struct target *target, int errnum,
108
108
char *buf, size_t buflen)
127
if (errnum < __PERF_ERRNO_TARGET__START ||
128
errnum >= __PERF_ERRNO_TARGET__END)
127
if (errnum < __TARGET_ERRNO__START || errnum >= __TARGET_ERRNO__END)
131
idx = errnum - __PERF_ERRNO_TARGET__START;
132
msg = perf_target__error_str[idx];
130
idx = errnum - __TARGET_ERRNO__START;
131
msg = target__error_str[idx];
134
133
switch (errnum) {
135
case PERF_ERRNO_TARGET__PID_OVERRIDE_CPU
136
... PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM:
134
case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM:
137
135
snprintf(buf, buflen, "%s", msg);
140
case PERF_ERRNO_TARGET__INVALID_UID:
141
case PERF_ERRNO_TARGET__USER_NOT_FOUND:
138
case TARGET_ERRNO__INVALID_UID:
139
case TARGET_ERRNO__USER_NOT_FOUND:
142
140
snprintf(buf, buflen, msg, target->uid_str);