bug in rpc for linux??

bug in rpc for linux??

Post by Matthew Haycraf » Wed, 12 Mar 1997 04:00:00



This is a multi-part message in MIME format.

--------------1E9ED53D39EF5D365010E47F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

ok, attached is the source to the client and server of an
example program found in the nutshell book...

Anyway.. after making a few changes (to make is more ansi complient),
I was able to compile it on an SGI and my linux box.
(still got 2 warnings on my linux box (for the client))

I can use the client while the server is running on the SGI.
the client works fine on the SGI.  However the server cores on
my linux box.

I ran gdb with it and saw this:
Program received signal SIGSEGV, Segmentation fault.
0x4003d4a4 in __libc_free ()

so for some reason some meory is improperly de-aloocated..
however the code from the book dose no dynamic allocation.

anyone heard of this problem before?
any solutions?
I want to develop the program on my linux box rather than on the SGI.

Thanks in advance,
--
.-.-..--._|_ _|_ Matthew="Gift of Jehovah" Haycraft="A hedged Enclosure"
| | |.--| |   |        I am right, you are wrong, so there! ;-P~~

--------------1E9ED53D39EF5D365010E47F
Content-Type: text/plain; charset=us-ascii; name="Makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Makefile"

CFLAGS=-g

client_server: client server

client:rls.o rls_xdr.o
        cc $(CFLAGS) -o rls rls.o rls_xdr.o

server:rls_svc.o read_dir.c rls_xdr.o
        cc $(CFLAGS) -o rls_svc rls_svc.o read_dir.c rls_xdr.o

rls.o:rls.c
        cc $(CFLAGS) -c rls.c

rls_xdr.o:rls_xdr.c
        cc $(CFLAGS) -c rls_xdr.c

rls_svc.o:rls_svc.c
        cc $(CFLAGS) -c rls_svc.c

--------------1E9ED53D39EF5D365010E47F
Content-Type: text/plain; charset=us-ascii; name="read_dir.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="read_dir.c"

#include <sys/types.h>
#include <sys/dir.h>
#include "rls.h"

int read_dir(char * dir)
{
        DIR * dirp;
        struct direct *d;

        /*open directory */
        dirp = opendir(dir);
        if (dirp == NULL) return(0);

        /*stuff filenames into dir buffer */
        dir[0] = '\0';
        while (d = readdir(dirp)) sprintf(dir, "%s%s\n",dir, d->d_name);

        /* return the result */
        closedir(dirp);
        return((int)dir);

Quote:}

--------------1E9ED53D39EF5D365010E47F
Content-Type: text/plain; charset=us-ascii; name="rls.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="rls.c"

#include <stdio.h>
#include <strings.h>
#include <rpc/rpc.h>
#include "rls.h"
void read_dir(char * host, char * dir);
int main(int argc, char * argv[])
{
        char dir[DIR_SIZE];
        /*call the remote procedure if registerd */
        strcpy(dir, argv[2]);
        read_dir(argv[1], dir); /*read_dir(host,directory)*/

        /* Spew out the results and bail out of here! */
        printf("%s\n", dir);
        exit(0);

Quote:}

void read_dir(char * host, char * dir)
{
        extern bool_t xdr_dir();
        enum clnt_stat clnt_stat;

        clnt_stat = callrpc (host, DIRPROG, DIRVERS, READDIR,
                       xdr_dir, dir, xdr_dir, dir);
        if(clnt_stat != 0)clnt_perrno(clnt_stat);

Quote:}

--------------1E9ED53D39EF5D365010E47F
Content-Type: image/x-xbitmap; name="rls.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="rls.h"

#define DIR_SIZE 8192
#define DIRPROG ((u_long) 0x20000000)  /*server program # */
#define DIRVERS ((u_long) 1)           /* program version number */
#define READDIR ((u_long) 1)           /* procedure num for look-up */

--------------1E9ED53D39EF5D365010E47F
Content-Type: text/plain; charset=us-ascii; name="rls_svc.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="rls_svc.c"

#include <rpc/rpc.h>
#include "rls.h"

typedef void *(* correct)(void *);

int main(int argc, char ** argv)
{
        extern bool_t xdr_dir();
        extern char * read_dir(char *);

        registerrpc(DIRPROG, DIRVERS, READDIR, (correct)(read_dir), xdr_dir, xdr_dir);
        svc_run();

Quote:}

--------------1E9ED53D39EF5D365010E47F
Content-Type: text/plain; charset=us-ascii; name="rls_xdr.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="rls_xdr.c"

#include <rpc/rpc.h>
#include "rls.h"
bool_t xdr_dir(XDR * xdrs, char * objp)
{
        return(xdr_string(xdrs, &objp, DIR_SIZE) );

Quote:}

--------------1E9ED53D39EF5D365010E47F--