Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
addpromise.py: small tweaks
Browse files Browse the repository at this point in the history
- report files without pledge()
- improve error message
- update pledge() regexp
  • Loading branch information
ligurio committed Nov 9, 2017
1 parent 9de994d commit 6d750e9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tools/addpromise.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
filename = sys.argv[1] filename = sys.argv[1]
promise = sys.argv[2].split(" ") promise = sys.argv[2].split(" ")
else: 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): if not os.path.exists(filename):
sys.exit('ERROR: %s was not found.' % sys.argv[1]) sys.exit('ERROR: %s was not found.' % sys.argv[1])
Expand All @@ -25,13 +25,15 @@ def main():


buf = "" buf = ""
# Example: pledge("stdio rpath proc exec", NULL) # Example: pledge("stdio rpath proc exec", NULL)
pledged = False
with open(filename, 'r') as source: with open(filename, 'r') as source:
for line in source: for line in source:
line = line.rstrip() line = line.rstrip()
pledge_match = re.findall(".*pledge\(\"(.*)\",.*\)", line) pledge_match = re.findall(".*pledge\(\"(.*)\",.*", line)
pledge_num = len(pledge_match) pledge_num = len(pledge_match)
print(filename, ":", pledge_match)
if pledge_num > 0: if pledge_num > 0:
print(filename, ":", pledge_match)
pledged = True
for p in promise: for p in promise:
promise_match = re.findall( promise_match = re.findall(
".*pledge\(\"(.*%s.*)\",.*\)" % p, line) ".*pledge\(\"(.*%s.*)\",.*\)" % p, line)
Expand All @@ -41,6 +43,9 @@ def main():
pledge_match[0], "%s %s" % (pledge_match[0], p)) pledge_match[0], "%s %s" % (pledge_match[0], p))
buf = "{}{}\n".format(buf, line) buf = "{}{}\n".format(buf, line)


if not pledged:
print(filename, ":", "None")

source = open(filename, 'w') source = open(filename, 'w')
source.write(buf) source.write(buf)
source.close() source.close()
Expand Down

0 comments on commit 6d750e9

Please sign in to comment.