lk.l_len = 0;
if (fcntl(fd, F_SETLKW, &lk) < 0) {
perror("fcntl lock");
- exit(1);
+ return -1;
}
return fd;
bool nic_exists(char *nic)
{
- char path[200];
+ char path[MAXPATHLEN];
int ret;
struct stat sb;
#if ISTEST
- ret = snprintf(path, 200, "/tmp/lxcnettest/%s", nic);
+ ret = snprintf(path, MAXPATHLEN, "/tmp/lxcnettest/%s", nic);
#else
- ret = snprintf(path, 200, "/sys/class/net/%s", nic);
+ ret = snprintf(path, MAXPATHLEN, "/sys/class/net/%s", nic);
#endif
- if (ret < 0 || ret >= 200)
- exit(1);
+ if (ret < 0 || ret >= MAXPATHLEN) // should never happen!
+ return true;
ret = stat(path, &sb);
if (ret != 0)
return false;
err = snprintf(*n2, IFNAMSIZ, "%sp", n1);
if (err < 0 || err >= IFNAMSIZ) {
fprintf(stderr, "nic name too long\n");
- exit(1);
+ return -1;
}
err = lxc_veth_create(n1, *n2);
if (err) {
fprintf(stderr, "failed to create %s-%s : %s\n", n1, *n2,
strerror(-err));
- exit(1);
+ return -1;
}
/* changing the high byte of the mac address to 0xfe, the bridge interface
close(fd);
return true;
#else
- // not yet implemented
char *veth1buf, *veth2buf;
veth1buf = alloca(IFNAMSIZ);
veth2buf = alloca(IFNAMSIZ);
ret = snprintf(veth1buf, IFNAMSIZ, "%s", nic);
if (ret < 0 || ret >= IFNAMSIZ) {
fprintf(stderr, "host nic name too long\n");
- exit(1);
+ return false;
}
/* create the nics */
out_del:
lxc_netdev_delete_by_name(veth1buf);
- exit(1);
+ return false;
#endif
}