From e774e8ef3467e81ed502e19b1719b4ab384d0083 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Jul 2003 14:18:41 +0000 Subject: Moved to trunk git-svn-id: file:///home/lennart/svn/public/libdaemon/trunk@38 153bfa13-eec0-0310-be40-b0cb6a0e1b4b --- LICENSE | 340 ++++++++++++++++++ Makefile.am | 36 ++ bootstrap.sh | 40 +++ configure.ac | 97 +++++ doc/Makefile.am | 53 +++ doc/README.html.in | 119 ++++++ doc/doxygen.conf.in | 997 +++++++++++++++++++++++++++++++++++++++++++++++++++ doc/style.css | 10 + examples/Makefile.am | 24 ++ examples/testd.c | 158 ++++++++ libdaemon.spec.in | 73 ++++ src/Makefile.am | 29 ++ src/dfork.c | 207 +++++++++++ src/dfork.h | 87 +++++ src/dlog.c | 58 +++ src/dlog.h | 63 ++++ src/dnonblock.c | 37 ++ src/dnonblock.h | 37 ++ src/dpid.c | 124 +++++++ src/dpid.h | 73 ++++ src/dsignal.c | 132 +++++++ src/dsignal.h | 65 ++++ 22 files changed, 2859 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile.am create mode 100755 bootstrap.sh create mode 100644 configure.ac create mode 100644 doc/Makefile.am create mode 100644 doc/README.html.in create mode 100644 doc/doxygen.conf.in create mode 100644 doc/style.css create mode 100644 examples/Makefile.am create mode 100644 examples/testd.c create mode 100644 libdaemon.spec.in create mode 100644 src/Makefile.am create mode 100644 src/dfork.c create mode 100644 src/dfork.h create mode 100644 src/dlog.c create mode 100644 src/dlog.h create mode 100644 src/dnonblock.c create mode 100644 src/dnonblock.h create mode 100644 src/dpid.c create mode 100644 src/dpid.h create mode 100644 src/dsignal.c create mode 100644 src/dsignal.h diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d60c31a --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..97b9f7b --- /dev/null +++ b/Makefile.am @@ -0,0 +1,36 @@ +# $Id$ +# +# This file is part of libdaemon. +# +# libdaemon is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# libdaemon is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libdaemon; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +EXTRA_DIST=bootstrap.sh README LICENSE libdaemon.spec +SUBDIRS=src doc examples + +MAINTAINERCLEANFILES = README libdaemon.spec +noinst_DATA = README libdaemon.spec + +README: + rm -f README + $(MAKE) -C doc README + ln -s doc/README README + +homepage: + test -d $$HOME/homepage/lennart + mkdir -p $$HOME/homepage/lennart/projects/libdaemon + cp *.tar.gz $$HOME/homepage/lennart/projects/libdaemon + cp doc/README.html doc/style.css $$HOME/homepage/lennart/projects/libdaemon + cp $$HOME/homepage/lennart/projects/libdaemon/README.html $$HOME/homepage/lennart/projects/libdaemon/index.html + cp -av doc/reference/ $$HOME/homepage/lennart/projects/libdaemon/ diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..e4bc091 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# $Id$ + +# This file is part of libdaemon. +# +# libdaemon is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# libdaemon is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libdaemon; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +if [ "x$1" = "xam" ] ; then + set -ex + automake -a -c + ./config.status +else + set -ex + + make maintainer-clean || true + + rm -rf autom4te.cache + rm -f config.cache + + aclocal + libtoolize -c --force + autoheader + automake -a -c + autoconf -Wall + + ./configure "$@" +fi + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..884d8d0 --- /dev/null +++ b/configure.ac @@ -0,0 +1,97 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +# $Id$ + +# This file is part of libdaemon. +# +# libdaemon is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# libdaemon is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libdaemon; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +AC_PREREQ(2.57) +AC_INIT([libdaemon], [0.3], [mzqnrzba@itaparica.org]) +AC_CONFIG_SRCDIR([src/dfork.c]) +AC_CONFIG_HEADERS([config.h]) +AM_INIT_AUTOMAKE([foreign -Wall]) +AM_MAINTAINER_MODE + +# Checks for programs. +AC_PROG_CC +AC_PROG_CXX +AC_PROG_LIBTOOL + +# If using GCC specifiy some additional parameters +if test "x$GCC" = "xyes" ; then + CFLAGS="$CFLAGS -pipe -Wall" +fi + +# Checks for libraries. + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h syslog.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_PID_T +AC_HEADER_TIME +AC_C_VOLATILE + +# Checks for library functions. +AC_FUNC_FORK +AC_FUNC_SELECT_ARGTYPES +AC_FUNC_VPRINTF +AC_CHECK_FUNCS([select strerror dup2 memset strrchr]) +AC_TYPE_MODE_T + +# DOXYGEN documentation generation +AC_ARG_ENABLE(doxygen, + AC_HELP_STRING([--disable-doxygen], [Turn off doxygen usage for documentation generation]), +[case "${enableval}" in + yes) doxygen=yes ;; + no) doxygen=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --disable-doxygen) ;; +esac],[doxygen=yes]) + +if test x$doxygen = xyes ; then + AC_CHECK_PROG(have_doxygen, doxygen, yes, no) + + if test x$have_doxygen = xno ; then + AC_MSG_ERROR([*** Sorry, you have to install doxygen or use --disable-doxygen ***]) + fi +fi + +AM_CONDITIONAL([USE_DOXYGEN], [test "x$doxygen" = xyes]) + +# LYNX documentation generation +AC_ARG_ENABLE(lynx, + AC_HELP_STRING([--disable-lynx], [Turn off lynx usage for documentation generation]), +[case "${enableval}" in + yes) lynx=yes ;; + no) lynx=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --disable-lynx) ;; +esac],[lynx=yes]) + +if test x$lynx = xyes ; then + AC_CHECK_PROG(have_lynx, lynx, yes, no) + + if test x$have_lynx = xno ; then + AC_MSG_ERROR([*** Sorry, you have to install lynx or use --disable-lynx ***]) + fi +fi + +AM_CONDITIONAL([USE_LYNX], [test "x$lynx" = xyes]) + +AC_CONFIG_FILES([src/Makefile Makefile doc/Makefile doc/README.html doc/doxygen.conf examples/Makefile libdaemon.spec]) +AC_OUTPUT diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..c9f5c50 --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,53 @@ +# $Id$ + +# This file is part of libdaemon. +# +# libdaemon is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# libdaemon is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libdaemon; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +noinst_DATA = README.html README reference +MAINTAINERCLEANFILES = README README.html +EXTRA_DIST = style.css README README.html README.html.in reference +CLEANFILES = + +if USE_DOXYGEN +reference: doxygen.conf + doxygen doxygen.conf + touch reference + +doxygen: + touch doxygen.conf + $(MAKE) reference + + +maintainer-clean-local: + rm -rf reference +endif + +if USE_LYNX +README: README.html + lynx --dump $^ | sed 's,file://localhost/.*/doc/README.html,README,' | sed 's,file://localhost/.*/doc/reference/,reference/,' > $@ + +CLEANFILES += README +endif + +tidy: README.html + tidy -e < README.html + +if USE_DOXYGEN +.PHONY: doxygen tidy +else +.PHONY: tidy +endif + diff --git a/doc/README.html.in b/doc/README.html.in new file mode 100644 index 0000000..0ca5307 --- /dev/null +++ b/doc/README.html.in @@ -0,0 +1,119 @@ + + + + + +libdaemon @PACKAGE_VERSION@ + + + + +

