Replace asprintf() by xasprintf().
This commit is contained in:
parent
3e55dc77f4
commit
73d77dd416
13 changed files with 52 additions and 51 deletions
|
@ -417,7 +417,7 @@ bool read_server_config()
|
||||||
|
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
asprintf(&fname, "%s/tinc.conf", confbase);
|
xasprintf(&fname, "%s/tinc.conf", confbase);
|
||||||
x = read_config_file(config_tree, fname);
|
x = read_config_file(config_tree, fname);
|
||||||
|
|
||||||
if(x == -1) { /* System error: complain */
|
if(x == -1) { /* System error: complain */
|
||||||
|
@ -469,7 +469,7 @@ FILE *ask_and_open(const char *filename, const char *what)
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
directory = get_current_dir_name();
|
directory = get_current_dir_name();
|
||||||
asprintf(&p, "%s/%s", directory, fn);
|
xasprintf(&p, "%s/%s", directory, fn);
|
||||||
free(fn);
|
free(fn);
|
||||||
free(directory);
|
free(directory);
|
||||||
fn = p;
|
fn = p;
|
||||||
|
|
|
@ -158,7 +158,7 @@ bool read_connection_config(connection_t *c)
|
||||||
|
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
||||||
x = read_config_file(c->config_tree, fname);
|
x = read_config_file(c->config_tree, fname);
|
||||||
free(fname);
|
free(fname);
|
||||||
|
|
||||||
|
|
17
src/graph.c
17
src/graph.c
|
@ -57,6 +57,7 @@
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "subnet.h"
|
#include "subnet.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
static bool graph_changed = true;
|
static bool graph_changed = true;
|
||||||
|
|
||||||
|
@ -269,18 +270,18 @@ void sssp_bfs(void)
|
||||||
n->mtuevent = NULL;
|
n->mtuevent = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
asprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
||||||
asprintf(&envp[1], "DEVICE=%s", device ? : "");
|
xasprintf(&envp[1], "DEVICE=%s", device ? : "");
|
||||||
asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
||||||
asprintf(&envp[3], "NODE=%s", n->name);
|
xasprintf(&envp[3], "NODE=%s", n->name);
|
||||||
sockaddr2str(&n->address, &address, &port);
|
sockaddr2str(&n->address, &address, &port);
|
||||||
asprintf(&envp[4], "REMOTEADDRESS=%s", address);
|
xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
|
||||||
asprintf(&envp[5], "REMOTEPORT=%s", port);
|
xasprintf(&envp[5], "REMOTEPORT=%s", port);
|
||||||
envp[6] = NULL;
|
envp[6] = NULL;
|
||||||
|
|
||||||
execute_script(n->status.reachable ? "host-up" : "host-down", envp);
|
execute_script(n->status.reachable ? "host-up" : "host-down", envp);
|
||||||
|
|
||||||
asprintf(&name,
|
xasprintf(&name,
|
||||||
n->status.reachable ? "hosts/%s-up" : "hosts/%s-down",
|
n->status.reachable ? "hosts/%s-up" : "hosts/%s-down",
|
||||||
n->name);
|
n->name);
|
||||||
execute_script(name, envp);
|
execute_script(name, envp);
|
||||||
|
@ -331,7 +332,7 @@ void dump_graph(void)
|
||||||
if(filename[0] == '|') {
|
if(filename[0] == '|') {
|
||||||
file = popen(filename + 1, "w");
|
file = popen(filename + 1, "w");
|
||||||
} else {
|
} else {
|
||||||
asprintf(&tmpname, "%s.new", filename);
|
xasprintf(&tmpname, "%s.new", filename);
|
||||||
file = fopen(tmpname, "w");
|
file = fopen(tmpname, "w");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -466,7 +466,7 @@ int main_loop(void)
|
||||||
for(node = connection_tree->head; node; node = node->next) {
|
for(node = connection_tree->head; node; node = node->next) {
|
||||||
c = node->data;
|
c = node->data;
|
||||||
|
|
||||||
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
||||||
if(stat(fname, &s) || s.st_mtime > last_config_check)
|
if(stat(fname, &s) || s.st_mtime > last_config_check)
|
||||||
terminate_connection(c, c->status.active);
|
terminate_connection(c, c->status.active);
|
||||||
free(fname);
|
free(fname);
|
||||||
|
|
|
@ -113,7 +113,7 @@ bool read_rsa_public_key(connection_t *c)
|
||||||
|
|
||||||
/* Else, check if a harnessed public key is in the config file */
|
/* Else, check if a harnessed public key is in the config file */
|
||||||
|
|
||||||
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
|
|
||||||
if(fp) {
|
if(fp) {
|
||||||
|
@ -128,7 +128,7 @@ bool read_rsa_public_key(connection_t *c)
|
||||||
|
|
||||||
/* Try again with PEM_read_RSA_PUBKEY. */
|
/* Try again with PEM_read_RSA_PUBKEY. */
|
||||||
|
|
||||||
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
|
|
||||||
if(fp) {
|
if(fp) {
|
||||||
|
@ -171,7 +171,7 @@ bool read_rsa_private_key(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
|
if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
|
||||||
asprintf(&fname, "%s/rsa_key.priv", confbase);
|
xasprintf(&fname, "%s/rsa_key.priv", confbase);
|
||||||
|
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
|
|
||||||
|
@ -228,8 +228,8 @@ bool setup_myself(void)
|
||||||
myself->connection = new_connection();
|
myself->connection = new_connection();
|
||||||
init_configuration(&myself->connection->config_tree);
|
init_configuration(&myself->connection->config_tree);
|
||||||
|
|
||||||
asprintf(&myself->hostname, _("MYSELF"));
|
xasprintf(&myself->hostname, _("MYSELF"));
|
||||||
asprintf(&myself->connection->hostname, _("MYSELF"));
|
xasprintf(&myself->connection->hostname, _("MYSELF"));
|
||||||
|
|
||||||
myself->connection->options = 0;
|
myself->connection->options = 0;
|
||||||
myself->connection->protocol_version = PROT_CURRENT;
|
myself->connection->protocol_version = PROT_CURRENT;
|
||||||
|
@ -257,7 +257,7 @@ bool setup_myself(void)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport))
|
if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport))
|
||||||
asprintf(&myport, "655");
|
xasprintf(&myport, "655");
|
||||||
|
|
||||||
/* Read in all the subnets specified in the host configuration file */
|
/* Read in all the subnets specified in the host configuration file */
|
||||||
|
|
||||||
|
@ -433,10 +433,10 @@ bool setup_myself(void)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Run tinc-up script to further initialize the tap interface */
|
/* Run tinc-up script to further initialize the tap interface */
|
||||||
asprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
||||||
asprintf(&envp[1], "DEVICE=%s", device ? : "");
|
xasprintf(&envp[1], "DEVICE=%s", device ? : "");
|
||||||
asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
||||||
asprintf(&envp[3], "NAME=%s", myself->name);
|
xasprintf(&envp[3], "NAME=%s", myself->name);
|
||||||
envp[4] = NULL;
|
envp[4] = NULL;
|
||||||
|
|
||||||
execute_script("tinc-up", envp);
|
execute_script("tinc-up", envp);
|
||||||
|
@ -571,10 +571,10 @@ void close_network_connections(void)
|
||||||
close(listen_socket[i].udp);
|
close(listen_socket[i].udp);
|
||||||
}
|
}
|
||||||
|
|
||||||
asprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
||||||
asprintf(&envp[1], "DEVICE=%s", device ? : "");
|
xasprintf(&envp[1], "DEVICE=%s", device ? : "");
|
||||||
asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
||||||
asprintf(&envp[3], "NAME=%s", myself->name);
|
xasprintf(&envp[3], "NAME=%s", myself->name);
|
||||||
envp[4] = NULL;
|
envp[4] = NULL;
|
||||||
|
|
||||||
exit_requests();
|
exit_requests();
|
||||||
|
|
|
@ -367,7 +367,7 @@ begin:
|
||||||
get_config_string(c->outgoing->cfg, &address);
|
get_config_string(c->outgoing->cfg, &address);
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(c->config_tree, "Port"), &port))
|
if(!get_config_string(lookup_config(c->config_tree, "Port"), &port))
|
||||||
asprintf(&port, "655");
|
xasprintf(&port, "655");
|
||||||
|
|
||||||
c->outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
|
c->outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
|
||||||
free(address);
|
free(address);
|
||||||
|
|
|
@ -128,7 +128,7 @@ char *sockaddr2hostname(const sockaddr_t *sa)
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
if(sa->sa.sa_family == AF_UNKNOWN) {
|
if(sa->sa.sa_family == AF_UNKNOWN) {
|
||||||
asprintf(&str, _("%s port %s"), sa->unknown.address, sa->unknown.port);
|
xasprintf(&str, _("%s port %s"), sa->unknown.address, sa->unknown.port);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ char *sockaddr2hostname(const sockaddr_t *sa)
|
||||||
gai_strerror(err));
|
gai_strerror(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
asprintf(&str, _("%s port %s"), address, port);
|
xasprintf(&str, _("%s port %s"), address, port);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -371,9 +371,9 @@ bool execute_script(const char *name, char **envp)
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
#ifndef HAVE_MINGW
|
#ifndef HAVE_MINGW
|
||||||
len = asprintf(&scriptname, "\"%s/%s\"", confbase, name);
|
len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name);
|
||||||
#else
|
#else
|
||||||
len = asprintf(&scriptname, "\"%s/%s.bat\"", confbase, name);
|
len = xasprintf(&scriptname, "\"%s/%s.bat\"", confbase, name);
|
||||||
#endif
|
#endif
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -75,7 +75,7 @@ bool send_request(connection_t *c, const char *format, ...)
|
||||||
|
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
/* Use vsnprintf instead of vasprintf: faster, no memory
|
/* Use vsnprintf instead of vxasprintf: faster, no memory
|
||||||
fragmentation, cleanup is automatic, and there is a limit on the
|
fragmentation, cleanup is automatic, and there is a limit on the
|
||||||
input buffer anyway */
|
input buffer anyway */
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ bool setup_device(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
||||||
asprintf(&iface, "tun%d", ppa);
|
xasprintf(&iface, "tun%d", ppa);
|
||||||
|
|
||||||
device_info = _("Solaris tun device");
|
device_info = _("Solaris tun device");
|
||||||
|
|
||||||
|
|
12
src/subnet.c
12
src/subnet.c
|
@ -480,15 +480,15 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
|
||||||
char netstr[MAXNETSTR + 7] = "SUBNET=";
|
char netstr[MAXNETSTR + 7] = "SUBNET=";
|
||||||
char *name, *address, *port;
|
char *name, *address, *port;
|
||||||
|
|
||||||
asprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
|
||||||
asprintf(&envp[1], "DEVICE=%s", device ? : "");
|
xasprintf(&envp[1], "DEVICE=%s", device ? : "");
|
||||||
asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
|
||||||
asprintf(&envp[3], "NODE=%s", owner->name);
|
xasprintf(&envp[3], "NODE=%s", owner->name);
|
||||||
|
|
||||||
if(owner != myself) {
|
if(owner != myself) {
|
||||||
sockaddr2str(&owner->address, &address, &port);
|
sockaddr2str(&owner->address, &address, &port);
|
||||||
asprintf(&envp[4], "REMOTEADDRESS=%s", address);
|
xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
|
||||||
asprintf(&envp[5], "REMOTEPORT=%s", port);
|
xasprintf(&envp[5], "REMOTEPORT=%s", port);
|
||||||
envp[6] = netstr;
|
envp[6] = netstr;
|
||||||
envp[7] = NULL;
|
envp[7] = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
|
22
src/tincd.c
22
src/tincd.c
|
@ -337,7 +337,7 @@ static bool keygen(int bits)
|
||||||
} else
|
} else
|
||||||
fprintf(stderr, _("Done.\n"));
|
fprintf(stderr, _("Done.\n"));
|
||||||
|
|
||||||
asprintf(&filename, "%s/rsa_key.priv", confbase);
|
xasprintf(&filename, "%s/rsa_key.priv", confbase);
|
||||||
f = ask_and_open(filename, _("private RSA key"));
|
f = ask_and_open(filename, _("private RSA key"));
|
||||||
|
|
||||||
if(!f)
|
if(!f)
|
||||||
|
@ -356,9 +356,9 @@ static bool keygen(int bits)
|
||||||
free(filename);
|
free(filename);
|
||||||
|
|
||||||
if(name)
|
if(name)
|
||||||
asprintf(&filename, "%s/hosts/%s", confbase, name);
|
xasprintf(&filename, "%s/hosts/%s", confbase, name);
|
||||||
else
|
else
|
||||||
asprintf(&filename, "%s/rsa_key.pub", confbase);
|
xasprintf(&filename, "%s/rsa_key.pub", confbase);
|
||||||
|
|
||||||
f = ask_and_open(filename, _("public RSA key"));
|
f = ask_and_open(filename, _("public RSA key"));
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ static void make_names(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(netname)
|
if(netname)
|
||||||
asprintf(&identname, "tinc.%s", netname);
|
xasprintf(&identname, "tinc.%s", netname);
|
||||||
else
|
else
|
||||||
identname = xstrdup("tinc");
|
identname = xstrdup("tinc");
|
||||||
|
|
||||||
|
@ -397,12 +397,12 @@ static void make_names(void)
|
||||||
if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) {
|
if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) {
|
||||||
if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) {
|
if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) {
|
||||||
if(!logfilename)
|
if(!logfilename)
|
||||||
asprintf(&logfilename, "%s/log/%s.log", identname);
|
xasprintf(&logfilename, "%s/log/%s.log", identname);
|
||||||
if(!confbase) {
|
if(!confbase) {
|
||||||
if(netname)
|
if(netname)
|
||||||
asprintf(&confbase, "%s/%s", installdir, netname);
|
xasprintf(&confbase, "%s/%s", installdir, netname);
|
||||||
else
|
else
|
||||||
asprintf(&confbase, "%s", installdir);
|
xasprintf(&confbase, "%s", installdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
|
@ -412,19 +412,19 @@ static void make_names(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!pidfilename)
|
if(!pidfilename)
|
||||||
asprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname);
|
xasprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname);
|
||||||
|
|
||||||
if(!logfilename)
|
if(!logfilename)
|
||||||
asprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
|
xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
|
||||||
|
|
||||||
if(netname) {
|
if(netname) {
|
||||||
if(!confbase)
|
if(!confbase)
|
||||||
asprintf(&confbase, CONFDIR "/tinc/%s", netname);
|
xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
|
||||||
else
|
else
|
||||||
logger(LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
|
logger(LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
|
||||||
} else {
|
} else {
|
||||||
if(!confbase)
|
if(!confbase)
|
||||||
asprintf(&confbase, CONFDIR "/tinc");
|
xasprintf(&confbase, CONFDIR "/tinc");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ bool setup_device(void)
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||||
asprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname);
|
xasprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname);
|
||||||
|
|
||||||
get_config_string(lookup_config(config_tree, "Interface"), &iface);
|
get_config_string(lookup_config(config_tree, "Interface"), &iface);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue