浏览代码

* Better error handling

git-svn-id: trunk@2350 -
daniel 19 年之前
父节点
当前提交
f1e849a469
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      utils/grab_vcsa.pp

+ 8 - 4
utils/grab_vcsa.pp

@@ -65,7 +65,7 @@ var thistty:string;
     ttystat:stat;
     ttystat:stat;
     s:string[15];
     s:string[15];
     c:char;
     c:char;
-    pid,parent,dummy:integer;
+    ppid,pid,parent,dummy:integer;
     device:longint;
     device:longint;
     f:text;
     f:text;
     found_vcsa:boolean;
     found_vcsa:boolean;
@@ -81,7 +81,10 @@ begin
         assign(f,'/proc/'+s+'/stat');
         assign(f,'/proc/'+s+'/stat');
         reset(f);
         reset(f);
         if ioresult<>0 then
         if ioresult<>0 then
-          break;
+          begin
+            found_vcsa:=false;
+            break;
+          end;
         read(f,dummy);
         read(f,dummy);
         read(f,c);
         read(f,c);
         repeat
         repeat
@@ -90,14 +93,15 @@ begin
         repeat
         repeat
           read(f,c);
           read(f,c);
         until c=' ';
         until c=' ';
+        ppid:=pid;
         read(f,pid);
         read(f,pid);
         read(f,dummy);
         read(f,dummy);
         read(f,dummy);
         read(f,dummy);
         read(f,device);
         read(f,device);
         close(f);
         close(f);
-        if device=0 then
-          break; {Not attached to a terminal, i.e. an xterm.}
         found_vcsa:=device and $ffffff00=$00000400; {/dev/tty*}
         found_vcsa:=device and $ffffff00=$00000400; {/dev/tty*}
+        if (device=0) or (pid=-1) or (ppid=pid) then
+          break; {Not attached to a terminal, i.e. an xterm.}
       until found_vcsa;
       until found_vcsa;
       if found_vcsa then
       if found_vcsa then
         begin
         begin