Changeset 14408 for titan/plugins


Ignore:
Timestamp:
03/04/12 14:05:14 (12 years ago)
Author:
nit
Message:

[titan] netlib, add 3 sek timeout for check nfs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • titan/plugins/networkbrowser/netlib/showmount.c

    r14401 r14408  
    3838#include <getopt.h>
    3939#include <unistd.h>
     40#include <sys/fcntl.h>
    4041
    4142#include "showmount.h"
     
    9091#define MAXHOSTLEN 256
    9192
     93int sockportopen(char* ip, int port, int tout)
     94{
     95        int fd = -1;
     96        int ret = 0, rest = 0, optval;
     97        socklen_t optlen = sizeof(optval);
     98        struct timeval timeout;
     99        struct sockaddr_in cliaddr;
     100
     101        memset(&cliaddr, 0, sizeof(struct sockaddr_in));
     102        cliaddr.sin_family = AF_INET;
     103        cliaddr.sin_port = htons(port);
     104
     105        fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
     106        if(fd < 0)
     107        {
     108                printf("can't open port socket\n");
     109                return 0;
     110        }
     111
     112        ret = inet_pton(AF_INET, ip, (void *)(&(cliaddr.sin_addr.s_addr)));
     113        if(ret < 0)
     114        {
     115                close(fd);
     116                printf("Can't set remote->sin_addr.s_addr\n");
     117                return 0;
     118        }
     119        else if(ret == 0)
     120        {
     121                close(fd);
     122                printf("%s is not a valid IP address\n", ip);
     123                return 0;
     124        }
     125
     126        fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
     127
     128        if(tout == -1) tout = 3000 * 1000;
     129        rest = tout % 1000000;
     130        tout = (tout - rest) / 1000000;
     131
     132        fd_set wfds;
     133
     134        ret = connect(fd, (struct sockaddr*) &cliaddr, sizeof(struct sockaddr));
     135        if(ret < 0)
     136        {
     137                if(errno == EINTR || errno == EINPROGRESS)
     138                {
     139                        FD_ZERO(&wfds);
     140                        FD_SET(fd, &wfds);
     141
     142                        timeout.tv_sec = tout;
     143                        timeout.tv_usec = rest;
     144                       
     145                        //ret = TEMP_FAILURE_RETRY(select(fd + 1, NULL, &wfds, NULL, &timeout));
     146                        ret = select(fd + 1, NULL, &wfds, NULL, &timeout);
     147                        if(ret == 1 && FD_ISSET(fd, &wfds))
     148                        {
     149                                close(fd);
     150                                return 1;
     151                        }
     152                }
     153                       
     154                if(ret <= 0)
     155                {
     156                        printf("can't connect\n");
     157                        close(fd);
     158                        return 0;
     159                }
     160        }
     161        close(fd);
     162        return 1;
     163}
     164
    92165int dump_cmp(char **p, char **q)
    93166{
     
    211284                memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
    212285        }
     286       
     287        //check port tcp
     288        int port111 = 0;
     289        port111 = sockportopen(hostname, 111, -1);
    213290
    214291        /* create mount deamon client */
    215 
    216292        server_addr.sin_port = 0;
    217293        msock = RPC_ANYSOCK;
    218         if ((mclient = clnttcp_create(&server_addr,
    219             MOUNTPROG, MOUNTVERS, &msock, 0, 0)) == NULL) {
     294       
     295        if(port111 == 1)
     296                mclient = clnttcp_create(&server_addr, MOUNTPROG, MOUNTVERS, &msock, 0, 0);
     297
     298        if(port111 == 1 && mclient == NULL)
     299        {
    220300                server_addr.sin_port = 0;
    221301                msock = RPC_ANYSOCK;
     
    229309                }
    230310        }
     311
     312        if(mclient == NULL) return(1);
     313
    231314        mclient->cl_auth = authunix_create_default();
    232315        total_timeout.tv_sec = 3;
Note: See TracChangeset for help on using the changeset viewer.