Add a safety back off, so we don't spam device with indefinite reboot loop.
This commit is contained in:
parent
600202b4d6
commit
ab73c2c47f
1 changed files with 26 additions and 0 deletions
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.mainloop.glib
|
import dbus.mainloop.glib
|
||||||
import dbus.service
|
import dbus.service
|
||||||
|
|
@ -156,6 +158,28 @@ class Device(dbus.service.Object):
|
||||||
logging.debug('RunCmd')
|
logging.debug('RunCmd')
|
||||||
return hexlify(tls.app(unhexlify(cmd))).decode()
|
return hexlify(tls.app(unhexlify(cmd))).decode()
|
||||||
|
|
||||||
|
backoff_file='/usr/share/python-validity/backoff'
|
||||||
|
|
||||||
|
# I don't know how to tell systemd to backoff in case of multiple instance of the same template service, help!
|
||||||
|
def backoff():
|
||||||
|
if os.path.isfile(backoff_file):
|
||||||
|
with open(backoff_file, 'r') as f:
|
||||||
|
lines = list(map(float, f.readlines()))
|
||||||
|
else:
|
||||||
|
lines=[]
|
||||||
|
|
||||||
|
while len(lines) > 0 and lines[0] + 60 < time.time():
|
||||||
|
lines=lines[1:]
|
||||||
|
|
||||||
|
lines += [time.time()]
|
||||||
|
|
||||||
|
with open(backoff_file, 'w') as f:
|
||||||
|
for l in lines:
|
||||||
|
f.write('%f\n' % l)
|
||||||
|
|
||||||
|
if len(lines) > 10:
|
||||||
|
raise Exception('Refusing to start more than 10 times per minute')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser('Open fprintd DBus service')
|
parser = argparse.ArgumentParser('Open fprintd DBus service')
|
||||||
parser.add_argument('--debug', help='Enable tracing', action='store_true')
|
parser.add_argument('--debug', help='Enable tracing', action='store_true')
|
||||||
|
|
@ -167,6 +191,8 @@ if __name__ == '__main__':
|
||||||
usb.trace_enabled = True
|
usb.trace_enabled = True
|
||||||
tls.trace_enabled = True
|
tls.trace_enabled = True
|
||||||
|
|
||||||
|
backoff()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.devpath is None:
|
if args.devpath is None:
|
||||||
init.open()
|
init.open()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue