| 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * Originally derived from nbdkit common/utils/exit-with-parent.h |
| 4 | * Copyright Red Hat |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * |
| 13 | * * Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * |
| 17 | * * Neither the name of Red Hat nor the names of its contributors may be |
| 18 | * used to endorse or promote products derived from this software without |
| 19 | * specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 23 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 24 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR |
| 25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 28 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | * SUCH DAMAGE. |
| 33 | */ |
| 34 | |
| 35 | #ifndef NBDKIT_EXIT_WITH_PARENT_H |
| 36 | #define NBDKIT_EXIT_WITH_PARENT_H |
| 37 | |
| 38 | /* Test if the feature is available on the platform. */ |
| 39 | static inline bool can_exit_with_parent(void) |
| 40 | { |
| 41 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) |
| 42 | return true; |
| 43 | #else |
| 44 | return false; |
| 45 | #endif |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * --exit-with-parent: kill the current process if the parent exits. |
| 50 | * This may return -1 on error. |
| 51 | * |
| 52 | * Note this will abort on platforms where can_exit_with_parent() |
| 53 | * returned false. |
| 54 | */ |
| 55 | extern int set_exit_with_parent(void); |
| 56 | |
| 57 | #endif /* NBDKIT_EXIT_WITH_PARENT_H */ |