782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
|
-
+
|
/* Handle incoming connections */
static void *filed_worker_thread(void *arg_v) {
struct filed_worker_thread_args *arg;
struct filed_http_request request;
struct sockaddr_in6 addr;
char logbuf_ip[128];
socklen_t addrlen;
int failure_count = 0, max_failure_count = MAX_FAILURE_COUNT;
int failure_count = 0, max_failure_count = FILED_MAX_FAILURE_COUNT;
int master_fd, fd;
/* Read arguments */
arg = arg_v;
master_fd = arg->fd;
|
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
|
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
|
+
+
+
|
fprintf(output, "%s\n", extra);
}
fprintf(output, "Usage: filed [<options>]\n");
fprintf(output, " Options:\n");
fprintf(output, " -h, --help\n");
fprintf(output, " -d, --daemon\n");
fprintf(output, " -v, --version\n");
fprintf(output, " -b <address>, --bind <address>\n");
fprintf(output, " -p <port>, --port <port>\n");
fprintf(output, " -t <count>, --threads <count>\n");
fprintf(output, " -c <entries>, --cache <entries>\n");
fprintf(output, " -l <file>, --log <file>\n");
fprintf(output, " -u <user>, --user <user>\n");
fprintf(output, " -r <directory>, --root <directory>\n");
if (long_help) {
fprintf(output, "\n");
fprintf(output, " Usage:\n");
fprintf(output, " -h (or --help) prints this usage information.\n");
fprintf(output, "\n");
fprintf(output, " -d (or --daemon) instructs filed to become a daemon after initializing\n");
fprintf(output, " the listening TCP socket and log files.\n");
fprintf(output, "\n");
fprintf(output, " -v (or --version) instructs filed print out the version number and exit.\n");
fprintf(output, "\n");
fprintf(output, " -b (or --bind) specifies the address to listen for incoming HTTP\n");
fprintf(output, " requests on. The default value is \"%s\".\n", BIND_ADDR);
fprintf(output, "\n");
fprintf(output, " -p (or --port) specifies the TCP port number to listen for incoming HTTP\n");
fprintf(output, " requests on. The default is %u.\n", (unsigned int) PORT);
fprintf(output, "\n");
|
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
|
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
|
-
+
-
-
+
+
+
|
close(fd_out);
return(0);
}
/* Run process */
int main(int argc, char **argv) {
struct option options[10];
struct option options[11];
const char *bind_addr = BIND_ADDR, *newroot = NULL, *log_file = LOG_FILE;
FILE *log_fp;
uid_t user = 0;
int port = PORT, thread_count = THREAD_COUNT;
int cache_size = CACHE_SIZE;
int init_ret, chroot_ret, setuid_ret, lookup_ret, chdir_ret;
int setuid_enabled = 0, daemon_enabled = 0;
int ch;
int fd;
/* Process arguments */
filed_getopt_long_setopt(&options[0], "port", required_argument, 'p');
filed_getopt_long_setopt(&options[1], "threads", required_argument, 't');
filed_getopt_long_setopt(&options[2], "cache", required_argument, 'c');
filed_getopt_long_setopt(&options[3], "bind", required_argument, 'b');
filed_getopt_long_setopt(&options[4], "user", required_argument, 'u');
filed_getopt_long_setopt(&options[5], "root", required_argument, 'r');
filed_getopt_long_setopt(&options[6], "help", no_argument, 'h');
filed_getopt_long_setopt(&options[7], "daemon", no_argument, 'd');
filed_getopt_long_setopt(&options[8], "log", required_argument, 'l');
filed_getopt_long_setopt(&options[9], NULL, 0, 0);
while ((ch = getopt_long(argc, argv, "p:t:c:b:u:r:l:hd", options, NULL)) != -1) {
filed_getopt_long_setopt(&options[9], "version", no_argument, 'v');
filed_getopt_long_setopt(&options[10], NULL, 0, 0);
while ((ch = getopt_long(argc, argv, "p:t:c:b:u:r:l:hdv", options, NULL)) != -1) {
switch(ch) {
case 'p':
port = atoi(optarg);
break;
case 't':
thread_count = atoi(optarg);
break;
|
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
|
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
|
+
+
+
+
|
break;
case 'l':
log_file = strdup(optarg);
break;
case 'd':
daemon_enabled = 1;
break;
case 'v':
printf("filed version %s\n", FILED_VERSION);
return(0);
case '?':
case ':':
filed_print_help(stderr, 0, NULL);
return(1);
case 'h':
filed_print_help(stdout, 1, NULL);
|