[systemd-devel] [PATCH] networkd-wait-online: use automatic cleanup

Tom Gundersen teg at jklm.no
Sat Mar 1 14:19:06 PST 2014


On Sat, Mar 1, 2014 at 10:52 PM, Thomas H.P. Andersen <phomes at gmail.com> wrote:
> From: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
>
> ---
> Only compile tested. I just wanted to get rid of the warnings about
> use of the uninitialized variables.

Applied. Thanks!

-t

>  Makefile.am                        |  3 ++-
>  src/network/network-util.h         | 28 ++++++++++++++++++++++++++++
>  src/network/networkd-wait-online.c | 12 +++++-------
>  3 files changed, 35 insertions(+), 8 deletions(-)
>  create mode 100644 src/network/network-util.h
>
> diff --git a/Makefile.am b/Makefile.am
> index c4a975d..1ad2756 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -2417,7 +2417,8 @@ libsystemd_network_la_SOURCES = \
>         src/libsystemd-network/dhcp-internal.h \
>         src/libsystemd-network/dhcp-protocol.h \
>         src/libsystemd-network/dhcp-lease-internal.h \
> -       src/libsystemd-network/sd-dhcp-lease.c
> +       src/libsystemd-network/sd-dhcp-lease.c \
> +       src/libsystemd-network/network-util.h
>
>  libsystemd_network_la_LIBADD = \
>         libsystemd-internal.la \
> diff --git a/src/network/network-util.h b/src/network/network-util.h
> new file mode 100644
> index 0000000..9979e6d
> --- /dev/null
> +++ b/src/network/network-util.h
> @@ -0,0 +1,28 @@
> +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
> +
> +#pragma once
> +
> +/***
> +  This file is part of systemd.
> +
> +  Copyright 2014 Thomas Hindø Paabøl Andersen
> +
> +  systemd is free software; you can redistribute it and/or modify it
> +  under the terms of the GNU Lesser General Public License as published by
> +  the Free Software Foundation; either version 2.1 of the License, or
> +  (at your option) any later version.
> +
> +  systemd is distributed in the hope that it will be useful, but
> +  WITHOUT ANY WARRANTY; without even the implied warranty of
> +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +  Lesser General Public License for more details.
> +
> +  You should have received a copy of the GNU Lesser General Public License
> +  along with systemd; If not, see <http://www.gnu.org/licenses/>.
> +***/
> +
> +#include "util.h"
> +
> +DEFINE_TRIVIAL_CLEANUP_FUNC(sd_network_monitor*, sd_network_monitor_unref);
> +
> +#define _cleanup_network_monitor_unref_ _cleanup_(sd_network_monitor_unrefp)
> diff --git a/src/network/networkd-wait-online.c b/src/network/networkd-wait-online.c
> index 51c6bbd..50b753b 100644
> --- a/src/network/networkd-wait-online.c
> +++ b/src/network/networkd-wait-online.c
> @@ -20,8 +20,10 @@
>  ***/
>
>  #include "sd-event.h"
> +#include "event-util.h"
>  #include "sd-daemon.h"
>  #include "sd-network.h"
> +#include "network-util.h"
>
>  #include "util.h"
>
> @@ -62,9 +64,9 @@ static int event_handler(sd_event_source *s, int fd, uint32_t revents,
>  }
>
>  int main(int argc, char *argv[]) {
> -        sd_event *event;
> -        sd_event_source *event_source;
> -        sd_network_monitor *monitor;
> +        _cleanup_event_unref_ sd_event *event = NULL;
> +        _cleanup_event_source_unref_ sd_event_source *event_source = NULL;
> +        _cleanup_network_monitor_unref_ sd_network_monitor *monitor = NULL;
>          int r, fd, events;
>
>          log_set_target(LOG_TARGET_AUTO);
> @@ -129,9 +131,5 @@ out:
>          sd_notify(false,
>                    "STATUS=All interfaces configured...");
>
> -        sd_event_source_unref(event_source);
> -        sd_event_unref(event);
> -        sd_network_monitor_unref(monitor);
> -
>          return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
>  }
> --
> 1.8.5.3
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list