Add stand-alone example program w/ Makefile and README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
0ade961e60
commit
225d8da17f
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
4
example/Makefile.am
Normal file
4
example/Makefile.am
Normal file
@ -0,0 +1,4 @@
|
||||
EXTRA_DIST = README.md example.c example.mk
|
||||
|
||||
pkgexampledir = $(docdir)/example
|
||||
pkgexample_DATA = $(EXTRA_DIST)
|
55
example/README.md
Normal file
55
example/README.md
Normal file
@ -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
|
||||
|
44
example/example.c
Normal file
44
example/example.c
Normal file
@ -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 <stdio.h>
|
||||
#include <syslog/syslog.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
openlog("example", LOG_PID, LOG_USER);
|
||||
syslogp(LOG_NOTICE, "MSGID", NULL, "Kilroy was here.");
|
||||
closelog();
|
||||
|
||||
return 0;
|
||||
}
|
10
example/example.mk
Normal file
10
example/example.mk
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user