[PATCH[ log: Do not BUG_ON in log_first_err

Submitted by Pavel Emelianov on Sept. 6, 2016, 9:50 p.m.

Details

Message ID 57CF3A2D.4040707@virtuozzo.com
State Rejected
Series "Bring some verbosity to RPC"
Headers show

Commit Message

Pavel Emelianov Sept. 6, 2016, 9:50 p.m.
It turned out that calling log_first_error() is possible w/o
calling log_keep_first_err(), so don't bug_on() on it, just
return NULL.

Reported-by: Adrian Reber <adrian@lisas.de>
Signed-off-by: Pavel Emelyanov <xemul@virtouzzo.com>

---

Patch hide | download patch | download mbox

diff --git a/criu/log.c b/criu/log.c
index 64ce8c5..6dd8530 100644
--- a/criu/log.c
+++ b/criu/log.c
@@ -114,8 +114,12 @@  static void log_note_err(char *msg)
 
 char *log_first_err(void)
 {
-	BUG_ON(!first_err);
-	return first_err->s[0] == '\0' ? NULL : first_err->s;
+	if (!first_err)
+		return NULL;
+	if (first_err->s[0] == '\0')
+		return NULL;
+
+	return first_err->s;
 }
 
 int log_init(const char *output)

Comments

Adrian Reber Sept. 7, 2016, 8:49 a.m.
On Wed, Sep 07, 2016 at 12:50:37AM +0300, Pavel Emelyanov wrote:
> It turned out that calling log_first_error() is possible w/o
> calling log_keep_first_err(), so don't bug_on() on it, just
> return NULL.
> 
> Reported-by: Adrian Reber <adrian@lisas.de>
> Signed-off-by: Pavel Emelyanov <xemul@virtouzzo.com>

Thanks. Now p.haul works again.

Reviewed-by: Adrian Reber <adrian@lisas.de>

> 
> ---
> 
> diff --git a/criu/log.c b/criu/log.c
> index 64ce8c5..6dd8530 100644
> --- a/criu/log.c
> +++ b/criu/log.c
> @@ -114,8 +114,12 @@ static void log_note_err(char *msg)
>  
>  char *log_first_err(void)
>  {
> -	BUG_ON(!first_err);
> -	return first_err->s[0] == '\0' ? NULL : first_err->s;
> +	if (!first_err)
> +		return NULL;
> +	if (first_err->s[0] == '\0')
> +		return NULL;
> +
> +	return first_err->s;
>  }
>  
>  int log_init(const char *output)