]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
command line option support
authorlaforge <laforge>
Tue, 16 Apr 2002 12:44:41 +0000 (12:44 +0000)
committerlaforge <laforge>
Tue, 16 Apr 2002 12:44:41 +0000 (12:44 +0000)
README
ulogd.c
ulogd.init

diff --git a/README b/README
index b6f1eab73d5b69e39543832ba22601a984120dfe..dd41f77461a11c9e197c2c36f146e558149270a1 100644 (file)
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
 Userspace logging facility for netfilter / linux 2.4
-$Id: README,v 1.5 2001/05/20 13:51:46 laforge Exp $
+$Id: README,v 1.6 2001/05/20 15:01:35 laforge Exp $
 
 Project Homepage: http://www.gnumonks.org/projects/
 Mailinglist: http://lists.gnumonks.org/mailman/listinfo/ulogd/
@@ -38,7 +38,9 @@ logging to a file) are included.
 
 ===> USAGE
 
-YOU MUST INSTALL THE ulog-patch from netfilter patch-o-matic FIRST !!
+The kernel part of the userspace logging facility (ipt_ULOG.o) is included
+in kernels >= 2.4.18-pre8.  If you are running older kernel versions, you MUST
+install the ulog-patch from netfilter patch-o-matic FIRST !!
 
 Please go to the netfilter homepage (http://netfilter.gnumonks.org/)
 and download the latest iptables package.  There is a system called
@@ -75,14 +77,14 @@ group 32. All packets get tagged with the ulog prefix "inp"
 
 iptables -A INPUT -j ULOG -p tcp --dport 80 --ulog-nlgroup 32 --ulog-prefix inp
 
-In the latest Version (0.2) I added another parameter (--ulog-cprange). 
+Since version 0.2,  I added another parameter (--ulog-cprange). 
 Using this parameter You are able to specify how much octets of the 
 packet should be copied from the kernel to userspace. 
 Setting --ulog-cprange to 0 does always copy the whole packet. Default is 0
 
 ===> COPYRIGHT + CREDITS
 
-The code is (C) 2000 by Harald Welte <laforge@gnumonks.org>
+The code is (C) 2000-2002 by Harald Welte <laforge@gnumonks.org>
 
 Thanks also to the valuable Contributions of Daniel Stone, Alexander
 Janssen and Michael Stolovitzsky.
diff --git a/ulogd.c b/ulogd.c
index 4abbd5a0ba694c349bcd6c87d10a513785fa61ca..b70a1f3c6e7380a4ed0397c2a91f29f16d2cc26b 100644 (file)
--- a/ulogd.c
+++ b/ulogd.c
@@ -1,6 +1,6 @@
-/* ulogd, Version $Revision: 1.22 $
+/* ulogd, Version $Revision: 1.23 $
  *
- * $Id: ulogd.c,v 1.22 2001/07/04 00:22:54 laforge Exp $
+ * $Id: ulogd.c,v 1.23 2001/09/01 11:56:27 laforge Exp $
  *
  * userspace logging daemon for the netfilter ULOG target
  * of the linux 2.4 netfilter subsystem.
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: ulogd.c,v 1.16 2001/05/26 23:19:28 laforge Exp $
+ * $Id: ulogd.c,v 1.23 2001/09/01 11:56:27 laforge Exp $
  *
  * Modifications:
  *     14 Jun 2001 Martin Josefsson <gandalf@wlug.westbo.se>
  *             - added SIGHUP handler for logfile cycling
+ *
+ *     10 Feb 2002 Alessandro Bono <a.bono@libero.it>
+ *             - added support for non-fork mode
+ *             - added support for logging to stdout
  */
 
+#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -36,6 +41,7 @@
 #include <dlfcn.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <getopt.h>
 #include <libipulog/libipulog.h>
 #include "conffile.h"
 #include "ulogd.h"
@@ -446,11 +452,15 @@ static int load_plugin(char *file)
 /* open the logfile */
 static int logfile_open(const char *name)
 {
-       logfile = fopen(name, "a");
-       if (!logfile) {
-               fprintf(stderr, "ERROR: unable to open logfile %s: %s\n", 
-                       name, strerror(errno));
-               exit(2);
+       if (!strcmp(name,"stdout")) {
+               logfile = stdout;
+       else {
+               logfile = fopen(name, "a");
+               if (!logfile) {
+                       fprintf(stderr, "ERROR: can't open logfile %s: %s\n", 
+                               name, strerror(errno));
+                       exit(2);
+               }
        }
        return 0;
 }
@@ -523,7 +533,8 @@ static void sigterm_handler(int signal)
 
        ipulog_destroy_handle(libulog_h);
        free(libulog_buf);
-       fclose(logfile);
+       if (logfile != stdout)
+               fclose(logfile);
        exit(0);
 }
 
@@ -539,11 +550,46 @@ static void sighup_handler(int signal)
        }
 }
 
