getopt() and lock improvements