sd-network.c revision 6bedfcbb2970e06a4d3280c8fb62083d252ede73
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
Copyright 2014 Tom Gundersen
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 <errno.h>
#include <poll.h>
#include <string.h>
#include "sd-network.h"
#include "fileio.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
#include "fd-util.h"
#include "parse-util.h"
_cleanup_free_ char *s = NULL;
int r;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*state = s;
s = NULL;
return 0;
}
_cleanup_strv_free_ char **a = NULL;
_cleanup_free_ char *s = NULL;
int r;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s)) {
return 0;
}
a = strv_split(s, " ");
if (!a)
return -ENOMEM;
strv_uniq(a);
r = strv_length(a);
*ret = a;
a = NULL;
return r;
}
}
}
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*state = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*filename = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*state = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*llmnr = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
r = read_full_file(p, &s, &size);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (size <= 0)
return -ENODATA;
*lldp = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*ret = s;
s = NULL;
return 0;
}
_cleanup_strv_free_ char **a = NULL;
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s)) {
return 0;
}
a = strv_split(s, " ");
if (!a)
return -ENOMEM;
strv_uniq(a);
r = strv_length(a);
*ret = a;
a = NULL;
return r;
}
}
}
}
}
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
return parse_boolean(s);
}
static inline int MONITOR_TO_FD(sd_network_monitor *m) {
return (int) (unsigned long) m - 1;
}
}
static int monitor_add_inotify_watch(int fd) {
int k;
if (k >= 0)
return 0;
return -errno;
if (k >= 0)
return 0;
return -errno;
if (k < 0)
return -errno;
return 0;
}
int k;
bool good = false;
assert_return(m, -EINVAL);
if (fd < 0)
return -errno;
k = monitor_add_inotify_watch(fd);
if (k < 0)
return k;
good = true;
}
if (!good)
return -EINVAL;
*m = FD_TO_MONITOR(fd);
fd = -1;
return 0;
}
int fd;
if (m) {
fd = MONITOR_TO_FD(m);
}
return NULL;
}
union inotify_event_buffer buffer;
struct inotify_event *e;
ssize_t l;
int fd, k;
assert_return(m, -EINVAL);
fd = MONITOR_TO_FD(m);
if (l < 0) {
return 0;
return -errno;
}
FOREACH_INOTIFY_EVENT(e, buffer, l) {
k = monitor_add_inotify_watch(fd);
if (k < 0)
return k;
if (k < 0)
return -errno;
}
}
return 0;
}
assert_return(m, -EINVAL);
return MONITOR_TO_FD(m);
}
assert_return(m, -EINVAL);
/* For now we will only return POLLIN here, since we don't
* need anything else ever for inotify. However, let's have
* this API to keep our options open should we later on need
* it. */
return POLLIN;
}
assert_return(m, -EINVAL);
/* For now we will only return (uint64_t) -1, since we don't
* need any timeout. However, let's have this API to keep our
* options open should we later on need it. */
return 0;
}