mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8587971fb9 | ||
|
|
6545ac8fd4 | ||
|
|
9105e8d3d8 | ||
|
|
3555af6a6a | ||
|
|
42715eab8a | ||
|
|
497d58dbf0 | ||
|
|
9ab70ebbcd | ||
|
|
bad363883d | ||
|
|
7f3215b3e6 | ||
|
|
729cc5307f | ||
|
|
66290d132f | ||
|
|
59f7a78441 | ||
|
|
b716776863 | ||
|
|
018ecaca15 | ||
|
|
a293c37777 | ||
|
|
a4937a93e2 |
No files matched your search
+21
-4
@@ -3,16 +3,31 @@ Change Log
|
|||||||
|
|
||||||
All notable changes to the project are documented in this file.
|
All notable changes to the project are documented in this file.
|
||||||
|
|
||||||
|
|
||||||
|
[v1.8.3][] - 2017-01-08
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Support absolute path in `pidfile()`. Needed by, e.g. Inadyn
|
||||||
|
- Add initial `debian/` packaging
|
||||||
|
- Update README with note on remembering to set `umask()`
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- In use-cases when `pidfile()` is called consecutively, e.g. on
|
||||||
|
`SIGHUP`, recreate PID file if it no longer exists
|
||||||
|
|
||||||
|
|
||||||
[v1.8.2][] - 2016-09-05
|
[v1.8.2][] - 2016-09-05
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- Updated build instructions in README.
|
- Updated build instructions in README.
|
||||||
- Converted touch(), makedir(), makefifo(), and erase() from macros to
|
- Converted `touch()`, `makedir()`, `makefifo()`, and `erase()` from
|
||||||
inline functions. Also removed implicit logging to stderr on error.
|
macros to inline functions. Also removed implicit logging to stderr
|
||||||
|
on error.
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Fix small memory leak in pidfile() ... at exit.
|
- Fix small memory leak in `pidfile()` ... at exit.
|
||||||
- Fixes for building on musl libc
|
- Fixes for building on musl libc
|
||||||
|
|
||||||
|
|
||||||
@@ -216,7 +231,9 @@ problems this may cause!
|
|||||||
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||||
|
|
||||||
|
|
||||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v1.8.1...HEAD
|
[UNRELEASED]: https://github.com/troglobit/libite/compare/v1.8.3...HEAD
|
||||||
|
[v1.8.3]: https://github.com/troglobit/libite/compare/v1.8.2...v1.8.3
|
||||||
|
[v1.8.2]: https://github.com/troglobit/libite/compare/v1.8.1...v1.8.2
|
||||||
[v1.8.1]: https://github.com/troglobit/libite/compare/v1.8.0...v1.8.1
|
[v1.8.1]: https://github.com/troglobit/libite/compare/v1.8.0...v1.8.1
|
||||||
[v1.8.0]: https://github.com/troglobit/libite/compare/v1.7.0...v1.8.0
|
[v1.8.0]: https://github.com/troglobit/libite/compare/v1.7.0...v1.8.0
|
||||||
[v1.7.0]: https://github.com/troglobit/libite/compare/v1.6.0...v1.7.0
|
[v1.7.0]: https://github.com/troglobit/libite/compare/v1.6.0...v1.7.0
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ libite_la_SOURCES = chomp.c copyfile.c dir.c fexist.c fisdir.c fmode.c fparsel
|
|||||||
|
|
||||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||||
libite_la_CFLAGS = -W -Wall -Wextra
|
libite_la_CFLAGS = -W -Wall -Wextra
|
||||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 3:0:0
|
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 3:1:0
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = libite.pc
|
pkgconfig_DATA = libite.pc
|
||||||
|
|||||||
@@ -70,6 +70,14 @@ and in your `Makefile.am`:
|
|||||||
proggy_LDADD = $(lite_LIBS)
|
proggy_LDADD = $(lite_LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
Important Note
|
||||||
|
--------------
|
||||||
|
|
||||||
|
When using functions like `mkpath()`, `makepath()`, and `makefifo()`,
|
||||||
|
make sure your `umask()` is correct so you do not accidentally create
|
||||||
|
files and directories accessible to other users than intended.
|
||||||
|
|
||||||
|
|
||||||
Helper Macros
|
Helper Macros
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@@ -223,11 +231,13 @@ Generic Functions
|
|||||||
with the `dst` name. On successful operation the source is removed
|
with the `dst` name. On successful operation the source is removed
|
||||||
and the function returns POSIX OK (0).
|
and the function returns POSIX OK (0).
|
||||||
|
|
||||||
- `pidfile(basename)`
|
- `pidfile(name)`
|
||||||
|
|
||||||
Create a daemon PID file in `_PATH_VARRUN` using either `basename` or,
|
Create a daemon PID file using either the `name` as a full path, if
|
||||||
if `basename` is `NULL`, `__progname`. The resulting file name is
|
`name` starts with `/`, or in `_PATH_VARRUN` using `name` as the
|
||||||
available to the user as a read-only pointer:
|
basename of the application. If `name` is `NULL`, then `__progname`
|
||||||
|
is used as the basename. The resulting file name is available to the
|
||||||
|
user as a read-only pointer:
|
||||||
|
|
||||||
extern char *__pidfile_name;
|
extern char *__pidfile_name;
|
||||||
|
|
||||||
@@ -238,14 +248,14 @@ Generic Functions
|
|||||||
|
|
||||||
The PID file is removed when the program exits, using an `atexit()`
|
The PID file is removed when the program exits, using an `atexit()`
|
||||||
handler. However, depending on how the program terminates the file
|
handler. However, depending on how the program terminates the file
|
||||||
may still exist even though the program is no longer running. This
|
may still exist even though the program is no longer running.
|
||||||
is only a problem for clients.
|
|
||||||
|
|
||||||
Calling this function multiple times updates the mtime of the file.
|
Calling this function multiple times updates the mtime of the file.
|
||||||
Only one `atexit()` handler is created, regardless of the amount of
|
Only one `atexit()` handler is created, regardless of the amount of
|
||||||
times the function is called.
|
times the function is called. If the file is removed, subsequent
|
||||||
|
calls to this function will recreate the file.
|
||||||
|
|
||||||
See below for link to OpenBSD man page.
|
See below for a link to OpenBSD man page.
|
||||||
|
|
||||||
- `pidfile_read(pidfile)`
|
- `pidfile_read(pidfile)`
|
||||||
|
|
||||||
@@ -316,9 +326,9 @@ The following are popular functions and highly useful macros from the
|
|||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
||||||
|
|
||||||
**Note:** this version of `pidfile()` has been extended to handle it
|
**Note:** the version of `pidfile()` in -lite has been extended to
|
||||||
being called multiple times, i.e. to not create multiple `atexit()`
|
handle it being called multiple times, i.e. to not create multiple
|
||||||
handlers, and also to export a few internal paths:
|
`atexit()` handlers, and also to export a few internal paths:
|
||||||
|
|
||||||
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
|
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
|
||||||
trailing slash requirement if you want to override it!
|
trailing slash requirement if you want to override it!
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT(libite, 1.8.2, https://github.com/troglobit/libite/issues)
|
AC_INIT(libite, 1.8.3, https://github.com/troglobit/libite/issues)
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
tmp/*
|
||||||
|
libuev/*
|
||||||
|
libuev*
|
||||||
|
autoreconf*
|
||||||
|
debhelper*
|
||||||
|
files
|
||||||
|
!*.dirs
|
||||||
|
!*.install
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
libite (1.8.2-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Initial release.
|
||||||
|
|
||||||
|
-- Joachim Nilsson <troglobit@gmail.com> Tue, 29 Nov 2016 08:23:35 +0100
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
config.log
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
9
|
||||||
Vendored
+51
@@ -0,0 +1,51 @@
|
|||||||
|
Source: libite
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
Build-Depends: dpkg-dev (>= 1.14.9), debhelper (>= 9), dh-autoreconf
|
||||||
|
Standards-Version: 3.9.6
|
||||||
|
Section: libs
|
||||||
|
Homepage: https://github.com/troglobit/libite/
|
||||||
|
Vcs-Git: https://github.com/troglobit/libite.git
|
||||||
|
Vcs-Browser: https://github.com/troglobit/libite/
|
||||||
|
|
||||||
|
Package: libite-dev
|
||||||
|
Priority: extra
|
||||||
|
Section: libdevel
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${misc:Depends}, libite (= ${binary:Version})
|
||||||
|
Description: static library, header files, and docs for libite
|
||||||
|
Static library, header files, and documentation for libite.
|
||||||
|
.
|
||||||
|
Libite is a lightweight library of frog DNA. It can be used to fill the
|
||||||
|
gaps in any dinosaur project. It holds useful functions and macros
|
||||||
|
developed by both Finit and the OpenBSD project. Most notably the
|
||||||
|
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
|
||||||
|
sys/queue.h and sys/tree.h API's.
|
||||||
|
.
|
||||||
|
Libite is the frog DNA missing in GNU libc. However, -lite does not aim
|
||||||
|
to become another GLIB! One noticeable gap in GLIBC is the missing
|
||||||
|
_SAFE macros in the BSD sys/queue.h API — highly recommended when
|
||||||
|
traversing lists to delete/free nodes.
|
||||||
|
.
|
||||||
|
The code is open sourced under a mix of the MIT/X11 license, the ISC
|
||||||
|
license used by OpenBSD, and BSD licenses, all of them are extremely
|
||||||
|
liberal and can be used freely in proprietary software if needed.
|
||||||
|
|
||||||
|
Package: libite
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${misc:Depends}, ${shlibs:Depends}
|
||||||
|
Description: That missing frog DNA you've been looking for. MIT/X11/ISC/BSD License.
|
||||||
|
Libite is a lightweight library of frog DNA. It can be used to fill the
|
||||||
|
gaps in any dinosaur project. It holds useful functions and macros
|
||||||
|
developed by both Finit and the OpenBSD project. Most notably the
|
||||||
|
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
|
||||||
|
sys/queue.h and sys/tree.h API's.
|
||||||
|
.
|
||||||
|
Libite is the frog DNA missing in GNU libc. However, -lite does not aim
|
||||||
|
to become another GLIB! One noticeable gap in GLIBC is the missing
|
||||||
|
_SAFE macros in the BSD sys/queue.h API — highly recommended when
|
||||||
|
traversing lists to delete/free nodes.
|
||||||
|
.
|
||||||
|
The code is open sourced under a mix of the MIT/X11 license, the ISC
|
||||||
|
license used by OpenBSD, and BSD licenses, all of them are extremely
|
||||||
|
liberal and can be used freely in proprietary software if needed.
|
||||||
Vendored
+84
@@ -0,0 +1,84 @@
|
|||||||
|
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||||
|
Source: https.//github.com/troglobit/libite/
|
||||||
|
|
||||||
|
Files: *
|
||||||
|
Copyright:
|
||||||
|
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||||
|
2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: MIT
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
Files: chomp.c
|
||||||
|
Copyright: 2014-2015 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: conio.h
|
||||||
|
Copyright: 2009-2013 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: dir.c
|
||||||
|
Copyright: 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: lfile.c
|
||||||
|
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: pidfile.c
|
||||||
|
Copyright: 1999 The NetBSD Foundation, Inc.
|
||||||
|
License: BSD-2-clause
|
||||||
|
|
||||||
|
Files: queue.h
|
||||||
|
Copyright: 1991, 1993 The Regents of the University of California.
|
||||||
|
License: BSD-3-clause
|
||||||
|
|
||||||
|
Files: reallocarray.c
|
||||||
|
Copyright: 2008 Otto Moerbeek <otto@drijf.net>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: rsync.c
|
||||||
|
Copyright: 2011, 2012 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: strdupa.h strndupa.h
|
||||||
|
Copyright: 2009 William Ahern
|
||||||
|
License: MIT
|
||||||
|
|
||||||
|
Files: strlcat.c strlcpy.c
|
||||||
|
Copyright: 998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
License: MIT
|
||||||
|
|
||||||
|
Files: strnlen.c
|
||||||
|
Copyright: 2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: strtonum.c
|
||||||
|
Copyright: 2004 Ted Unangst and Todd Miller
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: tempfile.c
|
||||||
|
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: tree.c
|
||||||
|
Copyright: 2015 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: tests/*.c
|
||||||
|
License: public-domain
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
README.md
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
usr/lib
|
||||||
|
usr/include
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
usr/include/lite/*.h
|
||||||
|
usr/lib/*/lib*.a
|
||||||
|
usr/lib/*/lib*.so
|
||||||
|
usr/lib/*/pkgconfig/lib*.pc
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
usr/lib
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
usr/lib/*/lib*.so.*
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
# Uncomment this to turn on verbose mode.
|
||||||
|
#export DH_VERBOSE=1
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@ --with autoreconf
|
||||||
|
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
3.0 (native)
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#ifndef pidfile
|
#ifndef pidfile
|
||||||
static char *pidfile_path = NULL;
|
static char *pidfile_path = NULL;
|
||||||
static pid_t pidfile_pid;
|
static pid_t pidfile_pid = 0;
|
||||||
|
|
||||||
static void pidfile_cleanup(void);
|
static void pidfile_cleanup(void);
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ pidfile(const char *basename)
|
|||||||
atexit_already = 0;
|
atexit_already = 0;
|
||||||
|
|
||||||
if (pidfile_path != NULL) {
|
if (pidfile_path != NULL) {
|
||||||
if (pid == pidfile_pid) {
|
if (!access(pidfile_path, R_OK) && pid == pidfile_pid) {
|
||||||
utimensat(0, pidfile_path, NULL, 0);
|
utimensat(0, pidfile_path, NULL, 0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -75,8 +75,13 @@ pidfile(const char *basename)
|
|||||||
atexit_already = 1;
|
atexit_already = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1)
|
if (basename[0] != '/') {
|
||||||
return (-1);
|
if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
if (asprintf(&pidfile_path, "%s", basename) == -1)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
if ((f = fopen(pidfile_path, "w")) == NULL) {
|
if ((f = fopen(pidfile_path, "w")) == NULL) {
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
@@ -96,6 +101,7 @@ pidfile(const char *basename)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
(void) fclose(f);
|
(void) fclose(f);
|
||||||
|
__pidfile_name = pidfile_path;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LITE extension, no need to set up another atexit() handler
|
* LITE extension, no need to set up another atexit() handler
|
||||||
@@ -114,7 +120,6 @@ pidfile(const char *basename)
|
|||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
__pidfile_name = pidfile_path;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -19,6 +19,6 @@ TESTS += tree
|
|||||||
check_PROGRAMS = $(TESTS)
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
# Ignore warnings about unused result, in e.g. write()
|
# Ignore warnings about unused result, in e.g. write()
|
||||||
CFLAGS = -W -Wall -Wextra -Wno-unused-result
|
|
||||||
CPPFLAGS = -D_GNU_SOURCE
|
CPPFLAGS = -D_GNU_SOURCE
|
||||||
LDADD = -L../ ../libite.la
|
LDADD = -L../ ../libite.la
|
||||||
|
LDFLAGS = -static
|
||||||
+20
-13
@@ -1,4 +1,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
@@ -34,27 +36,32 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
char *list[] = {
|
char *list[] = {
|
||||||
"/tmp/tok/",
|
"/tmp/libite-test/tok/",
|
||||||
"/tmp/tok2",
|
"/tmp/libite-test/tok2",
|
||||||
"/tmp/ab",
|
"/tmp/libite-test/ab",
|
||||||
"/tmp/b",
|
"/tmp/libite-test/b",
|
||||||
"/tmp/a/",
|
"/tmp/libite-test/a/",
|
||||||
"/tmp/a/b",
|
"/tmp/libite-test/a/b",
|
||||||
"/tmp/a/c/",
|
"/tmp/libite-test/a/c/",
|
||||||
"../../sometestdir/arpa/inet",
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; list[i]; i++)
|
|
||||||
rmdir(list[i]);
|
|
||||||
|
|
||||||
printf("Testing makepath() ...\n");
|
printf("Testing makepath() ...\n");
|
||||||
|
mkdir("/tmp/libite-test", 0755);
|
||||||
|
|
||||||
for (i = 0; list[i] && !ret; i++)
|
for (i = 0; list[i] && !ret; i++)
|
||||||
ret |= test_makepath(list[i]);
|
ret |= test_makepath(list[i]);
|
||||||
|
|
||||||
printf("\nCleaning up ...\n");
|
printf("\nCleaning up ...\n");
|
||||||
for (i = 0; list[i]; i++)
|
system("rm -rf /tmp/libite-test");
|
||||||
rmdir(list[i]);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* compile-command: "make makepath && ./makepath"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+77
-20
@@ -6,25 +6,30 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
extern char *__progname;
|
#define PRINT(args...) if (verbose) printf(args)
|
||||||
|
|
||||||
extern char *__pidfile_name;
|
extern char *__pidfile_name;
|
||||||
extern char *__pidfile_path;
|
extern char *__pidfile_path;
|
||||||
|
|
||||||
|
static char *ident;
|
||||||
|
static char *pidfile_arg;
|
||||||
static char PIDFILE[42];
|
static char PIDFILE[42];
|
||||||
static int verbose = 0;
|
static int verbose = 0;
|
||||||
static struct stat before, after;
|
static struct stat before, after;
|
||||||
|
|
||||||
static void sigterm_handler(int UNUSED(signo))
|
static void sigterm_handler(int UNUSED(signo))
|
||||||
{
|
{
|
||||||
if (verbose)
|
PRINT("Exiting ...\n");
|
||||||
printf("Exiting ...\n");
|
remove(PIDFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigalrm_handler(int UNUSED(signo))
|
static void sigalrm_handler(int UNUSED(signo))
|
||||||
{
|
{
|
||||||
pidfile(NULL);
|
PRINT("Calling pidfile(%s)\n", pidfile_arg ?: "NULL");
|
||||||
|
if (pidfile(pidfile_arg))
|
||||||
|
err(1, "failed creating1 %s", pidfile_arg);
|
||||||
if (!fexist(PIDFILE))
|
if (!fexist(PIDFILE))
|
||||||
err(1, "failed creating %s", PIDFILE);
|
err(1, "failed creating2 %s, created %s", PIDFILE, __pidfile_name);
|
||||||
stat(PIDFILE, &before);
|
stat(PIDFILE, &before);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,31 +41,40 @@ static int mtime()
|
|||||||
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
|
||||||
if (verbose)
|
PRINT("Calling pidfile() again to update mtime ...\n");
|
||||||
printf("Calling pidfile() again to update mtime ...\n");
|
if (pidfile(pidfile_arg))
|
||||||
pidfile(NULL);
|
err(1, "failed creating3 %s", pidfile_arg);
|
||||||
stat(PIDFILE, &after);
|
stat(PIDFILE, &after);
|
||||||
|
|
||||||
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
||||||
if (verbose) {
|
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
||||||
printf("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
||||||
printf("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return !ret;
|
return !ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int test_pidfile(char *arg0)
|
||||||
{
|
{
|
||||||
if (argc > 1 && !strcmp(argv[1], "-v"))
|
/* pidfile() argument */
|
||||||
verbose = 1;
|
pidfile_arg = arg0;
|
||||||
|
|
||||||
/* Override default _PATH_VARRUN in pidfile() */
|
/* Expected PID file name */
|
||||||
__pidfile_path = _PATH_TMP;
|
if (!arg0)
|
||||||
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", __pidfile_path, __progname);
|
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", __pidfile_path, ident);
|
||||||
|
else if (arg0[0] != '/')
|
||||||
|
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", __pidfile_path, arg0);
|
||||||
|
else
|
||||||
|
snprintf(PIDFILE, sizeof(PIDFILE), "%s", arg0);
|
||||||
|
|
||||||
|
PRINT("Verifying pidfile(%s) ... PID: %d\n", PIDFILE, getpid());
|
||||||
|
|
||||||
|
/* Remove any lingering files from previous test runs */
|
||||||
|
remove(PIDFILE);
|
||||||
|
|
||||||
signal(SIGTERM, sigterm_handler);
|
signal(SIGTERM, sigterm_handler);
|
||||||
signal(SIGALRM, sigalrm_handler);
|
signal(SIGALRM, sigalrm_handler);
|
||||||
|
|
||||||
|
/* For signalling test */
|
||||||
alarm(1);
|
alarm(1);
|
||||||
|
|
||||||
return test(pidfile_poll(PIDFILE) != getpid(), "Testing pidfile_poll()")
|
return test(pidfile_poll(PIDFILE) != getpid(), "Testing pidfile_poll()")
|
||||||
@@ -68,7 +82,50 @@ int main(int argc, char *argv[])
|
|||||||
|| test(mtime(), "Testing mtime update of followup pidfile() call")
|
|| test(mtime(), "Testing mtime update of followup pidfile() call")
|
||||||
|| test(pidfile_signal(PIDFILE, SIGTERM), "Testing signalling ourselves")
|
|| test(pidfile_signal(PIDFILE, SIGTERM), "Testing signalling ourselves")
|
||||||
;
|
;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *progname(char *arg0)
|
||||||
|
{
|
||||||
|
char *nm;
|
||||||
|
|
||||||
|
nm = strrchr(arg0, '/');
|
||||||
|
if (nm)
|
||||||
|
nm++;
|
||||||
|
else
|
||||||
|
nm = arg0;
|
||||||
|
|
||||||
|
return nm;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
size_t i;
|
||||||
|
char *pidfiles[] = {
|
||||||
|
NULL,
|
||||||
|
"pidfile_test1",
|
||||||
|
"/var/tmp/pidfile_test2.pid",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "-v"))
|
||||||
|
verbose = 1;
|
||||||
|
|
||||||
|
/* Override default _PATH_VARRUN in pidfile() */
|
||||||
|
__pidfile_path = _PATH_TMP;
|
||||||
|
|
||||||
|
/* Find __progname, not all C libraries support this */
|
||||||
|
ident = progname(argv[0]);
|
||||||
|
|
||||||
|
for (i = 0; i < NELEMS(pidfiles); i++)
|
||||||
|
ret += test_pidfile(pidfiles[i]);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* compile-command: "make pidfile && ./pidfile -v"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user