diff options
| author | Len Brown <len.brown@intel.com> | 2012-04-06 21:48:59 -0400 |
|---|---|---|
| committer | Len Brown <len.brown@intel.com> | 2012-04-06 21:48:59 -0400 |
| commit | eeaab2d8af2cf1d36d7086f22e9de42d6dd2995c (patch) | |
| tree | 369b9c91a6d808944f07d2290fec6f9fe2731904 /tools/perf/util/usage.c | |
| parent | ee01e663373343c63e0e3d364d09f6155378dbcc (diff) | |
| parent | aaef292acf3a78d9c0bb6fb72226077d286b45d7 (diff) | |
Merge branches 'idle-fix' and 'misc' into release
Diffstat (limited to 'tools/perf/util/usage.c')
| -rw-r--r-- | tools/perf/util/usage.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c index d76d1c0ff98f..52bb07c6442a 100644 --- a/tools/perf/util/usage.c +++ b/tools/perf/util/usage.c @@ -7,6 +7,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "util.h" +#include "debug.h" static void report(const char *prefix, const char *err, va_list params) { @@ -81,3 +82,41 @@ void warning(const char *warn, ...) warn_routine(warn, params); va_end(params); } + +uid_t parse_target_uid(const char *str, const char *tid, const char *pid) +{ + struct passwd pwd, *result; + char buf[1024]; + + if (str == NULL) + return UINT_MAX; + + /* UID and PID are mutually exclusive */ + if (tid || pid) { + ui__warning("PID/TID switch overriding UID\n"); + sleep(1); + return UINT_MAX; + } + + getpwnam_r(str, &pwd, buf, sizeof(buf), &result); + + if (result == NULL) { + char *endptr; + int uid = strtol(str, &endptr, 10); + + if (*endptr != '\0') { + ui__error("Invalid user %s\n", str); + return UINT_MAX - 1; + } + + getpwuid_r(uid, &pwd, buf, sizeof(buf), &result); + + if (result == NULL) { + ui__error("Problems obtaining information for user %s\n", + str); + return UINT_MAX - 1; + } + } + + return result->pw_uid; +} |
