Do not call exit on errors, return error code
Fix connecting to several devices

The connect function searches through a list of registred devices.
Make a copy of the pointer to the list, to avoid incrementing the
static device list pointer.