]> git.meshlink.io Git - meshlink/commitdiff
Replace asprintf() by xasprintf().
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 8 Sep 2009 16:18:36 +0000 (18:18 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 8 Sep 2009 16:18:36 +0000 (18:18 +0200)
13 files changed:
src/conf.c
src/connection.c
src/graph.c
src/net.c
src/net_setup.c
src/net_socket.c
src/netutl.c
src/process.c
src/protocol.c
src/solaris/device.c
src/subnet.c
src/tincd.c
src/uml_socket/device.c

index ce776804909d2b1afec88dfe26a45954f0ee7baa..d8a8d83214304e079d78f4324bc6685e153e1186 100644 (file)
@@ -417,7 +417,7 @@ bool read_server_config()
 
        cp();
 
-       asprintf(&fname, "%s/tinc.conf", confbase);
+       xasprintf(&fname, "%s/tinc.conf", confbase);
        x = read_config_file(config_tree, fname);
 
        if(x == -1) {                           /* System error: complain */
@@ -469,7 +469,7 @@ FILE *ask_and_open(const char *filename, const char *what)
                char *p;
 
                directory = get_current_dir_name();
-               asprintf(&p, "%s/%s", directory, fn);
+               xasprintf(&p, "%s/%s", directory, fn);
                free(fn);
                free(directory);
                fn = p;
index 9fd4002ba52a557453c1310b75bdc35fbf5c3a84..a2a188a60e327db520bdc6fec141fefca1ff8c97 100644 (file)
@@ -158,7 +158,7 @@ bool read_connection_config(connection_t *c)
 
        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);
        free(fname);
 
index 8564358566fa7250f47874352c0a4c0d9287542b..a267f052a196df31c1d797ca1e5cf0dc965d11d9 100644 (file)
@@ -57,6 +57,7 @@
 #include "process.h"
 #include "subnet.h"
 #include "utils.h"
+#include "xalloc.h"
 
 static bool graph_changed = true;
 
@@ -269,18 +270,18 @@ void sssp_bfs(void)
                                n->mtuevent = NULL;
                        }
 
-                       asprintf(&envp[0], "NETNAME=%s", netname ? : "");
-                       asprintf(&envp[1], "DEVICE=%s", device ? : "");
-                       asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-                       asprintf(&envp[3], "NODE=%s", n->name);
+                       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
+                       xasprintf(&envp[1], "DEVICE=%s", device ? : "");
+                       xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
+                       xasprintf(&envp[3], "NODE=%s", n->name);
                        sockaddr2str(&n->address, &address, &port);
-                       asprintf(&envp[4], "REMOTEADDRESS=%s", address);
-                       asprintf(&envp[5], "REMOTEPORT=%s", port);
+                       xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
+                       xasprintf(&envp[5], "REMOTEPORT=%s", port);
                        envp[6] = NULL;
 
                        execute_script(n->status.reachable ? "host-up" : "host-down", envp);
 
