src: set close-on-exec flag with fopen()
motionlib: fix potential file descriptor leak, set close-on-exec