Changeset 7444 for trunk/tools
- Timestamp:
- Nov 24, 2001, 3:21:39 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/CmdQd/CmdQd.c
r7278 r7444 1 /* $Id: CmdQd.c,v 1. 8 2001-10-31 21:46:49 bird Exp $1 /* $Id: CmdQd.c,v 1.9 2001-11-24 02:21:39 bird Exp $ 2 2 * 3 3 * Command Queue Daemon / Client. … … 59 59 * Job output (about 63KB) 60 60 * 61 * - Show jobs: 62 * Nothing. 63 * - Show jobs reponse: 64 * More output indicator. 65 * Job listing (about 63KB) 66 * 67 * - Show failed jobs: 68 * Nothing. 69 * - Show failed jobs reponse: 70 * More output indicator. 71 * Job listing (about 63KB) 72 * 73 * - Show (successfully) completed jobs: 74 * Nothing. 75 * - Show completed jobs reponse: 76 * More output indicator. 77 * Job listing (about 63KB) 78 * 79 * - Show running jobs: 80 * Nothing. 81 * - Show running jobs reponse: 82 * More output indicator. 83 * Job listing (about 63KB) 84 * 61 85 * - Kill: 62 86 * Nothing. … … 150 174 msgKill = 5, 151 175 msgKillResponse = 6, 176 msgShowJobs = 7, 177 msgShowJobsResponse = 8, 178 msgShowRunningJobs = 9, 179 msgShowRunningJobsResponse = 10, 180 msgShowCompletedJobs = 11, 181 msgShowCompletedJobsResponse = 12, 182 msgShowFailedJobs = 13, 183 msgShowFailedJobsResponse = 14, 152 184 msgDying = 0xff 153 } 185 } enmMsgType; 154 186 155 187 union … … 164 196 /* Environment block. */ 165 197 } Submit; 166 167 198 struct SubmitResponse 168 199 { … … 175 206 int iNothing; /* Dummy. */ 176 207 } Wait; 177 178 208 struct WaitResponse 179 209 { … … 190 220 int iNothing; /* dummy. */ 191 221 } Kill; 192 193 222 struct KillResponse 194 223 { 195 224 BOOL fRc; /* Success idicator. */ 196 225 } KillResponse; 226 227 228 struct ShowJobs 229 { 230 int iNothing; /* Dummy. */ 231 } ShowJobs; 232 struct ShowJobsResponse 233 { 234 BOOL fMore; /* More data. */ 235 char szOutput[SHARED_MEM_SIZE- 4 - 4 - 4 - 4 - 4 - 4]; 236 /* The listing of jobs. */ 237 } ShowJobsResponse; 238 239 240 struct ShowRunningJobs 241 { 242 int iNothing; /* Dummy. */ 243 } ShowRunningJobs; 244 struct ShowRunningJobsResponse 245 { 246 BOOL fMore; /* More data. */ 247 char szOutput[SHARED_MEM_SIZE- 4 - 4 - 4 - 4 - 4 - 4]; 248 /* The listing of jobs. */ 249 } ShowRunningJobsResponse; 250 251 252 struct ShowCompletedJobs 253 { 254 int iNothing; /* Dummy. */ 255 } ShowCompletedJobs; 256 struct ShowCompletedJobsResponse 257 { 258 BOOL fMore; /* More data. */ 259 char szOutput[SHARED_MEM_SIZE- 4 - 4 - 4 - 4 - 4 - 4]; 260 /* The listing of jobs. */ 261 } ShowCompletedJobsResponse; 262 263 264 struct ShowFailedJobs 265 { 266 int iNothing; /* Dummy. */ 267 } ShowFailedJobs; 268 struct ShowFailedJobsResponse 269 { 270 BOOL fMore; /* More data. */ 271 char szOutput[SHARED_MEM_SIZE- 4 - 4 - 4 - 4 - 4 - 4]; 272 /* The listing of jobs. */ 273 } ShowFailedJobsResponse; 197 274 198 275 } u1; … … 232 309 PSHAREDMEM pShrMem; /* Pointer to the shared memory. */ 233 310 311 HMTX hmtxJobQueue; /* Read/Write mutex for the two jobs queues below. */ 312 HEV hevJobQueue; /* Incomming job event sem. */ 234 313 PJOB pJobQueue; /* Linked list of jobs. */ 235 314 PJOB pJobQueueEnd; /* Last job entry. */ 236 HMTX hmtxJobQueue; /* Read/Write mutex. */237 HEV hevJobQueue; /* Incomming job event sem. */238 315 ULONG cJobs; /* Count of jobs submitted. */ 316 PJOB pJobRunning; /* Linked list of jobs. */ 317 PJOB pJobRunningEnd; /* Last job entry. */ 239 318 240 319 HMTX hmtxJobQueueFine; /* Read/Write mutex for the next two queues. */ … … 269 348 int QueryRunning(void); 270 349 int Kill(void); 350 int ShowJobs(void); 351 int ShowRunningJobs(void); 352 int ShowCompletedJobs(void); 353 int ShowFailedJobs(void); 271 354 /* shared memory helpers */ 272 355 int shrmemCreate(void); … … 327 410 return Kill(); 328 411 } 412 else if (!strcmp(argv[1], "showjobs")) 413 { 414 return ShowJobs(); 415 } 416 else if (!strcmp(argv[1], "showrunningjobs")) 417 { 418 return ShowRunningJobs(); 419 } 420 else if (!strcmp(argv[1], "showcompletedjobs")) 421 { 422 return ShowCompletedJobs(); 423 } 424 else if (!strcmp(argv[1], "showfailedjobs")) 425 { 426 return ShowFailedJobs(); 427 } 329 428 else if (!strcmp(argv[1], "init")) 330 429 { … … 363 462 { 364 463 printf( 365 "Command Queue Daemon v0.0. 1\n"464 "Command Queue Daemon v0.0.2\n" 366 465 "---------------------------\n" 367 466 "syntax: CmdQd.exe <command> [args]\n" … … 374 473 " Submits a command to the daemon.\n" 375 474 " Use '-<n>' to tell use to ignore return code 0-n.\n" 376 " 475 "\n" 377 476 " wait\n" 378 477 " Wait for all commands which are queued up to complete.\n" 379 478 " rc = count of failing commands.\n" 380 " 479 "\n" 381 480 " kill\n" 382 481 " Kills the daemon. Daemon will automatically die after\n" 383 482 " idling for some time.\n" 483 "\n" 384 484 " queryrunning\n" 385 485 " Checks if the daemon is running.\n" 386 486 " rc = 0 if running; rc != 0 if not running.\n" 487 "\n" 488 " showjobs - shows jobs queued for execution.\n" 489 " showrunningjobs - shows jobs currently running.\n" 490 " showcompletedjobs - shows jobs succesfully executed.\n" 491 " showfailedjobs - shows jobs which failed.\n" 387 492 "\n" 388 493 "Copyright (c) 2001 knut st. osmundsen (kosmunds@csc.com)\n" … … 657 762 } 658 763 764 765 case msgShowJobs: 766 { 767 /* 768 * Gain access to the job list. 769 */ 770 rc = DosRequestMutexSem(hmtxJobQueue, SEM_INDEFINITE_WAIT); 771 if (!rc) 772 { 773 int iJob = 0; 774 PJOB pJob = pJobQueue; 775 776 /* 777 * Big loop making and sending all messages. 778 */ 779 do 780 { 781 int cch; 782 char * pszOutput; 783 int cchOutput; 784 785 /* 786 * Make one message. 787 */ 788 pShrMem->enmMsgType = msgShowJobsResponse; 789 pszOutput = &pShrMem->u1.ShowJobsResponse.szOutput[0]; 790 cchOutput = sizeof(pShrMem->u1.ShowJobsResponse.szOutput) - 1; 791 792 /* 793 * Insert job info. 794 */ 795 while (pJob) 796 { 797 char szTmp[8192]; /* this is sufficient for one job. */ 798 799 /* 800 * Format output in temporary buffer and check if 801 * it's space left in the share buffer. 802 */ 803 cch = sprintf(szTmp, 804 "------------------ Job %d\n" 805 " command: %s\n" 806 " curdir: %s\n" 807 " rcIgnore: %d\n", 808 iJob, 809 pJob->JobInfo.szCommand, 810 pJob->JobInfo.szCurrentDir, 811 pJob->JobInfo.rcIgnore); 812 if (cch > cchOutput) 813 break; 814 815 /* 816 * Copy from temporary to shared buffer. 817 */ 818 memcpy(pszOutput, szTmp, cch); 819 pszOutput += cch; 820 cchOutput -= cch; 821 822 /* 823 * Next job. 824 */ 825 pJob = pJob->pNext; 826 iJob++; 827 } 828 829 /* 830 * Send the message. 831 */ 832 *pszOutput = '\0'; 833 pShrMem->u1.ShowJobsResponse.fMore = pJob != NULL; 834 rc = shrmemSendDaemon(TRUE); 835 836 } while (!rc && pJob); 837 838 839 /* 840 * Release the job list. 841 */ 842 DosReleaseMutexSem(hmtxJobQueue); 843 } 844 else 845 { 846 /* init response message */ 847 pShrMem->enmMsgType = msgShowJobsResponse; 848 sprintf(&pShrMem->u1.ShowJobsResponse.szOutput[0], 849 "Internal Error. Requesting of hmtxJobQueue failed with rc=%d\n", 850 rc); 851 rc = shrmemSendDaemon(TRUE); 852 } 853 854 855 /* 856 * Check if the waiting client died. 857 */ 858 if (rc == ERROR_ALREADY_POSTED) /* seems like this is the rc we get. */ 859 { 860 /* 861 * BUGBUG: This code is really fishy, but I'm to tired to make a real fix now. 862 * Hopefully this solves my current problem. 863 */ 864 ULONG ulDummy; 865 rc = DosRequestMutexSem(pShrMem->hmtx, 500); 866 rc = DosResetEventSem(pShrMem->hevClient, &ulDummy); 867 pShrMem->enmMsgType = msgUnknown; 868 rc = shrmemSendDaemon(TRUE); 869 } 870 break; 871 } 872 873 874 case msgShowFailedJobs: 875 { 876 /* 877 * Gain access to the finished job list. 878 */ 879 rc = DosRequestMutexSem(hmtxJobQueueFine, SEM_INDEFINITE_WAIT); 880 if (!rc) 881 { 882 int iJob = 0; 883 PJOB pJob = pJobFailed; 884 885 /* 886 * Big loop making and sending all messages. 887 */ 888 do 889 { 890 int cch; 891 char * pszOutput; 892 int cchOutput; 893 894 /* 895 * Make one message. 896 */ 897 pShrMem->enmMsgType = msgShowFailedJobsResponse; 898 pszOutput = &pShrMem->u1.ShowFailedJobsResponse.szOutput[0]; 899 cchOutput = sizeof(pShrMem->u1.ShowFailedJobsResponse.szOutput) - 1; 900 901 /* 902 * Insert job info. 903 */ 904 while (pJob) 905 { 906 char szTmp[8192]; /* this is sufficient for one job. */ 907 908 /* 909 * Format output in temporary buffer and check if 910 * it's space left in the share buffer. 911 */ 912 cch = sprintf(szTmp, 913 "------------------ Failed Job %d\n" 914 " command: %s\n" 915 " curdir: %s\n" 916 " rc: %d (rcIgnore=%d)\n", 917 iJob, 918 pJob->JobInfo.szCommand, 919 pJob->JobInfo.szCurrentDir, 920 pJob->rc, 921 pJob->JobInfo.rcIgnore); 922 if (cch > cchOutput) 923 break; 924 925 /* 926 * Copy from temporary to shared buffer. 927 */ 928 memcpy(pszOutput, szTmp, cch); 929 pszOutput += cch; 930 cchOutput -= cch; 931 932 /* 933 * Next job. 934 */ 935 pJob = pJob->pNext; 936 iJob++; 937 } 938 939 /* 940 * Send the message. 941 */ 942 *pszOutput = '\0'; 943 pShrMem->u1.ShowFailedJobsResponse.fMore = pJob != NULL; 944 rc = shrmemSendDaemon(TRUE); 945 946 } while (!rc && pJob); 947 948 949 /* 950 * Release the job list. 951 */ 952 DosReleaseMutexSem(hmtxJobQueueFine); 953 } 954 else 955 { 956 /* init response message */ 957 pShrMem->enmMsgType = msgShowFailedJobsResponse; 958 sprintf(&pShrMem->u1.ShowFailedJobsResponse.szOutput[0], 959 "Internal Error. Requesting of hmtxJobQueue failed with rc=%d\n", 960 rc); 961 rc = shrmemSendDaemon(TRUE); 962 } 963 964 965 /* 966 * Check if the waiting client died. 967 */ 968 if (rc == ERROR_ALREADY_POSTED) /* seems like this is the rc we get. */ 969 { 970 /* 971 * BUGBUG: This code is really fishy, but I'm to tired to make a real fix now. 972 * Hopefully this solves my current problem. 973 */ 974 ULONG ulDummy; 975 rc = DosRequestMutexSem(pShrMem->hmtx, 500); 976 rc = DosResetEventSem(pShrMem->hevClient, &ulDummy); 977 pShrMem->enmMsgType = msgUnknown; 978 rc = shrmemSendDaemon(TRUE); 979 } 980 break; 981 } 982 983 984 case msgShowRunningJobs: 985 { 986 /* 987 * Gain access to the job list. 988 */ 989 rc = DosRequestMutexSem(hmtxJobQueue, SEM_INDEFINITE_WAIT); 990 if (!rc) 991 { 992 int iJob = 0; 993 PJOB pJob = pJobRunning; 994 995 /* 996 * Big loop making and sending all messages. 997 */ 998 do 999 { 1000 int cch; 1001 char * pszOutput; 1002 int cchOutput; 1003 1004 /* 1005 * Make one message. 1006 */ 1007 pShrMem->enmMsgType = msgShowRunningJobsResponse; 1008 pszOutput = &pShrMem->u1.ShowRunningJobsResponse.szOutput[0]; 1009 cchOutput = sizeof(pShrMem->u1.ShowRunningJobsResponse.szOutput) - 1; 1010 1011 /* 1012 * Insert job info. 1013 */ 1014 while (pJob) 1015 { 1016 char szTmp[8192]; /* this is sufficient for one job. */ 1017 1018 /* 1019 * Format output in temporary buffer and check if 1020 * it's space left in the share buffer. 1021 */ 1022 cch = sprintf(szTmp, 1023 "------------------ Running Job %d\n" 1024 " command: %s\n" 1025 " curdir: %s\n" 1026 " rcIgnore: %d\n", 1027 iJob, 1028 pJob->JobInfo.szCommand, 1029 pJob->JobInfo.szCurrentDir, 1030 pJob->JobInfo.rcIgnore); 1031 if (cch > cchOutput) 1032 break; 1033 1034 /* 1035 * Copy from temporary to shared buffer. 1036 */ 1037 memcpy(pszOutput, szTmp, cch); 1038 pszOutput += cch; 1039 cchOutput -= cch; 1040 1041 /* 1042 * Next job. 1043 */ 1044 pJob = pJob->pNext; 1045 iJob++; 1046 } 1047 1048 /* 1049 * Send the message. 1050 */ 1051 *pszOutput = '\0'; 1052 pShrMem->u1.ShowRunningJobsResponse.fMore = pJob != NULL; 1053 rc = shrmemSendDaemon(TRUE); 1054 1055 } while (!rc && pJob); 1056 1057 1058 /* 1059 * Release the job list. 1060 */ 1061 DosReleaseMutexSem(hmtxJobQueue); 1062 } 1063 else 1064 { 1065 /* init response message */ 1066 pShrMem->enmMsgType = msgShowRunningJobsResponse; 1067 sprintf(&pShrMem->u1.ShowRunningJobsResponse.szOutput[0], 1068 "Internal Error. Requesting of hmtxJobQueue failed with rc=%d\n", 1069 rc); 1070 rc = shrmemSendDaemon(TRUE); 1071 } 1072 1073 1074 /* 1075 * Check if the waiting client died. 1076 */ 1077 if (rc == ERROR_ALREADY_POSTED) /* seems like this is the rc we get. */ 1078 { 1079 /* 1080 * BUGBUG: This code is really fishy, but I'm to tired to make a real fix now. 1081 * Hopefully this solves my current problem. 1082 */ 1083 ULONG ulDummy; 1084 rc = DosRequestMutexSem(pShrMem->hmtx, 500); 1085 rc = DosResetEventSem(pShrMem->hevClient, &ulDummy); 1086 pShrMem->enmMsgType = msgUnknown; 1087 rc = shrmemSendDaemon(TRUE); 1088 } 1089 break; 1090 } 1091 1092 1093 1094 case msgShowCompletedJobs: 1095 { 1096 /* 1097 * Gain access to the finished job list. 1098 */ 1099 rc = DosRequestMutexSem(hmtxJobQueueFine, SEM_INDEFINITE_WAIT); 1100 if (!rc) 1101 { 1102 int iJob = 0; 1103 PJOB pJob = pJobCompleted; 1104 1105 /* 1106 * Big loop making and sending all messages. 1107 */ 1108 do 1109 { 1110 int cch; 1111 char * pszOutput; 1112 int cchOutput; 1113 1114 /* 1115 * Make one message. 1116 */ 1117 pShrMem->enmMsgType = msgShowCompletedJobsResponse; 1118 pszOutput = &pShrMem->u1.ShowCompletedJobsResponse.szOutput[0]; 1119 cchOutput = sizeof(pShrMem->u1.ShowCompletedJobsResponse.szOutput) - 1; 1120 1121 /* 1122 * Insert job info. 1123 */ 1124 while (pJob) 1125 { 1126 char szTmp[8192]; /* this is sufficient for one job. */ 1127 1128 /* 1129 * Format output in temporary buffer and check if 1130 * it's space left in the share buffer. 1131 */ 1132 cch = sprintf(szTmp, 1133 "------------------ Completed Job %d\n" 1134 " command: %s\n" 1135 " curdir: %s\n" 1136 " rcIgnore: %d\n", 1137 iJob, 1138 pJob->JobInfo.szCommand, 1139 pJob->JobInfo.szCurrentDir, 1140 pJob->JobInfo.rcIgnore); 1141 if (cch > cchOutput) 1142 break; 1143 1144 /* 1145 * Copy from temporary to shared buffer. 1146 */ 1147 memcpy(pszOutput, szTmp, cch); 1148 pszOutput += cch; 1149 cchOutput -= cch; 1150 1151 /* 1152 * Next job. 1153 */ 1154 pJob = pJob->pNext; 1155 iJob++; 1156 } 1157 1158 /* 1159 * Send the message. 1160 */ 1161 *pszOutput = '\0'; 1162 pShrMem->u1.ShowCompletedJobsResponse.fMore = pJob != NULL; 1163 rc = shrmemSendDaemon(TRUE); 1164 1165 } while (!rc && pJob); 1166 1167 1168 /* 1169 * Release the finished job list. 1170 */ 1171 DosReleaseMutexSem(hmtxJobQueueFine); 1172 } 1173 else 1174 { 1175 /* init response message */ 1176 pShrMem->enmMsgType = msgShowCompletedJobsResponse; 1177 sprintf(&pShrMem->u1.ShowCompletedJobsResponse.szOutput[0], 1178 "Internal Error. Requesting of hmtxJobQueue failed with rc=%d\n", 1179 rc); 1180 rc = shrmemSendDaemon(TRUE); 1181 } 1182 1183 1184 /* 1185 * Check if the waiting client died. 1186 */ 1187 if (rc == ERROR_ALREADY_POSTED) /* seems like this is the rc we get. */ 1188 { 1189 /* 1190 * BUGBUG: This code is really fishy, but I'm to tired to make a real fix now. 1191 * Hopefully this solves my current problem. 1192 */ 1193 ULONG ulDummy; 1194 rc = DosRequestMutexSem(pShrMem->hmtx, 500); 1195 rc = DosResetEventSem(pShrMem->hevClient, &ulDummy); 1196 pShrMem->enmMsgType = msgUnknown; 1197 rc = shrmemSendDaemon(TRUE); 1198 } 1199 break; 1200 } 1201 1202 1203 1204 659 1205 default: 660 1206 Error("Internal error: Invalid message id %d\n", pShrMem->enmMsgType); … … 811 1357 if (pJob) 812 1358 { 1359 /* remove from input queue */ 813 1360 if (pJob != pJobQueueEnd) 814 1361 pJobQueue = pJob->pNext; … … 819 1366 DosResetEventSem(hevJobQueue, &ulIgnore); 820 1367 } 1368 1369 /* insert into running */ 1370 pJob ->pNext = NULL; 1371 if (pJobRunningEnd) 1372 pJobRunningEnd->pNext = pJob; 1373 else 1374 pJobRunning = pJobRunningEnd = pJob; 821 1375 } 822 1376 DosReleaseMutexSem(hmtxJobQueue); … … 972 1526 973 1527 /* 1528 * Remove from the running queue. 1529 */ 1530 if (DosRequestMutexSem(hmtxJobQueue, SEM_INDEFINITE_WAIT)) 1531 return; 1532 1533 if (pJobRunning != pJob) 1534 { 1535 PJOB pJobCur = pJobRunning; 1536 while (pJobCur) 1537 { 1538 if (pJobCur->pNext != pJob) 1539 { 1540 pJobCur->pNext = pJob->pNext; 1541 if (pJob == pJobRunningEnd) 1542 pJobRunningEnd = pJobCur; 1543 break; 1544 } 1545 pJobCur = pJobCur->pNext; 1546 } 1547 } 1548 else 1549 pJobRunning = pJobRunningEnd = NULL; 1550 1551 DosReleaseMutexSem(hmtxJobQueue); 1552 1553 1554 /* 974 1555 * Insert result in result queue. 975 1556 */ … … 1425 2006 return rc; 1426 2007 } 2008 2009 2010 /** 2011 * Shows the current queued commands. 2012 * Will write to stdout. 2013 * @returns 0 or -1 usually. 2014 */ 2015 int ShowJobs(void) 2016 { 2017 int rc; 2018 2019 rc = shrmemOpen(); 2020 if (rc) 2021 return rc; 2022 do 2023 { 2024 pShrMem->enmMsgType = msgShowJobs; 2025 pShrMem->u1.ShowJobs.iNothing = 0; 2026 rc = shrmemSendClient(msgShowJobsResponse); 2027 if (rc) 2028 { 2029 shrmemFree(); 2030 return -1; 2031 } 2032 printf("%s", pShrMem->u1.ShowJobsResponse.szOutput); 2033 /* 2034 * Release the client mutex if more data and yield the CPU. 2035 * So we can submit more work. (Odin nmake lib...) 2036 */ 2037 if (pShrMem->u1.ShowJobsResponse.fMore) 2038 { 2039 DosReleaseMutexSem(pShrMem->hmtxClient); 2040 DosSleep(0); 2041 rc = DosRequestMutexSem(pShrMem->hmtxClient, SEM_INDEFINITE_WAIT); 2042 if (rc) 2043 { 2044 Error("Fatal error: failed to get client mutex. rc=%d\n", rc); 2045 shrmemFree(); 2046 return -1; 2047 } 2048 } 2049 } while (pShrMem->u1.ShowJobsResponse.fMore); 2050 2051 shrmemFree(); 2052 return rc; 2053 } 2054 2055 2056 /** 2057 * Shows the current running jobs (not the output). 2058 * Will write to stdout. 2059 * @returns 0 or -1 usually. 2060 */ 2061 int ShowRunningJobs(void) 2062 { 2063 int rc; 2064 2065 rc = shrmemOpen(); 2066 if (rc) 2067 return rc; 2068 do 2069 { 2070 pShrMem->enmMsgType = msgShowRunningJobs; 2071 pShrMem->u1.ShowRunningJobs.iNothing = 0; 2072 rc = shrmemSendClient(msgShowRunningJobsResponse); 2073 if (rc) 2074 { 2075 shrmemFree(); 2076 return -1; 2077 } 2078 printf("%s", pShrMem->u1.ShowRunningJobsResponse.szOutput); 2079 /* 2080 * Release the client mutex if more data and yield the CPU. 2081 * So we can submit more work. (Odin nmake lib...) 2082 */ 2083 if (pShrMem->u1.ShowRunningJobsResponse.fMore) 2084 { 2085 DosReleaseMutexSem(pShrMem->hmtxClient); 2086 DosSleep(0); 2087 rc = DosRequestMutexSem(pShrMem->hmtxClient, SEM_INDEFINITE_WAIT); 2088 if (rc) 2089 { 2090 Error("Fatal error: failed to get client mutex. rc=%d\n", rc); 2091 shrmemFree(); 2092 return -1; 2093 } 2094 } 2095 } while (pShrMem->u1.ShowRunningJobsResponse.fMore); 2096 2097 shrmemFree(); 2098 return rc; 2099 } 2100 2101 2102 /** 2103 * Shows the current queue of successfully completed jobs (not the output). 2104 * Will write to stdout. 2105 * @returns 0 or -1 usually. 2106 */ 2107 int ShowCompletedJobs(void) 2108 { 2109 int rc; 2110 2111 rc = shrmemOpen(); 2112 if (rc) 2113 return rc; 2114 do 2115 { 2116 pShrMem->enmMsgType = msgShowCompletedJobs; 2117 pShrMem->u1.ShowCompletedJobs.iNothing = 0; 2118 rc = shrmemSendClient(msgShowCompletedJobsResponse); 2119 if (rc) 2120 { 2121 shrmemFree(); 2122 return -1; 2123 } 2124 printf("%s", pShrMem->u1.ShowCompletedJobsResponse.szOutput); 2125 /* 2126 * Release the client mutex if more data and yield the CPU. 2127 * So we can submit more work. (Odin nmake lib...) 2128 */ 2129 if (pShrMem->u1.ShowCompletedJobsResponse.fMore) 2130 { 2131 DosReleaseMutexSem(pShrMem->hmtxClient); 2132 DosSleep(0); 2133 rc = DosRequestMutexSem(pShrMem->hmtxClient, SEM_INDEFINITE_WAIT); 2134 if (rc) 2135 { 2136 Error("Fatal error: failed to get client mutex. rc=%d\n", rc); 2137 shrmemFree(); 2138 return -1; 2139 } 2140 } 2141 } while (pShrMem->u1.ShowCompletedJobsResponse.fMore); 2142 2143 shrmemFree(); 2144 return rc; 2145 } 2146 2147 2148 /** 2149 * Shows the current queue of failed jobs (not the output). 2150 * Will write to stdout. 2151 * @returns 0 or -1 usually. 2152 */ 2153 int ShowFailedJobs(void) 2154 { 2155 int rc; 2156 2157 rc = shrmemOpen(); 2158 if (rc) 2159 return rc; 2160 do 2161 { 2162 pShrMem->enmMsgType = msgShowFailedJobs; 2163 pShrMem->u1.ShowFailedJobs.iNothing = 0; 2164 rc = shrmemSendClient(msgShowFailedJobsResponse); 2165 if (rc) 2166 { 2167 shrmemFree(); 2168 return -1; 2169 } 2170 printf("%s", pShrMem->u1.ShowFailedJobsResponse.szOutput); 2171 /* 2172 * Release the client mutex if more data and yield the CPU. 2173 * So we can submit more work. (Odin nmake lib...) 2174 */ 2175 if (pShrMem->u1.ShowFailedJobsResponse.fMore) 2176 { 2177 DosReleaseMutexSem(pShrMem->hmtxClient); 2178 DosSleep(0); 2179 rc = DosRequestMutexSem(pShrMem->hmtxClient, SEM_INDEFINITE_WAIT); 2180 if (rc) 2181 { 2182 Error("Fatal error: failed to get client mutex. rc=%d\n", rc); 2183 shrmemFree(); 2184 return -1; 2185 } 2186 } 2187 } while (pShrMem->u1.ShowFailedJobsResponse.fMore); 2188 2189 shrmemFree(); 2190 return rc; 2191 } 2192 1427 2193 1428 2194
Note:
See TracChangeset
for help on using the changeset viewer.