diff --git a/Makefile.am b/Makefile.am index a08460d..6b30981 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -SUBDIRS = man src test +SUBDIRS = example man src test doc_DATA = README.md ChangeLog.md syslog.conf EXTRA_DIST = README.md ChangeLog.md syslog.conf diff --git a/configure.ac b/configure.ac index e5b55e1..22c958e 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,7 @@ AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_SRCDIR([src/syslogd.c]) AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([Makefile + example/Makefile man/Makefile src/Makefile src/libsyslog.pc diff --git a/example/Makefile.am b/example/Makefile.am new file mode 100644 index 0000000..7873168 --- /dev/null +++ b/example/Makefile.am @@ -0,0 +1,4 @@ +EXTRA_DIST = README.md example.c example.mk + +pkgexampledir = $(docdir)/example +pkgexample_DATA = $(EXTRA_DIST) diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..31d5918 --- /dev/null +++ b/example/README.md @@ -0,0 +1,55 @@ +Stand-alone Example syslogp() Application +========================================= + +This is a *very* simple stand-alone example application. The purpose is +to show how to use the sysklogd 2.x API, e.g. `syslogp()`, to use "new" +RFC5424 features like MsgID. + +Included in this directory are two files: + + - `example.c`: actual C code example + - `example.mk`: plain Makefile for building `example` + +Provided the two files are in the same (writable) directory, you can +build the application like this: + + make -f example.mk + + +GNU Autotools +------------- + +If you want to use GNU autoconf & automake instead. The following is +recommended in `configure.ac` and `Makefile.am` to build your +application. + +```sh +# configure.ac (snippet) + +# Check for pkg-config tool, required for next step +PKG_PROG_PKG_CONFIG + +# Check for required libraries +PKG_CHECK_MODULES([syslog], [libsyslog >= 2.0]) +``` + +and + +```Makefile +# Makefile.am (snippet) + +bin_PROGRAMS = example + +example_SOURCES = example.c +example_CFLAGS = $(syslog_CFLAGS) +example_LDADD = $(syslog_LIBS) +``` + +**NOTE:** Most free/open source software that uses `configure` default + to install to `/usr/local`. However, some Linux distributions do no + longer search that path for installed software, e.g. Fedora and Alpine + Linux. To help your configure script find its dependencies you have + to give the `pkg-config` a prefix path: + + PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig ./configure + diff --git a/example/example.c b/example/example.c new file mode 100644 index 0000000..7e1e857 --- /dev/null +++ b/example/example.c @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* Example of how to use NetBSD syslogp() API with libsyslog from sysklogd */ + +#include +#include + +int main(void) +{ + openlog("example", LOG_PID, LOG_USER); + syslogp(LOG_NOTICE, "MSGID", NULL, "Kilroy was here."); + closelog(); + + return 0; +} diff --git a/example/example.mk b/example/example.mk new file mode 100644 index 0000000..6c1b2b7 --- /dev/null +++ b/example/example.mk @@ -0,0 +1,10 @@ +# Simple Makefile for syslogp() example application +# +EXEC := example +OBJS := example.o +CFLAGS := `pkg-config --cflags libsyslog` +LDLIBS := `pkg-config --libs --static libsyslog` + +all: $(EXEC) + +$(EXEC): $(OBJS)