Changeset 540 for trunk/dll/systemf.c


Ignore:
Timestamp:
Nov 4, 2006, 10:18:01 PM (19 years ago)
Author:
root
Message:

runemf2: rework termination queue logic to work for multiple threads

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/systemf.c

    r519 r540  
    1616  15 Aug 06 SHL More error popups
    1717  01 Nov 06 SHL runemf2: temp fix for hung windows caused by termq errors
     18  03 Nov 06 SHL runemf2: rework termination queue logic to work for multiple threads
    1819
    1920***********************************************************************/
     
    596597//== runemf2() run requested app, return -1 if problem starting else return app rc ==
    597598
    598 int runemf2(int type, HWND hwnd, char *directory, char *environment,
     599int runemf2(int type, HWND hwnd, char *pszDirectory, char *pszEnvironment,
    599600            char *formatstring,...)
    600601{
     
    618619  va_list parguments;
    619620  int ret = -1;
    620   RESULTCODES rt;
     621  RESULTCODES results;
    621622  STARTDATA sdata;
    622623  REQUESTDATA rq;
    623   ULONG ulSessID, apptype, ulLength, ctr = 0;
     624  ULONG ulSessID, apptype, ulLength, ctr;
    624625  PID sessPID;
    625626  BOOL wasquote;
    626   char *s = NULL, *s2 = NULL, object[32] = "", *p, savedir[CCHMAXPATH];
    627   HQUEUE hque;
    628   char szQueueName[] = "\\QUEUES\\FM3WAIT";
    629   char tempdir[CCHMAXPATH];
     627  char *pszPgm, *pszArgs = NULL;
     628  char szObject[32] = "", *p, szSavedir[CCHMAXPATH];
     629  BOOL useTermQ = FALSE;
     630  char szTempdir[CCHMAXPATH];
     631
    630632  typedef struct {
    631633    USHORT usSessID;
     
    633635  } TERMINFO;
    634636
    635   TERMINFO *pTermInfo = NULL;
     637  TERMINFO *pTermInfo;
    636638  BYTE bPriority;
    637639  APIRET rc;
     
    639641  TIB *ptib;
    640642
    641   if (directory && *directory) {
    642     if (!DosQueryPathInfo(directory,
     643  // Shared by all threads
     644# define TERMQ_BASE_NAME "\\QUEUES\\FM3WAIT"
     645  static char szTermQName[30];
     646  static HQUEUE hTermQ;
     647  static HEV hTermQSem;
     648
     649  if (pszDirectory && *pszDirectory) {
     650    if (!DosQueryPathInfo(pszDirectory,
    643651                          FIL_QUERYFULLNAME,
    644                           tempdir,
    645                           sizeof(tempdir)))
    646       directory = tempdir;
     652                          szTempdir,
     653                          sizeof(szTempdir)))
     654      pszDirectory = szTempdir;
    647655  }
    648656
     
    650658    hwnd = HWND_DESKTOP;
    651659
    652   rc = DosAllocMem((PVOID)&s,
     660  rc = DosAllocMem((PVOID)&pszPgm,
    653661                   MAXSTRG,
    654662                   PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
     
    658666  }
    659667
    660   *savedir = 0;
    661 
    662   *s = 0;
     668  *szSavedir = 0;
     669
     670  *pszPgm = 0;
    663671  va_start(parguments,
    664672           formatstring);
    665   vsprintf(s,
     673  vsprintf(pszPgm,
    666674           formatstring,
    667675           parguments);
    668676  va_end(parguments);
    669677
    670   if (environment) {
    671     p = &environment[strlen(environment)] + 1;
     678  if (pszEnvironment) {
     679    p = &pszEnvironment[strlen(pszEnvironment)] + 1;
    672680    *p = 0;
    673     p = environment;
     681    p = pszEnvironment;
    674682    while ((p = convert_nl_to_nul(p)) != NULL)
    675683      ; // loop
    676684  }
    677685
    678   if (!*s) {
     686  if (!*pszPgm) {
    679687    p = GetCmdSpec(FALSE);
    680     strcpy(s, p);
    681     if (!*s) {
     688    strcpy(pszPgm, p);
     689    if (!*pszPgm) {
    682690      Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
    683691      return -1;
     
    685693  }
    686694
    687   if (*s) {
    688     if (*s == '<' && strchr(s, '>')) {
     695  if (*pszPgm) {
     696    if (*pszPgm == '<' && strchr(pszPgm, '>')) {
    689697      /* is a workplace object */
    690698      HOBJECT hWPSObject;
    691699      char temp;
    692700
    693       p = strchr(s, '>');
     701      p = strchr(pszPgm, '>');
    694702      p++;
    695703      temp = *p;
    696704      if (temp) {
    697         rc = DosAllocMem((PVOID)&s2,
     705        rc = DosAllocMem((PVOID)&pszArgs,
    698706                         MAXSTRG * 2,
    699707                         PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
    700708        if (rc)
    701           Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
     709          Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
    702710      }
    703711      else
    704         s2 = NULL;
     712        pszArgs = NULL;
    705713      *p = 0;
    706714      /* Find the handle of the WPS object */
    707       hWPSObject = WinQueryObject(s);
     715      hWPSObject = WinQueryObject(pszPgm);
    708716      *p = temp;
    709717      if (hWPSObject != NULLHANDLE) {
    710         if (s2 && *p) {
    711           sprintf(s2,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
    712           WinSetObjectData(hWPSObject,s2);
     718        if (pszArgs && *p) {
     719          sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
     720          WinSetObjectData(hWPSObject,pszArgs);
    713721        }
    714722        else
     
    723731        (type & 15) == DETACHED)
    724732    {
    725       strip_lead_char(" \t", s);
    726       p = s;
     733      strip_lead_char(" \t", pszPgm);
     734      p = pszPgm;
    727735      wasquote = FALSE;
    728736      while (*p &&
     
    756764      }
    757765      else
    758         p = s;
     766        p = pszPgm;
    759767      p[strlen(p) + 1] = 0;             /* double-terminate args */
    760       if (*s) {
    761         if (!strchr(s, '\\') &&
    762             !strchr(s, ':') &&
    763             directory &&
    764             *directory)
     768      if (*pszPgm) {
     769        if (!strchr(pszPgm, '\\') &&
     770            !strchr(pszPgm, ':') &&
     771            pszDirectory &&
     772            *pszDirectory)
    765773        {
    766           save_dir2(savedir);
    767           switch_to(directory);
    768         }
    769         rc = DosQAppType(s,&apptype);
    770         if (!strchr(s, '\\') &&
    771             !strchr(s, ':') &&
    772             directory &&
    773             *directory)
    774           switch_to(savedir);
     774          save_dir2(szSavedir);
     775          switch_to(pszDirectory);
     776        }
     777        rc = DosQAppType(pszPgm,&apptype);
     778        if (!strchr(pszPgm, '\\') &&
     779            !strchr(pszPgm, ':') &&
     780            pszDirectory &&
     781            *pszDirectory)
     782          switch_to(szSavedir);
    775783        if (rc) {
    776784          // fixme to be in fm2dll.str
    777           Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosQAppType failed for %s.", s);
    778           DosFreeMem(s);
    779           if (s2)
    780             DosFreeMem(s2);
     785          Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosQAppType failed for %s.", pszPgm);
     786          DosFreeMem(pszPgm);
     787          if (pszArgs)
     788            DosFreeMem(pszArgs);
    781789          return -1;
    782790        }
     
    786794          {
    787795            // fixme to be in fm2dll.str
    788             Runtime_Error(pszSrcFile, __LINE__, "apptype 0x%x unexpected for %s.", apptype, s);
    789             if (s)
    790               DosFreeMem(s);
    791             if (s2)
    792               DosFreeMem(s2);
     796            Runtime_Error(pszSrcFile, __LINE__, "apptype 0x%x unexpected for %s.", apptype, pszPgm);
     797            if (pszPgm)
     798              DosFreeMem(pszPgm);
     799            if (pszArgs)
     800              DosFreeMem(pszArgs);
    793801            return -1;
    794802          }
     
    796804              (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000))
    797805          {
    798             Runtime_Error(pszSrcFile, __LINE__, "apptype 0x%x unexpected for %s.", apptype, s);
    799             if (s)
    800               DosFreeMem(s);
    801             if (s2)
    802               DosFreeMem(s2);
     806            Runtime_Error(pszSrcFile, __LINE__, "apptype 0x%x unexpected for %s.", apptype, pszPgm);
     807            if (pszPgm)
     808              DosFreeMem(pszPgm);
     809            if (pszArgs)
     810              DosFreeMem(pszArgs);
    803811            return -1;
    804812          }
    805813        }
    806         memset(&rt, 0, sizeof(RESULTCODES));
    807         if (directory && *directory) {
    808           save_dir2(savedir);
    809           switch_to(directory);
    810         }
    811         ret = DosExecPgm(object, 24L,
    812                       (ULONG) (((type & 15) == ASYNCHRONOUS) * EXEC_ASYNC) +
    813                                (((type & 15) == DETACHED) * EXEC_BACKGROUND),
    814                                s, environment, &rt, s);
    815         if (directory && *directory)
    816           switch_to(savedir);
     814        memset(&results, 0, sizeof(results));
     815        if (pszDirectory && *pszDirectory) {
     816          save_dir2(szSavedir);
     817          switch_to(pszDirectory);
     818        }
     819        ret = DosExecPgm(szObject, sizeof(szObject),
     820                         ((type & 15) == ASYNCHRONOUS ?  EXEC_ASYNC : 0) +
     821                         ((type & 15) == DETACHED ? EXEC_BACKGROUND : 0),
     822                         pszPgm, pszEnvironment, &results, pszPgm);
     823        if (pszDirectory && *pszDirectory)
     824          switch_to(szSavedir);
    817825        if (ret) {
    818826          Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
    819                     GetPString(IDS_DOSEXECPGMFAILEDTEXT), s);
     827                    GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm);
    820828        }
    821829      }
     
    824832      if (~type & FULLSCREEN)
    825833        type |= WINDOWED;
    826       rc = DosAllocMem((PVOID) & s2, MAXSTRG * 2,
     834      rc = DosAllocMem((PVOID) & pszArgs, MAXSTRG * 2,
    827835                       PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
    828836      if (rc) {
    829         Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
    830         DosFreeMem(s);
     837        Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
     838        DosFreeMem(pszPgm);
    831839        return -1;
    832840      }
    833       *s2 = 0;
    834       memset(&sdata, 0, sizeof(STARTDATA));
    835       strip_lead_char(" \t", s);
    836       p = s;
     841      *pszArgs = 0;
     842      memset(&sdata, 0, sizeof(sdata));
     843      strip_lead_char(" \t", pszPgm);
     844      p = pszPgm;
    837845      wasquote = FALSE;
    838846      while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
     
    851859        else
    852860          p++;
    853       }
     861      } // while
    854862      if (*p) {
    855863        *p = 0;
     
    859867        p = NullStr;
    860868      if (*p)
    861         strcpy(s2, p);
    862 
    863       p = strrchr(s, '.');
     869        strcpy(pszArgs, p);
     870
     871      p = strrchr(pszPgm, '.');
    864872      if (p) {
    865873        char temp[CCHMAXPATH + 1];
    866874
    867875        if (!stricmp(p, ".BAT")) {
    868           strcpy(temp, s);
    869           strcpy(s, s2);
    870           strcpy(s2, "/C ");
    871           strcat(s2, temp);
    872           strcat(s2, " ");
    873           strcat(s2, s);
    874           strcpy(s, GetCmdSpec(TRUE));
    875         }
    876         else if (!stricmp(p, ".CMD")) {
    877           strcpy(temp, s);
    878           strcpy(s, s2);
    879           strcpy(s2, "/C ");
    880           strcat(s2, temp);
    881           strcat(s2, " ");
    882           strcat(s2, s);
    883           strcpy(s, GetCmdSpec(FALSE));
     876          strcpy(temp, pszPgm);
     877          strcpy(pszPgm, pszArgs);
     878          strcpy(pszArgs, "/C ");
     879          strcat(pszArgs, temp);
     880          strcat(pszArgs, " ");
     881          strcat(pszArgs, pszPgm);
     882          strcpy(pszPgm, GetCmdSpec(TRUE));             // DOS
     883        }
     884        else if (!stricmp(p, ".CMD") || !stricmp(p, ".BTM")) {
     885          // Assume 4OS2 is BTM
     886          strcpy(temp, pszPgm);
     887          strcpy(pszPgm, pszArgs);
     888          strcpy(pszArgs, "/C ");
     889          strcat(pszArgs, temp);
     890          strcat(pszArgs, " ");
     891          strcat(pszArgs, pszPgm);
     892          strcpy(pszPgm, GetCmdSpec(FALSE));            // OS/2
    884893        }
    885894      }
     
    887896      /* goddamned OS/2 limit */
    888897
    889       if (strlen(s) + strlen(s2) > 1024)
    890         s2[1024 - strlen(s)] = 0;
    891 
    892       if (!strchr(s, '\\') &&
    893           !strchr(s, ':') &&
    894           directory &&
    895           *directory)
     898      if (strlen(pszPgm) + strlen(pszArgs) > 1024)
     899        pszArgs[1024 - strlen(pszPgm)] = 0;
     900
     901      if (!strchr(pszPgm, '\\') &&
     902          !strchr(pszPgm, ':') &&
     903          pszDirectory &&
     904          *pszDirectory)
    896905      {
    897         save_dir2(savedir);
    898         switch_to(directory);
    899       }
    900       rc = DosQAppType(s,&apptype);
    901       if (!strchr(s, '\\') &&
    902           !strchr(s, ':') &&
    903           directory &&
    904           *directory)
    905         switch_to(savedir);
     906        save_dir2(szSavedir);
     907        switch_to(pszDirectory);
     908      }
     909      rc = DosQAppType(pszPgm,&apptype);
     910      if (!strchr(pszPgm, '\\') &&
     911          !strchr(pszPgm, ':') &&
     912          pszDirectory &&
     913          *pszDirectory)
     914        switch_to(szSavedir);
    906915      if (rc) {
    907916        // fixme to be in fm2dll.str
    908         Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosQAppType failed for %s.", s);
    909         DosFreeMem(s);
    910         if (s2)
    911           DosFreeMem(s2);
     917        Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosQAppType failed for %s.", pszPgm);
     918        DosFreeMem(pszPgm);
     919        if (pszArgs)
     920          DosFreeMem(pszArgs);
    912921        return -1;
    913922      }
    914923
    915924      if (apptype) {
    916         if ((apptype & FAPPTYP_DLL) || (apptype & FAPPTYP_VIRTDRV) ||
    917             (apptype & FAPPTYP_PHYSDRV) || (apptype & FAPPTYP_PROTDLL))
     925        if (apptype & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL))
    918926        {
    919927          // fixme to be in fm2dll.str
    920           Runtime_Error(pszSrcFile, __LINE__, "apptype %d unexpected for %s.", s);
    921           DosFreeMem(s);
    922           if (s2)
    923             DosFreeMem(s2);
     928          Runtime_Error(pszSrcFile, __LINE__, "apptype %d unexpected for %s.", pszPgm);
     929          DosFreeMem(pszPgm);
     930          if (pszArgs)
     931            DosFreeMem(pszArgs);
    924932          return -1;
    925933        }
    926         apptype &= (~FAPPTYP_BOUND);
    927         if ((apptype & FAPPTYP_DOS) || (apptype & FAPPTYP_WINDOWSREAL) ||
    928             (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000))
     934        apptype &= ~FAPPTYP_BOUND;
     935        if (apptype & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
    929936        {
    930           if ((apptype & FAPPTYP_WINDOWSREAL) ||
    931               (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000))
     937          if (apptype & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
    932938          {
    933             if (!(type & FULLSCREEN) && ((apptype & FAPPTYP_WINDOWSREAL) ||
    934                      (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000)))
     939            if (~type & FULLSCREEN &&
     940                apptype & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
    935941            {
    936               ret = RunSeamless(s, s2, hwnd);
    937               if (s)
    938                 DosFreeMem(s);
    939               if (s2)
    940                 DosFreeMem(s2);
     942              ret = RunSeamless(pszPgm, pszArgs, hwnd);
     943              if (pszPgm)
     944                DosFreeMem(pszPgm);
     945              if (pszArgs)
     946                DosFreeMem(pszArgs);
    941947              return ret ? 0 : -1;
    942948            }
    943949            else {
    944               strcat(s, " ");
    945               strcat(s, s2);
    946               *s2 = 0;
    947               if ((apptype & FAPPTYP_WINDOWSPROT) ||
    948                   (apptype & FAPPTYP_WINDOWSREAL) ||
    949                   (apptype & 0x1000))
    950                 strcat(s2, "/3 ");
    951               strcat(s2, s);
    952               strcpy(s, "WINOS2.COM");
     950              strcat(pszPgm, " ");
     951              strcat(pszPgm, pszArgs);
     952              *pszArgs = 0;
     953              if (apptype & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31))
     954                strcat(pszArgs, "/3 ");
     955              strcat(pszArgs, pszPgm);
     956              strcpy(pszPgm, "WINOS2.COM");
    953957            }
    954958          }
    955959          else {
    956             if (!(type & FULLSCREEN)) {
     960            if (~type & FULLSCREEN) {
    957961              type |= WINDOWED;
    958962              apptype = SSF_TYPE_WINDOWEDVDM;
    959963            }
    960964            else {
    961               type &= (~WINDOWED);
     965              type &= ~WINDOWED;
    962966              apptype = SSF_TYPE_VDM;
    963967            }
     
    965969        }
    966970        else if (apptype & FAPPTYP_32BIT) {
    967           apptype &= (~FAPPTYP_32BIT);
     971          apptype &= ~FAPPTYP_32BIT;
    968972          if (apptype == FAPPTYP_WINDOWAPI)
    969973            apptype = SSF_TYPE_PM;
     
    972976          else if (apptype == FAPPTYP_NOTWINDOWCOMPAT) {
    973977            apptype = SSF_TYPE_FULLSCREEN;
    974             type &= (~WINDOWED);
     978            type &= ~WINDOWED;
    975979            type |= FULLSCREEN;
    976980          }
     
    983987          apptype = SSF_TYPE_WINDOWABLEVIO;
    984988        else if (apptype == FAPPTYP_NOTWINDOWCOMPAT) {
    985           type &= (~WINDOWED);
     989          type &= ~WINDOWED;
    986990          apptype = SSF_TYPE_FULLSCREEN;
    987991        }
    988992        else
    989993          apptype = SSF_TYPE_DEFAULT;
    990         if (((type & FULLSCREEN) || !(type & WINDOWED)) &&
     994        if ((type & FULLSCREEN || ~type & WINDOWED) &&
    991995            apptype == SSF_TYPE_WINDOWABLEVIO)
    992996        {
     
    994998        }
    995999        // fixme parens?
    996         else if (((type & FULLSCREEN) || !(type & WINDOWED) &&
    997                   apptype == SSF_TYPE_WINDOWEDVDM))
     1000        else if (type & FULLSCREEN ||
     1001                 (type & WINDOWED && apptype == SSF_TYPE_WINDOWEDVDM))
    9981002          apptype = SSF_TYPE_VDM;
    9991003      }
    1000       if (apptype == SSF_TYPE_WINDOWEDVDM && (type & SEPARATEKEEP)) {
     1004      if (apptype == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) {
    10011005        type &= ~SEPARATEKEEP;
    10021006        type |= SEPARATE;
     
    10041008
    10051009      DosGetInfoBlocks(&ptib, &ppib);
    1006       fprintf(stderr,"runemf2 ptib %x pgm %s\n",ptib,s);
    1007 
    1008       if (type & WAIT) {
    1009         rc = DosCreateQueue(&hque, QUE_FIFO | QUE_CONVERT_ADDRESS, szQueueName);
    1010         if (rc) {
    1011           if (rc != ERROR_QUE_DUPLICATE)
    1012             Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
    1013           hque = (HQUEUE)0;             // Try to survive
    1014           *szQueueName = 0;             // Try to survive
    1015         }
    1016         else
    1017           fprintf(stderr,"runemf2 ptib %x hque %x created\n",ptib,hque);
    1018       }
     1010
     1011      if (~type & WAIT)
     1012        useTermQ = FALSE;
    10191013      else {
    1020         hque = (HQUEUE)0;               // No queue if not waiting
    1021         *szQueueName = 0;               // No queue if not waiting
    1022       }
     1014        rc = 0;
     1015        DosEnterCritSec();
     1016        if (!hTermQ) {
     1017          // Create term queue and event semaphore just once
     1018          sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid);
     1019          rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName);
     1020          if (rc) {
     1021            hTermQ = (HQUEUE)0;         // Try to survive
     1022            DosExitCritSec();
     1023            Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
     1024          }
     1025          else {
     1026            rc = DosCreateEventSem(NULL,(PHEV)&hTermQSem,0,FALSE);
     1027            if (rc) {
     1028                hTermQSem = (HEV)0;     // Try to survive
     1029                DosCloseQueue(hTermQ);
     1030                hTermQ = (HQUEUE)0;     // Try to survive
     1031                DosExitCritSec();
     1032                Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__,"DoCreateEventSem");
     1033            }
     1034            // if (!rc)
     1035            //  fprintf(stderr,"runemf2 qcreated ptib %x hTermQ %x\n",ptib,hTermQ);
     1036          }
     1037        } // if 1st time
     1038        useTermQ = hTermQ && hTermQSem;
     1039        if (!rc)
     1040          DosExitCritSec();
     1041      } // if wait
    10231042      sdata.Length = sizeof(sdata);
    10241043      sdata.Related = type & (WAIT | CHILD) ?
     
    10271046      sdata.TraceOpt = SSF_TRACEOPT_NONE;
    10281047      sdata.PgmTitle = NULL;
    1029       sdata.PgmName = s;
    1030       sdata.PgmInputs = (*s2) ? s2 : NULL;
    1031       sdata.TermQ = *szQueueName ? szQueueName : NULL;
    1032       sdata.Environment = environment;
     1048      sdata.PgmName = pszPgm;
     1049      sdata.PgmInputs = *pszArgs ? pszArgs : NULL;
     1050      sdata.TermQ = useTermQ ? szTermQName : NULL;
     1051      sdata.Environment = pszEnvironment;
    10331052      sdata.InheritOpt = SSF_INHERTOPT_PARENT;
    10341053      sdata.SessionType = (USHORT)apptype;
    1035       sdata.ObjectBuffer = object;
    1036       sdata.ObjectBuffLen = sizeof(object) - 1;
     1054      sdata.ObjectBuffer = szObject;
     1055      sdata.ObjectBuffLen = sizeof(szObject);
    10371056      sdata.IconFile = NULL;
    10381057      sdata.PgmHandle = 0L;
     
    10421061                        (SSF_CONTROL_MINIMIZE * ((type & MINIMIZED) != 0)) |
    10431062                       (SSF_CONTROL_INVISIBLE * ((type & INVISIBLE) != 0)));
    1044       if (directory && *directory) {
    1045         save_dir2(savedir);
    1046         switch_to(directory);
     1063      if (pszDirectory && *pszDirectory) {
     1064        save_dir2(szSavedir);
     1065        switch_to(pszDirectory);
    10471066      }
    10481067      ret = DosStartSession(&sdata, &ulSessID, &sessPID);
    1049       if (directory && *directory)
    1050         switch_to(savedir);
     1068      if (pszDirectory && *pszDirectory)
     1069        switch_to(szSavedir);
    10511070      if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
    10521071        Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
    1053                   GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),s,s2);
     1072                  GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs);
    10541073      }
    10551074      else if (type & WAIT) {
     
    10571076          ShowSession(hwnd, sessPID);
    10581077
    1059         if (!hque) {
    1060           // No queue
     1078        if (!useTermQ) {
     1079          // Could not create queue - fallback - fixme to be gone?
    10611080          STATUSDATA sd;
    10621081
     
    10771096        }
    10781097        else {
    1079           // This thread owns queue
    1080           fprintf(stderr,"runemf2 ptib %x hque %x sessID %x sessPID %x\n",ptib,hque,ulSessID,sessPID);
    1081           fflush(stderr);
    10821098          for (ctr = 0;; ctr++)
    10831099          {
    1084             // ulLength = sizeof(TERMINFO);
    1085             // fixme to supply event semaphore or not wait
    1086             rc = DosReadQueue(hque, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
    1087                               DCWW_NOWAIT, &bPriority, 0);
    1088             if (rc == ERROR_QUE_EMPTY) {
    1089               if (ctr > 20) {
    1090                 ShowSession(hwnd, sessPID);
    1091                 ulLength = sizeof(TERMINFO);
    1092                 rc = DosReadQueue(hque, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
    1093                                   DCWW_WAIT, &bPriority, 0);
    1094                 break;
     1100            if (ctr < 20) {
     1101              rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
     1102                                DCWW_NOWAIT, &bPriority, hTermQSem);
     1103              if (rc == ERROR_QUE_EMPTY) {
     1104                DosSleep(100);
     1105                continue;
    10951106              }
    1096               DosSleep(100);
    10971107            }
    10981108            else {
    1099               if (rc) {
    1100                 if (rc != ERROR_INVALID_PARAMETER)
    1101                   Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
    1102                 // ulLength = sizeof(TERMINFO);
    1103                 rc = DosReadQueue(hque, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
    1104                                   DCWW_WAIT, &bPriority, 0);
     1109              // fixme to not do this?
     1110              if (ctr == 20)
     1111                ShowSession(hwnd, sessPID);             // Show long running session
     1112              rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
     1113                                DCWW_WAIT, &bPriority, 0);
     1114            }
     1115
     1116            if (rc) {
     1117              // Oh heck
     1118              Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
     1119              DosSleep(500);
     1120              continue;
     1121            }
     1122
     1123            if (pTermInfo->usSessID == ulSessID)
     1124              break;                    // Our session is done
     1125
     1126            // Requeue for other thread
     1127            {
     1128              static ULONG ulLastSessID;
     1129              // fprintf(stderr,"runemf2 requeue other ptib %x sessId %x ti.sessId %x ti.rc %d\n",ptib,ulSessID,pTermInfo->usSessID,pTermInfo->usRC);
     1130              // fixme to be gone
     1131              if (ulLastSessID) {
     1132                DosSleep(500);
     1133                ulLastSessID = pTermInfo->usSessID;
    11051134              }
    1106               // fixme to be much smarter
    1107               if (!rc && pTermInfo && pTermInfo->usSessID != ulSessID) {
    1108                 // fixme to requeue
    1109                 continue;
    1110               }
    1111               break;
     1135              // requeue and do not free yet
     1136              rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority);
     1137              if (rc)
     1138                Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue");
     1139              DosSleep(100);            // Let other thread see queue entry
    11121140            }
    11131141          } // for
    1114           fprintf(stderr,"runemf2 ptib %x hque %x rq pid %x ul %d\n",ptib,hque,rq.pid,rq.ulData);
    1115           if (pTermInfo) {
    1116             ret = !(!pTermInfo->usRC);          // Set TRUE if rc 0
    1117             fprintf(stderr,"runemf2 ptib %x hque %x terminfo sessId %x rc %d\n",ptib,hque,pTermInfo->usSessID,pTermInfo->usRC);
    1118             DosFreeMem(pTermInfo);
    1119           }
    1120           DosCloseQueue(hque);
    1121           fprintf(stderr,"runemf2 ptib %x hque %x closed\n",ptib,hque);
    1122           fflush(stderr);
    1123         }
    1124       }
     1142
     1143          ret = !(!pTermInfo->usRC);            // Set TRUE if rc 0
     1144          // fprintf(stderr,"runemf2 term this ptib %x sessID %x rq.pid %x rq.data %x ti.rc %d\n",ptib,ulSessID,rq.pid,rq.ulData,pTermInfo->usRC);
     1145          // fflush(stderr);
     1146          DosFreeMem(pTermInfo);
     1147        }
     1148      } // if wait
    11251149      else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
    11261150        ShowSession(hwnd, sessPID);
     
    11301154ObjectInterrupt:
    11311155
    1132   if (s)
    1133     DosFreeMem(s);
    1134   if (s2)
    1135     DosFreeMem(s2);
     1156  if (pszPgm)
     1157    DosFreeMem(pszPgm);
     1158  if (pszArgs)
     1159    DosFreeMem(pszArgs);
    11361160  return ret;
    11371161}
Note: See TracChangeset for help on using the changeset viewer.