docs: def main():
      """
      Main program.
      """
      my_name = os.path.basename(sys.argv[0])
      if not my_name:
          my_name = "yhsm-yubikey-ksm"
      syslog.openlog(my_name, syslog.LOG_PID, syslog.LOG_LOCAL0)
  
      args = parse_args()
      args_fixup(args)
  
      aead_backend = None
      if args.db_url:
          # Using an SQL database for AEADs
          try:
              aead_backend = SQLBackend(args.db_url, args.key_handles)
          except Exception as e:
              my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                             'Could not connect to database "%s" : %s' % (args.db_url, e))
              return 1
      else:
          # Using the filesystem for AEADs
          try:
              aead_backend = FSBackend(args.aead_dir, args.key_handles)
          except Exception as e:
              my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                             'Could not create AEAD FSBackend: %s' % e)
              return 1
  
      if args.device == '-':
          # Using a soft-HSM with keys from stdin
          try:
              hsm = SoftYHSM.from_json(sys.stdin.read(), debug=args.debug)
          except ValueError as e:
              my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                             'Failed opening soft YHSM from stdin : %s' % (e))
              return 1
      elif os.path.isfile(args.device):
          # Using a soft-HSM from file
          try:
              hsm = SoftYHSM.from_file(args.device, debug=args.debug)
          except ValueError as e:
              my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                             'Failed opening soft YHSM "%s" : %s' % (args.device, e))
              return 1
      else:
          # Using a real HSM
          try:
              hsm = pyhsm.YHSM(device=args.device, debug=args.debug)
              context.files_preserve = [hsm.get_raw_device()]
          except serial.SerialException as e:
              my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                             'Failed opening YubiHSM device "%s" : %s' % (args.device, e))
              return 1
  
      if args.daemon:
          with context:
              run(hsm, aead_backend, args)
      else:
          try:
              run(hsm, aead_backend, args)
          except KeyboardInterrupt:
              print ""
              print "Shutting down"
              print ""