[systemd-devel] [PATCH 02/11] libsystemd-dhcp: Return proper error if bind fails

Lennart Poettering lennart at poettering.net
Fri Dec 20 13:23:13 PST 2013


On Fri, 20.12.13 16:35, Zbigniew Jędrzejewski-Szmek (zbyszek at in.waw.pl) wrote:

> On Fri, Dec 20, 2013 at 05:16:11PM +0200, Patrik Flykt wrote:
> > This also fixes a minor indentation damage.
> > ---
> >  src/libsystemd-dhcp/dhcp-network.c |    7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/src/libsystemd-dhcp/dhcp-network.c b/src/libsystemd-dhcp/dhcp-network.c
> > index 83a3084..3ff2d0b 100644
> > --- a/src/libsystemd-dhcp/dhcp-network.c
> > +++ b/src/libsystemd-dhcp/dhcp-network.c
> > @@ -31,8 +31,8 @@
> >  #include "dhcp-internal.h"
> >  
> >  int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
> > - {
> > -        int s;
> > +{
> > +        int s, err;
> >  
> >          s = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
> >                     htons(ETH_P_IP));
> > @@ -46,8 +46,9 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
> >          memset(link->ll.sll_addr, 0xff, ETH_ALEN);
> >  
> >          if (bind(s, &link->sa, sizeof(link->ll)) < 0) {
> > +                err = -errno;
> >                  close(s);
> > -                return -errno;
> > +                return err;
> 
> 'err' → 'r', for consistency with other code.

Actually, just use close_nointr_nofail() here, as that saves/restore
errno for you, then you don't need to store this in a temporary variable
at all...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list