0
0
mirror of https://github.com/darkk/redsocks.git synced 2025-08-29 13:15: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); httpr_client *httpr = (void*)(client + 1);
int len = 0; int len = 0;
assert(httpr->client_buffer.len);
assert(client->state >= httpr_recv_request); assert(client->state >= httpr_recv_request);
redsocks_touch_client(client); 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 *confname = "redsocks.conf";
static const char *pidfile = NULL;
static void terminate(int sig, short what, void *_arg) static void terminate(int sig, short what, void *_arg)
{ {
@ -55,7 +56,7 @@ int main(int argc, char **argv)
int opt; int opt;
int i; int i;
while ((opt = getopt(argc, argv, "tc:")) != -1) { while ((opt = getopt(argc, argv, "tc:p:")) != -1) {
switch (opt) { switch (opt) {
case 't': case 't':
conftest = true; conftest = true;
@ -63,10 +64,14 @@ int main(int argc, char **argv)
case 'c': case 'c':
confname = optarg; confname = optarg;
break; break;
case 'p':
pidfile = optarg;
break;
default: default:
printf( printf(
"Usage: %s [-t] [-c config]\n" "Usage: %s [-t] [-c config] [-p pidfile]\n"
" -t test config syntax\n", " -t test config syntax\n"
" -p write pid to pidfile\n",
argv[0]); argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -91,6 +96,7 @@ int main(int argc, char **argv)
error = parser_run(parser); error = parser_run(parser);
parser_stop(parser); parser_stop(parser);
fclose(f); fclose(f);
if (error) if (error)
return EXIT_FAILURE; 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)); assert(SIZEOF_ARRAY(exit_signals) == SIZEOF_ARRAY(terminators));
memset(terminators, 0, sizeof(terminators)); memset(terminators, 0, sizeof(terminators));
for (i = 0; i < SIZEOF_ARRAY(exit_signals); i++) { for (i = 0; i < SIZEOF_ARRAY(exit_signals); i++) {