libdaemon @PACKAGE_VERSION@

+ +

Copyright 2003 Lennart Poettering <mzyvoqnrzba [at] itaparica.org>

+ + + +

License

+ +

This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version.

+ +

This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.

+ +

You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

+ +

News

+ +
Thu July 10 2003:
+

Version 0.3 released; changes include: documentation update, build fixes, RPM spec file added

+ +
Thu July 10 2003:
+

Version 0.2 released; changes include: ugly umask error fix, documentation update

+ +
Mon July 7 2003:
+

Version 0.1 released

+ +

Overview

+ +

libdaemon is a lightweight C library which eases the writing of UNIX +daemons. It consists of the following parts:

+ +
    +
  • A wrapper around fork() which does the correct + daemonization procedure of a process
  • + +
  • A wrapper around syslog() for simpler and compatible + log output to Syslog or STDERR
  • + +
  • An API for writing PID files
  • + +
  • An API for serializing UNIX signals into a pipe for + usage with select() or poll()
  • +
+ +

Routines like these are included in most of the daemon software +available. It is not that simple to get it done right and code +duplication cannot be a goal.

+ +

libdaemon is currently used by ifplugd.

+ +

Status

+ +

Version 0.1 is feature complete.

+ +

Documentation

+ +

An extensive API reference is available

+ +

Requirements

+ +

libdaemon was developed and tested on Debian GNU/Linux +"testing" from Jul 2003, it should work on most other Linux +distributions (and maybe Unix versions) since it uses GNU Autoconf and +GNU libtool for source code configuration and shared library +management.

+ +

Installation

+ +

As this package is made with the GNU autotools you should run +./configure inside the distribution directory for configuring +the source tree. After that you should run make for +compilation and make install (as root) for installation of +libdaemon.

+ +

Acknowledgements

+ +

No special acknowledgements at this time, I am sorry.

+ +

Download

+ +

The newest release is always available from http://www.stud.uni-hamburg.de/~lennart/projects/libdaemon/

+ +

The current release is @PACKAGE_VERSION@

