source: trunk/dll/killproc.c@ 144

Last change on this file since 144 was 2, checked in by root, 23 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
RevLine 
[2]1#define INCL_DOSERRORS
2#define INCL_DOS
3#define INCL_WIN
4
5#include <os2.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#include <time.h>
10#include <ctype.h>
11#include <process.h>
12#include <limits.h>
13#include "procstat.h"
14#include "fm3dll.h"
15#include "fm3dlg.h"
16#include "fm3str.h"
17
18#pragma data_seg(DATA2)
19#pragma alloc_text(KILLPROC,FillKillList,FillKillList2,GetDosPgmName,KillDlgProc)
20
21
22CHAR *GetDosPgmName (PID pid,CHAR *string) {
23
24 HSWITCH hs;
25 SWCNTRL swctl;
26 PCH pch;
27
28 *string = 0;
29 hs = WinQuerySwitchHandle(0,pid);
30 if(hs) {
31 WinQuerySwitchEntry(hs,&swctl);
32 pch = swctl.szSwtitle;
33 while(*pch) {
34 if(*pch < 0x10)
35 if(pch != swctl.szSwtitle && *(pch - 1) == 0x20)
36 memmove(pch,pch + 1,strlen(pch));
37 else {
38 *pch = 0x20;
39 pch++;
40 }
41 else
42 pch++;
43 }
44 strcpy(string,swctl.szSwtitle);
45 }
46 if(!*string)
47 strcpy(string,GetPString(IDS_UNKNOWNDOSPROCTEXT));
48 return string;
49}
50
51
52VOID FillKillList2 (VOID *arg) {
53
54 HWND hwnd = *(HWND *)arg;
55 CHAR s[1036];
56 HAB thab;
57 HMQ thmq;
58 INT rc;
59 PROCESSINFO *ppi;
60 BUFFHEADER *pbh;
61 MODINFO *pmi;
62
63 thab = WinInitialize(0);
64 thmq = WinCreateMsgQueue(thab,0);
65 WinCancelShutdown(thmq,TRUE);
66
67 WinSendDlgItemMsg(hwnd,KILL_LISTBOX,LM_DELETEALL,MPVOID,MPVOID);
68 if(!DosAllocMem((PVOID)&pbh,USHRT_MAX + 4096,
69 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) {
70 rc = DosQProcStatus(pbh,USHRT_MAX);
71 if(!rc) {
72 ppi = pbh->ppi;
73 while(ppi->ulEndIndicator != PROCESS_END_INDICATOR ) {
74 if(ppi->pid != mypid) {
75 pmi = pbh->pmi;
76 while(pmi && ppi->hModRef != pmi->hMod)
77 pmi = pmi->pNext;
78 if(pmi) {
79 sprintf(s,"%04x ",ppi->pid);
80 if(!stricmp(pmi->szModName,"SYSINIT"))
81 GetDosPgmName(ppi->pid,s + strlen(s));
82 else {
83 if(*pmi->szModName)
84 strcat(s,pmi->szModName);
85 else
86 strcat(s,GetPString(IDS_UNKNOWNPROCTEXT));
87 }
88 if(WinIsWindow(thab,hwnd))
89 WinSendDlgItemMsg(hwnd,KILL_LISTBOX,LM_INSERTITEM,
90 MPFROM2SHORT(LIT_SORTASCENDING,0),
91 MPFROMP(s));
92 else
93 break;
94 }
95 }
96 ppi = (PPROCESSINFO)(ppi->ptiFirst + ppi->usThreadCount);
97 }
98 }
99 DosFreeMem(pbh);
100 }
101Abort:
102 if(WinIsWindow(thab,hwnd))
103 PostMsg(hwnd,UM_CONTAINER_FILLED,MPVOID,MPVOID);
104 WinDestroyMsgQueue(thmq);
105 WinTerminate(thab);
106}
107
108
109VOID FillKillList (VOID *arg) {
110
111 HWND hwnd = *(HWND *)arg;
112 CHAR s[1036],progname[1027],*p;
113 HAB thab;
114 HMQ thmq;
115 FILE *fp;
116 BOOL foundstart = FALSE;
117 INT rc;
118 CHAR *startstring = "Process and Thread Information";
119 CHAR *endstring = "System Semaphore Information";
120 PID pid;
121 HFILE oldstdout,newstdout;
122
123 DosError(FERR_DISABLEHARDERR);
124
125 thab = WinInitialize(0);
126 thmq = WinCreateMsgQueue(thab,0);
127 WinCancelShutdown(thmq,TRUE);
128
129 WinSendDlgItemMsg(hwnd,
130 KILL_LISTBOX,
131 LM_DELETEALL,
132 MPVOID,
133 MPVOID);
134 strcpy(s,"$PSTAT#$.#$#");
135 unlinkf("%s",s);
136 fp = fopen(s,"w");
137 if(fp) {
138 newstdout = -1;
139 if(DosDupHandle(fileno(stdout),&newstdout))
140 DosBeep(50,100);
141 oldstdout = fileno(stdout);
142 DosDupHandle(fileno(fp),&oldstdout);
143 rc = runemf2(SEPARATE | INVISIBLE | FULLSCREEN | BACKGROUND | WAIT,
144 hwnd,
145 NULL,
146 NULL,
147 "%s",
148 "PSTAT.EXE /C");
149 oldstdout = fileno(stdout);
150 DosDupHandle(newstdout,&oldstdout);
151 DosClose(newstdout);
152 fclose(fp);
153 if(rc == -1) {
154 saymsg(MB_CANCEL,
155 hwnd,
156 GetPString(IDS_ARGHTEXT),
157 GetPString(IDS_CANTRUNPSTATTEXT));
158 goto Abort;
159 }
160 }
161 else {
162 General_Error((HAB)0,
163 HWND_DESKTOP,
164 __FILE__,
165 __LINE__,
166 GetPString(IDS_REDIRECTERRORTEXT));
167 goto Abort;
168 }
169 fp = fopen(s,"r");
170 if(fp) {
171 while(!feof(fp)) {
172 strset(s,0);
173 if(!fgets(s,1025,fp))
174 break;
175 if(!foundstart) {
176 if(*s == ' ' && strstr(s,startstring))
177 foundstart = TRUE;
178 }
179 else {
180 if(*s == ' ' && strstr(s,endstring))
181 break;
182 if(*s == ' ' && s[5] == ' ' && isxdigit(s[1]) &&
183 isxdigit(s[2]) && isxdigit(s[3]) && isxdigit(s[4])) {
184 p = &s[1];
185 pid = strtol(&s[1],&p,16);
186 if(pid && pid != mypid) {
187 strcpy(progname,&s[30]);
188 p = strchr(progname,' ');
189 if(p)
190 *p = 0;
191 if(!stristr(progname,"\\PSTAT.EXE")) {
192 sprintf(s,"%04x %s",pid,progname);
193 WinSendDlgItemMsg(hwnd,
194 KILL_LISTBOX,
195 LM_INSERTITEM,
196 MPFROM2SHORT(LIT_SORTASCENDING,0),
197 MPFROMP(s));
198 }
199 }
200 }
201 }
202 }
203 fclose(fp);
204 }
205Abort:
206 DosForceDelete("$PSTAT#$.#$#");
207 PostMsg(hwnd,
208 UM_CONTAINER_FILLED,
209 MPVOID,
210 MPVOID);
211 WinDestroyMsgQueue(thmq);
212 WinTerminate(thab);
213}
214
215
216MRESULT EXPENTRY KillDlgProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) {
217
218 SHORT sSelect;
219 PID pid;
220 static BOOL listdone;
221 static HPOINTER hptrIcon = (HPOINTER)0;
222
223 switch(msg) {
224 case WM_INITDLG:
225 hptrIcon = WinLoadPointer(HWND_DESKTOP,
226 FM3ModHandle,
227 KILL_FRAME);
228 WinDefDlgProc(hwnd,
229 WM_SETICON,
230 MPFROMLONG(hptrIcon),
231 MPVOID);
232 WinCheckButton(hwnd,
233 KILL_CHECKBOX,
234 fUseQProcStat);
235 PostMsg(hwnd,
236 WM_COMMAND,
237 MPFROM2SHORT(KILL_RESCAN,0),
238 MPVOID);
239 break;
240
241 case UM_CONTAINER_FILLED:
242 listdone = TRUE;
243 if((SHORT)WinSendDlgItemMsg(hwnd,
244 KILL_LISTBOX,
245 LM_QUERYITEMCOUNT,
246 MPVOID,
247 MPVOID) == 0) {
248 if(!fUseQProcStat)
249 saymsg(MB_CANCEL,
250 hwnd,
251 GetPString(IDS_ICHOKEDTEXT),
252 GetPString(IDS_ISPSTATTHERETEXT));
253 else
254 saymsg(MB_CANCEL,
255 hwnd,
256 GetPString(IDS_ICHOKEDTEXT),
257 GetPString(IDS_DOSQPROCSTATFAILEDTEXT));
258 }
259 return 0;
260
261 case WM_CONTROL:
262 switch(SHORT1FROMMP(mp1)) {
263 case KILL_CHECKBOX:
264 fUseQProcStat = WinQueryButtonCheckstate(hwnd,
265 KILL_CHECKBOX);
266 PrfWriteProfileData(fmprof,
267 FM3Str,
268 "UseQProcStat",
269 &fUseQProcStat,
270 sizeof(BOOL));
271 PostMsg(hwnd,
272 WM_COMMAND,
273 MPFROM2SHORT(KILL_RESCAN,0),
274 MPVOID);
275 break;
276
277 case KILL_LISTBOX:
278 switch(SHORT2FROMMP(mp2)) {
279 case LN_ENTER:
280 WinSendDlgItemMsg(hwnd,
281 DID_OK,
282 BM_CLICK,
283 MPFROMSHORT(TRUE),
284 MPVOID);
285 break;
286 }
287 break;
288
289 default:
290 break;
291 }
292 return 0;
293
294 case WM_ADJUSTWINDOWPOS:
295 PostMsg(hwnd,
296 UM_STRETCH,
297 MPVOID,
298 MPVOID);
299 break;
300
301 case UM_STRETCH:
302 {
303 SWP swpC,swp,swpH;
304
305 WinQueryWindowPos(hwnd,&swp);
306 if(!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
307 WinQueryWindowPos(WinWindowFromID(hwnd,KILL_LISTBOX),&swpC);
308 WinQueryWindowPos(WinWindowFromID(hwnd,KILL_HDR),&swpH);
309 WinSetWindowPos(WinWindowFromID(hwnd,KILL_LISTBOX),HWND_TOP,
310 SysVal(SV_CXSIZEBORDER),
311 swpC.y,
312 swp.cx - (SysVal(SV_CXSIZEBORDER) * 2),
313 ((swp.cy - swpC.y) - (SysVal(SV_CYTITLEBAR) +
314 SysVal(SV_CYSIZEBORDER)) -
315 (swpH.cy + 8)),
316 SWP_MOVE | SWP_SIZE);
317 WinSetWindowPos(WinWindowFromID(hwnd,KILL_HDR),HWND_TOP,
318 SysVal(SV_CXSIZEBORDER) + 4,
319 swpC.y + ((swp.cy - swpC.y) -
320 (SysVal(SV_CYTITLEBAR) +
321 SysVal(SV_CYSIZEBORDER)) -
322 (swpH.cy + 4)),
323 swpH.cx,
324 swpH.cy,
325 SWP_MOVE);
326 }
327 }
328 return 0;
329
330 case WM_COMMAND:
331 switch(SHORT1FROMMP(mp1)) {
332 case KILL_RESCAN:
333 listdone = FALSE;
334 if(fUseQProcStat) {
335 if(_beginthread(FillKillList2,
336 NULL,
337 65536,
338 (PVOID)&hwnd) != -1)
339 DosSleep(250L);
340 else
341 WinDismissDlg(hwnd,0);
342 }
343 else {
344 if(_beginthread(FillKillList,
345 NULL,
346 65536,
347 (PVOID)&hwnd) != -1)
348 DosSleep(250L);
349 else
350 WinDismissDlg(hwnd,0);
351 }
352 break;
353
354 case KILL_SHOW:
355 case DID_OK:
356 sSelect = (USHORT)WinSendDlgItemMsg(hwnd,
357 KILL_LISTBOX,
358 LM_QUERYSELECTION,
359 MPFROMSHORT(LIT_FIRST),
360 MPVOID);
361 if(sSelect >= 0) {
362
363 CHAR s[31],*p;
364 APIRET error;
365
366 *s = 0;
367 WinSendDlgItemMsg(hwnd,
368 KILL_LISTBOX,
369 LM_QUERYITEMTEXT,
370 MPFROM2SHORT(sSelect,30),
371 MPFROMP(s));
372 if(*s) {
373 p = s;
374 pid = strtol(s,&p,16);
375 if(pid) {
376 if(SHORT1FROMMP(mp1) == DID_OK) {
377 error = DosKillProcess(DKP_PROCESS,pid);
378 if(error && error != ERROR_INVALID_PROCID)
379 Dos_Error(MB_CANCEL,
380 error,
381 hwnd,
382 __FILE__,
383 __LINE__,
384 GetPString(IDS_DOSKILLFAILEDTEXT));
385 else
386 WinSendDlgItemMsg(hwnd,
387 KILL_LISTBOX,
388 LM_DELETEITEM,
389 MPFROM2SHORT(sSelect,0),
390 MPVOID);
391 }
392 else if(!ShowSession(hwnd,pid))
393 Notify(GetPString(IDS_SORRYCANTSHOWTEXT));
394 }
395 }
396 }
397 break;
398
399 case DID_CANCEL:
400 if(listdone)
401 WinDismissDlg(hwnd,0);
402 else
403 DosBeep(100,100);
404 break;
405
406 case IDM_HELP:
407 saymsg(MB_ENTER | MB_ICONASTERISK,
408 hwnd,
409 GetPString(IDS_KILLPROCHELPTITLETEXT),
410 GetPString(IDS_KILLPROCHELPTEXT));
411 break;
412 }
413 return 0;
414
415 case WM_CLOSE:
416 if(!listdone) {
417 DosBeep(100,100);
418 return 0;
419 }
420 break;
421
422 case WM_DESTROY:
423 if(hptrIcon)
424 WinDestroyPointer(hptrIcon);
425 hptrIcon = (HPOINTER)0;
426 break;
427 }
428 return WinDefDlgProc(hwnd,msg,mp1,mp2);
429}
430
Note: See TracBrowser for help on using the repository browser.