Commit 6d108fb6 authored by 's avatar
Browse files

Error values instead of exit

git-svn-id: file:///home/svn/mapi/trunk@529 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 60023f7e
This diff is collapsed.
......@@ -28,38 +28,40 @@
static int sock;
static int mapidaddr_len;
static struct sockaddr_un mapidaddr;
static struct sockaddr_un fromaddr;
//static struct sockaddr_un fromaddr;
static char* mapidsocket;
void mapiipc_write(struct mapiipcbuf *qbuf)
int mapiipc_write(struct mapiipcbuf *qbuf)
//Sends an IPC message to mapid
{
qbuf->uid=getuid();
if(send(sock, qbuf, sizeof(struct mapiipcbuf), 0) == -1) {
WARNING_CMD(printf("send: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
// exit(1);
return -1;
}
return 0;
}
void mapiipc_read(struct mapiipcbuf *qbuf)
int mapiipc_read(struct mapiipcbuf *qbuf)
//Reads an IPC message. Blocking call
{
if(recv(sock, qbuf, MAX_SEND_SIZE, 0) == -1){
ERROR_CMD(printf("recv: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
exit(1);
//exit(1);
return -1;
}
return 0;
}
void mapiipc_client_init()
int mapiipc_client_init()
//Initializes IPC for mapi functions
{
if ((sock = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1) {
ERROR_CMD(printf("socket: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
exit(1);
//exit(1);
return -1;
}
mapidsocket=malloc(sizeof(MAPIDSOCKHOME)-2+strlen(getenv("HOME")));
sprintf(mapidsocket,MAPIDSOCKHOME,getenv("HOME"));
......@@ -71,7 +73,7 @@ void mapiipc_client_init()
if (connect(sock, (struct sockaddr *)&mapidaddr, mapidaddr_len) < 0)
{
// ERROR_CMD(printf("connect: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
// ERROR_CMD(printf("connect: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
free(mapidsocket);
mapidsocket=strdup(MAPIDSOCKGLOBAL);
strcpy(mapidaddr.sun_path, mapidsocket);
......@@ -79,10 +81,11 @@ void mapiipc_client_init()
if (connect(sock, (struct sockaddr *)&mapidaddr, mapidaddr_len) < 0)
ERROR_CMD(printf("connect: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
else
return;
exit(EXIT_FAILURE);
//exit(EXIT_FAILURE);
return -1;
}
free(mapidsocket);
return 0;
}
void mapiipc_client_close()
......@@ -95,17 +98,19 @@ void mapiipc_client_close()
struct sockaddr_in remoteaddr;
flist_t *remote_flowlist=NULL;
void mapiipc_remote_write(struct dmapiipcbuf *dbuf, struct host *h)
int mapiipc_remote_write(struct dmapiipcbuf *dbuf, struct host *h)
//Sends an IPC message to mapid
{
// qbuf->uid=getuid();
if(send(h->sockfd, dbuf, dbuf->length, 0) == -1) {
WARNING_CMD(printf("send: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
// exit(1);
return -1;
}
return 0;
}
void mapiipc_remote_write_to_all(remote_flowdescr_t* rflow)
int mapiipc_remote_write_to_all(remote_flowdescr_t* rflow)
{
host_flow* hflow;
flist_node_t* fnode;
......@@ -115,11 +120,12 @@ void mapiipc_remote_write_to_all(remote_flowdescr_t* rflow)
for (fnode=flist_head(rflow->host_flowlist); fnode!=NULL; fnode=flist_next(fnode)) {
hflow=(host_flow*)fnode->data;
hflow->dbuf->fd=hflow->fd;
mapiipc_remote_write(hflow->dbuf, hflow->rhost);
if (!mapiipc_remote_write(hflow->dbuf, hflow->rhost)) return -1;
rflow->pending_msgs++;
}
pthread_mutex_unlock(&rflow->mutex);
sem_wait(&rflow->fd_sem);
return 0;
}
void *mapiipc_comm_thread(void *host) {
......@@ -139,7 +145,7 @@ void *mapiipc_comm_thread(void *host) {
if (dbuf_bytes==0 || dbuf_bytes<dbuf->length) {
if( (recv_bytes=recv(((struct host *)host)->sockfd, (char*)&buffer+dbuf_bytes, DIMAPI_DATA_SIZE, 0)) == -1) {
//ERROR_CMD(printf("recv: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
exit(1);
//exit(1);
//printf("error 1\n");
continue ;
}
......@@ -174,9 +180,10 @@ void *mapiipc_comm_thread(void *host) {
else pthread_mutex_unlock(&rflow->mutex);
}
else {
printf("INTERNAL SERIOUS FAILURE %d\n",dbuf->fd);
exit(-1);
printf("Invalid IPC message, unknown fd %d\n",dbuf->fd);
//exit(-1);
//failure
continue;
}
dbuf_bytes=dbuf_bytes-dbuf->length;
......@@ -185,7 +192,7 @@ void *mapiipc_comm_thread(void *host) {
}
void mapiipc_remote_init(struct host *h)
int mapiipc_remote_init(struct host *h)
//Initializes IPC for dmapi functions
{
struct hostent* host=gethostbyname(h->hostname);
......@@ -193,7 +200,8 @@ void mapiipc_remote_init(struct host *h)
if ((h->sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
ERROR_CMD(printf("socket: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
exit(-1);
//exit(-1);
return -1;
}
/*
......@@ -203,7 +211,8 @@ void mapiipc_remote_init(struct host *h)
if (setsockopt(h->sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)) == -1) {
close(h->sockfd);
printf("Unexpected error on setsockopt()");
exit(-1);
//exit(-1);
return -1;
}
*/
......@@ -213,12 +222,14 @@ void mapiipc_remote_init(struct host *h)
if (setsockopt(h->sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)) == -1) {
close(h->sockfd);
printf("Unexpected error on setsockopt()");
exit(-1);
//exit(-1);
return -1;
}
if (host==NULL) {
printf("Could not determine address for %s\n",h->hostname);
exit(1);
//exit(1);
return -1;
}
// Construct name of dmapid's socket
......@@ -228,8 +239,10 @@ void mapiipc_remote_init(struct host *h)
if (connect(h->sockfd, (struct sockaddr *)&remoteaddr, sizeof(remoteaddr)) < 0) {
ERROR_CMD(printf("connect failed: %s [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
exit(EXIT_FAILURE);
//exit(EXIT_FAILURE);
return -1;
}
return 0;
}
......
......@@ -104,13 +104,13 @@ struct mapiipcbuf {
//IPC calls
//Initialize IPC functions
void mapiipc_client_init(void);
int mapiipc_client_init(void);
void mapiipc_daemon_init(void);
//Sends an IPC message
void mapiipc_write(struct mapiipcbuf *qbuf);
int mapiipc_write(struct mapiipcbuf *qbuf);
//Reads an IPC message. Blocking call.
void mapiipc_read(struct mapiipcbuf *qbuf);
int mapiipc_read(struct mapiipcbuf *qbuf);
//Send a file handle
......@@ -176,9 +176,9 @@ typedef struct remote_flowdescr {
//dmapi functions and ipcbuffer
void mapiipc_remote_init(struct host *h);
void mapiipc_remote_write(struct dmapiipcbuf *dbuf, struct host *h);
void mapiipc_remote_write_to_all(remote_flowdescr_t* rflow);
int mapiipc_remote_init(struct host *h);
int mapiipc_remote_write(struct dmapiipcbuf *dbuf, struct host *h);
int mapiipc_remote_write_to_all(remote_flowdescr_t* rflow);
void mapiipc_remote_close(struct host *h);
void *mapiipc_comm_thread(void *host);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment