2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 AtomPtr configFile
= NULL
;
26 AtomPtr pidFile
= NULL
;
33 "%s [ -h ] [ -v ] [ -x ] [ -c filename ] [ -- ] [ var=val... ]\n",
35 fprintf(stderr
, " -h: display this message.\n");
36 fprintf(stderr
, " -v: display the list of configuration variables.\n");
37 fprintf(stderr
, " -x: perform expiry on the disk cache.\n");
38 fprintf(stderr
, " -c: specify the configuration file to use.\n");
42 main(int argc
, char **argv
)
44 FdEventHandlerPtr listener
;
47 int expire
= 0, printConfig
= 0;
50 CONFIG_VARIABLE(daemonise
, CONFIG_BOOLEAN
, "Run as a daemon");
51 CONFIG_VARIABLE(pidFile
, CONFIG_ATOM
, "File with pid of running daemon.");
69 if(strcmp(argv
[i
], "--") == 0) {
72 } else if(strcmp(argv
[i
], "-h") == 0) {
75 } else if(strcmp(argv
[i
], "-v") == 0) {
78 } else if(strcmp(argv
[i
], "-x") == 0) {
81 } else if(strcmp(argv
[i
], "-c") == 0) {
88 releaseAtom(configFile
);
89 configFile
= internAtom(argv
[i
]);
98 configFile
= expandTilde(configFile
);
100 if(configFile
== NULL
) {
101 configFile
= expandTilde(internAtom("~/.polipo"));
103 if(access(configFile
->string
, F_OK
) < 0) {
104 releaseAtom(configFile
);
109 if(configFile
== NULL
) {
110 if(access("/etc/polipo/config", F_OK
) >= 0)
111 configFile
= internAtom("/etc/polipo/config");
112 if(configFile
&& access(configFile
->string
, F_OK
) < 0) {
113 releaseAtom(configFile
);
118 rc
= parseConfigFile(configFile
);
123 rc
= parseConfigLine(argv
[i
], "command line", 0, 0);
132 if(!expire
&& !printConfig
)
143 printConfigVariables(stdout
, 0);
153 do_daemonise(loggingToStderr());
156 writePid(pidFile
->string
);
158 listener
= create_listener(proxyAddress
->string
,
159 proxyPort
, httpAccept
, NULL
);
161 if(pidFile
) unlink(pidFile
->string
);
167 if(pidFile
) unlink(pidFile
->string
);