forked from danielwaterworth/Raphters
-
Notifications
You must be signed in to change notification settings - Fork 7
/
raphters.c
60 lines (49 loc) · 1.5 KB
/
raphters.c
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
/*
Copyright (C) 2011 Raphters authors,
This file is part of Raphters.
Raphters is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Raphters is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <fcgi_stdio.h>
#include <time.h>
#include "raphters.h"
#include "backtrace.h"
void (*user_segfault)() = 0;
void segfault() {
#if defined(DEBUG) || 1
response *r = response_empty();
response_add_header(r, "content-type", "text/plain");
response_send(r);
show_backtrace(stdout);
show_backtrace(stderr);
if (user_segfault) {
user_segfault();
}
#endif
}
void serve_forever() {
srand(time(0));
(void)install_segfault_handler(&segfault);
int uid = (int) geteuid();
if(uid = 0){
// never run webapp as root, its a security risk
uid = 1;
}
// set uid to non-root user
setuid(uid);
seteuid(uid);
init_handlers();
while(FCGI_Accept() >= 0) {
dispatch();
}
cleanup_handlers();
}