[CRIU] [PATCH] log: Don't show time stamp on pr_msg

Pavel Emelyanov xemul at parallels.com
Tue Nov 6 03:55:42 EST 2012


On 11/06/2012 11:24 AM, Cyrill Gorcunov wrote:
> In case if the pr_err happens before pr_msg,
> the string buffer will have dangling timestamp
> prefix. Skip it here.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>

Isn't it easier to do it like

@@ -182,11 +182,13 @@ void print_on_level(unsigned int loglevel, const char *format, ...)
 
 	if (unlikely(loglevel == LOG_MSG)) {
 		fd = STDOUT_FILENO;
+		off = buf_off;
 	} else {
 		if (loglevel > current_loglevel)
 			return;
 		fd = current_logfd;
 		print_ts();
+		off = 0;
 	}
 
 	va_start(params, format);
@@ -195,7 +197,6 @@ void print_on_level(unsigned int loglevel, const char *format, ...)
 
 	size += buf_off;
 
-	off = 0;
 	while (off < size) {
 		ret = write(fd, buffer + off, size - off);
 		if (ret <= 0)

?

> ---
>  log.c |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/log.c b/log.c
> index 9629897..8e17f86 100644
> --- a/log.c
> +++ b/log.c
> @@ -179,25 +179,28 @@ void print_on_level(unsigned int loglevel, const char *format, ...)
>  {
>  	va_list params;
>  	int fd, size, ret, off;
> +	char *where;
>  
>  	if (unlikely(loglevel == LOG_MSG)) {
>  		fd = STDOUT_FILENO;
> +		where = buffer + buf_off;
> +		size = 0;
>  	} else {
>  		if (loglevel > current_loglevel)
>  			return;
>  		fd = current_logfd;
>  		print_ts();
> +		where = buffer;
> +		size = buf_off;
>  	}
>  
>  	va_start(params, format);
> -	size = vsnprintf(buffer + buf_off, PAGE_SIZE - buf_off, format, params);
> +	size += vsnprintf(buffer + buf_off, PAGE_SIZE - buf_off, format, params);
>  	va_end(params);
>  
> -	size += buf_off;
> -
>  	off = 0;
>  	while (off < size) {
> -		ret = write(fd, buffer + off, size - off);
> +		ret = write(fd, where + off, size - off);
>  		if (ret <= 0)
>  			break;
>  		off += ret;
> 




More information about the CRIU mailing list