(nl_getlist): poll to get messages from kernel, and retry if the
message was lost (free_nlmsglist): free all linked elements, not just the first one git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15640 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000 - 2002 Kungliga Tekniska H<>gskolan
|
* Copyright (c) 2000 - 2002, 2005 Kungliga Tekniska H<>gskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -108,6 +108,7 @@ struct mbuf;
|
|||||||
#include <linux/rtnetlink.h>
|
#include <linux/rtnetlink.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
#include <netpacket/packet.h>
|
#include <netpacket/packet.h>
|
||||||
#include <net/ethernet.h> /* the L2 protocols */
|
#include <net/ethernet.h> /* the L2 protocols */
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
@@ -378,13 +379,30 @@ nl_getlist(int sd, int seq,
|
|||||||
struct nlmsghdr *nlh = NULL;
|
struct nlmsghdr *nlh = NULL;
|
||||||
int status;
|
int status;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
int tries = 3;
|
||||||
|
|
||||||
|
try_again:
|
||||||
status = nl_sendreq(sd, request, NLM_F_ROOT|NLM_F_MATCH, &seq);
|
status = nl_sendreq(sd, request, NLM_F_ROOT|NLM_F_MATCH, &seq);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
if (seq == 0)
|
if (seq == 0)
|
||||||
seq = (int)time(NULL);
|
seq = (int)time(NULL);
|
||||||
while(!done){
|
while(!done){
|
||||||
|
struct pollfd pfd;
|
||||||
|
|
||||||
|
pfd.fd = sd;
|
||||||
|
pfd.events = POLLIN | POLLPRI;
|
||||||
|
pfd.revents = 0;
|
||||||
|
status = poll(&pfd, 1, 1000);
|
||||||
|
if (status < 0)
|
||||||
|
return status;
|
||||||
|
else if (status == 0) {
|
||||||
|
seq++;
|
||||||
|
if (tries-- > 0)
|
||||||
|
goto try_again;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
status = nl_getmsg(sd, request, seq, &nlh, &done);
|
status = nl_getmsg(sd, request, seq, &nlh, &done);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
@@ -417,16 +435,17 @@ nl_getlist(int sd, int seq,
|
|||||||
static void
|
static void
|
||||||
free_nlmsglist(struct nlmsg_list *nlm0)
|
free_nlmsglist(struct nlmsg_list *nlm0)
|
||||||
{
|
{
|
||||||
struct nlmsg_list *nlm;
|
struct nlmsg_list *nlm, *nlm_next;
|
||||||
int saved_errno;
|
int saved_errno;
|
||||||
if (!nlm0)
|
if (!nlm0)
|
||||||
return;
|
return;
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
for (nlm=nlm0; nlm; nlm=nlm->nlm_next){
|
for (nlm=nlm0; nlm; nlm=nlm_next){
|
||||||
if (nlm->nlh)
|
if (nlm->nlh)
|
||||||
free(nlm->nlh);
|
free(nlm->nlh);
|
||||||
|
nlm_next=nlm->nlm_next;
|
||||||
|
free(nlm);
|
||||||
}
|
}
|
||||||
free(nlm0);
|
|
||||||
__set_errno(saved_errno);
|
__set_errno(saved_errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user