sd-network.c revision 81d98a39eb4cca743beba27f4ae21a0e199df785
/*-*- 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 <unistd.h>
#include <string.h>
#include <errno.h>
#include "util.h"
#include "macro.h"
#include "strv.h"
#include "fileio.h"
#include "sd-network.h"
#include "network-internal.h"
#include "dhcp-lease-internal.h"
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
else if (r < 0)
return r;
else if (!s)
return -EIO;
}
unsigned flags;
int r;
if (r < 0)
return 0;
return flags & IFF_LOOPBACK;
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
else if (r < 0)
return r;
else if (!s)
return -EIO;
if (streq(s, "unmanaged"))
return -EUNATCH;
else if (streq(s, "initializing"))
return -EBUSY;
*state = s;
s = NULL;
return 0;
}
_cleanup_free_ char *s = NULL;
int r;
&s, NULL);
if (r == -ENOENT)
return -ENODATA;
else if (r < 0)
return r;
else if (!s)
return -EIO;
*state = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
if (r == -ENOENT)
return -ENODATA;
else if (r < 0)
return r;
else if (!s)
return -EIO;
*state = s;
s = NULL;
return 0;
}
int r;
return -ENOMEM;
if (r < 0)
return r;
else if (!s)
return -EIO;
r = dhcp_lease_load(s, &lease);
if (r < 0)
return r;
return 0;
}
int r;
return -ENOMEM;
if (r < 0)
return r;
else if (!s)
return -EIO;
}
int r;
return -ENOMEM;
if (r < 0)
return r;
else if (!s)
return -EIO;
}
int r;
return -ENOMEM;
if (r < 0)
return r;
else if (!s)
return -EIO;
return parse_boolean(s);
}
int r = 0;
unsigned n = 0;
if (!d)
return -errno;
for (;;) {
int k;
unsigned index;
errno = 0;
return -errno;
if (!de)
break;
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
continue;
if (k < 0)
continue;
if (indices) {
if ((unsigned) r >= n) {
unsigned *t;
t = realloc(l, sizeof(unsigned) * n);
if (!t)
return -ENOMEM;
l = t;
}
assert((unsigned) r < n);
l[r++] = index;
} else
r++;
}
if (indices) {
*indices = l;
l = NULL;
}
return r;
}
static inline int MONITOR_TO_FD(sd_network_monitor *m) {
return (int) (unsigned long) m - 1;
}
}
int fd, k;
bool good = false;
assert_return(m, -EINVAL);
if (fd < 0)
return -errno;
if (k < 0) {
safe_close(fd);
return -errno;
}
good = true;
}
if (k < 0) {
safe_close(fd);
return -errno;
}
good = true;
}
if (!good) {
return -EINVAL;
}
*m = FD_TO_MONITOR(fd);
return 0;
}
int fd;
assert_return(m, NULL);
fd = MONITOR_TO_FD(m);
return NULL;
}
assert_return(m, -EINVAL);
return flush_fd(MONITOR_TO_FD(m));
}
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;
}