diff -urN ltspfs.orig/ltspfs.c ltspfs/ltspfs.c --- ltspfs.orig/ltspfs.c 2006-03-07 07:25:31 +0200 +++ ltspfs/ltspfs.c 2007-07-18 17:56:14 +0300 @@ -79,7 +79,7 @@ * have the packet length in them. */ - readn(sockfd, pktptr, BYTES_PER_XDR_UNIT); /* Read length */ + if (readn(sockfd, pktptr, BYTES_PER_XDR_UNIT) == -1) return -1; /* Read length */ xdr_int(in, &len); /* decode it */ len -= BYTES_PER_XDR_UNIT; /* reduce count */ pktptr += BYTES_PER_XDR_UNIT; /* skip over count in buffer */ @@ -123,13 +123,16 @@ * handle the locking and unlocking of the communication stream. */ -void +int send_recv(XDR *in, XDR *out, char *inbuf, char *outbuf) { + ssize_t r; + pthread_mutex_lock(&lock); /* Lock mutex */ writepacket(out, outbuf); /* Send out packet */ - readpacket(in, inbuf); /* Read response */ + r = readpacket(in, inbuf); /* Read response */ pthread_mutex_unlock(&lock); /* Unlock mutex */ + return r; } #if FUSE_MINOR_VERSION >= 3 @@ -220,6 +223,7 @@ char *auth_file; /* buffer to hold file */ FILE *pcmd; int opcode = LTSPFS_XAUTH; + ssize_t r; /* * Get the xauth token for our display. @@ -277,8 +281,9 @@ writepacket(&out, outbuf); /* Send command */ writen(sockfd, auth_file, size); /* Send authfile */ - readpacket(&in, inbuf); /* Read response */ + r = readpacket(&in, inbuf); /* Read response */ free(auth_file); + if (r == -1) return -1; return parse_return(&in); } @@ -305,7 +310,7 @@ xdr_int(&out, &opcode); /* build opcode */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ if (!xdr_int(&in, &res)) /* Did we get error? */ return -EACCES; /* bad arg */ @@ -384,7 +389,7 @@ xdr_int(&out, &opcode); /* build opcode */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ /* * Parse the return and populate returning link name buffer. @@ -442,7 +447,7 @@ pthread_mutex_lock(&lock); /* Lock mutex */ writepacket(&out, outbuf); - readpacket(&in, inbuf); /* Read response */ + if (readpacket(&in, inbuf) == -1) return -errno; /* Read response */ xdr_int(&in, &statcode); while (statcode == LTSP_STATUS_CONT) { /* Continue? */ @@ -459,7 +464,7 @@ } xdr_setpos(&in, 0); /* rewind data packet */ - readpacket(&in, inbuf); /* Read the next line */ + if (readpacket(&in, inbuf) == -1) return -errno; /* Read the next line */ xdr_int(&in, &statcode); /* And grab the statcode */ } @@ -503,7 +508,7 @@ pthread_mutex_lock(&lock); /* Lock mutex */ writepacket(&out, outbuf); - readpacket(&in, inbuf); /* Read response */ + if (readpacket(&in, inbuf) == -1) return -errno; /* Read response */ xdr_int(&in, &statcode); while (statcode == LTSP_STATUS_CONT) { /* Continue? */ @@ -522,7 +527,7 @@ r = filler(buf, dirpath, &st, 0); /* Call the filler function */ } /* endif !r */ xdr_setpos(&in, 0); /* reset our input buffer */ - readpacket(&in, inbuf); /* Read the next line */ + if (readpacket(&in, inbuf) == -1) return -errno; /* Read the next line */ xdr_int(&in, &statcode); /* And grab the statcode */ } @@ -558,7 +563,7 @@ xdr_u_longlong_t(&out, &rdev); /* build rdev */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -584,7 +589,7 @@ xdr_u_int(&out, &mode); /* build mode */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -608,7 +613,7 @@ xdr_int(&out, &opcode); /* build opcode */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -659,7 +664,7 @@ ptr = (char *)to; xdr_string(&out, &ptr, PATH_MAX); /* build to */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -721,7 +726,7 @@ xdr_u_int(&out, &mode); /* build mode */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -748,7 +753,7 @@ xdr_u_int(&out, &gid); /* build gid */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -774,7 +779,7 @@ xdr_longlong_t(&out, &size); /* build size */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -801,7 +806,7 @@ xdr_long(&out, &buf->modtime); /* build modtime */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -827,7 +832,7 @@ xdr_int(&out, &fi->flags); /* build open flags */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ return parse_return(&in); } @@ -858,7 +863,7 @@ pthread_mutex_lock(&lock); /* Lock mutex */ writepacket(&out, outbuf); - readpacket(&in, inbuf); /* Read response */ + if (readpacket(&in, inbuf) == -1) return -errno; /* Read response */ /* * Parse the return and populate the read buffer passed to us. @@ -874,7 +879,7 @@ if (res) /* Error, return error code */ return -returned; - readn(sockfd, buf, returned); /* read data payload */ + if (readn(sockfd, buf, returned) == -1) return -errno; /* read data payload */ pthread_mutex_unlock(&lock); /* Unlock mutex */ return returned; /* Return bytes read */ @@ -907,8 +912,9 @@ pthread_mutex_lock(&lock); /* Lock mutex */ writepacket(&out, outbuf); writen(sockfd, (char *)buf, size); /* Send data buffer */ - readpacket(&in, inbuf); /* Read response */ + res = readpacket(&in, inbuf); /* Read response */ pthread_mutex_unlock(&lock); /* Unlock mutex */ + if (res == -1) return -errno; /* * Parse the return. @@ -948,7 +954,7 @@ xdr_int(&out, &opcode); /* build opcode */ xdr_string(&out, &ptr, PATH_MAX); /* build path */ - send_recv(&in, &out, inbuf, outbuf); /* send output, recv response */ + if (send_recv(&in, &out, inbuf, outbuf) == -1) return -errno; /* send output, recv response */ /* * Parse the return and populate the stbuf structure @@ -1048,9 +1054,8 @@ xdr_string(&out, &ptr, PATH_MAX); /* build path */ writepacket(&out, outbuf); - readpacket(&in, inbuf); /* Read response */ - - xdr_int(&in, &res); + if (readpacket(&in, inbuf) == -1) res = -1; /* Read response */ + else xdr_int(&in, &res); if (res) { fprintf(stderr, "Couldn't mount %s\n", mp); close(sockfd);