1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/*
@mindmaze_header@
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <mmdlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include "mmerrno.h"
#include "mmlog.h"
#include "mmsysio.h"
#include "socket-testlib.h"
#include "tests-child-proc.h"
#include "threaddata-manipulation.h"
#define PASSED_FD 3
int main(int argc, char* argv[])
{
void* map = NULL;
int fd;
unsigned int mapsz;
int exitcode;
void *hndl = NULL;
union {
void* ptr;
intptr_t (*fn)(void*);
} symbol;
// If 3 argument looks like "mapfile-%i-%u", it means that the caller
// want us to map the file and size as specified in the argument
if (argc >= 3 && sscanf(argv[2], "mapfile-%i-%u", &fd, &mapsz) == 2) {
map = mm_mapfile(fd, 0, mapsz, MM_MAP_RDWR|MM_MAP_SHARED);
if (!map) {
mm_print_lasterror("mm_mapfile(%i, %u) failed", fd,
mapsz);
return EXIT_FAILURE;
}
}
exitcode = EXIT_SUCCESS;
if (argc < 2) {
fprintf(stderr, "Missing argument\n");
exitcode = EXIT_FAILURE;
goto exit;
} else if (!strcmp(argv[1], "run_socket_client")) {
run_socket_client(WR_PIPE_FD, RD_PIPE_FD, argc-2, argv+2);
} else {
exitcode = EXIT_FAILURE;
hndl = mm_dlopen(NULL, MM_LD_LAZY);
if (hndl == NULL)
goto exit;
/* Use union to allow cast between func pointer and void* */
symbol.ptr = mm_dlsym(hndl, argv[1]);
if (symbol.ptr == NULL) {
fprintf(stderr, "Unknown arg: %s\n", argv[1]);
exitcode = EXIT_FAILURE;
goto exit;
}
fprintf(stderr, "Running: %s\n", argv[1]);
/* function should return NULL on success */
exitcode = symbol.fn(map);
mm_log_debug("%s exited: %d", argv[1], exitcode);
}
exit:
mm_dlclose(hndl);
mm_unmap(map);
return exitcode;
}
|