+ +
+
Lennart Poettering <mzyvoqnrzba [at] itaparica.org>, July 2003
+
$Id$
+ + + diff --git a/doc/doxygen.conf.in b/doc/doxygen.conf.in new file mode 100644 index 0000000..1d3430d --- /dev/null +++ b/doc/doxygen.conf.in @@ -0,0 +1,997 @@ +# $Id$ + +# Doxyfile 1.2.18 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = "@PACKAGE_NAME@" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = "@PACKAGE_VERSION@" + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = reference + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, +# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en +# (Japanese with english messages), Korean, Norwegian, Polish, Portuguese, +# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish and Ukrainian. + +OUTPUT_LANGUAGE = English + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = YES + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these class will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = YES + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited +# members of a class in the documentation of that class as if those members were +# ordinary class members. Constructors, destructors and assignment operators of +# the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = NO + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. It is allowed to use relative paths in the argument list. + +STRIP_FROM_PATH = + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower case letters. If set to YES upper case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# users are adviced to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explict @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# reimplements. + +INHERIT_DOCS = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = NO + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = NO + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = NO + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consist of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. +# For instance some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = ../src/ +#../examples/testd.c + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp +# *.h++ *.idl *.odl + +FILE_PATTERNS = *.h + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories +# that are symbolic links (a Unix filesystem feature) are excluded from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = "../examples/" + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = *.c + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. + +INPUT_FILTER = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output dir. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non empty doxygen will try to run +# the html help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the Html help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript and frames is required (for instance Mozilla, Netscape 4.0+, +# or Internet explorer 4.0+). Note that for large projects the tree generation +# can take a very long time. In such cases it is better to disable this feature. +# Windows users are probably better off using the HTML help feature. + +GENERATE_TREEVIEW = YES + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimised for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assigments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = YES + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_XML = NO + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional + +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse the +# parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES tag can be used to specify one or more tagfiles. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in Html, RTF and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. Note that this +# option is superceded by the HAVE_DOT option below. This is only a fallback. It is +# recommended to install and use dot, since it yield more powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found on the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermedate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO + +# The CGI_NAME tag should be the name of the CGI script that +# starts the search engine (doxysearch) with the correct parameters. +# A script with this name will be generated by doxygen. + +CGI_NAME = search.cgi + +# The CGI_URL tag should be the absolute URL to the directory where the +# cgi binaries are located. See the documentation of your http daemon for +# details. + +CGI_URL = + +# The DOC_URL tag should be the absolute URL to the directory where the +# documentation is located. If left blank the absolute path to the +# documentation, with file:// prepended to it, will be used. + +DOC_URL = + +# The DOC_ABSPATH tag should be the absolute path to the directory where the +# documentation is located. If left blank the directory on the local machine +# will be used. + +DOC_ABSPATH = + +# The BIN_ABSPATH tag must point to the directory where the doxysearch binary +# is installed. + +BIN_ABSPATH = /usr/local/bin/ + +# The EXT_DOC_PATHS tag can be used to specify one or more paths to +# documentation generated for other projects. This allows doxysearch to search +# the documentation for these projects as well. + +EXT_DOC_PATHS = diff --git a/doc/style.css b/doc/style.css new file mode 100644 index 0000000..2535ff1 --- /dev/null +++ b/doc/style.css @@ -0,0 +1,10 @@ +/* $Id$ */ +body { color: black; background-color: white; margin: 0.5cm; } +a:link, a:visited { color: #900000; } +p { margin-left: 0.5cm; margin-right: 0.5cm; } +div.news-date { margin-left: 0.5cm; font-size: 80%; color: #4f0000; } +p.news-text { margin-left: 1cm; } +ul { margin-left: 0.5cm; } +h1 { color: #00009F; } +h2 { color: #00009F; } +h3 { color: #00004F; margin-left: 0.5cm; } diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 0000000..47c567d --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,24 @@ +# $Id$ +# +# This file is part of libdaemon. +# +# libdaemon is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# libdaemon is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libdaemon; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +noinst_PROGRAMS = testd + +AM_CPPFLAGS=-I../src + +testd_SOURCES=testd.c +testd_LDADD=../src/libdaemon.la diff --git a/examples/testd.c b/examples/testd.c new file mode 100644 index 0000000..12b2940 --- /dev/null +++ b/examples/testd.c @@ -0,0 +1,158 @@ +/* $Id$ */ + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include + +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + pid_t pid; + + /* Set indetification string for the daemon for both syslog and PID file */ + daemon_pid_file_ident = daemon_log_ident = daemon_ident_from_argv0(argv[0]); + + /* Check if we are called with -k parameter */ + if (argc >= 2 && !strcmp(argv[1], "-k")) { + int ret; + + /* Kill daemon with SIGINT */ + if ((ret = daemon_pid_file_kill(SIGINT)) < 0) + daemon_log(LOG_WARNING, "Failed to kill daemon"); + + return ret < 0 ? 1 : 0; + } + + /* Check that the daemon is not rung twice a the same time */ + if ((pid = daemon_pid_file_is_running()) >= 0) { + daemon_log(LOG_ERR, "Daemon already running on PID file %u", pid); + return 1; + + } + + /* Prepare for return value passing from the initialization procedure of the daemon process */ + daemon_retval_init(); + + /* Do the fork */ + if ((pid = daemon_fork()) < 0) { + + /* Exit on error */ + daemon_retval_done(); + return 1; + + } else if (pid) { /* The parent */ + int ret; + + /* Wait for 20 seconds for the return value passed from the daemon process */ + if ((ret = daemon_retval_wait(20)) < 0) { + daemon_log(LOG_ERR, "Could not recieve return value from daemon process."); + return 255; + } + + return ret; + + } else { /* The daemon */ + int fd, quit = 0; + fd_set fds; + + /* Create the PID file */ + if (daemon_pid_file_create() < 0) { + daemon_log(LOG_ERR, "Could not create PID file (%s).", strerror(errno)); + + /* Send the error condition to the parent process */ + daemon_retval_send(1); + goto finish; + } + + /* Initialize signal handling */ + if (daemon_signal_init(SIGINT, SIGQUIT, SIGHUP, 0) < 0) { + daemon_log(LOG_ERR, "Could not register signal handlers (%s).", strerror(errno)); + daemon_retval_send(2); + goto finish; + } + + /*... do some further init work here */ + + + /* Send OK to parent process */ + daemon_retval_send(0); + + daemon_log(LOG_INFO, "Sucessfully started"); + + + /* Prepare for select() on the signal fd */ + FD_ZERO(&fds); + FD_SET(fd = daemon_signal_fd(), &fds); + + while (!quit) { + fd_set fds2 = fds; + + /* Wait for an incoming signal */ + if (select(FD_SETSIZE, &fds2, 0, 0, 0) < 0) { + + /* If we've been interrupted by an incoming signal, continue */ + if (errno == EINTR) + continue; + + daemon_log(LOG_ERR, "select(): %s", strerror(errno)); + break; + } + + /* Check if a signal has been recieved */ + if (FD_ISSET(fd, &fds)) { + int sig; + + /* Get signal */ + if ((sig = daemon_signal_next()) <= 0) { + daemon_log(LOG_ERR, "daemon_signal_next() failed."); + break; + } + + /* Dispatch signal */ + switch (sig) { + + case SIGINT: + case SIGQUIT: + daemon_log(LOG_WARNING, "Got SIGINT or SIGQUIT"); + quit = 1; + break; + + case SIGHUP: + daemon_log(LOG_INFO, "Got a HUP"); + break; + + } + } + } + + /* Do a cleanup */ +finish: + daemon_log(LOG_INFO, "Exiting..."); + + daemon_signal_done(); + daemon_pid_file_remove(); + + return 0; + } +} diff --git a/libdaemon.spec.in b/libdaemon.spec.in new file mode 100644 index 0000000..1ef3a63 --- /dev/null +++ b/libdaemon.spec.in @@ -0,0 +1,73 @@ +%define debug_package %{nil} + +Summary: lightweight C library which eases the writing of UNIX daemons. +Name: libdaemon +Version: @PACKAGE_VERSION@ +Release: 1 +URL: http://www.stud.uni-hamburg.de/users/lennart/projects/libdaemon +Source: %{name}-%{version}.tar.gz +License: GPL +Group: System Environment/Libraries +BuildRoot: %{_tmppath}/%{name}-%{version}-root + +%description +libdaemon is a lightweight C library which eases the writing of UNIX daemons. +It consists of the following parts: + + * A wrapper around fork() which does the correct daemonization + procedure of a process + * A wrapper around syslog() for simpler and compatible log output to + Syslog or STDERR + * An API for writing PID files + * An API for serializing UNIX signals into a pipe for usage with + select() or poll() + +Routines like these are included in most of the daemon software available. It +is not that simple to get it done right and code duplication cannot be a goal. + +%package devel +Summary: Static libraries and header files for libdaemon development. +Group: Development/Libraries +Requires: libdaemon = %{version} + +%description devel + +The libdaemon-devel package contains the header files and static libraries +necessary for developing programs using libdaemon. + +%prep +%setup -q + +%build +%configure +make + +%install +%makeinstall + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%doc LICENSE README +%{_libdir}/*so.* +%{_libdir}/*.la + +%files devel +%defattr(-,root,root) +%doc LICENSE README +%doc doc/* +%{_includedir}/* +%{_libdir}/*.a +%{_libdir}/*.so + +%changelog +* Mon Jul 21 2003 Lennart Poettering 0.3 +- fixes +* Wed Jul 16 2003 Diego Santa Cruz 0.2 +- initial RPM diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..129660f --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,29 @@ +# $Id$ +# +# This file is part of libdaemon. +# +# libdaemon is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# libdaemon is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libdaemon; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +pkginclude_HEADERS = dlog.h dfork.h dsignal.h dnonblock.h dpid.h + +lib_LTLIBRARIES = libdaemon.la + +libdaemon_la_SOURCES = \ + dlog.c dlog.h \ + dfork.c dfork.h \ + dsignal.c dsignal.h \ + dnonblock.c dnonblock.h \ + dpid.c dpid.h + diff --git a/src/dfork.c b/src/dfork.c new file mode 100644 index 0000000..f9e10fb --- /dev/null +++ b/src/dfork.c @@ -0,0 +1,207 @@ +/* $Id$ */ + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dfork.h" +#include "dnonblock.h" +#include "dlog.h" + +static int _daemon_retval_pipe[2] = { -1, -1 }; + +static int _null_open(int f, int fd) { + int fd2; + + if ((fd2 = open("/dev/null", f)) < 0) + return -1; + + if (fd2 == fd) + return fd; + + if (dup2(fd2, fd) < 0) + return -1; + + close(fd2); + return fd; +} + +pid_t daemon_fork(void) { + pid_t pid; + int _pipe[2]; + FILE *pipe_in, *pipe_out; + + pid_t p = (pid_t) -1; + + if (pipe(_pipe) < 0 || !(pipe_out = fdopen(_pipe[0], "r")) || !(pipe_in = fdopen(_pipe[1], "w"))) { + daemon_log(LOG_ERR, "pipe() failed: %s", strerror(errno)); + return (pid_t) -1; + } + + daemon_nonblock(_pipe[1], 1); + + if ((pid = fork()) < 0) { // First fork + daemon_log(LOG_ERR, "First fork() failed: %s\n", strerror(errno)); + fclose(pipe_in); + fclose(pipe_out); + return (pid_t) -1; + + } else if (pid == 0) { + // First child + + fclose(pipe_out); + + if (_null_open(O_RDONLY, 0) < 0) { + daemon_log(LOG_ERR, "Failed to open /dev/null for STDIN: %s", strerror(errno)); + goto fail; + } + + if (_null_open(O_WRONLY, 1) < 0) { + daemon_log(LOG_ERR, "Failed to open /dev/null for STDOUT: %s", strerror(errno)); + goto fail; + } + + if (_null_open(O_WRONLY, 2) < 0) { + daemon_log(LOG_ERR, "Failed to open /dev/null for STDERR: %s", strerror(errno)); + goto fail; + } + + setsid(); + umask(0777); + chdir("/"); + + if ((pid = fork()) < 0) { // Second fork + daemon_log(LOG_ERR, "Second fork() failed: %s", strerror(errno)); + goto fail; + + } else if (pid == 0) { + // Second child + p = getpid(); + fwrite(&p, sizeof(p), 1, pipe_in); + fclose(pipe_in); + + + if (daemon_log_use & DAEMON_LOG_AUTO) + daemon_log_use = DAEMON_LOG_SYSLOG; + + return 0; + + } else { + // Second father + fclose(pipe_in); + exit(0); + } + + fail: + fwrite(&p, sizeof(p), 1, pipe_in); + fclose(pipe_in); + exit(0); + + } else { // First father + if (fread(&p, sizeof(p), 1, pipe_out) != 1) + p = (pid_t) -1; + + fclose(pipe_out); + return p; + } + +} + +int daemon_retval_init(void) { + if (pipe(_daemon_retval_pipe) < 0) + return -1; + + return 0; +} + +void daemon_retval_done(void) { + if (_daemon_retval_pipe[0] >= 0) + close(_daemon_retval_pipe[0]); + + if (_daemon_retval_pipe[1] >= 0) + close(_daemon_retval_pipe[1]); + + _daemon_retval_pipe[0] = _daemon_retval_pipe[1] = -1; +} + +int daemon_retval_send(int i) { + ssize_t r; + r = write(_daemon_retval_pipe[1], &i, sizeof(i)); + + daemon_retval_done(); + + if (r != sizeof(i)) { + + if (r < 0) + daemon_log(LOG_ERR, "read() failed while writing return value to pipe: %s", strerror(errno)); + else + daemon_log(LOG_ERR, "write() too short while writing return value from pipe"); + + return -1; + } + + return 0; +} + +int daemon_retval_wait(int timeout) { + ssize_t r; + int i; + + if (timeout > 0) { + struct timeval tv = { timeout, 0 }; + int s; + fd_set fds; + FD_ZERO(&fds); + FD_SET(_daemon_retval_pipe[0], &fds); + + if ((s = select(FD_SETSIZE, &fds, 0, 0, &tv)) != 1) { + + if (s < 0) + daemon_log(LOG_ERR, "select() failed while waiting for return value: %s", strerror(errno)); + else + daemon_log(LOG_ERR, "Timeout reached while wating for return value"); + + return -1; + } + } + + if ((r = read(_daemon_retval_pipe[0], &i, sizeof(i))) != sizeof(i)) { + + if (r < 0) + daemon_log(LOG_ERR, "read() failed while reading return value from pipe: %s", strerror(errno)); + else if (r == 0) + daemon_log(LOG_ERR, "read() failed with EOF while reading return value from pipe."); + else if (r > 0) + daemon_log(LOG_ERR, "read() too short while reading return value from pipe."); + + return -1; + } + + daemon_retval_done(); + + return i; +} + diff --git a/src/dfork.h b/src/dfork.h new file mode 100644 index 0000000..1554184 --- /dev/null +++ b/src/dfork.h @@ -0,0 +1,87 @@ +#ifndef foodaemonforkhfoo +#define foodaemonforkhfoo + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include + +/** \mainpage + * + * For a brief explanation of libdaemons's purpose, have a look on the README file. Thank you! + * + */ + +/** \example testd.c + * This is an example for the usage of libdaemon + */ + +/** \file + * + * Contains an API for doing a daemonizing fork(). + * + * You may daemonize by calling daemon_fork(), a function similar to + * the plain fork(). If you want to return a return value of the + * initialization procedure of the child from the parent, you may use + * the daemon_retval_xxx() functions. + */ + +/** Does a daemonizing fork(). For the new daemon process STDIN, + * STDOUT, STDERR are connected to /dev/null, the process is a session + * leader, the current directory is changed to /, the umask is set to + * 777. + * @return zero on success in the child, the PID of the new + * daemon process in the parent, nonzero on failure + */ +pid_t daemon_fork(void); + +/** Initializes the library for allowing the passing of a return value + * from the daemon initialization to the parent process. Call this + * before calling any of the other daemon_retval_xxx() functions in + * the parent, before forking. + * @return zero on success, nonzero on failure. + */ +int daemon_retval_init(void); + +/** Frees the resources allocated by daemon_retval_init(). This should + * be called if neither daemon_retval_wait() nor daemon_retval_send() + * is used. If a fork took place, the function should be called in + * both the parent and the daemon. */ +void daemon_retval_done(void); + +/** Wait the specified amount of seconds for the response of the + * daemon process and return the integer passed to + * daemon_retval_send() in the daemon process. Should be called just + * once from the parent process only. A subsequent call to + * daemon_retval_done() in the parent is ignored. + * @param timeout The timeout in seconds + * @return The integer passed daemon_retval_send() in the daemon + * process, or negative on failure. + */ +int daemon_retval_wait(int timeout); + +/** Send the specified integer to the parent process. Should be called + * just once from the daemon process only. A subsequent call to + * daemon_retval_done() in the daemon is ignored. + * @param s The integer to pass to daemon_retval_wait() in the parent process + * @return Zero on success, nonzero on failure. + */ +int daemon_retval_send(int s); + +#endif diff --git a/src/dlog.c b/src/dlog.c new file mode 100644 index 0000000..36ce5dc --- /dev/null +++ b/src/dlog.c @@ -0,0 +1,58 @@ +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include + +#include "dlog.h" + +enum daemon_log_flags daemon_log_use = DAEMON_LOG_AUTO|DAEMON_LOG_STDERR; +char* daemon_log_ident = 0; + +void daemon_log(int prio, const char* template, ...) { + va_list arglist; + va_start(arglist, template); + if (daemon_log_use & DAEMON_LOG_SYSLOG) { + openlog(daemon_log_ident ? daemon_log_ident : "UNKNOWN", LOG_PID|LOG_NDELAY, LOG_DAEMON); + vsyslog(prio, template, arglist); + closelog(); + } + + if (daemon_log_use & DAEMON_LOG_STDERR) { + vfprintf(stderr, template, arglist); + fprintf(stderr, "\n"); + } + + if (daemon_log_use & DAEMON_LOG_STDOUT) { + vfprintf(stdout, template, arglist); + fprintf(stdout, "\n"); + } + + + va_end(arglist); +} + +char *daemon_ident_from_argv0(char *argv0) { + char *p; + + if ((p = strrchr(argv0, '/'))) + return p+1; + + return argv0; +} diff --git a/src/dlog.h b/src/dlog.h new file mode 100644 index 0000000..8edf6b3 --- /dev/null +++ b/src/dlog.h @@ -0,0 +1,63 @@ +#ifndef foodaemonloghfoo +#define foodaemonloghfoo + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include + + +/** \file + * + * Contains a robust API for logging messages + */ + + +/** Specifies where to send the log messages to + */ +enum daemon_log_flags { + DAEMON_LOG_SYSLOG = 1, /**< Log messages are written to syslog */ + DAEMON_LOG_STDERR = 2, /**< Log messages are written to STDERR */ + DAEMON_LOG_STDOUT = 4, /**< Log messages are written to STDOUT */ + DAEMON_LOG_AUTO = 8 /**< If this is set a daemon_fork() will + change this to DAEMON_LOG_SYSLOG in + the daemon process. */ +}; + +/** This variable is used to specify the log target(s) to use. Defaults to DAEMON_LOG_STDERR|DAEMON_LOG_AUTO */ +extern enum daemon_log_flags daemon_log_use; + +/** Specifies the syslog identification, use daemon_ident_from_argv0() + * to set this to a sensible value or generate your own. */ +extern char* daemon_log_ident; + +/** Log a message using printf format strings using the specified syslog priority + * @param prio The syslog priority (PRIO_xxx constants) + * @param t,... The text message to log + */ +void daemon_log(int prio, const char* t, ...); + +/** Return a sensible syslog identification for daemon_log_ident + * generated from argv[0]. This will return a pointer to the file name + * of argv[0], i.e. strrchr(argv[0], '\')+1 + * @param argv0 argv[0] as passed to main() + * @return The identification string + */ +char *daemon_ident_from_argv0(char *argv0); + +#endif diff --git a/src/dnonblock.c b/src/dnonblock.c new file mode 100644 index 0000000..af24be2 --- /dev/null +++ b/src/dnonblock.c @@ -0,0 +1,37 @@ +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include + +#include "dnonblock.h" + +int daemon_nonblock(int fd, int b) { + int a; + if ((a = fcntl(fd, F_GETFL)) < 0) + return -1; + + if (b) + a |= O_NDELAY; + else + a &= ~O_NDELAY; + + if (fcntl(fd, F_SETFL, a) < 0) + return -1; + + return 0; +} diff --git a/src/dnonblock.h b/src/dnonblock.h new file mode 100644 index 0000000..62a45b3 --- /dev/null +++ b/src/dnonblock.h @@ -0,0 +1,37 @@ +#ifndef foodaemonnonblockhfoo +#define foodaemonnonblockhfoo + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +/** \file + * + * Contains a single function used to change a file descriptor to + * non-blocking mode using fcntl(). + */ + +/** Change the passed file descriptor to non-blocking or blocking + * mode, depending on b. + * @param fd The file descriptor to manipulation + * @param b TRUE if non-blocking mode should be enabled, FALSE if it + * should be disabled + * @return Zero on success, nonzero on failure. + */ +int daemon_nonblock(int fd, int b); + +#endif diff --git a/src/dpid.c b/src/dpid.c new file mode 100644 index 0000000..6d91cae --- /dev/null +++ b/src/dpid.c @@ -0,0 +1,124 @@ +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dpid.h" +#include "dlog.h" + +#define VARRUN "/var/run" + +const char *daemon_pid_file_ident = 0; +daemon_pid_file_proc_t daemon_pid_file_proc = daemon_pid_file_proc_default; + +const char *daemon_pid_file_proc_default(void) { + static char fn[PATH_MAX]; + snprintf(fn, sizeof(fn), "%s/%s.pid", VARRUN, daemon_pid_file_ident ? daemon_pid_file_ident : "unknown"); + return fn; +} + +pid_t daemon_pid_file_is_running(void) { + const char *fn; + static char txt[256]; + FILE *f; + pid_t pid; + + + if (!(fn = daemon_pid_file_proc())) + return (pid_t) -1; + + if (!(f = fopen(fn, "r"))) + return (pid_t) -1; + + if (!(fgets(txt, sizeof(txt), f))) { + daemon_log(LOG_WARNING, "PID file corrupt, removing. (%s)", fn); + unlink(fn); + fclose(f); + return (pid_t) -1; + } + + fclose(f); + + if ((pid = (pid_t) atoi(txt)) <= 0) { + daemon_log(LOG_WARNING, "PID file corrupt, removing. (%s)", fn); + unlink(fn); + return (pid_t) -1; + } + + if (kill(pid, 0) != 0 && errno != EPERM) { + daemon_log(LOG_WARNING, "Daemon %u killed: %s; removing PID file. (%s)", pid, strerror(errno), fn); + unlink(fn); + return (pid_t) -1; + } + + return pid; +} + +int daemon_pid_file_kill(int s) { + pid_t pid; + + if ((pid = daemon_pid_file_is_running()) < 0) + return -1; + + if (kill(pid, s) < 0) + return -1; + + return 0; +} + +int daemon_pid_file_create(void) { + const char *fn; + FILE *f; + mode_t save; + + if (!(fn = daemon_pid_file_proc())) + return -1; + + save = umask(022); + + if (!(f = fopen(fn, "w"))) + return -1; + + fprintf(f, "%u\n", getpid()); + fclose(f); + + umask(save); + + return 0; +} + +int daemon_pid_file_remove(void) { + const char *fn; + + if (!(fn = daemon_pid_file_proc())) + return -1; + + if (unlink(fn) < 0) + return -1; + + return 0; +} + diff --git a/src/dpid.h b/src/dpid.h new file mode 100644 index 0000000..8dde464 --- /dev/null +++ b/src/dpid.h @@ -0,0 +1,73 @@ +#ifndef foodaemonpidhfoo +#define foodaemonpidhfoo + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include + +/** \file + * + * Contains an API for manipulating PID files. + */ + +/** Prototype of a function for generating the name of a PID file. + */ +typedef const char* (*daemon_pid_file_proc_t)(void); + +/** Identification string for the PID file name, only used when + * daemon_pid_file_proc is set to daemon_pid_file_proc_default(). Use + * daemon_ident_from_argv0() to generate an identification string from + * argv[0] + */ +extern const char *daemon_pid_file_ident; + +/** A function pointer which is used to generate the name of the PID + * file to manipulate. Points to daemon_pid_file_proc_default() by + * default. + */ +extern daemon_pid_file_proc_t daemon_pid_file_proc; + +/** A function for creating a pid file name from + * daemon_pid_file_ident + * @return The PID file path + */ +const char *daemon_pid_file_proc_default(void); + +/** Creates PID pid file for the current process + * @return zero on success, nonzero on failure + */ +int daemon_pid_file_create(void); + +/** Removes the PID file of the current process + * @return zero on success, nonzero on failure + */ +int daemon_pid_file_remove(void); + +/** Returns the PID file of a running daemon, if available + * @return The PID or negative on failure + */ +pid_t daemon_pid_file_is_running(void); + +/** Kills a running daemon, if available + * @param s The signal to send + * @return zero on success, nonzero on failure + */ +int daemon_pid_file_kill(int s); + +#endif diff --git a/src/dsignal.c b/src/dsignal.c new file mode 100644 index 0000000..c41aa9d --- /dev/null +++ b/src/dsignal.c @@ -0,0 +1,132 @@ +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include + +#include "dsignal.h" +#include "dlog.h" +#include "dnonblock.h" + +static int _signal_pipe[2] = { -1, -1 }; + +static void _sigfunc(int s) { + write(_signal_pipe[1], &s, sizeof(s)); +} + +static int _init(void) { + + if (_signal_pipe[0] < 0 || _signal_pipe[1] < 0) { + if (pipe(_signal_pipe) < 0) { + daemon_log(LOG_ERR, "pipe(): %s", strerror(errno)); + return -1; + } + + if (daemon_nonblock(_signal_pipe[0], 1) < 0 || daemon_nonblock(_signal_pipe[1], 1) < 0) + return -1; + + } + + return 0; +} + +int daemon_signal_install(int s){ + struct sigaction sa; + + if (_init() < 0) + return -1; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = _sigfunc; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + + if (sigaction(s, &sa, NULL) < 0) { + daemon_log(LOG_ERR, "sigaction(%s, ...) failed.", strsignal(s)); + return -1; + } + + return 0; +} + +int daemon_signal_init(int s, ...) { + int sig, r = 0; + + va_list ap; + va_start(ap, s); + + if (_init() < 0) + return -1; + + sig = s; + while (sig > 0) { + if (daemon_signal_install(sig) < 0) { + r = -1; + break; + } + + sig = va_arg(ap, int); + } + + va_end(ap); + + + return r; +} + +void daemon_signal_done(void) { + if (_signal_pipe[0] != -1) + close(_signal_pipe[0]); + + if (_signal_pipe[1] != -1) + close(_signal_pipe[1]); + + _signal_pipe[0] = _signal_pipe[1] = -1; +} + +int daemon_signal_next(void) { + int s; + ssize_t r; + + if ((r = read(_signal_pipe[0], &s, sizeof(s))) == sizeof(s)) + return s; + + + if (r < 0) { + + if (errno == EAGAIN) + return 0; + else { + daemon_log(LOG_ERR, "read(signal_pipe[0], ...): %s", strerror(errno)); + return -1; + } + } + + daemon_log(LOG_ERR, "Short read() on signal pipe."); + return -1; +} + +int daemon_signal_fd(void) { + return _signal_pipe[0]; +} diff --git a/src/dsignal.h b/src/dsignal.h new file mode 100644 index 0000000..a26b5cc --- /dev/null +++ b/src/dsignal.h @@ -0,0 +1,65 @@ +#ifndef foodaemonsignalhfoo +#define foodaemonsignalhfoo + +/* + * This file is part of libdaemon. + * + * libdaemon is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libdaemon is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libdaemon; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +/** \file + * + * Contains the API for serializing signals to a pipe for + * usage with select() or poll(). + * + * You should register all signals you + * wish to handle with select() in your main loop with + * daemon_signal_init() or daemon_signal_install(). After that you + * should sleep on the file descriptor returned by daemon_signal_fd() + * and get the next signal recieved with daemon_signal_next(). You + * should call daemon_signal_done() before exiting. + */ + +/** Installs signal handlers for the specified signals + * @param s, ... The signals to install handlers for. The list should be terminated by -1 + * @return zero on success, nonzero on failure + */ +int daemon_signal_init(int s, ...); + +/** Install a signal handler for the specified signal + * @param s The signalto install handler for + * @return zero onsuccess,nonzero on failure + */ +int daemon_signal_install(int s); + +/** Free resources of signal handling, should be called before daemon exit + */ +void daemon_signal_done(void); + +/** Return the next signal recieved. This function will not + * block. Instead it returns 0 if no signal is queued. + * @return The next queued signal if one is queued, zero if none is + * queued, negative on failure. + */ +int daemon_signal_next(void); + +/** Return the file descriptor the daemon should select() on for + * reading. Whenever the descriptor is ready you should call + * daemon_signal_next() to get the next signal queued. + * @return The file descriptor or negative on failure + */ +int daemon_signal_fd(void); + +#endif -- cgit