Example #1
0
void get_homepath(char *homepath, const char *thisfile)
{
    char buf[_MAX_PATH];
    char *p;

    /* Fill in here (directory of thisfile). */
    strcpy(buf, PI_GetPrefix());

    /* Make homepath absolute.
     * 'homepath' contains ./ which breaks some modules when changing the CWD.
     * Relative LD_LIBRARY_PATH is a security problem.
     */
    p = realpath(buf, homepath);
    if(p == NULL) {
        FATALERROR("Error in making homepath absolute.\n");
        /* Fallback to relative path. */
        strcpy(homepath, buf);
    }

    /* Path must end with slash. / */
    strcat(homepath, "/");

    VS("homepath is %s\n", homepath);
}
Example #2
0
File: main.c Project: pdubroy/kurt
int main(int argc, char* argv[])
{
    char thisfile[_MAX_PATH];
    char homepath[_MAX_PATH];
    char archivefile[_MAX_PATH + 5];
    TOC *ptoc = NULL;
    int rc = 0;
    int pid;
    char *workpath = NULL;
    /* atexit(cleanUp); */
#ifdef FREEZE_EXCEPTIONS
    PyImport_FrozenModules = _PyImport_FrozenModules;
#endif
    /* fill in thisfile */
#ifdef __CYGWIN__
    if (strncasecmp(&argv[0][strlen(argv[0])-4], ".exe", 4)) {
        strcpy(thisfile, argv[0]);
        strcat(thisfile, ".exe");
        PI_SetProgramName(thisfile);
    }
    else
#endif
        PI_SetProgramName(argv[0]);
    strcpy(thisfile, PI_GetProgramFullPath());
    VS("thisfile is %s\n", thisfile);

    workpath = getenv( "_MEIPASS2" );
    VS("_MEIPASS2 (workpath) is %s\n", (workpath ? workpath : "NULL"));

    /* fill in here (directory of thisfile) */
    strcpy(homepath, PI_GetPrefix());
    strcat(homepath, "/");
    VS("homepath is %s\n", homepath);

    if (init(homepath, &thisfile[strlen(homepath)], workpath)) {
        /* no pkg there, so try the nonelf configuration */
        strcpy(archivefile, thisfile);
        strcat(archivefile, ".pkg");
        if (init(homepath, &archivefile[strlen(homepath)], workpath)) {
            FATALERROR("Cannot open self %s or archive %s\n",
                       thisfile, archivefile);
            return -1;
        }
    }

    if (workpath) {
        /* we're the "child" process */
        VS("Already have a workpath - running!\n");
        rc = doIt(argc, argv);
    }
    else {
        if (extractBinaries(&workpath)) {
            VS("Error extracting binaries\n");
            return -1;
        }

        if (workpath == NULL)
            workpath = homepath;

        VS("Executing self as child with ");
        /* run the "child" process, then clean up */
        setenv("_MEIPASS2", workpath, 1);

        /* add workpath to LD_LIBRARY_PATH */
        exportWorkpath(workpath, "LD_LIBRARY_PATH");
#ifdef __APPLE__
        /* add workpath to DYLD_LIBRARY_PATH */
        exportWorkpath(workpath, "DYLD_LIBRARY_PATH");
#endif
        pid = fork();
        if (pid == 0)
            execvp(thisfile, argv);
        /*
            wait(&rc);
            rc = WEXITSTATUS(rc);

            VS("Back to parent...\n");
            if (strcmp(workpath, homepath) != 0)
                clear(workpath);
        */
    }
    return rc;
}