smbc_open fails after network hiccup

mlitke at vigilos.com mlitke at vigilos.com
Wed Oct 15 17:06:57 GMT 2003


I am using samba 2.2.7-3.7.2 with RedHat 7.2.  I wrote a client that polls
a file on a windows machine and if the file changes it gets processed.  I
noticed that if the network connection between the box the client is running
on and the box it is trying to read the file from goes down the smbc_open
fails (but returns errno = 0) which I obviously expect to happen, but once
the network connection  is restored it continues to fail.  If I kill the
process and restart it works fine.  I thought perhaps rerunning the smbc_init
function might fix it, but after looking over the code it looks like smbc_init
will just return without doing anything since it was already run once.  Any
suggestions on how to get the client reading the windows box after a network
disconnect?  I could of course have the client restart itself, but I would
prefer to be able reinitialize the smb connection.

The client code looks something like:
---
if (0 != smbc_init (smbAuthFn , 0)){
    printf ("Error: Initializing the smbclient library [%s]\n",
            strerror (errno));
}

while (1){
    if (0 > (fd = smbc_open (fileName, O_RDONLY, 0))){
       printf ("Error: Opening file (%s) [%s]\n", fileName,
               strerror (errno));
       sleep (10);
       continue;
    }

    bytesRead = smbc_read (fd, fileBuf, sizeof (fileBuf));

    smbc_close (fd);

    ...

    sleep (10);
}
---

Thanks,
- Matt




More information about the samba-technical mailing list