Replace perror() with WHY_perror()

Puts more diagnostics to Android log
This commit is contained in:
Andrew Bettison 2012-05-08 14:45:26 +09:30
parent 8dd9a70852
commit 836f8332e8
10 changed files with 27 additions and 29 deletions

6
dna.c
View File

@ -277,15 +277,13 @@ int create_serval_instance_dir() {
DIR *d = opendir(instancepath);
if (!d) {
WHYF("Cannot access %s", instancepath);
perror("opendir");
return -1;
return WHY_perror("opendir");
}
closedir(d);
return 0;
}
WHYF("Cannot mkdir %s", instancepath);
perror("mkdir");
return -1;
return WHY_perror("mkdir");
}
return 0;
}

View File

@ -21,7 +21,7 @@ int app_monitor_cli(int argc, const char *const *argv, struct command_line_optio
struct sockaddr_un addr;
if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket error");
perror("socket");
exit(-1);
}
@ -34,7 +34,7 @@ int app_monitor_cli(int argc, const char *const *argv, struct command_line_optio
printf("last char='%c' %02x\n",p[len-1],p[len-1]);
if (connect(fd, (struct sockaddr*)&addr, len) == -1) {
perror("connect error");
perror("connect");
exit(-1);
}

View File

@ -186,7 +186,7 @@ int overlayServerMode()
if (r<0) {
/* select had a problem */
if (debug&DEBUG_IO) perror("poll()");
if (debug&DEBUG_IO) WHY_perror("poll()");
WHY("select() complained.");
} else if (r>0) {
/* We have data, so try to receive it */

View File

@ -191,7 +191,7 @@ int overlay_interface_init_socket(int interface,struct sockaddr_in src_addr,stru
int broadcastP=1;
if(setsockopt(I(fd), SOL_SOCKET, SO_BROADCAST, &broadcastP, sizeof(broadcastP)) < 0) {
WHY("Could not enable broadcast reception for socket. This is really bad.");
perror("setsockopt");
WHY_perror("setsockopt");
close(I(fd)); I(fd)=0;
return WHY("setsockopt() failed");
} else
@ -211,7 +211,7 @@ int overlay_interface_init_socket(int interface,struct sockaddr_in src_addr,stru
*/
if (debug&DEBUG_PACKETRX) fprintf(stderr,"src_addr=%08x\n",(unsigned int)broadcast.sin_addr.s_addr);
if(bind(I(fd),(struct sockaddr *)&broadcast,sizeof(broadcast))) {
perror("bind()");
WHY_perror("bind");
close(I(fd));
I(fd)=-1;
return WHY("MP HLR server could not bind to requested UDP port (bind() failed)");
@ -453,7 +453,7 @@ int overlay_broadcast_ensemble(int interface_number,
bcopy(bytes,&buf[128],len);
if (write(overlay_interfaces[interface_number].fd,buf,2048)!=2048)
{
perror("write()");
WHY_perror("write");
return WHY("write() failed");
}
else
@ -464,7 +464,7 @@ int overlay_broadcast_ensemble(int interface_number,
if(sendto(overlay_interfaces[interface_number].fd, bytes, len, 0, (struct sockaddr *)&s, sizeof(struct sockaddr_in)) != len)
{
/* Failed to send */
perror("sendto(c)");
WHY_perror("sendto(c)");
return WHY("sendto() failed");
}
else
@ -600,7 +600,7 @@ int overlay_interface_discover()
int family;
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddr()");
WHY_perror("getifaddr()");
return WHY("getifaddrs() failed");
}

View File

@ -162,8 +162,8 @@ int overlay_mdp_reply(int sock,struct sockaddr_un *recvaddr,int recvaddrlen,
int r=sendto(sock,(char *)mdpreply,replylen,0,
(struct sockaddr *)recvaddr,recvaddrlen);
if (r<replylen) {
perror("sendto(d)");
WHY("sendto() failed when sending MDP reply");
WHY_perror("sendto(d)");
printf("sock=%d, r=%d\n",sock,r);
return -1;
} else
@ -464,7 +464,7 @@ int overlay_saw_mdp_frame(int interface, overlay_mdp_frame *mdp,long long now)
int r=sendto(mdp_named_socket,mdp,overlay_mdp_relevant_bytes(mdp),0,(struct sockaddr*)&addr,sizeof(addr));
printf("r=%d\n",r);
if (r==overlay_mdp_relevant_bytes(mdp)) return 0;
perror("sendto(e)");
WHY_perror("sendto(e)");
return WHY("Failed to pass received MDP frame to client");
} else {
/* No socket is bound, ignore the packet ... except for magic sockets */
@ -1101,7 +1101,7 @@ int overlay_mdp_send(overlay_mdp_frame *mdp,int flags,int timeout_ms)
mdp->packetTypeAndFlags=MDP_ERROR;
mdp->error.error=1;
snprintf(mdp->error.message,128,"Error sending frame to MDP server.");
perror("sendto(f)");
WHY_perror("sendto(f)");
return -1;
} else {
if (!(flags&MDP_AWAITREPLY)) {
@ -1148,7 +1148,7 @@ int overlay_mdp_client_init()
mdp_client_socket = socket(AF_UNIX, SOCK_DGRAM, 0);
if (mdp_client_socket < 0) {
perror("socket");
WHY_perror("socket");
return WHY("Could not open socket to MDP server");
}
@ -1173,7 +1173,7 @@ int overlay_mdp_client_init()
int r=bind(mdp_client_socket, (struct sockaddr *)&name, len);
if (r) {
WHY("Could not bind MDP client socket to file name");
perror("bind");
WHY_perror("bind");
return -1;
}

View File

@ -113,8 +113,7 @@ int getBroadcastAddresses(struct in_addr peers[],int *peer_count,int peer_max){
if (debug&DEBUG_PEERS) fprintf(stderr,"Reading broadcast addresses (posix style)\n");
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddr()");
return WHY("getifaddrs() failed");
return WHY_perror("getifaddr");
}
for (ifa=ifaddr;ifa!=NULL;ifa=ifa->ifa_next) {

View File

@ -960,13 +960,13 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath)
int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0775);
if (fd == -1) {
ret = WHYF("Cannot open %s for write/create", filepath);
perror("open");
WHY_perror("open");
} else if (write(fd, fileblob, length) != length) {
ret = WHYF("Error writing %lld bytes to %s ", (long long) length, filepath);
perror("write");
WHY_perror("write");
} else if (close(fd) == -1) {
ret = WHYF("Error flushing to %s ", filepath);
perror("close");
WHY_perror("close");
} else {
ret = 1;
cli_puts("filehash"); cli_delim(":");

View File

@ -338,7 +338,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m,
close (sock);
if (debug&DEBUG_RHIZOME) {
WHY("Failed to open socket to peer's rhizome web server");
perror("connect");
WHY_perror("connect");
}
return -1;
}

View File

@ -739,6 +739,7 @@ int setReason(char *fmt, ...);
#define WHY(X) setReason("%s:%d:%s() %s",__FILE__,__LINE__,__FUNCTION__,X)
#define WHYRETNULL(X) { setReason("%s:%d:%s() %s",__FILE__,__LINE__,__FUNCTION__,X); return NULL; }
#define WHYF(F, ...) setReason("%s:%d:%s() " F, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define WHY_perror(X) setReason("%s:%d:%s() %s: %s [errno=%d]" X, __FILE__, __LINE__, __FUNCTION__, X, strerror(errno), errno)
overlay_buffer *ob_new(int size);
int ob_free(overlay_buffer *b);

View File

@ -164,7 +164,7 @@ int server(char *backing_file)
FILE *f=fopen(filename,"w");
if (!f) {
WHYF("Could not write to PID file %s", filename);
perror("fopen");
WHY_perror("fopen");
return -1;
}
server_getpid = getpid();
@ -607,8 +607,8 @@ int createServerSocket()
sock=socket(PF_INET,SOCK_DGRAM,0);
if (sock<0) {
fprintf(stderr,"Could not create UDP socket.\n");
perror("socket");
WHY("Could not create UDP socket.");
WHY_perror("socket");
exit(-3);
}
@ -623,14 +623,14 @@ int createServerSocket()
errno=0;
if(setsockopt(sock, IPPROTO_IP, IP_RECVTTL, &TRUE,sizeof(TRUE))<0)
perror("setsockopt(IP_RECVTTL)");
WHY_perror("setsockopt(IP_RECVTTL)");
bind_addr.sin_family = AF_INET;
bind_addr.sin_port = htons( PORT_DNA );
bind_addr.sin_addr.s_addr = htonl( INADDR_ANY );
if(bind(sock,(struct sockaddr *)&bind_addr,sizeof(bind_addr))) {
fprintf(stderr,"MP HLR server could not bind to UDP port %d\n", PORT_DNA);
perror("bind");
WHYF("MP HLR server could not bind to UDP port %d", PORT_DNA);
WHY_perror("bind");
exit(-3);
}
return 0;