diff --git a/http-relay.c b/http-relay.c index 37dfda4..1e3ae67 100644 --- a/http-relay.c +++ b/http-relay.c @@ -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); diff --git a/main.c b/main.c index 959cf58..89a2cce 100644 --- a/main.c +++ b/main.c @@ -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++) {