@@ -20,46 +20,50 @@ def __call__(self):
20
20
while np is None or np != self .waitfor :
21
21
(np , self .status )= os .wait ()
22
22
except OSError :
23
- if pid :
23
+ if np :
24
24
print ("Chld process {} never exited, but no more children left" .format (self .waitfor ))
25
25
self .status = - 1
26
26
27
- for f in os .listdir ("mount" ):
28
- src = os .path .join ("mount" , f )
29
- dst = os .path .join ("autolab" , f )
30
- shutil .copy (src , dst )
27
+ def main ():
28
+ for f in os .listdir ("mount" ):
29
+ src = os .path .join ("mount" , f )
30
+ dst = os .path .join ("autolab" , f )
31
+ shutil .copy (src , dst )
31
32
32
- autolabuser = pwd .getpwnam ("autolab" )
33
- (r_p , w_p )= os .pipe ()
34
- pid = os .fork ()
35
- if pid == 0 :
36
- os .close (r_p )
37
- os .setgroups ([])
38
- os .setgid (autolabuser .pw_gid )
39
- os .setuid (autolabuser .pw_uid )
40
- args = ["autodriver" ]
41
- args .extend (sys .argv [1 :])
42
- args .append ("autolab" )
43
- if w_p != 1 :
44
- os .dup2 (w_p , 1 )
45
- if w_p != 2 :
46
- os .dup2 (w_p , 2 )
47
- if w_p > 2 :
48
- os .close (w_p )
49
- os .execvp (args [0 ], args )
50
- os .close (w_p )
51
- waiter = WaitLoop (pid )
52
- thr = threading .Thread (target = waiter )
53
- thr .start ()
54
- rpf = os .fdopen (r_p )
55
- shutil .copyfileobj (rpf , open ("mount/feedback" , "w" ))
56
- #print("Copied output")
57
- rpf .close ()
58
- thr .join ()
59
- # if core, exit -1, else pass through code.
60
- if os .WIFSIGNALED (waiter .status ):
61
- status = - 1
62
- else :
63
- status = os .WEXITSTATUS (waiter .status )
64
- #print("Status is {}".format(status))
65
- sys .exit (status )
33
+ autolabuser = pwd .getpwnam ("autolab" )
34
+ (r_p , w_p )= os .pipe ()
35
+ pid = os .fork ()
36
+ if pid == 0 :
37
+ os .close (r_p )
38
+ os .setgroups ([])
39
+ os .setgid (autolabuser .pw_gid )
40
+ os .setuid (autolabuser .pw_uid )
41
+ args = ["autodriver" ]
42
+ args .extend (sys .argv [1 :])
43
+ args .append ("autolab" )
44
+ if w_p != 1 :
45
+ os .dup2 (w_p , 1 )
46
+ if w_p != 2 :
47
+ os .dup2 (w_p , 2 )
48
+ if w_p > 2 :
49
+ os .close (w_p )
50
+ os .execvp (args [0 ], args )
51
+ os .close (w_p )
52
+ waiter = WaitLoop (pid )
53
+ thr = threading .Thread (target = waiter )
54
+ thr .start ()
55
+ rpf = os .fdopen (r_p )
56
+ shutil .copyfileobj (rpf , open ("mount/feedback" , "w" ))
57
+ #print("Copied output")
58
+ rpf .close ()
59
+ thr .join ()
60
+ # if core, exit -1, else pass through code.
61
+ if os .WIFSIGNALED (waiter .status ):
62
+ status = - 1
63
+ else :
64
+ status = os .WEXITSTATUS (waiter .status )
65
+ #print("Status is {}".format(status))
66
+ sys .exit (status )
67
+
68
+ if __name__ == '__main__' :
69
+ main ()
0 commit comments