io: fix race and don't close fd twice
io: add lem_inputbuf_init() helper
parsers: split out from io library