diff options
author | Damian Johnson <atagar@torproject.org> | 2010-12-22 09:15:24 -0800 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-01-03 12:04:56 -0500 |
commit | 8708ffa655820df9db587228a6a60a9d1ccbf039 (patch) | |
tree | c6ca1376e532a31ccd817b6bda884dcef48bdbcf /src/or/control.c | |
parent | 93a6d53ef33f61a711c7a5b0583dae88a160d730 (diff) | |
download | tor-8708ffa655820df9db587228a6a60a9d1ccbf039.tar.gz tor-8708ffa655820df9db587228a6a60a9d1ccbf039.zip |
Implementing getinfo options for the pid, uid, user, and descriptor limit as per proposal 173.
Diffstat (limited to 'src/or/control.c')
-rw-r--r-- | src/or/control.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c index 22f426330f..e4ab387d79 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -33,6 +33,11 @@ #include "routerlist.h" #include "routerparse.h" +#ifndef MS_WINDOWS +#include <pwd.h> +#include <sys/resource.h> +#endif + /** Yield true iff <b>s</b> is the state of a control_connection_t that has * finished authentication and is accepting commands. */ #define STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN) @@ -1345,6 +1350,55 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, return -1; } *answer = tor_dup_ip(addr); + } else if (!strcmp(question, "process/pid")) { + int myPid = -1; + + #ifdef MS_WINDOWS + myPid = _getpid(); + #else + myPid = getpid(); + #endif + + tor_asprintf(answer, U64_FORMAT, U64_PRINTF_ARG(myPid)); + } else if (!strcmp(question, "process/uid")) { + #ifdef MS_WINDOWS + *answer = tor_strdup("-1"); + #else + int myUid = geteuid(); + tor_asprintf(answer, U64_FORMAT, U64_PRINTF_ARG(myUid)); + #endif + } else if (!strcmp(question, "process/user")) { + #ifdef MS_WINDOWS + *answer = tor_strdup(""); + #else + int myUid = geteuid(); + struct passwd *myPwEntry = getpwuid(myUid); + + if (myPwEntry) { + *answer = tor_strdup(myPwEntry->pw_name); + } else { + *answer = tor_strdup(""); + } + #endif + } else if (!strcmp(question, "process/descriptor-limit")) { + /** platform specifc limits are from the set_max_file_descriptors function + * of src/common/compat.c */ + #ifdef HAVE_GETRLIMIT + struct rlimit descriptorLimit; + + if (getrlimit(RLIMIT_NOFILE, &descriptorLimit) == 0) { + tor_asprintf(answer, U64_FORMAT, + U64_PRINTF_ARG(descriptorLimit.rlim_max)); + } else { + *answer = tor_strdup("-1"); + } + #elif defined(CYGWIN) || defined(__CYGWIN__) + *answer = tor_strdup("3200"); + #elif defined(MS_WINDOWS) + *answer = tor_strdup("15000"); + #else + *answer = tor_strdup("15000"); + #endif } else if (!strcmp(question, "dir-usage")) { *answer = directory_dump_request_log(); } else if (!strcmp(question, "fingerprint")) { @@ -1902,6 +1956,10 @@ static const getinfo_item_t getinfo_items[] = { "Number of versioning authorities agreeing on the status of the " "current version"), ITEM("address", misc, "IP address of this Tor host, if we can guess it."), + ITEM("process/pid", misc, "Process id belonging to the main tor process."), + ITEM("process/uid", misc, "User id running the tor process."), + ITEM("process/user", misc,"Username under which the tor process is running."), + ITEM("process/descriptor-limit", misc, "File descriptor limit."), ITEM("dir-usage", misc, "Breakdown of bytes transferred over DirPort."), PREFIX("desc-annotations/id/", dir, "Router annotations by hexdigest."), PREFIX("dir/server/", dir,"Router descriptors as retrieved from a DirPort."), |