Commit a73eb530 authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

soccr: add prefixes for log messages and print errno

loge() will start a message with "Error:" and
logd() will start a message with "Debug:".
logerr() will add strerror(errno) to the end of messages.

travis-ci: success for series starting with [01/21] build: install libnet-dev
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent cb7948d9
...@@ -21,8 +21,9 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c ...@@ -21,8 +21,9 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
log = fn; log = fn;
} }
#define loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, msg, ##__VA_ARGS__); } while (0) #define loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, "Error: " msg, ##__VA_ARGS__); } while (0)
#define logd(msg, ...) do { if (log && (log_level >= SOCCR_LOG_DBG)) log(SOCCR_LOG_DBG, msg, ##__VA_ARGS__); } while (0) #define logerr(msg, ...) loge(msg ": %s\n", ##__VA_ARGS__, strerror(errno))
#define logd(msg, ...) do { if (log && (log_level >= SOCCR_LOG_DBG)) log(SOCCR_LOG_DBG, "Debug: " msg, ##__VA_ARGS__); } while (0)
static int tcp_repair_on(int fd) static int tcp_repair_on(int fd)
{ {
...@@ -30,7 +31,7 @@ static int tcp_repair_on(int fd) ...@@ -30,7 +31,7 @@ static int tcp_repair_on(int fd)
ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux)); ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
if (ret < 0) if (ret < 0)
loge("Can't turn TCP repair mode ON\n"); logerr("Can't turn TCP repair mode ON");
return ret; return ret;
} }
...@@ -41,7 +42,7 @@ static void tcp_repair_off(int fd) ...@@ -41,7 +42,7 @@ static void tcp_repair_off(int fd)
ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux)); ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
if (ret < 0) if (ret < 0)
loge("Failed to turn off repair mode on socket: %m\n"); logerr("Failed to turn off repair mode on socket");
} }
struct libsoccr_sk { struct libsoccr_sk {
...@@ -83,7 +84,7 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str ...@@ -83,7 +84,7 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
socklen_t olen = sizeof(*ti); socklen_t olen = sizeof(*ti);
if (getsockopt(sk->fd, SOL_TCP, TCP_INFO, ti, &olen) || olen != sizeof(*ti)) { if (getsockopt(sk->fd, SOL_TCP, TCP_INFO, ti, &olen) || olen != sizeof(*ti)) {
loge("Failed to obtain TCP_INFO\n"); logerr("Failed to obtain TCP_INFO");
return -1; return -1;
} }
...@@ -99,21 +100,21 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str ...@@ -99,21 +100,21 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
data->state = TCP_ESTABLISHED; data->state = TCP_ESTABLISHED;
if (ioctl(sk->fd, SIOCOUTQ, &size) == -1) { if (ioctl(sk->fd, SIOCOUTQ, &size) == -1) {
loge("Unable to get size of snd queue\n"); logerr("Unable to get size of snd queue");
return -1; return -1;
} }
data->outq_len = size; data->outq_len = size;
if (ioctl(sk->fd, SIOCOUTQNSD, &size) == -1) { if (ioctl(sk->fd, SIOCOUTQNSD, &size) == -1) {
loge("Unable to get size of unsent data\n"); logerr("Unable to get size of unsent data");
return -1; return -1;
} }
data->unsq_len = size; data->unsq_len = size;
if (ioctl(sk->fd, SIOCINQ, &size) == -1) { if (ioctl(sk->fd, SIOCINQ, &size) == -1) {
loge("Unable to get size of recv queue\n"); logerr("Unable to get size of recv queue");
return -1; return -1;
} }
...@@ -151,7 +152,7 @@ static int get_stream_options(struct libsoccr_sk *sk, struct libsoccr_sk_data *d ...@@ -151,7 +152,7 @@ static int get_stream_options(struct libsoccr_sk *sk, struct libsoccr_sk_data *d
return 0; return 0;
err_sopt: err_sopt:
loge("\tsockopt failed\n"); logerr("\tsockopt failed");
return -1; return -1;
} }
...@@ -166,7 +167,7 @@ static int get_window(struct libsoccr_sk *sk, struct libsoccr_sk_data *data) ...@@ -166,7 +167,7 @@ static int get_window(struct libsoccr_sk *sk, struct libsoccr_sk_data *data)
if (errno == ENOPROTOOPT) if (errno == ENOPROTOOPT)
return 0; return 0;
loge("Unable to get window properties\n"); logerr("Unable to get window properties");
return -1; return -1;
} }
...@@ -241,12 +242,12 @@ static int get_queue(int sk, int queue_id, ...@@ -241,12 +242,12 @@ static int get_queue(int sk, int queue_id,
return 0; return 0;
err_sopt: err_sopt:
loge("\tsockopt failed\n"); logerr("\tsockopt failed");
err_buf: err_buf:
return -1; return -1;
err_recv: err_recv:
loge("\trecv failed (%d, want %d)\n", ret, len); logerr("\trecv failed (%d, want %d)", ret, len);
free(buf); free(buf);
goto err_buf; goto err_buf;
} }
...@@ -310,12 +311,12 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq) ...@@ -310,12 +311,12 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq)
logd("\tSetting %d queue seq to %u\n", queue, seq); logd("\tSetting %d queue seq to %u\n", queue, seq);
if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) { if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) {
loge("Can't set repair queue\n"); logerr("Can't set repair queue");
return -1; return -1;
} }
if (setsockopt(sk->fd, SOL_TCP, TCP_QUEUE_SEQ, &seq, sizeof(seq)) < 0) { if (setsockopt(sk->fd, SOL_TCP, TCP_QUEUE_SEQ, &seq, sizeof(seq)) < 0) {
loge("Can't set queue seq\n"); logerr("Can't set queue seq");
return -1; return -1;
} }
...@@ -385,14 +386,14 @@ int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, ...@@ -385,14 +386,14 @@ int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_OPTIONS, if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_OPTIONS,
opts, onr * sizeof(struct tcp_repair_opt)) < 0) { opts, onr * sizeof(struct tcp_repair_opt)) < 0) {
loge("Can't repair options\n"); logerr("Can't repair options");
return -2; return -2;
} }
if (data->opt_mask & TCPI_OPT_TIMESTAMPS) { if (data->opt_mask & TCPI_OPT_TIMESTAMPS) {
if (setsockopt(sk->fd, SOL_TCP, TCP_TIMESTAMP, if (setsockopt(sk->fd, SOL_TCP, TCP_TIMESTAMP,
&data->timestamp, sizeof(data->timestamp)) < 0) { &data->timestamp, sizeof(data->timestamp)) < 0) {
loge("Can't set timestamp\n"); logerr("Can't set timestamp");
return -3; return -3;
} }
} }
...@@ -413,7 +414,7 @@ int libsoccr_set_sk_data(struct libsoccr_sk *sk, ...@@ -413,7 +414,7 @@ int libsoccr_set_sk_data(struct libsoccr_sk *sk,
}; };
if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_WINDOW, &wopt, sizeof(wopt))) { if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_WINDOW, &wopt, sizeof(wopt))) {
loge("Unable to set window parameters\n"); logerr("Unable to set window parameters");
return -1; return -1;
} }
} }
...@@ -456,7 +457,7 @@ static int __send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len) ...@@ -456,7 +457,7 @@ static int __send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len)
continue; continue;
} }
loge("Can't restore %d queue data (%d), want (%d:%d:%d)\n", logerr("Can't restore %d queue data (%d), want (%d:%d:%d)",
queue, ret, chunk, len, max_chunk); queue, ret, chunk, len, max_chunk);
goto err; goto err;
} }
...@@ -474,7 +475,7 @@ static int send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len) ...@@ -474,7 +475,7 @@ static int send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len)
logd("\tRestoring TCP %d queue data %u bytes\n", queue, len); logd("\tRestoring TCP %d queue data %u bytes\n", queue, len);
if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) { if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) {
loge("Can't set repair queue\n"); logerr("Can't set repair queue");
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment