cserve2: prevent infinite loop during connection

In case of EACCESS, there is no point trying forever
In case of EINTR (interrupt), we can consider for now
that any signal will prevent the use of cserve2.
If we don't do that, Ctrl+C simply won't work :)
This commit is contained in:
Jean-Philippe Andre 2013-06-18 20:50:17 +09:00 committed by Cedric Bail
parent 6adb604dae
commit 1821c91d10
1 changed files with 13 additions and 1 deletions

View File

@ -107,10 +107,22 @@ _server_connect(void)
len = strlen(remote.sun_path) + sizeof(remote.sun_family);
for (;;)
{
errno = 0;
if (connect(s, (struct sockaddr *)&remote, len) != -1) break;
if (errno == EACCES)
{
ERR("not authorized to connect to cserve2!");
return EINA_FALSE;
}
ERR("cserve2 connect failed: [%d] %s. Retrying...", errno, strerror(errno));
usleep(1000);
errno = 0;
usleep(10000);
if (errno == EINTR)
{
WRN("received interruption while trying to connect to cserve2!");
return EINA_FALSE;
}
/* FIXME: Here we should identify the error, maybe signal the daemon manager
* that we need cserve2 to [re]start or just quit and return false.