[Pkg-ocaml-maint-commits] r1344 - in trunk/projects/approx: . debian
Eric Cooper
ecc-guest@costa.debian.org
Thu, 05 May 2005 15:21:55 +0000
Author: ecc-guest
Date: 2005-05-05 15:21:54 +0000 (Thu, 05 May 2005)
New Revision: 1344
Modified:
trunk/projects/approx/approx.8
trunk/projects/approx/approx.ml
trunk/projects/approx/debian/NEWS
trunk/projects/approx/debian/changelog
trunk/projects/approx/gc_approx.ml
Log:
added --foreground and --error options to approx (closes: #306898)
Modified: trunk/projects/approx/approx.8
===================================================================
--- trunk/projects/approx/approx.8 2005-05-04 02:28:31 UTC (rev 1343)
+++ trunk/projects/approx/approx.8 2005-05-05 15:21:54 UTC (rev 1344)
@@ -11,6 +11,7 @@
.SH SYNOPSIS
.PP
.B approx
+[\fIOPTION\fP]...
.SH DESCRIPTION
.B approx
@@ -30,6 +31,16 @@
.BR gc_approx (8)
program removes these from the cache.
+.SH OPTIONS
+.TP
+.BR \-e ", " \-\^\-error
+Messages are printed to standard error instead of the system log.
+.TP
+.BR \-f ", " \-\^\-foreground
+The
+.B approx
+server runs in the foreground instead of detaching as a daemon.
+
.SH EXAMPLES
By default,
.B approx
Modified: trunk/projects/approx/approx.ml
===================================================================
--- trunk/projects/approx/approx.ml 2005-05-04 02:28:31 UTC (rev 1343)
+++ trunk/projects/approx/approx.ml 2005-05-05 15:21:54 UTC (rev 1344)
@@ -6,14 +6,46 @@
open Default_config
open Http_daemon
open Printf
+open Unix
+let usage () =
+ prerr_endline "Usage: approx [options]";
+ prerr_endline "Proxy server for Debian archive files";
+ prerr_endline "Options:";
+ prerr_endline " -e|--error log to stderr instead of syslog";
+ prerr_endline " -f|--foreground stay in foreground instead of detaching";
+ exit 1
+
+let use_stderr = ref false
+let foreground = ref false
+
+let () =
+ for i = 1 to Array.length Sys.argv - 1 do
+ match Sys.argv.(i) with
+ | "-e" | "--error" -> use_stderr := true
+ | "-f" | "--foreground" -> foreground := true
+ | _ -> usage ()
+ done
+
let prog = Filename.basename Sys.argv.(0)
-let log = Syslog.openlog ~facility: `LOG_DAEMON prog
+let log =
+ if !use_stderr then
+ None
+ else
+ Some (Syslog.openlog ~facility: `LOG_DAEMON prog)
-let message fmt = kprintf (Syslog.syslog log `LOG_INFO) fmt
+let message fmt =
+ let print =
+ match log with
+ | Some conn -> Syslog.syslog conn `LOG_INFO
+ | None -> prerr_endline
+ in
+ kprintf print fmt
let error_message = function
+ | Sys_error str ->
+ message "%s" str
| Unix.Unix_error (err, str, arg) ->
if err = Unix.EADDRINUSE && str = "bind" then
begin
@@ -337,17 +369,24 @@
| [] -> serve_file req#path req#headers chan
| _ -> respond_forbidden ~url: req#path chan
-let daemon () =
- ignore (Unix.setsid ());
- List.iter Unix.close [Unix.stdin; Unix.stdout; Unix.stderr];
+let server () =
try
Unix.chdir cache_dir;
print_config ();
main (daemon_spec ~port ~callback ~mode: `Single ~timeout: None ())
with e ->
- error_message e
+ error_message e;
+ exit 1
+let daemonize proc =
+ ignore (setsid ());
+ List.iter close [stdin; stdout; stderr];
+ (* double fork to detach daemon *)
+ if fork () = 0 && fork () = 0 then
+ proc ()
+
let () =
- (* double fork to detach daemon *)
- if Unix.fork () = 0 && Unix.fork () = 0 then
- daemon ()
+ if !foreground then
+ server ()
+ else
+ daemonize server
Modified: trunk/projects/approx/debian/NEWS
===================================================================
--- trunk/projects/approx/debian/NEWS 2005-05-04 02:28:31 UTC (rev 1343)
+++ trunk/projects/approx/debian/NEWS 2005-05-05 15:21:54 UTC (rev 1344)
@@ -1,3 +1,10 @@
+approx (1.14) unstable; urgency=low
+
+The --foreground and --error options allow approx to be run more
+easily from the command line, a debugger, or the runit init scheme.
+
+ -- Eric Cooper <ecc@cmu.edu> Thu, 5 May 2005 10:43:36 -0400
+
approx (1.13) unstable; urgency=low
The approx daemon always uses /var/cache/approx now;
Modified: trunk/projects/approx/debian/changelog
===================================================================
--- trunk/projects/approx/debian/changelog 2005-05-04 02:28:31 UTC (rev 1343)
+++ trunk/projects/approx/debian/changelog 2005-05-05 15:21:54 UTC (rev 1344)
@@ -1,3 +1,9 @@
+approx (1.14) unstable; urgency=low
+
+ * added --foreground and --error options to approx (closes: #306898)
+
+ -- Eric Cooper <ecc@cmu.edu> Thu, 5 May 2005 10:43:36 -0400
+
approx (1.13) unstable; urgency=low
* make sure /var/cache/approx exists before trying to chown it
Modified: trunk/projects/approx/gc_approx.ml
===================================================================
--- trunk/projects/approx/gc_approx.ml 2005-05-04 02:28:31 UTC (rev 1343)
+++ trunk/projects/approx/gc_approx.ml 2005-05-05 15:21:54 UTC (rev 1344)
@@ -14,7 +14,7 @@
let usage () =
prerr_endline "Usage: gc_approx [options]";
- prerr_endline "Garbage-collect the approx cache.";
+ prerr_endline "Garbage-collect the approx cache";
prerr_endline "Options:";
prerr_endline " -f|--fast do not validate MD5 checksums";
prerr_endline " -k|--keep do not remove files";