-                       asprintf(&name,
+                       xasprintf(&name,
                                         n->status.reachable ? "hosts/%s-up" : "hosts/%s-down",
                                         n->name);
                        execute_script(name, envp);
@@ -331,7 +332,7 @@ void dump_graph(void)
        if(filename[0] == '|') {
                file = popen(filename + 1, "w");
        } else {
-               asprintf(&tmpname, "%s.new", filename);
+               xasprintf(&tmpname, "%s.new", filename);
                file = fopen(tmpname, "w");
        }
 
index 7f17252d3d52ea432f4ed4fe77fce8b12d9d1c48..4a2af954c53e871bebae6dd33113017716809708 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -466,7 +466,7 @@ int main_loop(void)
                        for(node = connection_tree->head; node; node = node->next) {
                                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)
                                        terminate_connection(c, c->status.active);
                                free(fname);
index 94e25b624035a2daba320ee8a392db7a568279b9..4eef68eda8f3d3fc37d24819205389e70702a509 100644 (file)
@@ -113,7 +113,7 @@ bool read_rsa_public_key(connection_t *c)
 
        /* 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");
 
        if(fp) {
@@ -128,7 +128,7 @@ bool read_rsa_public_key(connection_t *c)
 
        /* 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");
 
        if(fp) {
@@ -171,7 +171,7 @@ bool read_rsa_private_key(void)
        }
 
        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");
 
@@ -228,8 +228,8 @@ bool setup_myself(void)
        myself->connection = new_connection();
        init_configuration(&myself->connection->config_tree);
 
-       asprintf(&myself->hostname, _("MYSELF"));
-       asprintf(&myself->connection->hostname, _("MYSELF"));
+       xasprintf(&myself->hostname, _("MYSELF"));
+       xasprintf(&myself->connection->hostname, _("MYSELF"));
 
        myself->connection->options = 0;
        myself->connection->protocol_version = PROT_CURRENT;
@@ -257,7 +257,7 @@ bool setup_myself(void)
                return false;
 
        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 */
 
@@ -433,10 +433,10 @@ bool setup_myself(void)
                return false;
 
        /* Run tinc-up script to further initialize the tap interface */
-       asprintf(&envp[0], "NETNAME=%s", netname ? : "");
-       asprintf(&envp[1], "DEVICE=%s", device ? : "");
-       asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-       asprintf(&envp[3], "NAME=%s", myself->name);
+       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
+       xasprintf(&envp[1], "DEVICE=%s", device ? : "");
+       xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
+       xasprintf(&envp[3], "NAME=%s", myself->name);
        envp[4] = NULL;
 
        execute_script("tinc-up", envp);
@@ -571,10 +571,10 @@ void close_network_connections(void)
                close(listen_socket[i].udp);
        }
 
-       asprintf(&envp[0], "NETNAME=%s", netname ? : "");
-       asprintf(&envp[1], "DEVICE=%s", device ? : "");
-       asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-       asprintf(&envp[3], "NAME=%s", myself->name);
+       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
+       xasprintf(&envp[1], "DEVICE=%s", device ? : "");
+       xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
+       xasprintf(&envp[3], "NAME=%s", myself->name);
        envp[4] = NULL;
 
        exit_requests();
index 865df78637cddcfb57b8c8019e5ee4c44e1c2127..8df9f38075356632ab778336e9966689bbfa027f 100644 (file)
@@ -367,7 +367,7 @@ begin:
                get_config_string(c->outgoing->cfg, &address);
 
                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);
                free(address);
index 206486056de095597f0006f1eddd5d8df339e4c0..909441e1320101340bf3af7a2b2d209dd1d09ea6 100644 (file)
@@ -128,7 +128,7 @@ char *sockaddr2hostname(const sockaddr_t *sa)
        cp();
 
        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;
        }
 
@@ -139,7 +139,7 @@ char *sockaddr2hostname(const sockaddr_t *sa)
                           gai_strerror(err));
        }
 
-       asprintf(&str, _("%s port %s"), address, port);
+       xasprintf(&str, _("%s port %s"), address, port);
 
        return str;
 }
index c2940bc52c3a545c1ecc003f929e68725f505819..28bba02d6013d6a480eb1e4ea4b24f5728e83e8f 100644 (file)
@@ -371,9 +371,9 @@ bool execute_script(const char *name, char **envp)
        cp();
 
 #ifndef HAVE_MINGW
-       len = asprintf(&scriptname, "\"%s/%s\"", confbase, name);
+       len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name);
 #else
-       len = asprintf(&scriptname, "\"%s/%s.bat\"", confbase, name);
+       len = xasprintf(&scriptname, "\"%s/%s.bat\"", confbase, name);
 #endif
        if(len < 0)
                return false;
index 2e93cff40582a0673840f26b97f10813cdc251ff..85133954b89ad642675c480c4e9756a21d5c6640 100644 (file)
@@ -75,7 +75,7 @@ bool send_request(connection_t *c, const char *format, ...)
 
        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
           input buffer anyway */
 
