#include "file_utils.h"
#include "log.h"
#include "macro.h"
+#include "memory_utils.h"
#include "network.h"
#include "nl.h"
#include "raw_syscalls.h"
#define PHYSNAME "/sys/class/net/%s/phy80211/name"
static char *is_wlan(const char *ifname)
{
+ __do_free char *path;
int i, ret;
long physlen;
size_t len;
- char *path;
FILE *f;
char *physname = NULL;
len = strlen(ifname) + strlen(PHYSNAME) - 1;
- path = alloca(len + 1);
+ path = must_realloc(NULL, len + 1);
ret = snprintf(path, len, PHYSNAME, ifname);
if (ret < 0 || (size_t)ret >= len)
goto bad;
}
/* Generate random names until we find one that doesn't exist. */
- while (true) {
+ for (;;) {
name[0] = '\0';
(void)strlcpy(name, template, IFNAMSIZ);
for (i = 0; i < strlen(name); i++) {
if (name[i] == 'X') {
#ifdef HAVE_RAND_R
- name[i] = padchar[rand_r(&seed) % (strlen(padchar) - 1)];
+ name[i] = padchar[rand_r(&seed) % strlen(padchar)];
#else
- name[i] = padchar[rand() % (strlen(padchar) - 1)];
+ name[i] = padchar[rand() % strlen(padchar)];
#endif
}
}
}
if (child == 0) {
- int ret;
- size_t retlen;
char pidstr[INTTYPE_TO_STRLEN(pid_t)];
close(pipefd[0]);
if (child == 0) {
char *hostveth;
- int ret;
close(pipefd[0]);
netdev->link);
clear_ifindices:
- /* We need to clear any ifindeces we recorded so liblxc won't
+ /* We need to clear any ifindices we recorded so liblxc won't
* have cached stale data which would cause it to fail on reboot
* we're we don't re-read the on-disk config file.
*/
netdev->name[0] != '\0' ? netdev->name : "(null)",
netdev->ifindex);
} else if (ret < 0) {
- errno = -ret;
- SYSWARN("Failed to remove interface \"%s\" with index %d",
- netdev->name[0] != '\0' ? netdev->name : "(null)",
- netdev->ifindex);
+ WARN("Failed to remove interface \"%s\" with index %d",
+ netdev->name[0] != '\0' ? netdev->name : "(null)",
+ netdev->ifindex);
goto clear_ifindices;
}
INFO("Removed interface \"%s\" with index %d",
ret = lxc_netdev_delete_by_name(hostveth);
if (ret < 0) {
- errno = -ret;
- SYSWARN("Failed to remove interface \"%s\" from \"%s\"",
- hostveth, netdev->link);
+ WARN("Failed to remove interface \"%s\" from \"%s\"",
+ hostveth, netdev->link);
goto clear_ifindices;
}
INFO("Removed interface \"%s\" from \"%s\"", hostveth, netdev->link);
hostveth, netdev->link);
clear_ifindices:
- /* We need to clear any ifindeces we recorded so liblxc won't
+ /* We need to clear any ifindices we recorded so liblxc won't
* have cached stale data which would cause it to fail on reboot
* we're we don't re-read the on-disk config file.
*/
/* set the network device up */
if (netdev->flags & IFF_UP) {
- int err;
-
err = lxc_netdev_up(current_ifname);
if (err) {
errno = -err;
return -1;
}
- TRACE("Sent network device names and ifindeces to parent");
+ TRACE("Sent network device names and ifindices to parent");
return 0;
}