2009-05-26 23:18:34 +02:00
|
|
|
// curop.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "namespace.h"
|
|
|
|
#include "security.h"
|
2009-10-12 21:12:16 +02:00
|
|
|
#include "client.h"
|
2009-05-26 23:18:34 +02:00
|
|
|
|
|
|
|
namespace mongo {
|
|
|
|
|
2009-10-16 21:36:34 +02:00
|
|
|
struct CurOp {
|
2009-05-26 23:18:34 +02:00
|
|
|
void reset(time_t now, const sockaddr_in &_client) {
|
|
|
|
active = true;
|
|
|
|
opNum++;
|
|
|
|
startTime = now;
|
|
|
|
ns[0] = '?'; // just in case not set later
|
|
|
|
*query = 0;
|
|
|
|
killCurrentOp = 0;
|
|
|
|
client = _client;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
unsigned opNum;
|
|
|
|
time_t startTime;
|
|
|
|
int op;
|
|
|
|
char ns[Namespace::MaxNsLen+2];
|
|
|
|
char query[128];
|
2009-12-08 17:34:57 +01:00
|
|
|
char zero; // what's this for?
|
2009-05-26 23:18:34 +02:00
|
|
|
struct sockaddr_in client;
|
|
|
|
|
|
|
|
CurOp() {
|
2009-10-16 21:36:34 +02:00
|
|
|
active = false;
|
2009-05-26 23:18:34 +02:00
|
|
|
opNum = 0;
|
2009-12-07 21:42:26 +01:00
|
|
|
startTime = 0;
|
|
|
|
op = 0;
|
2009-05-26 23:18:34 +02:00
|
|
|
// These addresses should never be written to again. The zeroes are
|
|
|
|
// placed here as a precaution because currentOp may be accessed
|
|
|
|
// without the db mutex.
|
2009-12-07 21:42:26 +01:00
|
|
|
memset(ns, 0, sizeof(ns));
|
|
|
|
memset(query, 0, sizeof(query));
|
2009-12-08 17:34:57 +01:00
|
|
|
zero = 0;
|
2009-05-26 23:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BSONObj info() {
|
2009-10-12 21:12:16 +02:00
|
|
|
AuthenticationInfo *ai = currentClient.get()->ai;
|
2009-10-09 20:59:44 +02:00
|
|
|
if( !ai->isAuthorized("admin") ) {
|
2009-05-26 23:18:34 +02:00
|
|
|
BSONObjBuilder b;
|
|
|
|
b.append("err", "unauthorized");
|
|
|
|
return b.obj();
|
|
|
|
}
|
|
|
|
return infoNoauth();
|
|
|
|
}
|
|
|
|
|
|
|
|
BSONObj infoNoauth() {
|
|
|
|
BSONObjBuilder b;
|
|
|
|
b.append("opid", opNum);
|
|
|
|
b.append("active", active);
|
|
|
|
if( active )
|
|
|
|
b.append("secs_running", (int) (time(0)-startTime));
|
|
|
|
if( op == 2004 )
|
|
|
|
b.append("op", "query");
|
|
|
|
else if( op == 2005 )
|
|
|
|
b.append("op", "getMore");
|
|
|
|
else if( op == 2001 )
|
|
|
|
b.append("op", "update");
|
|
|
|
else if( op == 2002 )
|
|
|
|
b.append("op", "insert");
|
|
|
|
else if( op == 2006 )
|
|
|
|
b.append("op", "delete");
|
|
|
|
else
|
|
|
|
b.append("op", op);
|
|
|
|
b.append("ns", ns);
|
|
|
|
b.append("query", query);
|
2009-12-07 21:42:26 +01:00
|
|
|
// b.append("inLock", ??
|
2009-05-26 23:18:34 +02:00
|
|
|
stringstream clientStr;
|
|
|
|
clientStr << inet_ntoa( client.sin_addr ) << ":" << ntohs( client.sin_port );
|
|
|
|
b.append("client", clientStr.str());
|
|
|
|
return b.obj();
|
|
|
|
}
|
2009-10-16 21:36:34 +02:00
|
|
|
};
|
2009-05-26 23:18:34 +02:00
|
|
|
|
|
|
|
}
|