| 1 | /* |
| 2 | * Copyright (C) 2009 Pierre-Marc Fournier |
| 3 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: LGPL-2.1-only |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <unistd.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <stdlib.h> |
| 13 | |
| 14 | #define TRACEPOINT_DEFINE |
| 15 | #define TRACEPOINT_CREATE_PROBES |
| 16 | #include "ust_tests_daemon.h" |
| 17 | |
| 18 | int main(int argc, char **argv, char *env[]) |
| 19 | { |
| 20 | int result; |
| 21 | |
| 22 | if (argc < 1) { |
| 23 | fprintf(stderr, "usage: daemon\n"); |
| 24 | exit(1); |
| 25 | } |
| 26 | |
| 27 | pid_t parent_pid = getpid(); |
| 28 | printf("parent_pid %d\n", parent_pid); |
| 29 | tracepoint(ust_tests_daemon, before_daemon, parent_pid); |
| 30 | |
| 31 | result = daemon(0, 1); |
| 32 | if (result == 0) { |
| 33 | printf("child_pid %d\n", getpid()); |
| 34 | |
| 35 | tracepoint(ust_tests_daemon, after_daemon_child, getpid()); |
| 36 | } else { |
| 37 | tracepoint(ust_tests_daemon, after_daemon_parent); |
| 38 | perror("daemon"); |
| 39 | exit(1); |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |