| 1 |
/* waitdaemon -- Verify that waitdaemon() is functional. |
| 2 |
Copyright (C) 2010-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
/* Verify that waitdaemon() in libinetutils.a is functional. |
| 20 |
This is needed by syslogd. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <config.h> |
| 24 |
|
| 25 |
#include <stdio.h> |
| 26 |
#include <unistd.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
#include <sys/types.h> |
| 30 |
#include <signal.h> |
| 31 |
#include <errno.h> |
| 32 |
|
| 33 |
#include <error.h> |
| 34 |
#include <progname.h> |
| 35 |
#include <libinetutils.h> |
| 36 |
#include <attribute.h> |
| 37 |
|
| 38 |
extern int waitdaemon (int nochdir, int noclose, int maxwait); |
| 39 |
|
| 40 |
void |
| 41 |
doexit (int signo MAYBE_UNUSED) |
| 42 |
{ |
| 43 |
_exit (EXIT_SUCCESS); |
| 44 |
} |
| 45 |
|
| 46 |
int |
| 47 |
main (int argc MAYBE_UNUSED, char *argv[]) |
| 48 |
{ |
| 49 |
pid_t ppid; |
| 50 |
|
| 51 |
set_program_name (argv[0]); |
| 52 |
|
| 53 |
signal (SIGTERM, doexit); /* Parent exits nicely at SIGTERM. */ |
| 54 |
|
| 55 |
ppid = waitdaemon (0, 0, 5); /* Five seconds of delay. */ |
| 56 |
|
| 57 |
/* Child should return here before parent. */ |
| 58 |
if (ppid > 0) |
| 59 |
kill (ppid, SIGTERM); /* Bless the parent process. */ |
| 60 |
|
| 61 |
/* Only grand child reaches this statement. */ |
| 62 |
return EXIT_FAILURE; |
| 63 |
} |