[1/2] service: Factor out err setting

Submitted by Pavel Emelianov on Aug. 24, 2016, 6:11 p.m.

Details

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

Commit Message

Pavel Emelianov Aug. 24, 2016, 6:11 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/cr-service.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-service.c b/criu/cr-service.c
index fdd37d9..a2b4027 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -110,6 +110,17 @@  err:
 	return -1;
 }
 
+static void set_resp_err(CriuResp *resp)
+{
+	int errn;
+
+	errn = get_cr_errno();
+	if (errn) {
+		resp->has_cr_errno = true;
+		resp->cr_errno = errn;
+	}
+}
+
 static void send_criu_err(int sk, char *msg)
 {
 	CriuResp resp = CRIU_RESP__INIT;
@@ -118,10 +129,7 @@  static void send_criu_err(int sk, char *msg)
 
 	resp.type = CRIU_REQ_TYPE__EMPTY;
 	resp.success = false;
-	if (get_cr_errno()) {
-		resp.has_cr_errno = true;
-		resp.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&resp);
 
 	send_criu_msg(sk, &resp);
 }
@@ -133,10 +141,7 @@  int send_criu_dump_resp(int socket_fd, bool success, bool restored)
 
 	msg.type = CRIU_REQ_TYPE__DUMP;
 	msg.success = success;
-	if (get_cr_errno()) {
-		msg.has_cr_errno = true;
-		msg.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&msg);
 	msg.dump = &resp;
 
 	resp.has_restored = true;
@@ -151,10 +156,7 @@  static int send_criu_pre_dump_resp(int socket_fd, bool success)
 
 	msg.type = CRIU_REQ_TYPE__PRE_DUMP;
 	msg.success = success;
-	if (get_cr_errno()) {
-		msg.has_cr_errno = true;
-		msg.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&msg);
 
 	return send_criu_msg(socket_fd, &msg);
 }
@@ -166,10 +168,7 @@  int send_criu_restore_resp(int socket_fd, bool success, int pid)
 
 	msg.type = CRIU_REQ_TYPE__RESTORE;
 	msg.success = success;
-	if (get_cr_errno()) {
-		msg.has_cr_errno = true;
-		msg.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&msg);
 	msg.restore = &resp;
 
 	resp.pid = pid;

Comments

Cyrill Gorcunov Aug. 26, 2016, 10:55 a.m.
On Wed, Aug 24, 2016 at 09:11:45PM +0300, Pavel Emelyanov wrote:
> 
> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
> ---
>  criu/cr-service.c | 31 +++++++++++++++----------------
>  1 file changed, 15 insertions(+), 16 deletions(-)
> 
> diff --git a/criu/cr-service.c b/criu/cr-service.c
> index fdd37d9..a2b4027 100644
> --- a/criu/cr-service.c
> +++ b/criu/cr-service.c
> @@ -110,6 +110,17 @@ err:
>  	return -1;
>  }
>  
> +static void set_resp_err(CriuResp *resp)
> +{
> +	int errn;
> +
> +	errn = get_cr_errno();
> +	if (errn) {
> +		resp->has_cr_errno = true;
> +		resp->cr_errno = errn;
> +	}
> +}

Why not simply

static void set_resp_err(CriuResp *resp)
{
	resp->cr_errno = get_cr_errno();
	resp->has_cr_errno = resp->cr_errno ? true : false;
}
Pavel Emelianov Aug. 29, 2016, 1:07 p.m.
On 08/26/2016 01:55 PM, Cyrill Gorcunov wrote:
> On Wed, Aug 24, 2016 at 09:11:45PM +0300, Pavel Emelyanov wrote:
>>
>> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
>> ---
>>  criu/cr-service.c | 31 +++++++++++++++----------------
>>  1 file changed, 15 insertions(+), 16 deletions(-)
>>
>> diff --git a/criu/cr-service.c b/criu/cr-service.c
>> index fdd37d9..a2b4027 100644
>> --- a/criu/cr-service.c
>> +++ b/criu/cr-service.c
>> @@ -110,6 +110,17 @@ err:
>>  	return -1;
>>  }
>>  
>> +static void set_resp_err(CriuResp *resp)
>> +{
>> +	int errn;
>> +
>> +	errn = get_cr_errno();
>> +	if (errn) {
>> +		resp->has_cr_errno = true;
>> +		resp->cr_errno = errn;
>> +	}
>> +}
> 
> Why not simply
> 
> static void set_resp_err(CriuResp *resp)
> {
> 	resp->cr_errno = get_cr_errno();
> 	resp->has_cr_errno = resp->cr_errno ? true : false;
> }

Yup, pretty possible. Will do.

-- Pavel