Changeset 4665 for zzuf


Ignore:
Timestamp:
Oct 5, 2010, 2:08:03 PM (9 years ago)
Author:
Sam Hocevar
Message:

Proper child command line construction on Win32. There is no need
to hardcode stuff for debugging purposes any longer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/myfork.c

    r4664 r4665  
    174174    STARTUPINFO sinfo;
    175175    HANDLE pid;
    176     int ret;
     176    char *cmdline;
     177    int i, ret, len;
    177178#endif
    178179
     
    274275    pid = GetCurrentProcess();
    275276
     277    /* Inherit standard handles */
    276278    memset(&sinfo, 0, sizeof(sinfo));
    277279    sinfo.cb = sizeof(sinfo);
    278 
    279280    sinfo.hStdInput = (HANDLE)_get_osfhandle(pipes[0][CHILD_FD(0)]);
    280281    sinfo.hStdOutput = (HANDLE)_get_osfhandle(pipes[1][CHILD_FD(1)]);
    281282    sinfo.hStdError = (HANDLE)_get_osfhandle(pipes[2][CHILD_FD(2)]);
    282283    sinfo.dwFlags = STARTF_USESTDHANDLES;
    283     ret = CreateProcess(NULL, child->newargv[0], NULL, NULL, TRUE,
     284
     285    /* Build the commandline */
     286    for (i = 0, len = 0; child->newargv[i]; i++)
     287        len += strlen(child->newargv[i]) + 1;
     288    cmdline = malloc(len);
     289    for (i = 0, len = 0; child->newargv[i]; i++)
     290    {
     291        strcpy(cmdline + len, child->newargv[i]);
     292        len += strlen(child->newargv[i]) + 1;
     293        cmdline[len - 1] = ' ';
     294    }
     295    cmdline[len - 1] = '\0';
     296
     297    /* Create the process in suspended state */
     298    ret = CreateProcess(child->newargv[0], cmdline, NULL, NULL, TRUE,
    284299                        CREATE_SUSPENDED, NULL, NULL, &sinfo, &pinfo);
    285     if(!ret)
     300    free(cmdline);
     301
     302    if (!ret)
    286303        return -1;
    287304
Note: See TracChangeset for help on using the changeset viewer.