mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-16 06:06:16 +00:00
* Logging for scgi calls.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1100 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+22
-7
@@ -52,6 +52,7 @@
|
|||||||
#include "rpc/command_slot.h"
|
#include "rpc/command_slot.h"
|
||||||
#include "rpc/command_variable.h"
|
#include "rpc/command_variable.h"
|
||||||
#include "rpc/parse_commands.h"
|
#include "rpc/parse_commands.h"
|
||||||
|
#include "rpc/scgi.h"
|
||||||
#include "utils/file_status_cache.h"
|
#include "utils/file_status_cache.h"
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
@@ -61,10 +62,18 @@
|
|||||||
typedef torrent::ChunkManager CM_t;
|
typedef torrent::ChunkManager CM_t;
|
||||||
|
|
||||||
torrent::Object
|
torrent::Object
|
||||||
apply_execute_log(const torrent::Object& rawArgs) {
|
apply_log(int logType, const torrent::Object& rawArgs) {
|
||||||
if (rpc::execFile.log_fd() != -1) {
|
if (rpc::execFile.log_fd() != -1) {
|
||||||
::close(rpc::execFile.log_fd());
|
switch (logType) {
|
||||||
rpc::execFile.set_log_fd(-1);
|
case 0: ::close(rpc::execFile.log_fd()); rpc::execFile.set_log_fd(-1); break;
|
||||||
|
case 1:
|
||||||
|
if (control->scgi()) {
|
||||||
|
::close(control->scgi()->log_fd());
|
||||||
|
control->scgi()->set_log_fd(-1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawArgs.is_string() && !rawArgs.as_string().empty()) {
|
if (rawArgs.is_string() && !rawArgs.as_string().empty()) {
|
||||||
@@ -73,11 +82,16 @@ apply_execute_log(const torrent::Object& rawArgs) {
|
|||||||
if (logFd < 0)
|
if (logFd < 0)
|
||||||
throw torrent::input_error("Could not open execute log file.");
|
throw torrent::input_error("Could not open execute log file.");
|
||||||
|
|
||||||
rpc::execFile.set_log_fd(logFd);
|
switch (logType) {
|
||||||
control->core()->push_log("Opened execute log file.");
|
case 0: rpc::execFile.set_log_fd(logFd); break;
|
||||||
|
case 1: if (control->scgi()) control->scgi()->set_log_fd(logFd); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
control->core()->push_log("Opened log file.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
control->core()->push_log("Closed execute log file.");
|
control->core()->push_log("Closed log file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return torrent::Object();
|
return torrent::Object();
|
||||||
@@ -209,7 +223,8 @@ initialize_command_local() {
|
|||||||
ADD_COMMAND_LIST("execute_capture", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_throw | rpc::ExecFile::flag_expand_tilde | rpc::ExecFile::flag_capture));
|
ADD_COMMAND_LIST("execute_capture", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_throw | rpc::ExecFile::flag_expand_tilde | rpc::ExecFile::flag_capture));
|
||||||
ADD_COMMAND_LIST("execute_capture_nothrow", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_expand_tilde | rpc::ExecFile::flag_capture));
|
ADD_COMMAND_LIST("execute_capture_nothrow", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_expand_tilde | rpc::ExecFile::flag_capture));
|
||||||
|
|
||||||
ADD_COMMAND_STRING_UN("execute_log", std::ptr_fun(&apply_execute_log));
|
ADD_COMMAND_STRING("log.execute", rak::bind_ptr_fn(&apply_log, 0));
|
||||||
|
ADD_COMMAND_STRING("log.xmlrpc", rak::bind_ptr_fn(&apply_log, 1));
|
||||||
|
|
||||||
*rpc::Command::argument(0) = "placeholder.0";
|
*rpc::Command::argument(0) = "placeholder.0";
|
||||||
*rpc::Command::argument(1) = "placeholder.1";
|
*rpc::Command::argument(1) = "placeholder.1";
|
||||||
|
|||||||
@@ -492,6 +492,6 @@ initialize_command_network() {
|
|||||||
ADD_VARIABLE_BOOL("peer_exchange", true);
|
ADD_VARIABLE_BOOL("peer_exchange", true);
|
||||||
|
|
||||||
// Not really network stuff:
|
// Not really network stuff:
|
||||||
ADD_VARIABLE_BOOL("handshake_log", false);
|
ADD_VARIABLE_BOOL ("log.handshake", false);
|
||||||
ADD_VARIABLE_STRING("tracker_dump", "");
|
ADD_VARIABLE_STRING("log.tracker", "");
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
static const int max_tasks = 10;
|
static const int max_tasks = 10;
|
||||||
|
|
||||||
SCgi() {}
|
SCgi() : m_logFd(-1) {}
|
||||||
virtual ~SCgi();
|
virtual ~SCgi();
|
||||||
|
|
||||||
void open_port(void* sa, unsigned int length, bool dontRoute);
|
void open_port(void* sa, unsigned int length, bool dontRoute);
|
||||||
@@ -66,6 +66,9 @@ public:
|
|||||||
|
|
||||||
void set_slot_process(slot_process::base_type* s) { m_slotProcess.set(s); }
|
void set_slot_process(slot_process::base_type* s) { m_slotProcess.set(s); }
|
||||||
|
|
||||||
|
int log_fd() const { return m_logFd; }
|
||||||
|
void set_log_fd(int fd) { m_logFd = fd; }
|
||||||
|
|
||||||
virtual void event_read();
|
virtual void event_read();
|
||||||
virtual void event_write();
|
virtual void event_write();
|
||||||
virtual void event_error();
|
virtual void event_error();
|
||||||
@@ -78,6 +81,7 @@ private:
|
|||||||
void open(void* sa, unsigned int length);
|
void open(void* sa, unsigned int length);
|
||||||
|
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
int m_logFd;
|
||||||
slot_process m_slotProcess;
|
slot_process m_slotProcess;
|
||||||
SCgiTask m_task[max_tasks];
|
SCgiTask m_task[max_tasks];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -174,6 +174,13 @@ SCgiTask::event_read() {
|
|||||||
control->poll()->remove_read(this);
|
control->poll()->remove_read(this);
|
||||||
control->poll()->insert_write(this);
|
control->poll()->insert_write(this);
|
||||||
|
|
||||||
|
if (m_parent->log_fd() >= 0) {
|
||||||
|
// Clean up logging, this is just plain ugly...
|
||||||
|
// write(m_logFd, "\n---\n", sizeof("\n---\n"));
|
||||||
|
write(m_parent->log_fd(), m_buffer, m_bufferSize);
|
||||||
|
write(m_parent->log_fd(), "\n---\n", sizeof("\n---\n"));
|
||||||
|
}
|
||||||
|
|
||||||
// Close if the call failed, else stay open to write back data.
|
// Close if the call failed, else stay open to write back data.
|
||||||
if (!m_parent->receive_call(this, m_body, m_bufferSize - std::distance(m_buffer, m_body)))
|
if (!m_parent->receive_call(this, m_body, m_bufferSize - std::distance(m_buffer, m_body)))
|
||||||
close();
|
close();
|
||||||
|
|||||||
Reference in New Issue
Block a user