summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-07-06 17:41:11 +0100
committerRichard Purdie <rpurdie@linux.intel.com>2010-07-16 12:31:19 +0100
commit5c44f9a78dd310b31df2d84128c4b3ca468d685d (patch)
tree89bd33570db4c27bb782a7d6eb341fcd4d7b4f71
parent8a5b5080a2fa0db7972573cfcd8e04abedb22618 (diff)
downloadpoky-5c44f9a78dd310b31df2d84128c4b3ca468d685d.tar.gz
bitbake: runqueue: Separate out task forking code into a new function
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rw-r--r--bitbake/lib/bb/runqueue.py117
1 files changed, 61 insertions, 56 deletions
diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py
index c82affca3c..8814343377 100644
--- a/bitbake/lib/bb/runqueue.py
+++ b/bitbake/lib/bb/runqueue.py
@@ -942,62 +942,7 @@ class RunQueue:
942 self.stats.taskSkipped() 942 self.stats.taskSkipped()
943 continue 943 continue
944 944
945 sys.stdout.flush() 945 pid, pipein, pipeout = self.fork_off_task(fn, task, taskname)
946 sys.stderr.flush()
947 try:
948 pipein, pipeout = os.pipe()
949 pid = os.fork()
950 except OSError as e:
951 bb.msg.fatal(bb.msg.domain.RunQueue, "fork failed: %d (%s)" % (e.errno, e.strerror))
952 if pid == 0:
953 os.close(pipein)
954 # Save out the PID so that the event can include it the
955 # events
956 bb.event.worker_pid = os.getpid()
957 bb.event.worker_pipe = pipeout
958
959 self.state = runQueueChildProcess
960 # Make the child the process group leader
961 os.setpgid(0, 0)
962 # No stdin
963 newsi = os.open('/dev/null', os.O_RDWR)
964 os.dup2(newsi, sys.stdin.fileno())
965 # Stdout to a logfile
966 #logout = data.expand("${TMPDIR}/log/stdout.%s" % os.getpid(), self.cfgData, True)
967 #mkdirhier(os.path.dirname(logout))
968 #newso = open(logout, 'w')
969 #os.dup2(newso.fileno(), sys.stdout.fileno())
970 #os.dup2(newso.fileno(), sys.stderr.fileno())
971
972 bb.event.fire(runQueueTaskStarted(task, self.stats, self), self.cfgData)
973 bb.msg.note(1, bb.msg.domain.RunQueue,
974 "Running task %d of %d (ID: %s, %s)" % (self.stats.completed + self.stats.active + 1,
975 self.stats.total,
976 task,
977 self.get_user_idstring(task)))
978
979 bb.data.setVar("__RUNQUEUE_DO_NOT_USE_EXTERNALLY", self, self.cooker.configuration.data)
980 bb.data.setVar("__RUNQUEUE_DO_NOT_USE_EXTERNALLY2", fn, self.cooker.configuration.data)
981 try:
982 the_data = self.cooker.bb_cache.loadDataFull(fn, self.cooker.configuration.data)
983
984 if not self.cooker.configuration.dry_run:
985 bb.build.exec_task(taskname, the_data)
986 os._exit(0)
987
988 except bb.build.FuncFailed:
989 bb.msg.error(bb.msg.domain.Build, "task stack execution failed")
990 os._exit(1)
991 except bb.build.EventException as e:
992 event = e.args[1]
993 bb.msg.error(bb.msg.domain.Build, "%s event exception, aborting" % bb.event.getName(event))
994 os._exit(1)
995 except Exception:
996 from traceback import format_exc
997 bb.msg.error(bb.msg.domain.Build, "Build of %s %s failed" % (fn, taskname))
998 bb.msg.error(bb.msg.domain.Build, format_exc())
999 os._exit(1)
1000 os._exit(0)
1001 946
1002 self.build_pids[pid] = task 947 self.build_pids[pid] = task
1003 self.build_pipes[pid] = runQueuePipe(pipein, pipeout, self.cfgData) 948 self.build_pipes[pid] = runQueuePipe(pipein, pipeout, self.cfgData)
@@ -1083,6 +1028,66 @@ class RunQueue:
1083 self.state = runQueueComplete 1028 self.state = runQueueComplete
1084 return 1029 return
1085 1030
1031 def fork_off_task(self, fn, task, taskname):
1032 sys.stdout.flush()
1033 sys.stderr.flush()
1034 try:
1035 pipein, pipeout = os.pipe()
1036 pid = os.fork()
1037 except OSError as e:
1038 bb.msg.fatal(bb.msg.domain.RunQueue, "fork failed: %d (%s)" % (e.errno, e.strerror))
1039 if pid == 0:
1040 os.close(pipein)
1041 # Save out the PID so that the event can include it the
1042 # events
1043 bb.event.worker_pid = os.getpid()
1044 bb.event.worker_pipe = pipeout
1045
1046 self.state = runQueueChildProcess
1047 # Make the child the process group leader
1048 os.setpgid(0, 0)
1049 # No stdin
1050 newsi = os.open('/dev/null', os.O_RDWR)
1051 os.dup2(newsi, sys.stdin.fileno())
1052 # Stdout to a logfile
1053 #logout = data.expand("${TMPDIR}/log/stdout.%s" % os.getpid(), self.cfgData, True)
1054 #mkdirhier(os.path.dirname(logout))
1055 #newso = open(logout, 'w')
1056 #os.dup2(newso.fileno(), sys.stdout.fileno())
1057 #os.dup2(newso.fileno(), sys.stderr.fileno())
1058
1059 bb.event.fire(runQueueTaskStarted(task, self.stats, self), self.cfgData)
1060 bb.msg.note(1, bb.msg.domain.RunQueue,
1061 "Running task %d of %d (ID: %s, %s)" % (self.stats.completed + self.stats.active + 1,
1062 self.stats.total,
1063 task,
1064 self.get_user_idstring(task)))
1065
1066 bb.data.setVar("__RUNQUEUE_DO_NOT_USE_EXTERNALLY", self, self.cooker.configuration.data)
1067 bb.data.setVar("__RUNQUEUE_DO_NOT_USE_EXTERNALLY2", fn, self.cooker.configuration.data)
1068 try:
1069 the_data = self.cooker.bb_cache.loadDataFull(fn, self.cooker.configuration.data)
1070
1071 if not self.cooker.configuration.dry_run:
1072 bb.build.exec_task(taskname, the_data)
1073 os._exit(0)
1074
1075 except bb.build.FuncFailed:
1076 bb.msg.error(bb.msg.domain.Build, "task stack execution failed")
1077 os._exit(1)
1078 except bb.build.EventException as e:
1079 event = e.args[1]
1080 bb.msg.error(bb.msg.domain.Build, "%s event exception, aborting" % bb.event.getName(event))
1081 os._exit(1)
1082 except Exception:
1083 from traceback import format_exc
1084 bb.msg.error(bb.msg.domain.Build, "Build of %s %s failed" % (fn, taskname))
1085 bb.msg.error(bb.msg.domain.Build, format_exc())
1086 os._exit(1)
1087 os._exit(0)
1088 return pid, pipein, pipeout
1089
1090
1086 def dump_data(self, taskQueue): 1091 def dump_data(self, taskQueue):
1087 """ 1092 """
1088 Dump some debug information on the internal data structures 1093 Dump some debug information on the internal data structures