File examples/wsdemo.c changed (mode: 100644) (index 94e11ed..8078778) |
13 |
13 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
14 |
14 |
#include <time.h> |
#include <time.h> |
15 |
15 |
#include <stdarg.h> |
#include <stdarg.h> |
|
16 |
|
#include <sys/capability.h> |
16 |
17 |
|
|
17 |
18 |
#include <Conn.h> |
#include <Conn.h> |
18 |
19 |
#include <json.h> |
#include <json.h> |
|
... |
... |
static const char main_screen[] = |
727 |
728 |
"</div>\n\n" |
"</div>\n\n" |
728 |
729 |
"" |
"" |
729 |
730 |
"<div class=\"gem\" width=\"120px\">\n" |
"<div class=\"gem\" width=\"120px\">\n" |
730 |
|
"Progress bar 2 (svg)\n" |
|
|
731 |
|
"Progress bar 2 (SVG)\n" |
731 |
732 |
"<svg height=\"20\" width=\"110\" style=\"border: 1px solid black\">\n" |
"<svg height=\"20\" width=\"110\" style=\"border: 1px solid black\">\n" |
732 |
733 |
" <defs>\n" |
" <defs>\n" |
733 |
734 |
" <linearGradient id=\"per2_gra1\" gradientTransform=\"rotate(90)\">\n" |
" <linearGradient id=\"per2_gra1\" gradientTransform=\"rotate(90)\">\n" |
|
... |
... |
static const char main_screen[] = |
751 |
752 |
" available width, but no more than 100px; previous values are pushed by the server.</div>\n" |
" available width, but no more than 100px; previous values are pushed by the server.</div>\n" |
752 |
753 |
"</div>\n\n" |
"</div>\n\n" |
753 |
754 |
"" |
"" |
754 |
|
"<div class=\"gem\" TODOwidth=\"420px\">\n" |
|
|
755 |
|
"<div class=\"gem\">\n" |
755 |
756 |
"Bandwidth (SVG)\n" |
"Bandwidth (SVG)\n" |
756 |
757 |
"<svg id=\"band1_container\" height=\"102\" width=\"100\" style=\"border: 1px solid green\">\n" |
"<svg id=\"band1_container\" height=\"102\" width=\"100\" style=\"border: 1px solid green\">\n" |
757 |
758 |
" <g id=\"band1\"></g>\n" |
" <g id=\"band1\"></g>\n" |
|
... |
... |
static void ws1(struct Conn *C) |
1022 |
1023 |
goto again; |
goto again; |
1023 |
1024 |
} |
} |
1024 |
1025 |
|
|
|
1026 |
|
/* |
|
1027 |
|
* Drop privileges |
|
1028 |
|
* returns -1 on error |
|
1029 |
|
*/ |
|
1030 |
|
static void drop_privileges(struct Conn *C) |
|
1031 |
|
{ |
|
1032 |
|
int ret, err; |
|
1033 |
|
cap_t caps; |
|
1034 |
|
|
|
1035 |
|
chdir("/"); |
|
1036 |
|
|
|
1037 |
|
err = -1; |
|
1038 |
|
while (1) { |
|
1039 |
|
caps = cap_get_proc(); |
|
1040 |
|
if (!caps) { |
|
1041 |
|
Log(0, "Cannot obtain caps: %s!\n", strerror(errno)); |
|
1042 |
|
break; |
|
1043 |
|
} |
|
1044 |
|
|
|
1045 |
|
ret = cap_clear(caps); |
|
1046 |
|
if (ret == -1) { |
|
1047 |
|
Log(0, "Cannot clear caps: %s!\n", strerror(errno)); |
|
1048 |
|
break; |
|
1049 |
|
} |
|
1050 |
|
|
|
1051 |
|
ret = cap_set_proc(caps); |
|
1052 |
|
if (ret == -1) { |
|
1053 |
|
Log(0, "Cannot set caps: %s!\n", strerror(errno)); |
|
1054 |
|
break; |
|
1055 |
|
} |
|
1056 |
|
|
|
1057 |
|
err = 0; |
|
1058 |
|
break; |
|
1059 |
|
} |
|
1060 |
|
if (caps) |
|
1061 |
|
cap_free(caps); |
|
1062 |
|
|
|
1063 |
|
if (err != 0) |
|
1064 |
|
Conn_close(C); |
|
1065 |
|
} |
|
1066 |
|
|
1025 |
1067 |
int main(void) |
int main(void) |
1026 |
1068 |
{ |
{ |
1027 |
|
int ret; |
|
|
1069 |
|
int ret, fd; |
1028 |
1070 |
struct Conn *C; |
struct Conn *C; |
1029 |
|
char *stats; |
|
|
1071 |
|
char *stats, path[256]; |
|
1072 |
|
struct timeval now; |
|
1073 |
|
struct tm tm; |
1030 |
1074 |
|
|
1031 |
|
setlinebuf(stdout); |
|
|
1075 |
|
gettimeofday(&now, NULL); |
|
1076 |
|
localtime_r(&now.tv_sec, &tm); |
|
1077 |
|
snprintf(path, sizeof(path), "/var/log/Conn/wsdemo-%04d-%02d-%02d.log", |
|
1078 |
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); |
|
1079 |
|
fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0600); |
|
1080 |
|
if (fd == -1) { |
|
1081 |
|
fprintf(stderr, "Cannot open log file: %s!\n", strerror(errno)); |
|
1082 |
|
return 1; |
|
1083 |
|
} |
1032 |
1084 |
|
|
1033 |
|
Conn_debug(2, debug); |
|
|
1085 |
|
Conn_debug(fd, debug); |
1034 |
1086 |
|
|
1035 |
1087 |
ret = Conn_init(0); |
ret = Conn_init(0); |
1036 |
1088 |
if (ret == -1) { |
if (ret == -1) { |
|
... |
... |
int main(void) |
1074 |
1126 |
|
|
1075 |
1127 |
Conn_set_cb(C, CONN_CB_ACCEPT, accept_cb); |
Conn_set_cb(C, CONN_CB_ACCEPT, accept_cb); |
1076 |
1128 |
Conn_set_cb(C, CONN_CB_CLOSE, close_cb); |
Conn_set_cb(C, CONN_CB_CLOSE, close_cb); |
|
1129 |
|
Conn_set_cb(C, CONN_CB_WORKER_START, drop_privileges); |
1077 |
1130 |
|
|
1078 |
1131 |
ret = Conn_commit(C); |
ret = Conn_commit(C); |
1079 |
1132 |
if (ret != 0) { |
if (ret != 0) { |