Changeset 540 for trunk/dll/systemf.c
- Timestamp:
- Nov 4, 2006, 10:18:01 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/systemf.c
r519 r540 16 16 15 Aug 06 SHL More error popups 17 17 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 18 19 19 20 ***********************************************************************/ … … 596 597 //== runemf2() run requested app, return -1 if problem starting else return app rc == 597 598 598 int runemf2(int type, HWND hwnd, char * directory, char *environment,599 int runemf2(int type, HWND hwnd, char *pszDirectory, char *pszEnvironment, 599 600 char *formatstring,...) 600 601 { … … 618 619 va_list parguments; 619 620 int ret = -1; 620 RESULTCODES r t;621 RESULTCODES results; 621 622 STARTDATA sdata; 622 623 REQUESTDATA rq; 623 ULONG ulSessID, apptype, ulLength, ctr = 0;624 ULONG ulSessID, apptype, ulLength, ctr; 624 625 PID sessPID; 625 626 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 630 632 typedef struct { 631 633 USHORT usSessID; … … 633 635 } TERMINFO; 634 636 635 TERMINFO *pTermInfo = NULL;637 TERMINFO *pTermInfo; 636 638 BYTE bPriority; 637 639 APIRET rc; … … 639 641 TIB *ptib; 640 642 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, 643 651 FIL_QUERYFULLNAME, 644 tempdir,645 sizeof( tempdir)))646 directory = tempdir;652 szTempdir, 653 sizeof(szTempdir))) 654 pszDirectory = szTempdir; 647 655 } 648 656 … … 650 658 hwnd = HWND_DESKTOP; 651 659 652 rc = DosAllocMem((PVOID)& s,660 rc = DosAllocMem((PVOID)&pszPgm, 653 661 MAXSTRG, 654 662 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); … … 658 666 } 659 667 660 *s avedir = 0;661 662 * s= 0;668 *szSavedir = 0; 669 670 *pszPgm = 0; 663 671 va_start(parguments, 664 672 formatstring); 665 vsprintf( s,673 vsprintf(pszPgm, 666 674 formatstring, 667 675 parguments); 668 676 va_end(parguments); 669 677 670 if ( environment) {671 p = & environment[strlen(environment)] + 1;678 if (pszEnvironment) { 679 p = &pszEnvironment[strlen(pszEnvironment)] + 1; 672 680 *p = 0; 673 p = environment;681 p = pszEnvironment; 674 682 while ((p = convert_nl_to_nul(p)) != NULL) 675 683 ; // loop 676 684 } 677 685 678 if (!* s) {686 if (!*pszPgm) { 679 687 p = GetCmdSpec(FALSE); 680 strcpy( s, p);681 if (!* s) {688 strcpy(pszPgm, p); 689 if (!*pszPgm) { 682 690 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT); 683 691 return -1; … … 685 693 } 686 694 687 if (* s) {688 if (* s == '<' && strchr(s, '>')) {695 if (*pszPgm) { 696 if (*pszPgm == '<' && strchr(pszPgm, '>')) { 689 697 /* is a workplace object */ 690 698 HOBJECT hWPSObject; 691 699 char temp; 692 700 693 p = strchr( s, '>');701 p = strchr(pszPgm, '>'); 694 702 p++; 695 703 temp = *p; 696 704 if (temp) { 697 rc = DosAllocMem((PVOID)& s2,705 rc = DosAllocMem((PVOID)&pszArgs, 698 706 MAXSTRG * 2, 699 707 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 700 708 if (rc) 701 709 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 702 710 } 703 711 else 704 s2= NULL;712 pszArgs = NULL; 705 713 *p = 0; 706 714 /* Find the handle of the WPS object */ 707 hWPSObject = WinQueryObject( s);715 hWPSObject = WinQueryObject(pszPgm); 708 716 *p = temp; 709 717 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); 713 721 } 714 722 else … … 723 731 (type & 15) == DETACHED) 724 732 { 725 strip_lead_char(" \t", s);726 p = s;733 strip_lead_char(" \t", pszPgm); 734 p = pszPgm; 727 735 wasquote = FALSE; 728 736 while (*p && … … 756 764 } 757 765 else 758 p = s;766 p = pszPgm; 759 767 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) 765 773 { 766 save_dir2(s avedir);767 switch_to( directory);768 } 769 rc = DosQAppType( s,&apptype);770 if (!strchr( s, '\\') &&771 !strchr( s, ':') &&772 directory &&773 * directory)774 switch_to(s avedir);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); 775 783 if (rc) { 776 784 // 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); 781 789 return -1; 782 790 } … … 786 794 { 787 795 // 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); 793 801 return -1; 794 802 } … … 796 804 (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000)) 797 805 { 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); 803 811 return -1; 804 812 } 805 813 } 806 memset(&r t, 0, sizeof(RESULTCODES));807 if ( directory && *directory) {808 save_dir2(s avedir);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(s avedir);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); 817 825 if (ret) { 818 826 Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__, 819 GetPString(IDS_DOSEXECPGMFAILEDTEXT), s);827 GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm); 820 828 } 821 829 } … … 824 832 if (~type & FULLSCREEN) 825 833 type |= WINDOWED; 826 rc = DosAllocMem((PVOID) & s2, MAXSTRG * 2,834 rc = DosAllocMem((PVOID) & pszArgs, MAXSTRG * 2, 827 835 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 828 836 if (rc) { 829 830 DosFreeMem( s);837 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 838 DosFreeMem(pszPgm); 831 839 return -1; 832 840 } 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; 837 845 wasquote = FALSE; 838 846 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) { … … 851 859 else 852 860 p++; 853 } 861 } // while 854 862 if (*p) { 855 863 *p = 0; … … 859 867 p = NullStr; 860 868 if (*p) 861 strcpy( s2, p);862 863 p = strrchr( s, '.');869 strcpy(pszArgs, p); 870 871 p = strrchr(pszPgm, '.'); 864 872 if (p) { 865 873 char temp[CCHMAXPATH + 1]; 866 874 867 875 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 884 893 } 885 894 } … … 887 896 /* goddamned OS/2 limit */ 888 897 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) 896 905 { 897 save_dir2(s avedir);898 switch_to( directory);899 } 900 rc = DosQAppType( s,&apptype);901 if (!strchr( s, '\\') &&902 !strchr( s, ':') &&903 directory &&904 * directory)905 switch_to(s avedir);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); 906 915 if (rc) { 907 916 // 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); 912 921 return -1; 913 922 } 914 923 915 924 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)) 918 926 { 919 927 // 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); 924 932 return -1; 925 933 } 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)) 929 936 { 930 if ((apptype & FAPPTYP_WINDOWSREAL) || 931 (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000)) 937 if (apptype & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31)) 932 938 { 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)) 935 941 { 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); 941 947 return ret ? 0 : -1; 942 948 } 943 949 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"); 953 957 } 954 958 } 955 959 else { 956 if ( !(type & FULLSCREEN)) {960 if (~type & FULLSCREEN) { 957 961 type |= WINDOWED; 958 962 apptype = SSF_TYPE_WINDOWEDVDM; 959 963 } 960 964 else { 961 type &= (~WINDOWED);965 type &= ~WINDOWED; 962 966 apptype = SSF_TYPE_VDM; 963 967 } … … 965 969 } 966 970 else if (apptype & FAPPTYP_32BIT) { 967 apptype &= (~FAPPTYP_32BIT);971 apptype &= ~FAPPTYP_32BIT; 968 972 if (apptype == FAPPTYP_WINDOWAPI) 969 973 apptype = SSF_TYPE_PM; … … 972 976 else if (apptype == FAPPTYP_NOTWINDOWCOMPAT) { 973 977 apptype = SSF_TYPE_FULLSCREEN; 974 type &= (~WINDOWED);978 type &= ~WINDOWED; 975 979 type |= FULLSCREEN; 976 980 } … … 983 987 apptype = SSF_TYPE_WINDOWABLEVIO; 984 988 else if (apptype == FAPPTYP_NOTWINDOWCOMPAT) { 985 type &= (~WINDOWED);989 type &= ~WINDOWED; 986 990 apptype = SSF_TYPE_FULLSCREEN; 987 991 } 988 992 else 989 993 apptype = SSF_TYPE_DEFAULT; 990 if (( (type & FULLSCREEN) || !(type & WINDOWED)) &&994 if ((type & FULLSCREEN || ~type & WINDOWED) && 991 995 apptype == SSF_TYPE_WINDOWABLEVIO) 992 996 { … … 994 998 } 995 999 // 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)) 998 1002 apptype = SSF_TYPE_VDM; 999 1003 } 1000 if (apptype == SSF_TYPE_WINDOWEDVDM && (type & SEPARATEKEEP)) {1004 if (apptype == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) { 1001 1005 type &= ~SEPARATEKEEP; 1002 1006 type |= SEPARATE; … … 1004 1008 1005 1009 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; 1019 1013 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 1023 1042 sdata.Length = sizeof(sdata); 1024 1043 sdata.Related = type & (WAIT | CHILD) ? … … 1027 1046 sdata.TraceOpt = SSF_TRACEOPT_NONE; 1028 1047 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; 1033 1052 sdata.InheritOpt = SSF_INHERTOPT_PARENT; 1034 1053 sdata.SessionType = (USHORT)apptype; 1035 sdata.ObjectBuffer = object;1036 sdata.ObjectBuffLen = sizeof( object) - 1;1054 sdata.ObjectBuffer = szObject; 1055 sdata.ObjectBuffLen = sizeof(szObject); 1037 1056 sdata.IconFile = NULL; 1038 1057 sdata.PgmHandle = 0L; … … 1042 1061 (SSF_CONTROL_MINIMIZE * ((type & MINIMIZED) != 0)) | 1043 1062 (SSF_CONTROL_INVISIBLE * ((type & INVISIBLE) != 0))); 1044 if ( directory && *directory) {1045 save_dir2(s avedir);1046 switch_to( directory);1063 if (pszDirectory && *pszDirectory) { 1064 save_dir2(szSavedir); 1065 switch_to(pszDirectory); 1047 1066 } 1048 1067 ret = DosStartSession(&sdata, &ulSessID, &sessPID); 1049 if ( directory && *directory)1050 switch_to(s avedir);1068 if (pszDirectory && *pszDirectory) 1069 switch_to(szSavedir); 1051 1070 if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) { 1052 1071 Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__, 1053 GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT), s,s2);1072 GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs); 1054 1073 } 1055 1074 else if (type & WAIT) { … … 1057 1076 ShowSession(hwnd, sessPID); 1058 1077 1059 if (! hque) {1060 // No queue1078 if (!useTermQ) { 1079 // Could not create queue - fallback - fixme to be gone? 1061 1080 STATUSDATA sd; 1062 1081 … … 1077 1096 } 1078 1097 else { 1079 // This thread owns queue1080 fprintf(stderr,"runemf2 ptib %x hque %x sessID %x sessPID %x\n",ptib,hque,ulSessID,sessPID);1081 fflush(stderr);1082 1098 for (ctr = 0;; ctr++) 1083 1099 { 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; 1095 1106 } 1096 DosSleep(100);1097 1107 } 1098 1108 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; 1105 1134 } 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 1112 1140 } 1113 1141 } // 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 1125 1149 else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE))) 1126 1150 ShowSession(hwnd, sessPID); … … 1130 1154 ObjectInterrupt: 1131 1155 1132 if ( s)1133 DosFreeMem( s);1134 if ( s2)1135 DosFreeMem( s2);1156 if (pszPgm) 1157 DosFreeMem(pszPgm); 1158 if (pszArgs) 1159 DosFreeMem(pszArgs); 1136 1160 return ret; 1137 1161 }
Note:
See TracChangeset
for help on using the changeset viewer.