index 748b54597b809773a12685b2e41045ba289faaad..f76bbbd5feeb4c87db1543d64497c52eb142661a 100644 (file)
@@ -100,7 +100,7 @@ bool setup_device(void)
        }
 
        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");
 
index 9547829fa74b7563478c9f04fe1828282ae81b37..334729db255cf18f6d5eb2736a82063791e4c2c2 100644 (file)
@@ -480,15 +480,15 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
        char netstr[MAXNETSTR + 7] = "SUBNET=";
        char *name, *address, *port;
 
-       asprintf(&envp[0], "NETNAME=%s", netname ? : "");
-       asprintf(&envp[1], "DEVICE=%s", device ? : "");
-       asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-       asprintf(&envp[3], "NODE=%s", owner->name);
+       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
+       xasprintf(&envp[1], "DEVICE=%s", device ? : "");
+       xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
+       xasprintf(&envp[3], "NODE=%s", owner->name);
 
        if(owner != myself) {
                sockaddr2str(&owner->address, &address, &port);
-               asprintf(&envp[4], "REMOTEADDRESS=%s", address);
-               asprintf(&envp[5], "REMOTEPORT=%s", port);
+               xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
+               xasprintf(&envp[5], "REMOTEPORT=%s", port);
                envp[6] = netstr;
                envp[7] = NULL;
        } else {
index da3c33fa32e485e7b5164dbe1bb2f9f73363f869..a13e2661046f58d2ca64df3a423e1e0a1e492f17 100644 (file)
@@ -337,7 +337,7 @@ static bool keygen(int bits)
        } else
                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"));
 
        if(!f)
@@ -356,9 +356,9 @@ static bool keygen(int bits)
        free(filename);
 
        if(name)
-               asprintf(&filename, "%s/hosts/%s", confbase, name);
+               xasprintf(&filename, "%s/hosts/%s", confbase, name);
        else
-               asprintf(&filename, "%s/rsa_key.pub", confbase);
+               xasprintf(&filename, "%s/rsa_key.pub", confbase);
 
        f = ask_and_open(filename, _("public RSA key"));
 
@@ -389,7 +389,7 @@ static void make_names(void)
 #endif
 
        if(netname)
-               asprintf(&identname, "tinc.%s", netname);
+               xasprintf(&identname, "tinc.%s", netname);
        else
                identname = xstrdup("tinc");
 
@@ -397,12 +397,12 @@ static void make_names(void)
        if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) {
                if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) {
                        if(!logfilename)
-                               asprintf(&logfilename, "%s/log/%s.log", identname);
+                               xasprintf(&logfilename, "%s/log/%s.log", identname);
                        if(!confbase) {
                                if(netname)
-                                       asprintf(&confbase, "%s/%s", installdir, netname);
+                                       xasprintf(&confbase, "%s/%s", installdir, netname);
                                else
-                                       asprintf(&confbase, "%s", installdir);
+                                       xasprintf(&confbase, "%s", installdir);
                        }
                }
                RegCloseKey(key);
@@ -412,19 +412,19 @@ static void make_names(void)
 #endif
 
        if(!pidfilename)
-               asprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname);
+               xasprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname);
 
        if(!logfilename)
-               asprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
+               xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
 
        if(netname) {
                if(!confbase)
-                       asprintf(&confbase, CONFDIR "/tinc/%s", netname);
+                       xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
                else
                        logger(LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
        } else {
                if(!confbase)
-                       asprintf(&confbase, CONFDIR "/tinc");
+                       xasprintf(&confbase, CONFDIR "/tinc");
        }
 }
 
index 62a6f2eb65a762f4a940a7e77b13e4dddf91fc69..de0b4a556a310a5a6ebae534963d968b1c9523a4 100644 (file)
@@ -71,7 +71,7 @@ bool setup_device(void)
        cp();
 
        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);