network: Use g_strdup_printf() instead of virAsprintf()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
c2d0db54df
commit
52a6b45e18
@ -368,8 +368,7 @@ networkDnsmasqLeaseFileNameDefault(virNetworkDriverStatePtr driver,
|
|||||||
{
|
{
|
||||||
char *leasefile;
|
char *leasefile;
|
||||||
|
|
||||||
ignore_value(virAsprintf(&leasefile, "%s/%s.leases",
|
leasefile = g_strdup_printf("%s/%s.leases", driver->dnsmasqStateDir, netname);
|
||||||
driver->dnsmasqStateDir, netname));
|
|
||||||
return leasefile;
|
return leasefile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,8 +379,7 @@ networkDnsmasqLeaseFileNameCustom(virNetworkDriverStatePtr driver,
|
|||||||
{
|
{
|
||||||
char *leasefile;
|
char *leasefile;
|
||||||
|
|
||||||
ignore_value(virAsprintf(&leasefile, "%s/%s.status",
|
leasefile = g_strdup_printf("%s/%s.status", driver->dnsmasqStateDir, bridge);
|
||||||
driver->dnsmasqStateDir, bridge));
|
|
||||||
return leasefile;
|
return leasefile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,8 +390,7 @@ networkDnsmasqConfigFileName(virNetworkDriverStatePtr driver,
|
|||||||
{
|
{
|
||||||
char *conffile;
|
char *conffile;
|
||||||
|
|
||||||
ignore_value(virAsprintf(&conffile, "%s/%s.conf",
|
conffile = g_strdup_printf("%s/%s.conf", driver->dnsmasqStateDir, netname);
|
||||||
driver->dnsmasqStateDir, netname));
|
|
||||||
return conffile;
|
return conffile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +401,7 @@ networkRadvdPidfileBasename(const char *netname)
|
|||||||
/* this is simple but we want to be sure it's consistently done */
|
/* this is simple but we want to be sure it's consistently done */
|
||||||
char *pidfilebase;
|
char *pidfilebase;
|
||||||
|
|
||||||
ignore_value(virAsprintf(&pidfilebase, "%s-radvd", netname));
|
pidfilebase = g_strdup_printf("%s-radvd", netname);
|
||||||
return pidfilebase;
|
return pidfilebase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,8 +412,7 @@ networkRadvdConfigFileName(virNetworkDriverStatePtr driver,
|
|||||||
{
|
{
|
||||||
char *configfile;
|
char *configfile;
|
||||||
|
|
||||||
ignore_value(virAsprintf(&configfile, "%s/%s-radvd.conf",
|
configfile = g_strdup_printf("%s/%s-radvd.conf", driver->radvdStateDir, netname);
|
||||||
driver->radvdStateDir, netname));
|
|
||||||
return configfile;
|
return configfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,13 +508,13 @@ networkBridgeDummyNicName(const char *brname)
|
|||||||
* a possible numeric ending (eg virbr0, virbr1, etc), we grab
|
* a possible numeric ending (eg virbr0, virbr1, etc), we grab
|
||||||
* the first 8 and last 3 characters of the string.
|
* the first 8 and last 3 characters of the string.
|
||||||
*/
|
*/
|
||||||
ignore_value(virAsprintf(&nicname, "%.*s%s%s",
|
nicname = g_strdup_printf("%.*s%s%s",
|
||||||
/* space for last 3 chars + "-nic" + NULL */
|
/* space for last 3 chars + "-nic" + NULL */
|
||||||
(int)(IFNAMSIZ - (3 + sizeof(dummyNicSuffix))),
|
(int)(IFNAMSIZ - (3 + sizeof(dummyNicSuffix))),
|
||||||
brname, brname + strlen(brname) - 3,
|
brname, brname + strlen(brname) - 3,
|
||||||
dummyNicSuffix));
|
dummyNicSuffix);
|
||||||
} else {
|
} else {
|
||||||
ignore_value(virAsprintf(&nicname, "%s%s", brname, dummyNicSuffix));
|
nicname = g_strdup_printf("%s%s", brname, dummyNicSuffix);
|
||||||
}
|
}
|
||||||
return nicname;
|
return nicname;
|
||||||
}
|
}
|
||||||
@ -748,20 +744,12 @@ networkStateInitialize(bool privileged,
|
|||||||
if (!(configdir && rundir))
|
if (!(configdir && rundir))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((virAsprintf(&network_driver->networkConfigDir,
|
network_driver->networkConfigDir = g_strdup_printf("%s/qemu/networks", configdir);
|
||||||
"%s/qemu/networks", configdir) < 0) ||
|
network_driver->networkAutostartDir = g_strdup_printf("%s/qemu/networks/autostart", configdir);
|
||||||
(virAsprintf(&network_driver->networkAutostartDir,
|
network_driver->stateDir = g_strdup_printf("%s/network/lib", rundir);
|
||||||
"%s/qemu/networks/autostart", configdir) < 0) ||
|
network_driver->pidDir = g_strdup_printf("%s/network/run", rundir);
|
||||||
(virAsprintf(&network_driver->stateDir,
|
network_driver->dnsmasqStateDir = g_strdup_printf("%s/dnsmasq/lib", rundir);
|
||||||
"%s/network/lib", rundir) < 0) ||
|
network_driver->radvdStateDir = g_strdup_printf("%s/radvd/lib", rundir);
|
||||||
(virAsprintf(&network_driver->pidDir,
|
|
||||||
"%s/network/run", rundir) < 0) ||
|
|
||||||
(virAsprintf(&network_driver->dnsmasqStateDir,
|
|
||||||
"%s/dnsmasq/lib", rundir) < 0) ||
|
|
||||||
(virAsprintf(&network_driver->radvdStateDir,
|
|
||||||
"%s/radvd/lib", rundir) < 0)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(network_driver->stateDir) < 0) {
|
if (virFileMakePath(network_driver->stateDir) < 0) {
|
||||||
@ -2294,9 +2282,8 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj)
|
|||||||
* network. But also unset it if there *are* ipv6 addresses, as we
|
* network. But also unset it if there *are* ipv6 addresses, as we
|
||||||
* can't be sure of its default value.
|
* can't be sure of its default value.
|
||||||
*/
|
*/
|
||||||
if (virAsprintf(&field, SYSCTL_PATH "/net/ipv6/conf/%s/disable_ipv6",
|
field = g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/disable_ipv6",
|
||||||
def->bridge) < 0)
|
def->bridge);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (access(field, W_OK) < 0 && errno == ENOENT) {
|
if (access(field, W_OK) < 0 && errno == ENOENT) {
|
||||||
if (!enableIPv6)
|
if (!enableIPv6)
|
||||||
@ -2321,9 +2308,8 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj)
|
|||||||
/* Prevent guests from hijacking the host network by sending out
|
/* Prevent guests from hijacking the host network by sending out
|
||||||
* their own router advertisements.
|
* their own router advertisements.
|
||||||
*/
|
*/
|
||||||
if (virAsprintf(&field, SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra",
|
field = g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra",
|
||||||
def->bridge) < 0)
|
def->bridge);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virFileWriteStr(field, "0", 0) < 0) {
|
if (virFileWriteStr(field, "0", 0) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -2335,9 +2321,7 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj)
|
|||||||
/* All interfaces used as a gateway (which is what this is, by
|
/* All interfaces used as a gateway (which is what this is, by
|
||||||
* definition), must always have autoconf=0.
|
* definition), must always have autoconf=0.
|
||||||
*/
|
*/
|
||||||
if (virAsprintf(&field, SYSCTL_PATH "/net/ipv6/conf/%s/autoconf",
|
field = g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", def->bridge);
|
||||||
def->bridge) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virFileWriteStr(field, "0", 0) < 0) {
|
if (virFileWriteStr(field, "0", 0) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -3306,8 +3290,7 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets,
|
|||||||
templ = def->bridge;
|
templ = def->bridge;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (virAsprintf(&newname, templ, id) < 0)
|
newname = g_strdup_printf(templ, id);
|
||||||
goto cleanup;
|
|
||||||
/* check if this name is used in another libvirt network or
|
/* check if this name is used in another libvirt network or
|
||||||
* there is an existing device with that name. ignore errors
|
* there is an existing device with that name. ignore errors
|
||||||
* from virNetDevExists(), just in case it isn't implemented
|
* from virNetDevExists(), just in case it isn't implemented
|
||||||
|
@ -153,10 +153,8 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
server_duid = g_strdup(getenv("DNSMASQ_SERVER_DUID"));
|
server_duid = g_strdup(getenv("DNSMASQ_SERVER_DUID"));
|
||||||
|
|
||||||
if (virAsprintf(&custom_lease_file,
|
custom_lease_file = g_strdup_printf(LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status",
|
||||||
LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status",
|
interface);
|
||||||
interface) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
|
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user