Permalink
Browse files

addpromise.py: small tweaks

- report files without pledge()
- improve error message
- update pledge() regexp
  • Loading branch information...
ligurio committed Nov 9, 2017
1 parent 9de994d commit 6d750e96514a31a1a8b23577f8685dccae7fb494
Showing with 8 additions and 3 deletions.
  1. +8 −3 tools/addpromise.py
View
@@ -15,7 +15,7 @@ def main():
filename = sys.argv[1]
promise = sys.argv[2].split(" ")
else:
sys.exit("ERROR: Please specify a source file and promise.")
sys.exit("ERROR: Please specify a source file and promise. Default: [\"wpath\", \"cpath\", \"rpath\", \"flock\"].")
if not os.path.exists(filename):
sys.exit('ERROR: %s was not found.' % sys.argv[1])
@@ -25,13 +25,15 @@ def main():
buf = ""
# Example: pledge("stdio rpath proc exec", NULL)
pledged = False
with open(filename, 'r') as source:
for line in source:
line = line.rstrip()
pledge_match = re.findall(".*pledge\(\"(.*)\",.*\)", line)
pledge_match = re.findall(".*pledge\(\"(.*)\",.*", line)
pledge_num = len(pledge_match)
print(filename, ":", pledge_match)
if pledge_num > 0:
print(filename, ":", pledge_match)
pledged = True
for p in promise:
promise_match = re.findall(
".*pledge\(\"(.*%s.*)\",.*\)" % p, line)
@@ -41,6 +43,9 @@ def main():
pledge_match[0], "%s %s" % (pledge_match[0], p))
buf = "{}{}\n".format(buf, line)
if not pledged:
print(filename, ":", "None")
source = open(filename, 'w')
source.write(buf)
source.close()

0 comments on commit 6d750e9

Please sign in to comment.