Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/man8/tinyproxy.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Use an alternate configuration file.

Don't daemonize and stay in the foreground. Useful for debugging purposes.

=item B<-n <file-descriptor>>

After initialization write a newline to an open file-descriptor then close it.
This is to notify a service supervisor that Tinyproxy is up and ready.

=item B<-h>

Display a short help screen of command line arguments and exit.
Expand Down
21 changes: 20 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ display_usage (void)
"Options are:\n"
" -d Do not daemonize (run in foreground).\n"
" -c FILE Use an alternate configuration file.\n"
" -n FD Send a ready notification on an open FD.\n"
" -h Display this usage information.\n"
" -v Display version information.\n");

Expand Down Expand Up @@ -291,6 +292,7 @@ int
main (int argc, char **argv)
{
int opt, daemonized = TRUE;
int notify_fd = -1;

srand(time(NULL)); /* for hashmap seeds */

Expand All @@ -308,7 +310,7 @@ main (int argc, char **argv)

config_file = SYSCONFDIR "/tinyproxy.conf";

while ((opt = getopt (argc, argv, "c:vdh")) != EOF) {
while ((opt = getopt (argc, argv, "c:n:vdh")) != EOF) {
switch (opt) {
case 'v':
display_version ();
Expand All @@ -322,6 +324,14 @@ main (int argc, char **argv)
config_file = optarg;
break;

case 'n':
notify_fd = atoi(optarg);
if (notify_fd < 3) {
fprintf (stderr, "Notification FD must be 3 or greater.\n");
exit (EX_OSERR);
}
break;

case 'h':
display_usage ();
exit (EX_OK);
Expand Down Expand Up @@ -404,6 +414,15 @@ main (int argc, char **argv)
/* Start the main loop */
log_message (LOG_INFO, "Starting main loop. Accepting connections.");

/* Notify a service supervisor */
if (notify_fd >= 3) {
if (write(notify_fd, "\n", 1) != 1)
log_message (LOG_WARNING,
"Failed to send readiness notification on FD%d: %s.",
notify_fd, strerror (errno));
close(notify_fd);
}

child_main_loop ();

log_message (LOG_NOTICE, "Shutting down.");
Expand Down
Loading