Index: filed.1 ================================================================== --- filed.1 +++ filed.1 @@ -5,10 +5,11 @@ .SH SYNOPSIS .ll +10 .B filed .RB [{ \-h | \-\-help }] .RB [{ \-d | \-\-daemon }] +.RB [{ \-v | \-\-version }] .RB [{ \-b | \-\-bind } .IR address ] .RB [{ \-p | \-\-port } .IR port ] .RB [{ \-t | \-\-threads } @@ -37,10 +38,16 @@ Instructs .B filed to become a daemon after initializing the listening TCP socket and log files. +.TP +.B -v (or --version) +Instructs +.B filed +to print out its version number and then exit. + .TP .B -b (or --bind) Specifies the address to listen for incoming HTTP requests on. Index: filed.c ================================================================== --- filed.c +++ filed.c @@ -18,12 +18,13 @@ #include #include #include /* Compile time constants */ +#define FILED_VERSION "0.9" #define FILED_SENDFILE_MAX 16777215 -#define MAX_FAILURE_COUNT 30 +#define FILED_MAX_FAILURE_COUNT 30 #define FILED_DEFAULT_TYPE "application/octet-stream" /* Default values */ #define PORT 80 #define THREAD_COUNT 5 @@ -784,11 +785,11 @@ 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; @@ -871,10 +872,11 @@ fprintf(output, "Usage: filed []\n"); fprintf(output, " Options:\n"); fprintf(output, " -h, --help\n"); fprintf(output, " -d, --daemon\n"); + fprintf(output, " -v, --version\n"); fprintf(output, " -b
, --bind
\n"); fprintf(output, " -p , --port \n"); fprintf(output, " -t , --threads \n"); fprintf(output, " -c , --cache \n"); fprintf(output, " -l , --log \n"); @@ -886,10 +888,12 @@ 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"); @@ -1031,11 +1035,11 @@ 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; @@ -1052,12 +1056,13 @@ 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': @@ -1085,10 +1090,14 @@ 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);