1*a4527715Sguenther /* $OpenBSD: ab.c,v 1.1 2014/11/23 08:46:49 guenther Exp $ */
2*a4527715Sguenther
3*a4527715Sguenther /*
4*a4527715Sguenther * Copyright (c) 2014 Philip Guenther <guenther@openbsd.org>
5*a4527715Sguenther *
6*a4527715Sguenther * Permission to use, copy, modify, and distribute this software for any
7*a4527715Sguenther * purpose with or without fee is hereby granted, provided that the above
8*a4527715Sguenther * copyright notice and this permission notice appear in all copies.
9*a4527715Sguenther *
10*a4527715Sguenther * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*a4527715Sguenther * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*a4527715Sguenther * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*a4527715Sguenther * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*a4527715Sguenther * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*a4527715Sguenther * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*a4527715Sguenther * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*a4527715Sguenther */
18*a4527715Sguenther
19*a4527715Sguenther #include <stdlib.h>
20*a4527715Sguenther #include <stdio.h>
21*a4527715Sguenther #include <pthread.h>
22*a4527715Sguenther
23*a4527715Sguenther #define CALLBACK(file, name) \
24*a4527715Sguenther static void name(void) \
25*a4527715Sguenther { \
26*a4527715Sguenther fprintf(file, "libab "#name"\n"); \
27*a4527715Sguenther fflush(file); \
28*a4527715Sguenther }
29*a4527715Sguenther
CALLBACK(stdout,cleanup)30*a4527715Sguenther CALLBACK(stdout, cleanup)
31*a4527715Sguenther
32*a4527715Sguenther void
33*a4527715Sguenther ab(void)
34*a4527715Sguenther {
35*a4527715Sguenther atexit(cleanup);
36*a4527715Sguenther }
37*a4527715Sguenther
38*a4527715Sguenther static FILE *otherf;
39*a4527715Sguenther
CALLBACK(stdout,atfork_prepare)40*a4527715Sguenther CALLBACK(stdout, atfork_prepare)
41*a4527715Sguenther CALLBACK(stdout, atfork_parent)
42*a4527715Sguenther CALLBACK(otherf, atfork_child)
43*a4527715Sguenther
44*a4527715Sguenther void
45*a4527715Sguenther ab_atfork(FILE *f)
46*a4527715Sguenther {
47*a4527715Sguenther otherf = f;
48*a4527715Sguenther pthread_atfork(atfork_prepare, atfork_parent, atfork_child);
49*a4527715Sguenther }
50