handleCmdLine.c
2.13 KB
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
61
62
63
64
65
66
67
68
69
70
#include <unistd.h> /* for getopt */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "../include/appConfig.h"
int
handleCmdLine(tAppConfig * config, int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "Dvp:l:n:b:")) != -1) {
switch (opt) {
case 'p':
/* port */
config->port = atoi(optarg);
break;
case 'l':
/* logPath */
strncpy(config->logPath, optarg, sizeof(config->logPath)-1);
break;
case 'n':
/* logNamePattern */
strncpy(config->namePat, optarg, sizeof(config->namePat)-1);
break;
case 'b':
/* maxPending (connection backlog) */
config->maxPending = atoi(optarg);
break;
case 'v':
/* verbose */
config->verbose = 1;
break;
case 'D':
/* verbose */
config->doDaemon = 1;
break;
default:
/* '?' */
fprintf(
stderr,
"Usage: %s [-p port] [-l logPath] [-n logNamePattern] [-c maxClient] [-b backlog] [-v] [-D]\n"
"Defaults:\n"
"\t%-20s: port this service will use [%d]\n"
"\t%-20s: path where the logfiles will be stored [%s/]\n"
"\t%-20s: patten used by strftime to create the log filename [%s]\n"
"\t%-20s: maximum connection backlog [%d]\n"
"\t%-20s: be more verbose in syslog [off]\n"
"\t%-20s: deamonize me\n",
argv[0],
"-p port", DEFAULTPORT,
"-l logPath", DEFAULTPATH,
"-n logNamePattern", LOGNAMEPATTERN,
"-b backlog", MAXPENDING,
"-v",
"-D");
exit(EXIT_FAILURE);
}
}
return 0;
}