Hi all, I have been briefly working with the creator of darkstat, Emil Mikulic, for improving the use of this software of MacOS. The idea is to have darkstat working nicely as a clean service.
For doing this, Emil have made some changes in the code for adding a new option (--no-daemon, see attached patch) for preventing darkstat to fork when started, and I have created a launchd plist config file for setting up darkstat as a MacOS service (without the need of third part tools like daemonic). The method I am using is to drop a service file into /Library/LaunchDaemons/ (see attached document), and let launchd do its job. This approach means that darkstat run as a system wide service. The trick is just to use a different label for each distribution (fink and macports) in order to avoid conflict in case darkstat is installed from both of them (not a smart move, but anyway...) What I would like to do is to validate those modifications with both of the fink and macports mainteneurs of darkstat, and to make a new release (so I can have it directly on my machines without the need of patching manually; yes, I am lazy :) What do you think of all of this? Damien Clauzel
diff --git a/NEWS b/NEWS index 4a41598..0ec2855 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ debugging purposes. The "-d" argument is no longer recognized, and will prevent darkstat from starting, so make sure you adjust any startup scripts you may have. +After 3.0.708, --debug was split into --verbose and --no-daemon. + Since v3.0.694, darkstat is able to save its internal database into a file and reload it on startup. The file format is, by design, incompatible with the format from darkstat v2. diff --git a/cap.c b/cap.c index 882d63a..3ace4a0 100644 --- a/cap.c +++ b/cap.c @@ -233,7 +233,7 @@ cap_poll(fd_set *read_set break; #endif } - /*FIXME*/fprintf(stderr, "%-20d\r", total); + /*FIXME*/if (want_verbose) fprintf(stderr, "%-20d\r", total); } void diff --git a/darkstat.1 b/darkstat.1 index 2f69b33..58a6b7d 100644 --- a/darkstat.1 +++ b/darkstat.1 @@ -5,7 +5,7 @@ .\" You may use, modify and redistribute this file under the terms of the .\" GNU General Public License version 2. (see COPYING.GPL) .\" -.TH darkstat 1 "May 2008" darkstat "User Manuals" +.TH darkstat 1 "June 2008" darkstat "User Manuals" .SH NAME darkstat v3 \- network statistics gatherer .\" @@ -16,7 +16,9 @@ darkstat v3 \- network statistics gatherer ] [ .BI \-r " file" ] [ -.BI \-\-debug +.BI \-\-verbose +] [ +.BI \-\-no-daemon ] [ .BI \-\-no\-promisc ] [ @@ -81,9 +83,13 @@ and arguments are mutually exclusive. .\" .TP -.BI \-\-debug -Debugging mode: do not detach from the controlling terminal, -stay in the foreground instead. +.BI \-\-verbose +Print debugging messages to the terminal. +.\" +.TP +.BI \-\-no\-daemon +Do not detach from the controlling terminal; +stay in the foreground. .\" .TP .BI \-\-no\-promisc @@ -96,6 +102,8 @@ filter. .TP .BI \-\-no\-dns Do not resolve IPs to host names. +This can significantly reduce memory footprint on small systems +as an extra process is created for DNS resolving. .\" .TP .BI \-p " port" @@ -282,6 +290,11 @@ We only want to account for SSH traffic: darkstat -i fxp0 -f "port 22" .PP .\" +We don't want to account for network internal traffic: +.IP +darkstat \-i fxp0 \-f "not (src net 192.168.0 and dst net 192.168.0)" +.PP +.\" (For a full reference on filter syntax, refer to the .BR tcpdump (1) manpage) diff --git a/darkstat.c b/darkstat.c index 380e585..93df8fe 100644 --- a/darkstat.c +++ b/darkstat.c @@ -69,8 +69,10 @@ static void cb_interface(const char *arg) { interface = arg; } const char *capfile = NULL; static void cb_capfile(const char *arg) { capfile = arg; } +static void cb_verbose(const char *arg _unused_) { want_verbose = 1; } + int want_daemonize = 1; -static void cb_debug(const char *arg _unused_) { want_daemonize = 0; } +static void cb_no_daemon(const char *arg _unused_) { want_daemonize = 0; } int want_promisc = 1; static void cb_no_promisc(const char *arg _unused_) { want_promisc = 0; } @@ -171,7 +173,8 @@ struct cmdline_arg { static struct cmdline_arg cmdline_args[] = { {"-i", "interface", cb_interface, 0}, {"-r", "file", cb_capfile, 0}, - {"--debug", NULL, cb_debug, 0}, + {"--verbose", NULL, cb_verbose, 0}, + {"--no-daemon", NULL, cb_no_daemon, 0}, {"--no-promisc", NULL, cb_no_promisc, 0}, {"--no-dns", NULL, cb_no_dns, 0}, {"-p", "port", cb_port, 0}, @@ -208,7 +211,9 @@ usage(void) int width, first; struct cmdline_arg *arg; - printf("\n"); + printf(PACKAGE_STRING " (built with libpcap %d.%d)\n\n", + PCAP_VERSION_MAJOR, PCAP_VERSION_MINOR); + width = printf("usage: darkstat "); first = 1; @@ -310,9 +315,6 @@ int main(int argc, char **argv) { test_64order(); - printf(PACKAGE_STRING " (built with libpcap %d.%d)\n", - PCAP_VERSION_MAJOR, PCAP_VERSION_MINOR); - parse_cmdline(argc-1, argv+1); if (capfile) { diff --git a/err.c b/err.c index cb3aad6..0628cd7 100644 --- a/err.c +++ b/err.c @@ -1,5 +1,5 @@ /* darkstat 3 - * copyright (c) 2001-2007 Emil Mikulic. + * copyright (c) 2001-2008 Emil Mikulic. * * err.c: BSD-like err() and warn() functions * @@ -127,11 +127,14 @@ unlock(void) } } +int want_verbose = 0; + void verbosef(const char *format, ...) { va_list va; + if (!want_verbose) return; lock(); fprintf(stderr, "darkstat (%05d): ", (int)getpid()); va_start(va, format); diff --git a/err.h b/err.h index fbc87c3..602d849 100644 --- a/err.h +++ b/err.h @@ -1,5 +1,5 @@ /* darkstat 3 - * copyright (c) 2001-2007 Emil Mikulic. + * copyright (c) 2001-2008 Emil Mikulic. * * err.h: BSD-like err() and warn() functions * @@ -22,6 +22,7 @@ void errx(const int code, const char *format, ...); void warn(const char *format, ...); void warnx(const char *format, ...); +extern int want_verbose; void verbosef(const char *format, ...); void dverbosef(const char *format _unused_, ...);
DISTRIB.darkstat.plist
Description: XML document
signature.asc
Description: Ceci est une partie de message numériquement signée
_______________________________________________ macports-users mailing list macports-users@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macports-users