in schemes.py [0:0]
def run_damon(target, is_target_cmd, init_regions, attrs, old_attrs):
if os.path.isfile(attrs.rfile_path):
os.rename(attrs.rfile_path, attrs.rfile_path + '.old')
if attrs.apply():
print('attributes (%s) failed to be applied' % attrs)
cleanup_exit(old_attrs, -1)
print('# damon attrs: %s %s' % (attrs.attr_str(), attrs.record_str()))
for line in attrs.schemes.split('\n'):
print('# scheme: %s' % line)
if is_target_cmd:
p = subprocess.Popen(target, shell=True, executable='/bin/bash')
target = p.pid
if _damon.set_target(target, init_regions):
print('target setting (%s, %s) failed' % (target, init_regions))
cleanup_exit(old_attrs, -2)
if _damon.turn_damon('on'):
print('could not turn on damon' % target)
cleanup_exit(old_attrs, -3)
while not _damon.is_damon_running():
time.sleep(1)
print('Press Ctrl+C to stop')
if is_target_cmd:
p.wait()
while True:
# damon will turn it off by itself if the target tasks are terminated.
if not _damon.is_damon_running():
break
time.sleep(1)
cleanup_exit(old_attrs, 0)