0
0
mirror of https://github.com/darkk/redsocks.git synced 2025-08-28 12:45:30 +00:00

add pidfile option

This commit is contained in:
Bin Jin 2010-11-24 14:44:02 +08:00
parent 651754834f
commit 0ed9eeb920
2 changed files with 19 additions and 4 deletions

View File

@ -267,7 +267,6 @@ static void httpr_relay_write_cb(struct bufferevent *buffev, void *_arg)
httpr_client *httpr = (void*)(client + 1);
int len = 0;
assert(httpr->client_buffer.len);
assert(client->state >= httpr_recv_request);
redsocks_touch_client(client);

22
main.c
View File

@ -38,6 +38,7 @@ app_subsys *subsystems[] = {
};
static const char *confname = "redsocks.conf";
static const char *pidfile = NULL;
static void terminate(int sig, short what, void *_arg)
{
@ -55,7 +56,7 @@ int main(int argc, char **argv)
int opt;
int i;
while ((opt = getopt(argc, argv, "tc:")) != -1) {
while ((opt = getopt(argc, argv, "tc:p:")) != -1) {
switch (opt) {
case 't':
conftest = true;
@ -63,10 +64,14 @@ int main(int argc, char **argv)
case 'c':
confname = optarg;
break;
case 'p':
pidfile = optarg;
break;
default:
printf(
"Usage: %s [-t] [-c config]\n"
" -t test config syntax\n",
"Usage: %s [-t] [-c config] [-p pidfile]\n"
" -t test config syntax\n"
" -p write pid to pidfile\n",
argv[0]);
return EXIT_FAILURE;
}
@ -91,6 +96,7 @@ int main(int argc, char **argv)
error = parser_run(parser);
parser_stop(parser);
fclose(f);
if (error)
return EXIT_FAILURE;
@ -107,6 +113,16 @@ int main(int argc, char **argv)
}
}
if (pidfile) {
f = fopen(pidfile, "w");
if (!f) {
perror("Unable to open pidfile for write");
return EXIT_FAILURE;
}
fprintf(f, "%d\n", getpid());
fclose(f);
}
assert(SIZEOF_ARRAY(exit_signals) == SIZEOF_ARRAY(terminators));
memset(terminators, 0, sizeof(terminators));
for (i = 0; i < SIZEOF_ARRAY(exit_signals); i++) {