compat: backport tty_{lock,unlock,locked}