+static struct option opts[] = {
+       { "version", 0, NULL, 'V' },
+       { "daemon", 0, NULL, 'd' },
+       { "help", 0, NULL, 'h' },
+       { 0 }
+};
+
 int main(int argc, char* argv[])
 {
        int len;
+       char argch;
+       int daemonize = 0;
        ulog_packet_msg_t *upkt;
 
+       while ((argch = getopt_long(argc, argv, "Vdh::", opts, NULL)) != -1) {
+               switch (argch) {
+               default:
+               case '?':
+                       if (isprint(optopt))
+                               fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+                       else
+                               fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+
+                       print_usage();
+                       exit(1);
+                       break;
+               case 'h':
+                       print_usage();
+                       exit(0);
+                       break;
+               case 'd':
+                       daemonize = 1;
+                       break;
+               case 'V':
+                       printf("ulogd Version %s\n");
+                       printf("Copyright (C) 2000-2002 Harald Welte\n");
+                       break
+               }
+       }
+
        if (init_conffile(ULOGD_CONFIGFILE)) {
                ulogd_log(ULOGD_FATAL, "parse_conffile error\n");
                exit(1);
@@ -577,41 +623,38 @@ int main(int argc, char* argv[])
                exit(1);
        }
 
-#ifndef DEBUG
-       if (!fork()) { 
-
-               fclose(stdout);
+       if (daemonize){
+               if (fork()) {
+                       exit(0);
+               }
+               if (logfile != stdout)
+                       fclose(stdout);
                fclose(stderr);
-#endif
-               signal(SIGTERM, &sigterm_handler);
-               signal(SIGHUP, &sighup_handler);
+       }
 
-               ulogd_log(ULOGD_NOTICE, 
-                         "initialization finished, entering main loop\n");
-
-               /* endless loop receiving packets and handling them over to
-                * handle_packet */
-               while (len = ipulog_read(libulog_h, libulog_buf, MYBUFSIZ, 1)) {
-
-                       if (len <= 0) {
-                               /* this is not supposed to happen */
-                               ulogd_log(ULOGD_ERROR, "ipulog_read == %d!\n",
-                                         len);
-                       } else {
-                               while (upkt = ipulog_get_packet(libulog_h,
-                                                      libulog_buf, len)) {
-                                       DEBUGP("==> packet received\n");
-                                       handle_packet(upkt);
-                               }
-                       }
-               }
+       signal(SIGTERM, &sigterm_handler);
+       signal(SIGHUP, &sighup_handler);
+
+       ulogd_log(ULOGD_NOTICE, 
+                 "initialization finished, entering main loop\n");
 
-               /* hackish, but result is the same */
-               sigterm_handler(SIGTERM);       
+       /* endless loop receiving packets and handling them over to
+        * handle_packet */
+       while (len = ipulog_read(libulog_h, libulog_buf, MYBUFSIZ, 1)) {
 
-#ifndef DEBUG
-       } else {
-               exit(0);
+               if (len <= 0) {
+                       /* this is not supposed to happen */
+                       ulogd_log(ULOGD_ERROR, "ipulog_read == %d!\n",
+                                 len);
+               } else {
+                       while (upkt = ipulog_get_packet(libulog_h,
+                                              libulog_buf, len)) {
+                               DEBUGP("==> packet received\n");
+                               handle_packet(upkt);
+                       }
+               }
        }
-#endif
+
+       /* hackish, but result is the same */
+       sigterm_handler(SIGTERM);       
 }
index f56e3c5368f5c578cdbd5ae38b2fd30cef76ca5c..b58a6f7dfc45f9bb95a158ab8d9c51b916c4808b 100755 (executable)
@@ -10,7 +10,7 @@
 
 function start()
 {
-       gprintf "Starting %s: " "ulogd"
+       printf "Starting %s: " "ulogd"
        daemon /usr/sbin/ulogd
        echo
        touch /var/lock/subsys/ulogd
@@ -19,8 +19,8 @@ function start()
 
 function stop()
 {
-       gprintf "Stopping %s: " "ulogd"
-       killprocparent ulogd
+       printf "Stopping %s: " "ulogd"
+       killproc ulogd
        echo
        rm -f /var/lock/subsys/ulogd
 }
@@ -28,7 +28,7 @@ function stop()
 
 function reload()
 {
-       pid=`pidoffather ulogd`
+       pid=`pidof ulogd`
        if [ "x$pid" != "x" ]; then
                kill -HUP $pid 2>/dev/null
        fi
@@ -54,7 +54,7 @@ case "$1" in
        status ulogd
        ;;
   *)
-       gprintf "Usage: %s {start|stop|status|restart|reload}\n" "ulogd"
+       printf "Usage: %s {start|stop|status|restart|reload}\n" "ulogd"
        exit 1
 esac