1 |
1325 |
phoenix |
/*
|
2 |
|
|
* This test program will register the maximum number of exit functions
|
3 |
|
|
* with on_exit(). When this program exits, each exit function should get
|
4 |
|
|
* called in the reverse order in which it was registered. (If the system
|
5 |
|
|
* supports more than 25 exit functions, the function names will loop, but
|
6 |
|
|
* the effect will be the same. Feel free to add more functions if desired)
|
7 |
|
|
*/
|
8 |
|
|
#include <stdio.h>
|
9 |
|
|
#include <stdlib.h>
|
10 |
|
|
|
11 |
|
|
typedef void (*efuncp) (int, void *);
|
12 |
|
|
|
13 |
|
|
/* All functions call exit(), in order to test that exit functions can call
|
14 |
|
|
* exit() without screwing everything up. The value passed in through arg gets
|
15 |
|
|
* used as the next exit status.
|
16 |
|
|
*/
|
17 |
|
|
static void exitfunc0(int status, void *arg) { printf("Executing exitfunc0 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
18 |
|
|
static void exitfunc1(int status, void *arg) { printf("Executing exitfunc1 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
19 |
|
|
static void exitfunc2(int status, void *arg) { printf("Executing exitfunc2 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
20 |
|
|
static void exitfunc3(int status, void *arg) { printf("Executing exitfunc3 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
21 |
|
|
static void exitfunc4(int status, void *arg) { printf("Executing exitfunc4 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
22 |
|
|
static void exitfunc5(int status, void *arg) { printf("Executing exitfunc5 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
23 |
|
|
static void exitfunc6(int status, void *arg) { printf("Executing exitfunc6 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
24 |
|
|
static void exitfunc7(int status, void *arg) { printf("Executing exitfunc7 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
25 |
|
|
static void exitfunc8(int status, void *arg) { printf("Executing exitfunc8 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
26 |
|
|
static void exitfunc9(int status, void *arg) { printf("Executing exitfunc9 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
27 |
|
|
static void exitfunc10(int status, void *arg) { printf("Executing exitfunc10 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
28 |
|
|
static void exitfunc11(int status, void *arg) { printf("Executing exitfunc11 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
29 |
|
|
static void exitfunc12(int status, void *arg) { printf("Executing exitfunc12 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
30 |
|
|
static void exitfunc13(int status, void *arg) { printf("Executing exitfunc13 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
31 |
|
|
static void exitfunc14(int status, void *arg) { printf("Executing exitfunc14 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
32 |
|
|
static void exitfunc15(int status, void *arg) { printf("Executing exitfunc15 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
33 |
|
|
static void exitfunc16(int status, void *arg) { printf("Executing exitfunc16 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
34 |
|
|
static void exitfunc17(int status, void *arg) { printf("Executing exitfunc17 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
35 |
|
|
static void exitfunc18(int status, void *arg) { printf("Executing exitfunc18 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
36 |
|
|
static void exitfunc19(int status, void *arg) { printf("Executing exitfunc19 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
37 |
|
|
static void exitfunc20(int status, void *arg) { printf("Executing exitfunc20 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
38 |
|
|
static void exitfunc21(int status, void *arg) { printf("Executing exitfunc21 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
39 |
|
|
static void exitfunc22(int status, void *arg) { printf("Executing exitfunc22 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
40 |
|
|
static void exitfunc23(int status, void *arg) { printf("Executing exitfunc23 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
41 |
|
|
static void exitfunc24(int status, void *arg) { printf("Executing exitfunc24 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
|
42 |
|
|
|
43 |
|
|
static efuncp func_table[] =
|
44 |
|
|
{
|
45 |
|
|
exitfunc0, exitfunc1, exitfunc2, exitfunc3, exitfunc4,
|
46 |
|
|
exitfunc5, exitfunc6, exitfunc7, exitfunc8, exitfunc9,
|
47 |
|
|
exitfunc10, exitfunc11, exitfunc12, exitfunc13, exitfunc14,
|
48 |
|
|
exitfunc15, exitfunc16, exitfunc17, exitfunc18, exitfunc19,
|
49 |
|
|
exitfunc20, exitfunc21, exitfunc22, exitfunc23, exitfunc24
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
/* glibc dynamically adds exit functions, so it will keep adding until
|
53 |
|
|
* it runs out of memory! So this will limit the number of exit functions
|
54 |
|
|
* we add in the loop below. uClibc has a set limit (currently 20), so the
|
55 |
|
|
* loop will go until it can't add any more (so it should not hit this limit).
|
56 |
|
|
*/
|
57 |
|
|
#define ON_EXIT_LIMIT 20
|
58 |
|
|
|
59 |
|
|
int
|
60 |
|
|
main ( void )
|
61 |
|
|
{
|
62 |
|
|
int i = 0;
|
63 |
|
|
int count = 0;
|
64 |
|
|
int numfuncs = sizeof(func_table)/sizeof(efuncp);
|
65 |
|
|
|
66 |
|
|
/* loop until no more can be added */
|
67 |
|
|
while(count < ON_EXIT_LIMIT && on_exit(func_table[i], (void *)count) >= 0) {
|
68 |
|
|
count++;
|
69 |
|
|
printf("Registered exitfunc%d with on_exit()\n", i);
|
70 |
|
|
i = (i+1) % numfuncs;
|
71 |
|
|
}
|
72 |
|
|
printf("%d functions registered with on_exit.\n", count);
|
73 |
|
|
exit(count);
|
74 |
|
|
}
|
75 |
|
|
|