-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScriptRunner.fcgi.in
executable file
·93 lines (75 loc) · 2.22 KB
/
ScriptRunner.fcgi.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!@PIKE@ -M@prefix@/scriptrunner/lib -P@prefix@/scriptrunner/lib
import Tools.Logging;
inherit ScriptRunner.Runner;
constant my_version = "0.4";
//#define RUN_THREADED
string session_storagetype = "ram";
string session_storagedir = ""; // not required for ram storage.
//string session_storagetype = "sqlite";
//string session_storagedir = "/tmp/scriptrunner_storage.db";
//string session_storagetype = "file";
//string session_storagedir = "/tmp/scriptrunner_storage";
string logfile_path = "/tmp/scriptrunner.log";
string session_cookie_name = "PSESSIONID";
int session_timeout = 3600;
string mode = "FastCGI";
int start_listener(int port)
{
int sock;
if(!port)
{
Log.info("Starting listener on stdin socket.");
f = Stdio.stdin.dup();
sock = f->query_fd();
}
else
{
Log.info("Starting listener on port %d.", (int)port);
sock = Public.Web.___FCGI.open_socket(":" + (int)port, 128);
}
#ifdef RUN_THREADED
for (int i = 0; i < 8; i++) {
Thread.Thread(request_loop, sock, i);
}
return (-1);
#else
request_loop(sock, 0);
return 0;
#endif
}
void request_loop(int sock, int id)
{
String.Buffer response = String.Buffer();
#ifdef RUN_THREADED
Thread.Mutex lock;
Thread.MutexKey key;
lock = Thread.Mutex();
key = lock->lock();
#endif
object request = Public.Web.___FCGI.FCGI(sock);
#ifdef RUN_THREADED
key = 0;
#endif
do{
request->accept();
requests ++;
object request_id;
mixed e;
if(catch(request_id = ScriptRunner.RequestID(request)))
{
#ifdef RUN_THREADED
key = lock->lock();
#endif
request->write("Status: 500 Server Error\r\n");
request->write("Content-type: text/html\r\n\r\n");
request->write("<h1>Error 500: Internal Server Error</h1>");
request->write("The server was unable to parse your request.\n");
request->finish();
#ifdef RUN_THREADED
key = 0;
#endif
continue;
}
handle_request(request_id, id);
} while (!shutdown);
}