view jupyter_c_kernel/resources/master.c @ 75:a1e3b056a4bd 1.2.2

Merge pull request #40 from halfhorst/master add resources/ as package data committer: GitHub <>
author Brendan Rius <>
date Wed, 24 Jan 2018 11:01:54 +0100
parents resources/master.c@7857f8eea835 resources/master.c@b6b613c2a28a
line wrap: on
line source

#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

typedef int (*main_t)(int, char **, char **);

int main(int argc, char **argv, char **envp)
    char *error = NULL;

    setbuf(stdout, NULL);
    setbuf(stderr, NULL);
    if (argc < 2) {
        fprintf(stderr, "USAGE: %s PROGRAM\nWhere PROGRAM is the user's program to supervise\n", argv[0]);
        return EXIT_FAILURE;
    void *userhandle = dlopen(argv[1], RTLD_LAZY);
    if (userhandle == NULL) {
        fprintf(stderr, "%s: %s\n", argv[0], dlerror());
        return EXIT_FAILURE;
    main_t usermain = dlsym(userhandle, "main");
    if ((error = dlerror()) != NULL) {
        fprintf(stderr, "%s: %s\n", argv[0], error);
        return EXIT_FAILURE;

    /* Call Users main, but make master.c invisible by removing first argument */
    return usermain(argc-1, argv+1, envp);