VirtualBox

Ignore:
Timestamp:
Sep 15, 2006 2:30:32 AM (18 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/w32/subproc/sub_proc.c

    r284 r501  
     1/* Process handling for Windows.
     2Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
     32006 Free Software Foundation, Inc.
     4This file is part of GNU Make.
     5
     6GNU Make is free software; you can redistribute it and/or modify it under the
     7terms of the GNU General Public License as published by the Free Software
     8Foundation; either version 2, or (at your option) any later version.
     9
     10GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     11WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     13
     14You should have received a copy of the GNU General Public License along with
     15GNU Make; see the file COPYING.  If not, write to the Free Software
     16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
     17
    118#include <stdlib.h>
    219#include <stdio.h>
    320#include <process.h>  /* for msvc _beginthreadex, _endthreadex */
     21#include <signal.h>
    422#include <windows.h>
    523
     
    3149
    3250/* keep track of children so we can implement a waitpid-like routine */
    33 static sub_process *proc_array[256];
     51static sub_process *proc_array[MAXIMUM_WAIT_OBJECTS];
    3452static int proc_index = 0;
    3553static int fake_exits_pending = 0;
     
    6684process_wait_for_any_private(void)
    6785{
    68         HANDLE handles[256];
     86        HANDLE handles[MAXIMUM_WAIT_OBJECTS];
    6987        DWORD retval, which;
    7088        int i;
     
    120138process_register(HANDLE proc)
    121139{
    122         proc_array[proc_index++] = (sub_process *) proc;
     140        if (proc_index < MAXIMUM_WAIT_OBJECTS)
     141                proc_array[proc_index++] = (sub_process *) proc;
     142}
     143
     144/*
     145 * Return the number of processes that we are still waiting for.
     146 */
     147int
     148process_used_slots(void)
     149{
     150        return proc_index;
    123151}
    124152
     
    163191
    164192long
    165 process_errno(HANDLE proc)
    166 {
    167         return (((sub_process *)proc)->lerrno);
     193process_signal(HANDLE proc)
     194{
     195        if (proc == INVALID_HANDLE_VALUE) return 0;
     196        return (((sub_process *)proc)->signal);
    168197}
    169198
    170199long
    171 process_signal(HANDLE proc)
    172 {
    173         return (((sub_process *)proc)->signal);
    174 }
    175 
    176         long
    177200process_last_err(HANDLE proc)
    178201{
     202        if (proc == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE;
    179203        return (((sub_process *)proc)->last_err);
    180204}
    181205
    182         long
     206long
    183207process_exit_code(HANDLE proc)
    184208{
     209        if (proc == INVALID_HANDLE_VALUE) return EXIT_FAILURE;
    185210        return (((sub_process *)proc)->exit_code);
    186211}
    187212
    188         char *
     213/*
     2142006-02:
     215All the following functions are currently unused.
     216All of them would crash gmake if called with argument INVALID_HANDLE_VALUE.
     217Hence whoever wants to use one of this functions must invent and implement
     218a reasonable error handling for this function.
     219
     220char *
    189221process_outbuf(HANDLE proc)
    190222{
     
    192224}
    193225
    194         char *
     226char *
    195227process_errbuf(HANDLE proc)
    196228{
     
    198230}
    199231
    200         int
     232int
    201233process_outcnt(HANDLE proc)
    202234{
     
    204236}
    205237
    206         int
     238int
    207239process_errcnt(HANDLE proc)
    208240{
     
    210242}
    211243
    212         void
     244void
    213245process_pipes(HANDLE proc, int pipes[3])
    214246{
     
    218250        return;
    219251}
    220 
     252*/
    221253
    222254        HANDLE
     
    369401 * Description:   Create the child process to be helped
    370402 *
    371  * Returns:
     403 * Returns: success <=> 0
    372404 *
    373405 * Notes/Dependencies:
     
    523555                        pproc->last_err = GetLastError();
    524556                        pproc->lerrno = E_FORK;
    525                         fprintf(stderr, "process_begin: CreateProcess(%s, %s, ...) failed.\n", exec_path, command_line);
     557                        fprintf(stderr, "process_begin: CreateProcess(%s, %s, ...) failed.\n",
     558                                exec_path ? exec_path : "NULL", command_line);
    526559                        if (envblk) free(envblk);
    527560                        free( command_line );
     
    535568
    536569        /* Close the halves of the pipes we don't need */
    537         if (pproc->sv_stdin) {
    538                 CloseHandle((HANDLE)pproc->sv_stdin[1]);
    539                 (HANDLE)pproc->sv_stdin[1] = 0;
    540         }
    541         if (pproc->sv_stdout) {
    542                 CloseHandle((HANDLE)pproc->sv_stdout[1]);
    543                 (HANDLE)pproc->sv_stdout[1] = 0;
    544         }
    545         if (pproc->sv_stderr) {
    546                 CloseHandle((HANDLE)pproc->sv_stderr[1]);
    547                 (HANDLE)pproc->sv_stderr[1] = 0;
    548         }
     570        CloseHandle((HANDLE)pproc->sv_stdin[1]);
     571        CloseHandle((HANDLE)pproc->sv_stdout[1]);
     572        CloseHandle((HANDLE)pproc->sv_stderr[1]);
     573        pproc->sv_stdin[1] = 0;
     574        pproc->sv_stdout[1] = 0;
     575        pproc->sv_stderr[1] = 0;
    549576
    550577        free( command_line );
     
    658685        bool_t stdin_eof = FALSE, stdout_eof = FALSE, stderr_eof = FALSE;
    659686        HANDLE childhand = (HANDLE) pproc->pid;
    660         HANDLE tStdin, tStdout, tStderr;
    661         DWORD dwStdin, dwStdout, dwStderr;
     687        HANDLE tStdin = NULL, tStdout = NULL, tStderr = NULL;
     688        unsigned int dwStdin, dwStdout, dwStderr;
    662689        HANDLE wait_list[4];
    663690        DWORD wait_count;
     
    675702                stdin_eof = TRUE;
    676703                CloseHandle((HANDLE)pproc->sv_stdin[0]);
    677                 (HANDLE)pproc->sv_stdin[0] = 0;
     704                pproc->sv_stdin[0] = 0;
    678705        } else {
    679706                tStdin = (HANDLE) _beginthreadex( 0, 1024,
    680                         (unsigned (__stdcall *) (void *))proc_stdin_thread, pproc, 0,
    681                         (unsigned int *) &dwStdin);
     707                        (unsigned (__stdcall *) (void *))proc_stdin_thread,
     708                                                  pproc, 0, &dwStdin);
    682709                if (tStdin == 0) {
    683710                        pproc->last_err = GetLastError();
     
    692719        tStdout = (HANDLE) _beginthreadex( 0, 1024,
    693720                (unsigned (__stdcall *) (void *))proc_stdout_thread, pproc, 0,
    694                 (unsigned int *) &dwStdout);
     721                &dwStdout);
    695722        tStderr = (HANDLE) _beginthreadex( 0, 1024,
    696723                (unsigned (__stdcall *) (void *))proc_stderr_thread, pproc, 0,
    697                 (unsigned int *) &dwStderr);
     724                &dwStderr);
    698725
    699726        if (tStdout == 0 || tStderr == 0) {
     
    740767                if (ready_hand == tStdin) {
    741768                        CloseHandle((HANDLE)pproc->sv_stdin[0]);
    742                         (HANDLE)pproc->sv_stdin[0] = 0;
     769                        pproc->sv_stdin[0] = 0;
    743770                        CloseHandle(tStdin);
    744771                        tStdin = 0;
     
    748775
    749776                        CloseHandle((HANDLE)pproc->sv_stdout[0]);
    750                         (HANDLE)pproc->sv_stdout[0] = 0;
     777                        pproc->sv_stdout[0] = 0;
    751778                        CloseHandle(tStdout);
    752779                        tStdout = 0;
     
    756783
    757784                        CloseHandle((HANDLE)pproc->sv_stderr[0]);
    758                         (HANDLE)pproc->sv_stderr[0] = 0;
     785                        pproc->sv_stderr[0] = 0;
    759786                        CloseHandle(tStderr);
    760787                        tStderr = 0;
     
    763790                } else if (ready_hand == childhand) {
    764791
    765                         GetExitCodeResult = GetExitCodeProcess(childhand, (DWORD*)&pproc->exit_code);
     792                        DWORD ierr;
     793                        GetExitCodeResult = GetExitCodeProcess(childhand, &ierr);
     794                        if (ierr == CONTROL_C_EXIT) {
     795                                pproc->signal = SIGINT;
     796                        } else {
     797                                pproc->exit_code = ierr;
     798                        }
    766799                        if (GetExitCodeResult == FALSE) {
    767800                                pproc->last_err = GetLastError();
     
    812845        DWORD wait_return;
    813846        BOOL GetExitCodeResult;
     847        DWORD ierr;
    814848
    815849        if (proc == NULL)
     
    855889        }
    856890
    857         GetExitCodeResult = GetExitCodeProcess(childhand, (DWORD*)&pproc->exit_code);
     891        GetExitCodeResult = GetExitCodeProcess(childhand, &ierr);
     892        if (ierr == CONTROL_C_EXIT) {
     893                pproc->signal = SIGINT;
     894        } else {
     895                pproc->exit_code = ierr;
     896        }
    858897        if (GetExitCodeResult == FALSE) {
    859898                pproc->last_err = GetLastError();
     
    11561195  HANDLE hProcess;
    11571196
     1197  if (proc_index >= MAXIMUM_WAIT_OBJECTS) {
     1198        DB (DB_JOBS, ("process_easy: All process slots used up\n"));
     1199        return INVALID_HANDLE_VALUE;
     1200  }
    11581201  if (DuplicateHandle(GetCurrentProcess(),
    11591202                      GetStdHandle(STD_INPUT_HANDLE),
     
    11641207                      DUPLICATE_SAME_ACCESS) == FALSE) {
    11651208    fprintf(stderr,
    1166             "process_easy: DuplicateHandle(In) failed (e=%d)\n",
     1209            "process_easy: DuplicateHandle(In) failed (e=%ld)\n",
    11671210            GetLastError());
    11681211    return INVALID_HANDLE_VALUE;
     
    11761219                      DUPLICATE_SAME_ACCESS) == FALSE) {
    11771220    fprintf(stderr,
    1178            "process_easy: DuplicateHandle(Out) failed (e=%d)\n",
     1221           "process_easy: DuplicateHandle(Out) failed (e=%ld)\n",
    11791222           GetLastError());
    11801223    return INVALID_HANDLE_VALUE;
     
    11881231                      DUPLICATE_SAME_ACCESS) == FALSE) {
    11891232    fprintf(stderr,
    1190             "process_easy: DuplicateHandle(Err) failed (e=%d)\n",
     1233            "process_easy: DuplicateHandle(Err) failed (e=%ld)\n",
    11911234            GetLastError());
    11921235    return INVALID_HANDLE_VALUE;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette