Diff

Differences From Artifact [c245fb8d4f]:

To Artifact [a6b140c86c]:


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