aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 20:24:41 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 20:29:03 +0200
commit1c42eca6cdae99804b7020d89ae220308e4daff5 (patch)
tree62dc276ed87bf49dd186a6a3fdaff50f37d84700
parentfix Alpine builds (diff)
downloadcimple-1c42eca6cdae99804b7020d89ae220308e4daff5.tar.gz
cimple-1c42eca6cdae99804b7020d89ae220308e4daff5.zip
make proper "error" messages
Previously, the client had no way to distinguish errors from succesful calls.
Diffstat (limited to '')
-rw-r--r--src/msg.c16
-rw-r--r--src/msg.h4
-rw-r--r--src/server.c11
-rw-r--r--src/worker.c14
4 files changed, 28 insertions, 17 deletions
diff --git a/src/msg.c b/src/msg.c
index 5a7e165..d1f3b5e 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -5,26 +5,26 @@
#include <stdlib.h>
#include <string.h>
-void msg_success(struct msg *msg)
+int msg_success(struct msg *msg)
{
- msg->argc = 0;
- msg->argv = NULL;
+ char *argv[] = {"success", NULL};
+ return msg_from_argv(msg, argv);
}
-void msg_error(struct msg *msg)
+int msg_error(struct msg *msg)
{
- msg->argc = -1;
- msg->argv = NULL;
+ char *argv[] = {"error", NULL};
+ return msg_from_argv(msg, argv);
}
int msg_is_success(const struct msg *msg)
{
- return msg->argc == 0;
+ return msg->argc == 1 && !strcmp(msg->argv[0], "success");
}
int msg_is_error(const struct msg *msg)
{
- return msg->argc < 0;
+ return msg->argc == 1 && !strcmp(msg->argv[0], "error");
}
static int msg_copy_argv(struct msg *msg, char **argv)
diff --git a/src/msg.h b/src/msg.h
index e60f2ce..f6b85e6 100644
--- a/src/msg.h
+++ b/src/msg.h
@@ -6,8 +6,8 @@ struct msg {
char **argv;
};
-void msg_success(struct msg *);
-void msg_error(struct msg *);
+int msg_success(struct msg *);
+int msg_error(struct msg *);
int msg_is_success(const struct msg *);
int msg_is_error(const struct msg *);
diff --git a/src/server.c b/src/server.c
index a84016e..c2941c5 100644
--- a/src/server.c
+++ b/src/server.c
@@ -227,11 +227,16 @@ static int msg_ci_run_handler(struct server *server, int client_fd, const struct
ret = msg_ci_run_queue(server, msg->argv[1], msg->argv[2]);
if (ret < 0)
- msg_error(&response);
+ ret = msg_error(&response);
else
- msg_success(&response);
+ ret = msg_success(&response);
- return msg_send(client_fd, &response);
+ if (ret < 0)
+ return ret;
+
+ ret = msg_send(client_fd, &response);
+ msg_free(&response);
+ return ret;
}
static int msg_ci_run_parser(const struct msg *msg)
diff --git a/src/worker.c b/src/worker.c
index fbf609b..baba9b0 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -88,13 +88,19 @@ static int msg_ci_run_handler(struct worker *worker, const struct msg *request)
int ret = 0;
ret = msg_ci_run_do(request->argv[1], request->argv[2], &result);
+ proc_output_free(&result);
+
if (ret < 0)
- msg_error(&response);
+ ret = msg_error(&response);
else
- msg_success(&response);
- proc_output_free(&result);
+ ret = msg_success(&response);
- return msg_send(worker->fd, &response);
+ if (ret < 0)
+ return ret;
+
+ ret = msg_send(worker->fd, &response);
+ msg_free(&response);
+ return ret;
}
static int msg_ci_run_parser(const struct msg *msg)