rbb         99/06/08 08:38:12

  Added:       apr/threadproc/win32 proc.c signals.c thread.c
                        threadcancel.c threadpriv.c threadproc.dsp
                        threadproc.h
  Log:
  First pass at thread/process stuff for Win32.
  
  Revision  Changes    Path
  1.1                  apache-apr/apr/threadproc/win32/proc.c
  
  Index: proc.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "threadproc.h"
  #include "fileio.h"
  
  #include "apr_thread_proc.h"
  #include "apr_file_io.h"
  #include "apr_general.h"
  #include "apr_lib.h"
  #include <signal.h>
  #include <string.h>
  
  ap_status_t ap_createprocattr_init(ap_context_t *cont, struct procattr_t 
**new)
  {
      (*new) = (struct procattr_t *)ap_palloc(cont, 
                sizeof(struct procattr_t));
  
      if ((*new) == NULL) {
          return APR_ENOMEM;
      }
      (*new)->cntxt = cont;
      (*new)->parent_in = NULL;
      (*new)->child_in = NULL;
      (*new)->parent_out = NULL;
      (*new)->child_out = NULL;
      (*new)->parent_err = NULL;
      (*new)->child_err = NULL;
      (*new)->currdir = NULL; 
      (*new)->cmdtype = APR_PROGRAM;
        (*new)->detached = TRUE;
  
      memset(&(*new)->si, 0, sizeof((*new)->si));
  
        return APR_SUCCESS;
  }
  
  ap_status_t ap_setprocattr_io(struct procattr_t *attr, ap_int32_t in, 
                                   ap_int32_t out, ap_int32_t err)
  {
      ap_status_t stat;
      if (in) {
          if ((stat = ap_create_pipe(attr->cntxt, &attr->child_in, 
                              &attr->parent_in)) != APR_SUCCESS) {
              return stat;
          }
      } 
      if (out) {
          if ((stat = ap_create_pipe(attr->cntxt, &attr->parent_out, 
                              &attr->child_out)) != APR_SUCCESS) {
              return stat;
          }
      } 
      if (err) {
          if ((stat = ap_create_pipe(attr->cntxt, &attr->parent_err, 
                              &attr->child_err)) != APR_SUCCESS) {
              return stat;
          }
      } 
      return APR_SUCCESS;
  }
  
  ap_status_t ap_setprocattr_dir(struct procattr_t *attr, 
                                   char *dir) 
  {
      attr->currdir = ap_pstrdup(attr->cntxt, dir);
      if (attr->currdir) {
          return APR_SUCCESS;
      }
      return APR_ENOMEM;
  }
  
  ap_status_t ap_setprocattr_cmdtype(struct procattr_t *attr,
                                       ap_cmdtype_e cmd) 
  {
      attr->cmdtype = cmd;
      return APR_SUCCESS;
  }
  
  ap_status_t ap_setprocattr_detach(struct procattr_t *attr,
                                                                        
ap_int32_t det) 
  {
      attr->detached = det;
      return APR_SUCCESS;
  }
  
  ap_status_t ap_create_process(ap_context_t *cont, char *progname, 
                                 char *const args[], char **env, 
                                 struct procattr_t *attr, struct proc_t **new)
  {
      int i;
        char *cmdline;
        HANDLE hCurrentProcess;
        HANDLE hParentindup, hParentoutdup,hParenterrdup;
  
      (*new) = (struct proc_t *)ap_palloc(cont, sizeof(struct proc_t));
  
      if ((*new) == NULL) {
          return APR_ENOMEM;
      }
  
      (*new)->cntxt = cont;
        (*new)->attr = attr;
  
        attr->si.cb = sizeof(attr->si);
        attr->si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
        attr->si.wShowWindow = SW_HIDE;
        if (attr->child_in) {
                attr->si.hStdInput = attr->child_in->filehand;
        }
  
        if (attr->child_out) {
                attr->si.hStdOutput = attr->child_out->filehand;
        }
  
        if (attr->child_err) {
                attr->si.hStdError = attr->child_err->filehand;
        }
  
        cmdline = args[0];
        i = 1;
        while (args[i]) {
                cmdline = ap_pstrcat(cont, cmdline, " ", args[i], NULL);
                i++;
        }
      /*
       * When the pipe handles are created, the security descriptor
       * indicates that the handle can be inherited.  However, we do not
       * want the server side handles to the pipe to be inherited by the
       * child CGI process. If the child CGI does inherit the server
       * side handles, then the child may be left around if the server
       * closes its handles (e.g. if the http connection is aborted),
       * because the child will have a valid copy of handles to both
       * sides of the pipes, and no I/O error will occur.  Microsoft
       * recommends using DuplicateHandle to turn off the inherit bit
       * under NT and Win95.
       */
      hCurrentProcess = GetCurrentProcess();
      if ((attr->child_in && !DuplicateHandle(hCurrentProcess, 
attr->parent_in->filehand, 
                                                            hCurrentProcess,
                                                            &hParentindup, 0, 
FALSE,
                                                            
DUPLICATE_SAME_ACCESS))
        || (attr->child_out && !DuplicateHandle(hCurrentProcess, 
attr->parent_out->filehand,
                                                                
hCurrentProcess, &hParentoutdup,
                                                                                
    0, FALSE, DUPLICATE_SAME_ACCESS))
        || (attr->child_err && !DuplicateHandle(hCurrentProcess, 
attr->parent_err->filehand,
                                                                                
        hCurrentProcess, &hParenterrdup,
                                                                                
        0, FALSE, DUPLICATE_SAME_ACCESS))) {
                if (attr->child_in) {
                        ap_close(attr->child_in);
                        ap_close(attr->parent_in);
                }
                if (attr->child_out) {
                        ap_close(attr->child_out);
                        ap_close(attr->parent_out);
                }
                if (attr->child_err) {
                        ap_close(attr->child_err);
                        ap_close(attr->parent_err);
                }
                return 0;
      }
      else {
                if (attr->child_in) {
                        ap_close(attr->parent_in);
                    attr->parent_in->filehand = hParentindup;
                }
                if (attr->child_out) {
                        ap_close(attr->parent_out);
                        attr->parent_out->filehand = hParentoutdup;
                }
                if (attr->child_err) {
                    ap_close(attr->parent_err);
                    attr->parent_err->filehand = hParenterrdup;
                }
      }
  
      if (CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, env, attr->currdir, 
                &attr->si, &(*new)->pi)) {
                if (attr->detached) {
                        CloseHandle((*new)->pi.hProcess);
                }
                if (attr->child_in) {
                        ap_close(attr->child_in);
                }
                if (attr->child_out) {
                        ap_close(attr->child_out);
                }
                if (attr->child_err) {
                        ap_close(attr->child_err);
                }
                CloseHandle((*new)->pi.hThread);
                return APR_SUCCESS;
        }
  
        return GetLastError();
  }
  
  ap_status_t ap_get_childin(struct proc_t *proc, ap_file_t **new)
  {
      (*new) = proc->attr->parent_in;
      return APR_SUCCESS; 
  }
  
  ap_status_t ap_get_childout(struct proc_t *proc, ap_file_t **new)
  {
      (*new) = proc->attr->parent_out; 
      return APR_SUCCESS;
  }
  
  ap_status_t ap_get_childerr(struct proc_t *proc, ap_file_t **new)
  {
      (*new) = proc->attr->parent_err; 
      return APR_SUCCESS;
  }    
  
  ap_status_t ap_wait_proc(struct proc_t *proc, 
                             ap_wait_how_e wait)
  {
      pid_t stat;
      if (!proc)
          return APR_ENOPROC;
      if (wait == APR_WAIT) {
          if ((stat = WaitForSingleObject(proc->pi.hProcess, INFINITE)) == 
WAIT_OBJECT_0) {
              return APR_CHILD_DONE;
          }
          else if (stat == WAIT_TIMEOUT) {
              return APR_CHILD_NOTDONE;
          }
          return APR_EEXIST;
      }
      if ((stat = WaitForSingleObject(proc->pi.hProcess, 0)) == WAIT_OBJECT_0) {
              return APR_CHILD_DONE;
          }
          else if (stat == WAIT_TIMEOUT) {
              return APR_CHILD_NOTDONE;
          }
          return APR_EEXIST;
  } 
  
  
  
  
  1.1                  apache-apr/apr/threadproc/win32/signals.c
  
  Index: signals.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "threadproc.h"
  #include "fileio.h"
  #include "apr_thread_proc.h"
  #include "apr_file_io.h"
  #include "apr_general.h"
  #include <signal.h>
  #include <string.h>
  #ifdef HAVE_SYS_WAIT
  #include <sys/wait.h>
  #endif
  
  /* Windows only really support killing process, but that will do for now. */
  ap_status_t ap_kill(struct proc_t *proc, int signal)
  {
      if (TerminateProcess(proc->pi.hProcess, signal) == 0) {
          return errno;
      }
      return APR_SUCCESS;
  }
  
  
  
  
  1.1                  apache-apr/apr/threadproc/win32/thread.c
  
  Index: thread.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "threadproc.h"
  #include "apr_thread_proc.h"
  #include "apr_general.h"
  #include "apr_lib.h"
  #include <process.h>
  
  
  ap_status_t ap_create_threadattr(ap_context_t *cont, struct threadattr_t 
**new)
  {
      (*new) = (struct threadattr_t *)ap_palloc(cont, 
                sizeof(struct threadattr_t));
  
      if ((*new) == NULL) {
          return APR_ENOMEM;
      }
  
      (*new)->cntxt = cont;
      return APR_SUCCESS;
  }
  
  ap_status_t ap_setthreadattr_detach(struct threadattr_t *attr, ap_int32_t on)
  {
      attr->detach = on;
        return APR_SUCCESS;
  }
  
  ap_status_t ap_getthreadattr_detach(struct threadattr_t *attr)
  {
      if (attr->detach == 1)
          return APR_DETACH;
      return APR_NOTDETACH;
  }
  
  ap_status_t ap_create_thread(ap_context_t *cont, struct threadattr_t *attr, 
                               ap_thread_start_t func, void *data, 
                               struct thread_t **new)
  {
      ap_status_t stat;
        unsigned temp;
   
      (*new) = (struct thread_t *)ap_palloc(cont, sizeof(struct thread_t));
  
      if ((*new) == NULL) {
          return APR_ENOMEM;
      }
  
      (*new)->cntxt = cont;
      
      stat = ap_create_context(cont, NULL, &(*new)->cntxt);
      if (stat != APR_SUCCESS) {
          return stat;
      }
  
        /* Use 0 for Thread Stack Size, because that will default the stack to 
the
         * same size as the calling thread. 
        */
      if (((*new)->td = (HANDLE *)_beginthreadex(func, 0, data, NULL, 0, 
&temp)) == 0) {
          return APR_EEXIST;
      }
  
        if (attr->detach) {
                CloseHandle((*new)->td);
        }
  
        return APR_SUCCESS;
  }
  
  ap_status_t ap_thread_exit(ap_thread_t *thd, ap_status_t *retval)
  {
      ap_destroy_pool(thd->cntxt);
      _endthreadex(*retval);
        return APR_SUCCESS;
  }
  
  ap_status_t ap_thread_join(struct thread_t *thd, ap_status_t *retval)
  {
      ap_status_t stat;
  
      if ((stat = WaitForSingleObject(thd->td, INFINITE)) == WAIT_OBJECT_0) {
                if (GetExitCodeThread(thd->td, retval) == 0) {
                        return APR_SUCCESS;
                }
                return APR_EEXIST;
      }
      else {
          return stat;
      }
  }
  
  ap_status_t ap_thread_detach(struct thread_t *thd)
  {
      if (CloseHandle(thd->td)) {
          return APR_SUCCESS;
      }
      else {
          return APR_EEXIST;
      }
  }
  
  
  
  
  
  1.1                  apache-apr/apr/threadproc/win32/threadcancel.c
  
  Index: threadcancel.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "threadproc.h"
  #include "apr_thread_proc.h"
  #include "apr_general.h"
  
  
  ap_status_t ap_cancel_thread(struct thread_t *thd)
  {
      if (TerminateThread(thd->td, APR_SUCCESS) == 0) {
          return APR_EEXIST;
      }
      else {
          return APR_SUCCESS;
      }
  }
  
  /*  Not sure of the best way to do this just yet.
  ap_status_t ap_setcanceltype(ap_context_t *cont, ap_int32_t type)
  {
        
  }
  
  ap_status_t ap_setcancelstate(ap_context_t *cont, ap_int32_t type)
  {
      ap_status_t stat;
      if ((stat = pthread_setcanceltype(type, NULL)) == 0) {
          return APR_SUCCESS;
      }
      else {
          return stat;
      }
  }
  */
  
  
  
  1.1                  apache-apr/apr/threadproc/win32/threadpriv.c
  
  Index: threadpriv.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "threadproc.h"
  #include "apr_thread_proc.h"
  #include "apr_general.h"
  #include "apr_errno.h"
  
  ap_status_t ap_create_thread_private(ap_context_t *cont, void (*dest)(void *),
                                       struct threadkey_t **key)
  {
        (*key)->key = TlsAlloc();
        return APR_SUCCESS;
  }
  
  ap_status_t ap_get_thread_private(struct threadkey_t *key, void **new)
  {
      if ((*new) = TlsGetValue(key->key)) {
                return APR_SUCCESS;
        }
        return APR_EEXIST;
  }
  
  ap_status_t ap_set_thread_private(struct threadkey_t *key, void *priv)
  {
      if (TlsSetValue(key->key, priv)) {
                return APR_SUCCESS;
        }
        return APR_EEXIST;
  }
  
  ap_status_t ap_delete_thread_private(struct threadkey_t *key)
  {
      if (TlsFree(key->key)) {
          return APR_SUCCESS; 
      }
      return APR_EEXIST;
  }
  
  
  
  
  1.1                  apache-apr/apr/threadproc/win32/threadproc.dsp
  
  Index: threadproc.dsp
  ===================================================================
  # Microsoft Developer Studio Project File - Name="threadproc" - Package 
