aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/worker.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-05-13 10:58:41 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-05-13 11:37:46 +0200
commitcd917f48454875ad6b7fc69455281d72760c44ee (patch)
tree70a7a43fe43b7f893468f9120def5513774a242c /src/worker.c
parentadd command module to handle request-response communications (diff)
downloadcimple-cd917f48454875ad6b7fc69455281d72760c44ee.tar.gz
cimple-cd917f48454875ad6b7fc69455281d72760c44ee.zip
best practices & coding style fixes
* I don't really need to declare all variables at the top of the function anymore. * Default-initialize variables more. * Don't set the output parameter until the object is completely constructed.
Diffstat (limited to 'src/worker.c')
-rw-r--r--src/worker.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/worker.c b/src/worker.c
index ae9a578..8c731f2 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -32,15 +32,13 @@ struct worker {
int worker_create(struct worker **_worker, const struct settings *settings)
{
- struct worker *worker;
int ret = 0;
- *_worker = malloc(sizeof(struct worker));
- if (!*_worker) {
+ struct worker *worker = malloc(sizeof(struct worker));
+ if (!worker) {
log_errno("malloc");
return -1;
}
- worker = *_worker;
ret = libgit_init();
if (ret < 0)
@@ -51,6 +49,7 @@ int worker_create(struct worker **_worker, const struct settings *settings)
goto git_shutdown;
worker->fd = ret;
+ *_worker = worker;
return ret;
git_shutdown:
@@ -74,7 +73,7 @@ void worker_destroy(struct worker *worker)
static int msg_send_new_worker(const struct worker *worker)
{
static const char *argv[] = {CMD_NEW_WORKER, NULL};
- struct msg *msg;
+ struct msg *msg = NULL;
int ret = 0;
ret = msg_from_argv(&msg, argv);
@@ -152,7 +151,7 @@ int worker_main(struct worker *worker, UNUSED int argc, UNUSED char *argv[])
return ret;
while (!global_stop_flag) {
- struct msg *request;
+ struct msg *request = NULL;
log("Waiting for a new command\n");