summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-26 14:58:12 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-26 14:58:12 +0000
commitf72ce0dc37f0b66ba2651b2fe7d39603f089abed (patch)
tree2facf10a91a09dbe5af9282639bfdaa98f98130f /src
parentadded -4 and -6 switches to udp socket (diff)
moved from %m to %s and strerror
Diffstat (limited to 'src')
-rw-r--r--src/bsd/tun.c2
-rw-r--r--src/daemon.h22
-rw-r--r--src/linux/tun.c4
-rw-r--r--src/sysexec.h2
-rw-r--r--src/uanytun.c12
-rw-r--r--src/udp.c7
6 files changed, 25 insertions, 24 deletions
diff --git a/src/bsd/tun.c b/src/bsd/tun.c
index 4c50c40..d5697c5 100644
--- a/src/bsd/tun.c
+++ b/src/bsd/tun.c
@@ -123,7 +123,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
if(dynamic)
log_printf(ERROR, "can't open device file dynamically: no unused node left");
else
- log_printf(ERROR, "can't open device file (%s): %m", device_file);
+ log_printf(ERROR, "can't open device file (%s): %s", device_file, strerror(errno));
tun_close(dev);
return -1;
diff --git a/src/daemon.h b/src/daemon.h
index 4cc10e8..ac0516e 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -84,19 +84,19 @@ int priv_drop(priv_info_t* priv)
}
if(setgid(priv->gr_->gr_gid)) {
- log_printf(ERROR, "setgid('%s') failed: %m", priv->gr_->gr_name);
+ log_printf(ERROR, "setgid('%s') failed: %s", priv->gr_->gr_name, strerror(errno));
return -1;
}
gid_t gr_list[1];
- gr_list[0] = priv->gr_->gr_gid;
- if(setgroups (1, gr_list)) {
- log_printf(ERROR, "setgroups(['%s']) failed: %m", priv->gr_->gr_name);
+ gr_list[0] = priv->gr_->gr_gid;
+ if(setgroups (1, gr_list)) {
+ log_printf(ERROR, "setgroups(['%s']) failed: %s", priv->gr_->gr_name, strerror(errno));
return -1;
}
if(setuid(priv->pw_->pw_uid)) {
- log_printf(ERROR, "setuid('%s') failed: %m", priv->pw_->pw_name);
+ log_printf(ERROR, "setuid('%s') failed: %s", priv->pw_->pw_name, strerror(errno));
return -1;
}
@@ -113,12 +113,12 @@ int do_chroot(const char* chrootdir)
}
if(chroot(chrootdir)) {
- log_printf(ERROR, "can't chroot to %s: %m", chrootdir);
+ log_printf(ERROR, "can't chroot to %s: %s", chrootdir, strerror(errno));
return -1;
}
log_printf(NOTICE, "we are in chroot jail (%s) now", chrootdir);
if(chdir("/")) {
- log_printf(ERROR, "can't change to /: %m");
+ log_printf(ERROR, "can't change to /: %s", strerror(errno));
return -1;
}
}
@@ -129,7 +129,7 @@ void daemonize()
pid = fork();
if(pid < 0) {
- log_printf(ERROR, "daemonizing failed at fork(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at fork(): %s, exitting", strerror(errno));
exit(-1);
}
if(pid) exit(0);
@@ -137,19 +137,19 @@ void daemonize()
umask(0);
if(setsid() < 0) {
- log_printf(ERROR, "daemonizing failed at setsid(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at setsid(): %s, exitting", strerror(errno));
exit(-1);
}
pid = fork();
if(pid < 0) {
- log_printf(ERROR, "daemonizing failed at fork(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at fork(): %s, exitting", strerror(errno));
exit(-1);
}
if(pid) exit(0);
if ((chdir("/")) < 0) {
- log_printf(ERROR, "daemonizing failed at chdir(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at chdir(): %s, exitting", strerror(errno));
exit(-1);
}
diff --git a/src/linux/tun.c b/src/linux/tun.c
index 87cc815..c2187a6 100644
--- a/src/linux/tun.c
+++ b/src/linux/tun.c
@@ -64,7 +64,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
dev->fd_ = open(DEFAULT_DEVICE, O_RDWR);
if(dev->fd_ < 0) {
- log_printf(ERROR, "can't open device file (%s): %m", DEFAULT_DEVICE);
+ log_printf(ERROR, "can't open device file (%s): %s", DEFAULT_DEVICE, strerror(errno));
tun_close(dev);
return -1;
}
@@ -94,7 +94,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
} else if(!ioctl(dev->fd_, (('T' << 8) | 202), &ifr)) {
dev->actual_name_ = strdup(ifr.ifr_name);
} else {
- log_printf(ERROR, "tun/tap device ioctl failed: %m");
+ log_printf(ERROR, "tun/tap device ioctl failed: %s", strerror(errno));
tun_close(dev);
return -1;
}
diff --git a/src/sysexec.h b/src/sysexec.h
index a50ec06..b724433 100644
--- a/src/sysexec.h
+++ b/src/sysexec.h
@@ -58,7 +58,7 @@ int exec_script(const char* script, const char* ifname)
}
execl("/bin/sh", "/bin/sh", script, ifname, NULL);
// if execl return, an error occurred
- log_printf(ERROR, "error on executing script: %m");
+ log_printf(ERROR, "error on executing script: %s", strerror(errno));
return -1;
}
int status = 0;
diff --git a/src/uanytun.c b/src/uanytun.c
index 380dca5..83b16bb 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -147,7 +147,7 @@ int process_tun_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plai
int len = tun_read(dev, plain_packet_get_payload(plain_packet), plain_packet_get_payload_length(plain_packet));
if(len == -1) {
- log_printf(ERROR, "error on reading from device: %m");
+ log_printf(ERROR, "error on reading from device: %s", strerror(errno));
return 0;
}
@@ -171,7 +171,7 @@ int process_tun_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plai
len = udp_write(sock, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet));
if(len == -1)
- log_printf(ERROR, "error on sending udp packet: %m");
+ log_printf(ERROR, "error on sending udp packet: %s", strerror(errno));
return 0;
}
@@ -186,7 +186,7 @@ int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, pla
memset(&remote, 0, sizeof(udp_endpoint_t));
int len = udp_read(sock, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet), &remote);
if(len == -1) {
- log_printf(ERROR, "error on receiving udp packet: %m");
+ log_printf(ERROR, "error on receiving udp packet: %s", strerror(errno));
return 0;
}
else if(len < encrypted_packet_get_header_length()) {
@@ -236,7 +236,7 @@ int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, pla
len = tun_write(dev, plain_packet_get_payload(plain_packet), plain_packet_get_payload_length(plain_packet));
if(len == -1)
- log_printf(ERROR, "error on writing to device: %m");
+ log_printf(ERROR, "error on writing to device: %s", strerror(errno));
return 0;
}
@@ -272,7 +272,7 @@ int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
int ret = select(nfds, &readfds, NULL, NULL, NULL);
if(ret == -1 && errno != EINTR) {
- log_printf(ERROR, "select returned with error: %m");
+ log_printf(ERROR, "select returned with error: %s", strerror(errno));
return_value = -1;
break;
}
@@ -442,7 +442,7 @@ int main(int argc, char* argv[])
if(opt.pid_file_) {
pid_file = fopen(opt.pid_file_, "w");
if(!pid_file) {
- log_printf(WARNING, "unable to open pid file: %m");
+ log_printf(WARNING, "unable to open pid file: %s", strerror(errno));
}
}
diff --git a/src/udp.c b/src/udp.c
index e75e1ef..921612e 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -38,6 +38,7 @@
#include "log.h"
+#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -87,7 +88,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resol
sock->fd_ = socket(res->ai_family, SOCK_DGRAM, 0);
if(sock->fd_ < 0) {
- log_printf(ERROR, "Error on opening udp socket: %m");
+ log_printf(ERROR, "Error on opening udp socket: %s", strerror(errno));
freeaddrinfo(res);
udp_close(sock);
return -1;
@@ -95,7 +96,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resol
errcode = bind(sock->fd_, res->ai_addr, res->ai_addrlen);
if(errcode) {
- log_printf(ERROR, "Error on binding udp socket: %m");
+ log_printf(ERROR, "Error on binding udp socket: %s", strerror(errno));
freeaddrinfo(res);
udp_close(sock);
return -1;
@@ -106,7 +107,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resol
log_printf(NOTICE, "disabling V4-Mapped addresses");
int on = 1;
if(setsockopt(sock->fd_, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)))
- log_printf(ERROR, "Error on setting IPV6_V6ONLY socket option: %m");
+ log_printf(ERROR, "Error on setting IPV6_V6ONLY socket option: %s", strerror(errno));
}
#endif
freeaddrinfo(res);