Skip to content

Commit 5c70b3b

Browse files
committed
New filter: exitwhen: exit gracefully when an event occurs.
1 parent 598ea32 commit 5c70b3b

20 files changed

+1348
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ plugins/*/*.3
127127
/tests/test-data
128128
/tests/test-delay
129129
/tests/test-exit-with-parent
130+
/tests/test-exitwhen-pipe-closed
130131
/tests/test-ext2
131132
/tests/test-file-block
132133
/tests/test-golang

configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ filters="\
104104
delay \
105105
error \
106106
exitlast \
107+
exitwhen \
107108
exportname \
108109
ext2 \
109110
extentlist \
@@ -1228,6 +1229,7 @@ AC_CONFIG_FILES([Makefile
12281229
filters/delay/Makefile
12291230
filters/error/Makefile
12301231
filters/exitlast/Makefile
1232+
filters/exitwhen/Makefile
12311233
filters/exportname/Makefile
12321234
filters/ext2/Makefile
12331235
filters/extentlist/Makefile

docs/nbdkit-captive.pod

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ You can run nbdkit under another process and have nbdkit reliably
1515
clean up. There are two techniques depending on whether you want
1616
nbdkit to start the other process (L</CAPTIVE NBDKIT>), or if you want
1717
the other process to start nbdkit (L</EXIT WITH PARENT>). Another way
18-
is to have nbdkit exit after the last client connection, see
19-
L<nbdkit-exitlast-filter(1)>.
18+
is to have nbdkit exit after the last client connection
19+
(L<nbdkit-exitlast-filter(1)>) or after an event
20+
(L<nbdkit-exitwhen-filter(1)>).
2021

2122
=head1 CAPTIVE NBDKIT
2223

@@ -150,10 +151,14 @@ C<nbdkit --exit-with-parent> only from the main thread (unless you
150151
actually want nbdkit to exit with the thread, but that may not work
151152
reliably on all operating systems).
152153

154+
To exit when an unrelated process exits, use
155+
L<nbdkit-exitwhen-filter(1)> C<exit-when-process-exits> feature.
156+
153157
=head1 SEE ALSO
154158

155159
L<nbdkit(1)>,
156160
L<nbdkit-exitlast-filter(1)>,
161+
L<nbdkit-exitwhen-filter(1)>,
157162
L<prctl(2)> (on Linux),
158163
L<procctl(2)> (on FreeBSD).
159164

docs/nbdkit-service.pod

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ L</SOCKET ACTIVATION>.
145145
L<nbdkit(1)>,
146146
L<nbdkit-client(1)>,
147147
L<nbdkit-exitlast-filter(1)>,
148+
L<nbdkit-exitwhen-filter(1)>,
148149
L<nbdkit-ip-filter(1)>,
149150
L<nbdkit-limit-filter(1)>,
150151
L<systemd(1)>,

filters/exitlast/nbdkit-exitlast-filter.pod

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ resources when nbdkit is not in use (see L<nbdkit-service(1)>).
1717
Another use is to ensure nbdkit exits after the client has finished
1818
(but see also nbdkit-captive(1) for other ways to do this).
1919

20+
To exit when an event occurs, try L<nbdkit-exitwhen-filter(1)>.
21+
2022
=head1 PARAMETERS
2123

2224
There are no parameters specific to nbdkit-exitlast-filter. Any
@@ -42,6 +44,7 @@ C<nbdkit-exitlast-filter> first appeared in nbdkit 1.20.
4244
=head1 SEE ALSO
4345

4446
L<nbdkit(1)>,
47+
L<nbdkit-exitwhen-filter(1)>,
4548
L<nbdkit-ip-filter(1)>,
4649
L<nbdkit-limit-filter(1)>,
4750
L<nbdkit-rate-filter(1)>,

filters/exitwhen/Makefile.am

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# nbdkit
2+
# Copyright (C) 2019-2020 Red Hat Inc.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are
6+
# met:
7+
#
8+
# * Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
#
11+
# * Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in the
13+
# documentation and/or other materials provided with the distribution.
14+
#
15+
# * Neither the name of Red Hat nor the names of its contributors may be
16+
# used to endorse or promote products derived from this software without
17+
# specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26+
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29+
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30+
# SUCH DAMAGE.
31+
32+
include $(top_srcdir)/common-rules.mk
33+
34+
EXTRA_DIST = nbdkit-exitwhen-filter.pod
35+
36+
filter_LTLIBRARIES = nbdkit-exitwhen-filter.la
37+
38+
nbdkit_exitwhen_filter_la_SOURCES = \
39+
exitwhen.c \
40+
$(top_srcdir)/include/nbdkit-filter.h \
41+
$(NULL)
42+
43+
nbdkit_exitwhen_filter_la_CPPFLAGS = \
44+
-I$(top_srcdir)/include \
45+
-I$(top_srcdir)/common/utils \
46+
$(NULL)
47+
nbdkit_exitwhen_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
48+
nbdkit_exitwhen_filter_la_LIBADD = \
49+
$(top_builddir)/common/utils/libutils.la \
50+
$(IMPORT_LIBRARY_ON_WINDOWS) \
51+
$(NULL)
52+
nbdkit_exitwhen_filter_la_LDFLAGS = \
53+
-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
54+
-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
55+
$(NULL)
56+
57+
if HAVE_POD
58+
59+
man_MANS = nbdkit-exitwhen-filter.1
60+
CLEANFILES += $(man_MANS)
61+
62+
nbdkit-exitwhen-filter.1: nbdkit-exitwhen-filter.pod
63+
$(PODWRAPPER) --section=1 --man $@ \
64+
--html $(top_builddir)/html/$@.html \
65+
$<
66+
67+
endif HAVE_POD

0 commit comments

Comments
 (0)