Owner=<4>
  # Microsoft Developer Studio Generated Build File, Format Version 5.00
  # ** DO NOT EDIT **
  
  # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
  
  CFG=threadproc - Win32 Debug
  !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  !MESSAGE use the Export Makefile command and run
  !MESSAGE 
  !MESSAGE NMAKE /f "threadproc.mak".
  !MESSAGE 
  !MESSAGE You can specify a configuration when running NMAKE
  !MESSAGE by defining the macro CFG on the command line. For example:
  !MESSAGE 
  !MESSAGE NMAKE /f "threadproc.mak" CFG="threadproc - Win32 Debug"
  !MESSAGE 
  !MESSAGE Possible choices for configuration are:
  !MESSAGE 
  !MESSAGE "threadproc - Win32 Release" (based on\
   "Win32 (x86) Dynamic-Link Library")
  !MESSAGE "threadproc - Win32 Debug" (based on\
   "Win32 (x86) Dynamic-Link Library")
  !MESSAGE 
  
  # Begin Project
  # PROP Scc_ProjName ""
  # PROP Scc_LocalPath ""
  CPP=cl.exe
  MTL=midl.exe
  RSC=rc.exe
  
  !IF  "$(CFG)" == "threadproc - Win32 Release"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 0
  # PROP BASE Output_Dir "Release"
  # PROP BASE Intermediate_Dir "Release"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 0
  # PROP Output_Dir "Release"
  # PROP Intermediate_Dir "Release"
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" 
/YX /FD /c
  # ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX 
