[CRIU] [PATCH 06/21] soccr: add prefixes for log messages and print errno

Andrei Vagin avagin at openvz.org
Mon Nov 28 11:27:41 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

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.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 soccr/soccr.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/soccr/soccr.c b/soccr/soccr.c
index 2467c1a..019eeea 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -21,8 +21,9 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
 	log = fn;
 }
 
-#define loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, 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 loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, "Error: " 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)
 {
@@ -30,7 +31,7 @@ static int tcp_repair_on(int fd)
 
 	ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
 	if (ret < 0)
-		loge("Can't turn TCP repair mode ON\n");
+		logerr("Can't turn TCP repair mode ON");
 
 	return ret;
 }
@@ -41,7 +42,7 @@ static void tcp_repair_off(int fd)
 
 	ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
 	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 {
@@ -83,7 +84,7 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
 	socklen_t 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;
 	}
 
@@ -99,21 +100,21 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
 	data->state = TCP_ESTABLISHED;
 
 	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;
 	}
 
 	data->outq_len = size;
 
 	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;
 	}
 
 	data->unsq_len = size;
 
 	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;
 	}
 
@@ -151,7 +152,7 @@ static int get_stream_options(struct libsoccr_sk *sk, struct libsoccr_sk_data *d
 	return 0;
 
 err_sopt:
-	loge("\tsockopt failed\n");
+	logerr("\tsockopt failed");
 	return -1;
 }
 
@@ -166,7 +167,7 @@ static int get_window(struct libsoccr_sk *sk, struct libsoccr_sk_data *data)
 		if (errno == ENOPROTOOPT)
 			return 0;
 
-		loge("Unable to get window properties\n");
+		logerr("Unable to get window properties");
 		return -1;
 	}
 
@@ -241,12 +242,12 @@ static int get_queue(int sk, int queue_id,
 	return 0;
 
 err_sopt:
-	loge("\tsockopt failed\n");
+	logerr("\tsockopt failed");
 err_buf:
 	return -1;
 
 err_recv:
-	loge("\trecv failed (%d, want %d)\n", ret, len);
+	logerr("\trecv failed (%d, want %d)", ret, len);
 	free(buf);
 	goto err_buf;
 }
@@ -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);
 
 	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;
 	}
 
 	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;
 	}
 
@@ -385,14 +386,14 @@ int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
 
 	if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_OPTIONS,
 				opts, onr * sizeof(struct tcp_repair_opt)) < 0) {
-		loge("Can't repair options\n");
+		logerr("Can't repair options");
 		return -2;
 	}
 
 	if (data->opt_mask & TCPI_OPT_TIMESTAMPS) {
 		if (setsockopt(sk->fd, SOL_TCP, TCP_TIMESTAMP,
 				&data->timestamp, sizeof(data->timestamp)) < 0) {
-			loge("Can't set timestamp\n");
+			logerr("Can't set timestamp");
 			return -3;
 		}
 	}
@@ -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))) {
-			loge("Unable to set window parameters\n");
+			logerr("Unable to set window parameters");
 			return -1;
 		}
 	}
@@ -456,7 +457,7 @@ static int __send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len)
 				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);
 			goto err;
 		}
@@ -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);
 
 	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;
 	}
 
-- 
2.7.4



More information about the CRIU mailing list