aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2010-12-22 09:15:24 -0800
committerNick Mathewson <nickm@torproject.org>2011-01-03 12:04:56 -0500
commit8708ffa655820df9db587228a6a60a9d1ccbf039 (patch)
treec6ca1376e532a31ccd817b6bda884dcef48bdbcf
parent93a6d53ef33f61a711c7a5b0583dae88a160d730 (diff)
downloadtor-8708ffa655820df9db587228a6a60a9d1ccbf039.tar.gz
tor-8708ffa655820df9db587228a6a60a9d1ccbf039.zip
Implementing getinfo options for the pid, uid, user, and descriptor limit as per proposal 173.
-rw-r--r--doc/spec/control-spec.txt9
-rw-r--r--src/or/control.c58
2 files changed, 67 insertions, 0 deletions
diff --git a/doc/spec/control-spec.txt b/doc/spec/control-spec.txt
index e8a314c930..45fa3e7c84 100644
--- a/doc/spec/control-spec.txt
+++ b/doc/spec/control-spec.txt
@@ -566,6 +566,15 @@
"next-circuit/IP:port"
XXX todo.
+ "process/pid" -- Process id belonging to the main tor process.
+ "process/uid" -- User id running the tor process, -1 if unknown (this is
+ unimplemented on Windows, returning -1).
+ "process/user" -- Username under which the tor process is running,
+ providing an empty string if none exists (this is unimplemented on
+ Windows, returning an empty string).
+ "process/descriptor-limit" -- Upper bound on the file descriptor limit, -1
+ if unknown.
+
"dir/status-vote/current/consensus" [added in Tor 0.2.1.6-alpha]
"dir/status/authority"
"dir/status/fp/<F>"
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."),