/FD /c
  # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
  # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
  # ADD BASE RSC /l 0x409 /d "NDEBUG"
  # ADD RSC /l 0x409 /d "NDEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
  # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
  
  !ELSEIF  "$(CFG)" == "threadproc - Win32 Debug"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 1
  # PROP BASE Output_Dir "Debug"
  # PROP BASE Intermediate_Dir "Debug"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
  # PROP Output_Dir "Debug"
  # PROP Intermediate_Dir "Debug"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D 
"_WINDOWS" /YX /FD /c
  # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\include" /I 
"..\..\..\include" /I "..\..\file_io\win32" /D "WIN32" /D "_DEBUG" /D 
"_WINDOWS" /D "NEED_TLS_SPEC" /YX /FD /c
  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
  # ADD RSC /l 0x409 /d "_DEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
  # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib ..\..\file_io\win32\Debug\file_io.lib ..\..\lib\Debug\lib.lib 
..\..\misc\win32\Debug\misc.lib /nologo /subsystem:windows /dll /debug 
/machine:I386 /pdbtype:sept
  
  !ENDIF 
  
  # Begin Target
  
  # Name "threadproc - Win32 Release"
  # Name "threadproc - Win32 Debug"
  # Begin Source File
  
  SOURCE=.\proc.c
  # End Source File
  # Begin Source File
  
  SOURCE=.\signals.c
  # End Source File
  # Begin Source File
  
  SOURCE=.\thread.c
  # End Source File
  # Begin Source File
  
  SOURCE=.\threadcancel.c
  # End Source File
  # Begin Source File
  
  SOURCE=.\threadpriv.c
  # End Source File
  # Begin Source File
  
  SOURCE=.\threadproc.def
  # End Source File
  # Begin Source File
  
  SOURCE=.\threadproc.h
  # End Source File
  # End Target
  # End Project
  
  
  
  1.1                  apache-apr/apr/threadproc/win32/threadproc.h
  
  Index: threadproc.h
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include <windows.h>
  #include "apr_thread_proc.h"
  #include "apr_file_io.h"
  
  #ifndef THREAD_PROC_H
  #define THREAD_PROC_H
  
  #define SHELL_PATH "/bin/sh"
  
  struct thread_t {
      ap_context_t *cntxt;
      HANDLE td;
        ap_int32_t cancel;
        ap_int32_t cancel_how;
  };
  
  struct threadattr_t {
      ap_context_t *cntxt;
      ap_int32_t detach;
  
  };
  
  struct threadkey_t {
      ap_context_t *cntxt;
      DWORD key;
  
  };
  
  struct procattr_t {
      ap_context_t *cntxt;
        STARTUPINFO si;
      ap_file_t *parent_in;
      ap_file_t *child_in;
      ap_file_t *parent_out;
      ap_file_t *child_out;
      ap_file_t *parent_err;
      ap_file_t *child_err;
      char *currdir;
      ap_int32_t cmdtype;
        ap_int32_t detached;
  };
  
  struct proc_t {
      ap_context_t *cntxt;
        PROCESS_INFORMATION pi;
      struct procattr_t *attr;
  };
  
  #endif  /* ! THREAD_PROC_H */
  
  
  
  

Reply via email to