def execute(self, name, options, parameters):
try:
self._cmdLock.acquire()
self._log.debug("execute(%s, %s, %s)", name, options, parameters)
if not name.startswith("/"):
raise CF.InvalidFileName(CF.CF_EINVAL, "Filename must be absolute")
if self.isLocked(): raise CF.Device.InvalidState("System is locked down")
if self.isDisabled(): raise CF.Device.InvalidState("System is disabled")
priority = 0
stack_size = 4096
invalidOptions = []
for option in options:
val = option.value.value()
if option.id == CF.ExecutableDevice.PRIORITY_ID:
if ((not isinstance(val, int)) and (not isinstance(val, long))):
invalidOptions.append(option)
else:
priority = val
elif option.id == CF.ExecutableDevice.STACK_SIZE_ID:
if ((not isinstance(val, int)) and (not isinstance(val, long))):
invalidOptions.append(option)
else:
stack_size = val
if len(invalidOptions) > 0:
self._log.error("execute() received invalid options %s", invalidOptions)
raise CF.ExecutableDevice.InvalidOptions(invalidOptions)
command = name[1:] # This is relative to our CWD
self._log.debug("Running %s %s", command, os.getcwd())
if not os.path.isfile(command):
raise CF.InvalidFileName(CF.CF_EINVAL, "File could not be found %s" % command)
os.chmod(command, os.stat(command)[0] | stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
finally:
self._cmdLock.release()
return self._execute(command, options, parameters)
评论列表
文章目录