From patchwork Mon Nov 16 09:14:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1400716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23c; helo=mail-lj1-x23c.google.com; envelope-from=swupdate+bncbcxploxj6ikrbgmgzh6qkgqeyuahuxa@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=mkZZXmpe; dkim-atps=neutral Received: from mail-lj1-x23c.google.com (mail-lj1-x23c.google.com [IPv6:2a00:1450:4864:20::23c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CZNhG3RByz9sSn for ; Mon, 16 Nov 2020 20:15:09 +1100 (AEDT) Received: by mail-lj1-x23c.google.com with SMTP id j3sf8250488lji.19 for ; Mon, 16 Nov 2020 01:15:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1605518105; cv=pass; d=google.com; s=arc-20160816; b=L5AMg4Gg/Mzy7xBGaXLapZA2uxtDXF7cGbf5Ywu5P1PWcxfoF5enELkUlkbOoq7RkM dd2NxfsJyC+Q1+K3ZDCpD8U38MxWlgqiS3yeEierDJ372eujgTgsHgakmSE2yxEjLTsh 42oPe17sPoqe6NCfXBhE1gx5h3zwsWDSu8mbt5kJEiZz5Yrb7a6WRK3mG9wGjId6nQDc mjOH57X/tTESaRZpJVA8WxPBaii03ONY70iybF1Y6tZtFLR4aK1lYLl+FndGwprVWs/S BOO2dOzd+OkKUZOHnlpw7m/eyYxXSyVcGWf9laqVWwjeyrW4YjeWarILUTiP8BBpEfE9 +xiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=WE6tlLeRpMOyo9YUOhtRa6+XwV+oPlj7AqBksvrQGtE=; b=dhrmWMCyKcS5R5nI80hRay7pMTKhJW7hCLqsXVFlXPKVAxwEo/Q/XH3GVeZDbzwdUe ufjK/cJKNwAet9ryA0cLi+2/WQV6DdYZ6cSFbQiOGy5UH1FhtZv4CdtK3Szf2cW4oATh SrUySt8rF5T4afN38YeYG41doH0EeXk9VxxOj2wpc+XZpx5kCQutQfPZdvR76J/KGa/4 /6a84RbovTtql/MbfdPyCgHOiRw1aCmf91qdHZGtpCjYMNj5rKHLjbX40qToun6LXWtq rfz+4a2ydqo534SxKoS6pddorM+xA2bL9mUpIfGB/LQaSnsXhlTlthO93huzlAlvEe4T ihUw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=WE6tlLeRpMOyo9YUOhtRa6+XwV+oPlj7AqBksvrQGtE=; b=mkZZXmpeyQRKXK7dySxcsmLXxyKwc2Gt9ab9l2z/Sxd9CKZ2qeaVnLO8O/obisXbOu DMULi+LAyGbVIZO5tTrN0nkbCUqh0jiEH18apMbavLRjcugt/QizJGnL1GC69V2LruK1 kk+GwdoIAQt2Y73fI000fUQPylQbGmL0c8cronSlQT/45oBtC8nlX8O71m55NcuOeAxF /vsisusAGMyPR24dUnAw8f83qCwt6eu9oHOIVuqT3jVdRBBks8V2jQL05Qtwk17Unyt/ 6O73r0hKYPTonC9aalkdj4arQ1kfR8R3c7hu1YdLrS3nSZ60msOI5dR7H019cv6iDNiS C2UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=WE6tlLeRpMOyo9YUOhtRa6+XwV+oPlj7AqBksvrQGtE=; b=dxtdusa/TytXavjSaDAc9kXXyIAwPtTkChvljeOduKzugvlkqSKOcByUlYsXdMyxLo RQmfZy96OTbwDsphcJkv0Vts7Q4JbqPVYVpLyZjnTmnwA3kkybe62W2NFzaK9qYtOjNV NMfMQE3gDxt48E4KN4a9ZY2Boc7DqMdnTUT0L+pYqUk4Nlfyrf8dvcKVjjh6CcKUuOaL 8f7ZRvxEI9bWl5qnug8Nj2vgFYUyBk6oXvTB+6HFyCYAcqF+T7jMB5DXG1QSvVuWRdbQ 8CZMxcovEJM/Mn/jwwegBbXj1UY+Lc6APOrwMJGqrlEbaPLo6xaRCcyRJ4TNVypqTVQ5 yFpA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532rJivFmbt3FnILAV+BESBORosA3s8qa/ZC9fCEKz/zzD6qe/Qb 5RODd0TZbdabtR4XtAavQOQ= X-Google-Smtp-Source: ABdhPJxih6qWuVDiqYiWBTnCV4qdqd6jOOw8pkdMNX5pCgIqUX1OMChduFb2c5RNbjB26zPVLkN1SQ== X-Received: by 2002:a05:6512:108f:: with SMTP id j15mr5737301lfg.160.1605518105695; Mon, 16 Nov 2020 01:15:05 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:ccc2:: with SMTP id c185ls8048506lfg.3.gmail; Mon, 16 Nov 2020 01:15:04 -0800 (PST) X-Received: by 2002:a19:6a07:: with SMTP id u7mr5947530lfu.252.1605518104407; Mon, 16 Nov 2020 01:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605518104; cv=none; d=google.com; s=arc-20160816; b=dG42cF0J0c4gxAbTv847dDDrWxyNtj0ZE3bdD3ZLdub0osMsHdWs8gtavP8R+eVM2Y hh2895WXIyzYBBHJJxL8H4/pHrbmLjgUrErmcuFNA2/smSyXbectzXKt7WWAPJLiMUGF f2qPZ2fuD+hyMYPew5TAZ6h9A9BoM6ZbYQ5Q5rrKKFh/mvGo3wcpvyCoc8N82z91nsWR FYq/5/5rDpbkUmjKqwfngsQS/dIXMnX8yX1iTn3jVMhpH/kYoOszY8qw0MbhbIGWTggR w6oc53QqZbkR8kOK98fQ2MZuBy8xW149K3U4VwVLyfue69ArepisAu4B46TM2sK7dhdU URnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ieubZbmjBRnaYQOhHDslsZEoU2dHyP+F7YdbF5NpKZY=; b=L8Qjfl5kN7oRbaslwZqndmzV2TmmvcuJQfscr2xwik02DqSW+sQq53yExWbeh2iRv4 C7xeccJ9yPSwxNHzYl9T8a0AK94y2/34d6XsilLUgBVztQ48IMr+M0ZhAmGSXPltYRlY mCqh8W8eVIcI+6Mbir/4VMVXNnHwVKSWYPXDmJsMEulUwDKznQM1Fyqp/ZkRfIUINHRy nEJjf9MkVfodIZ2KWB9LMJkuYixsgpDO0P/9NEtZYUWyjivIomyzB++s1rm2rX+dC5re EaAjN3oYhJ8Cb+7rMw3/v3bliA6iTmz10IXTLFMeQ9yCEbOaUwnEQoZSQzzsQ1gQXNgV QdDg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id o13si437256lfo.5.2020.11.16.01.15.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Nov 2020 01:15:04 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4CZNh76f6hz1qsZv; Mon, 16 Nov 2020 10:15:03 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4CZNh76QQmz1qs0c; Mon, 16 Nov 2020 10:15:03 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id cXSZvxWRaapG; Mon, 16 Nov 2020 10:15:02 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Mon, 16 Nov 2020 10:15:02 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id DFFA64540859; Mon, 16 Nov 2020 10:15:00 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 67F0Ch_kQ-Sv; Mon, 16 Nov 2020 10:14:57 +0100 (CET) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.64]) by babic.homelinux.org (Postfix) with ESMTP id D723945408FE; Mon, 16 Nov 2020 10:14:49 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH V3 04/10] IPC: rework install IPC for future extensions Date: Mon, 16 Nov 2020 10:14:39 +0100 Message-Id: <20201116091445.797119-5-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201116091445.797119-1-sbabic@denx.de> References: <20201116091445.797119-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The IPC was originally very simple and used just to send a SWU to SWUpdate. Later, additional features were added to communicate with internal SWUpdate's processes, like suricatta or the installer. The same message for install was (mis)used, letting the interface quite confused. Adding new commands is then difficult, because changes in the messages mean changes in more subsystems.This patch addresses all these topics. The message used to communicate with processes is renamed to "procmsg" from "instmsg", but without changing its fields. A new "instmsg" is created from scratch and this contains an "install request" structuire, that the originator must fill with setup for the installation. Each interface is updated to the new interface. The API ro external processes is changed, but it will contain a field to track the API version and to allow to have compatibility layers in future to avoid further breakages. The "install request" is thought to add more information as in the past, and to allow to change an installation per instance, while most parameters are now set just at the startup via configuration file or command line parameters. Signed-off-by: Stefano Babic --- core/network_thread.c | 20 ++++-------- core/stream_interface.c | 8 ++--- corelib/channel_curl.c | 7 +++-- corelib/downloader.c | 1 + include/installer_priv.h | 6 ++-- include/network_ipc.h | 40 ++++++++++++++---------- ipc/network_ipc.c | 57 ++++++++++++++++------------------ mongoose/mongoose_interface.c | 3 +- suricatta/server_hawkbit.c | 14 ++++----- suricatta/suricatta.c | 6 ++-- tools/swupdate-hawkbitcfg.c | 20 ++++++------ tools/swupdate-sendtohawkbit.c | 12 +++---- 12 files changed, 97 insertions(+), 97 deletions(-) diff --git a/core/network_thread.c b/core/network_thread.c index 2c383b7..a3c10a0 100644 --- a/core/network_thread.c +++ b/core/network_thread.c @@ -263,7 +263,7 @@ void *network_thread (void *data) switch (msg.type) { case POST_UPDATE: if (postupdate(get_swupdate_cfg(), - msg.data.instmsg.len > 0 ? msg.data.instmsg.buf : NULL) == 0) { + msg.data.procmsg.len > 0 ? msg.data.procmsg.buf : NULL) == 0) { msg.type = ACK; sprintf(msg.data.msg, "Post-update actions successfully executed."); } else { @@ -279,14 +279,14 @@ void *network_thread (void *data) * the payload */ - pipe = pctl_getfd_from_type(msg.data.instmsg.source); + pipe = pctl_getfd_from_type(msg.data.procmsg.source); if (pipe < 0) { ERROR("Cannot find channel for requested process"); msg.type = NACK; break; } TRACE("Received Message for %s", - pctl_getname_from_type(msg.data.instmsg.source)); + pctl_getname_from_type(msg.data.procmsg.source)); if (fcntl(pipe, F_GETFL) < 0 && errno == EBADF) { ERROR("Pipe not available or closed: %d", pipe); msg.type = NACK; @@ -316,10 +316,10 @@ void *network_thread (void *data) FD_ZERO(&pipefds); FD_SET(pipe, &pipefds); tv.tv_usec = 0; - if (!msg.data.instmsg.timeout) + if (!msg.data.procmsg.timeout) tv.tv_sec = DEFAULT_INTERNAL_TIMEOUT; else - tv.tv_sec = msg.data.instmsg.timeout; + tv.tv_sec = msg.data.procmsg.timeout; ret = select(pipe + 1, &pipefds, NULL, NULL, &tv); /* @@ -349,15 +349,7 @@ void *network_thread (void *data) TRACE("Incoming network request: processing..."); if (instp->status == IDLE) { instp->fd = ctrlconnfd; - instp->source = msg.data.instmsg.source; - - /* - * Communicate if a dry run is asked and set it - */ - if (msg.type == REQ_INSTALL_DRYRUN) - instp->dry_run = 1; - else - instp->dry_run = 0; + instp->req = msg.data.instmsg.req; /* * Prepare answer diff --git a/core/stream_interface.c b/core/stream_interface.c index 633116d..e7298d9 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -500,7 +500,7 @@ void *network_initializer(void *data) /* * Check if the dry run flag is overwritten */ - if (inst.dry_run) + if (inst.req.dry_run) software->globals.dry_run = 1; else software->globals.dry_run = 0; @@ -606,9 +606,9 @@ void *network_initializer(void *data) */ int get_install_info(sourcetype *source, char *buf, size_t len) { - len = min(len, inst.len); - memcpy(buf, inst.data, len); - *source = inst.source; + len = min(len - 1, strlen(inst.req.info)); + strncpy(buf, inst.req.info, len); + *source = inst.req.source; return len; } diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 5c80770..bf39063 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -1040,8 +1040,11 @@ channel_op_res_t channel_get_file(channel_t *this, void *data) struct swupdate_request req; swupdate_prepare_req(&req); req.dry_run = channel_data->dry_run; - req.len = channel_data->info == NULL ? 0 : strlen(channel_data->info); - req.info = channel_data->info; + req.source = channel_data->source; + if (channel_data->info) { + strncpy(req.info, channel_data->info, + sizeof(req.info) - 1 ); + } for (int retries = 3; retries >= 0; retries--) { file_handle = ipc_inst_start_ext(channel_data->source, &req, sizeof(struct swupdate_request)); diff --git a/corelib/downloader.c b/corelib/downloader.c index 462d379..cda5cb1 100644 --- a/corelib/downloader.c +++ b/corelib/downloader.c @@ -49,6 +49,7 @@ static RECOVERY_STATUS download_from_url(channel_data_t* channel_data) TRACE("Image download started : %s", channel_data->url); RECOVERY_STATUS result = SUCCESS; + channel_data->source = SOURCE_DOWNLOADER; channel_op_res_t chanresult = channel->get_file(channel, channel_data); if (chanresult != CHANNEL_OK) { result = FAILURE; diff --git a/include/installer_priv.h b/include/installer_priv.h index 9322a68..1a7013a 100644 --- a/include/installer_priv.h +++ b/include/installer_priv.h @@ -9,6 +9,7 @@ #define _INSTALLER_PRIV_H #include "swupdate_status.h" +#include "network_ipc.h" struct installer { int fd; /* install image file handle */ @@ -16,10 +17,7 @@ struct installer { RECOVERY_STATUS last_install; /* result from last installation */ int last_error; /* error code if installation failed */ char errormsg[64]; /* error message if installation failed */ - sourcetype source; /* Who triggered the update */ - int dry_run; /* set it if no changes in hardware must be done */ - unsigned int len; /* Len of data valid in info, data is optional */ - char data[2048]; /* This is a placeholder for installation request */ + struct swupdate_request req; }; #endif diff --git a/include/network_ipc.h b/include/network_ipc.h index 18da134..238709f 100644 --- a/include/network_ipc.h +++ b/include/network_ipc.h @@ -49,6 +49,21 @@ enum { CMD_ENABLE /* Enable or disable suricatta mode */ }; +#define SWUPDATE_API_VERSION 0x1 +/* + * Install structure to be filled before calling + * ipc and async functions + */ +struct swupdate_request { + unsigned int apiversion; + sourcetype source; + bool dry_run; + size_t len; + char info[512]; + char software_set[256]; + char running_mode[256]; +}; + typedef union { char msg[128]; struct { @@ -57,6 +72,14 @@ typedef union { int error; char desc[2048]; } status; + struct { + struct swupdate_request req; + unsigned int len; /* Len of data valid in buf */ + char buf[2048]; /* + * Buffer that each source can fill + * with additional information + */ + } instmsg; struct { sourcetype source; /* Who triggered the update */ int cmd; /* Optional encoded command */ @@ -66,7 +89,7 @@ typedef union { * Buffer that each source can fill * with additional information */ - } instmsg; + } procmsg; struct { char key_ascii[65]; /* Key size in ASCII (256 bit, 32 bytes bin) + termination */ char ivt_ascii[33]; /* Key size in ASCII (16 bytes bin) + termination */ @@ -79,21 +102,6 @@ typedef struct { msgdata data; } ipc_message; -#define SWUPDATE_API_VERSION 0x1 -/* - * Install structure to be filled before calling - * ipc and async functions - */ -struct swupdate_request { - unsigned int apiversion; - int type; - bool dry_run; - size_t len; - const char *info; - char *software_set; - char *running_mode; -}; - char *get_ctrl_socket(void); int ipc_inst_start(void); int ipc_inst_start_ext(sourcetype source, void *priv, ssize_t size); diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c index d817ffc..71bbb50 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -72,20 +72,20 @@ int ipc_postupdate(ipc_message *msg) { ssize_t ret; char* tmpbuf = NULL; - if (msg->data.instmsg.len > 0) { - if ((tmpbuf = strndupa(msg->data.instmsg.buf, - msg->data.instmsg.len > sizeof(msg->data.instmsg.buf) - ? sizeof(msg->data.instmsg.buf) - : msg->data.instmsg.len)) == NULL) { + if (msg->data.procmsg.len > 0) { + if ((tmpbuf = strndupa(msg->data.procmsg.buf, + msg->data.procmsg.len > sizeof(msg->data.procmsg.buf) + ? sizeof(msg->data.procmsg.buf) + : msg->data.procmsg.len)) == NULL) { close(connfd); return -1; } } memset(msg, 0, sizeof(*msg)); if (tmpbuf != NULL) { - msg->data.instmsg.buf[sizeof(msg->data.instmsg.buf) - 1] = '\0'; - strncpy(msg->data.instmsg.buf, tmpbuf, sizeof(msg->data.instmsg.buf) - 1); - msg->data.instmsg.len = strnlen(tmpbuf, sizeof(msg->data.instmsg.buf) - 1); + msg->data.procmsg.buf[sizeof(msg->data.procmsg.buf) - 1] = '\0'; + strncpy(msg->data.procmsg.buf, tmpbuf, sizeof(msg->data.procmsg.buf) - 1); + msg->data.procmsg.len = strnlen(tmpbuf, sizeof(msg->data.procmsg.buf) - 1); } msg->magic = IPC_MAGIC; msg->type = POST_UPDATE; @@ -181,18 +181,28 @@ int ipc_inst_start_ext(sourcetype source, void *priv, ssize_t size) int connfd; ipc_message msg; ssize_t ret; - bool dry_run = false; - struct swupdate_request *req = NULL; - size_t len = 0; - const char *buf = NULL; + struct swupdate_request *req; + struct swupdate_request localreq; + if (priv) { + /* + * To be expanded: in future if more API will + * be supported, a conversion will be take place + * to send to the installer a single identifiable + * request + */ if (size != sizeof(struct swupdate_request)) return -EINVAL; req = (struct swupdate_request *)priv; - dry_run = req->dry_run; - len = req->len; - buf = req->info; + } else { + /* + * ensure that a valid install request + * reaches the installer, add an empty + * one with default values + */ + swupdate_prepare_req(&localreq); + req = &localreq; } connfd = prepare_ipc(); if (connfd < 0) @@ -204,22 +214,9 @@ int ipc_inst_start_ext(sourcetype source, void *priv, ssize_t size) * Command is request to install */ msg.magic = IPC_MAGIC; - msg.type = (!dry_run) ? REQ_INSTALL : REQ_INSTALL_DRYRUN; - - /* - * Pass data from interface originating - * the update, if any - */ - msg.data.instmsg.source = source; - if (len > sizeof(msg.data.instmsg.buf)) - len = sizeof(msg.data.instmsg.buf); - if (!source) { - msg.data.instmsg.len = 0; - } else { - msg.data.instmsg.len = len; - memcpy(msg.data.instmsg.buf, buf, len); - } + msg.type = REQ_INSTALL; + msg.data.instmsg.req = *req; ret = write(connfd, &msg, sizeof(msg)); if (ret != sizeof(msg)) { close(connfd); diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index d34262b..8bb41bf 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -291,7 +291,8 @@ static void upload_handler(struct mg_connection *nc, int ev, void *p) struct swupdate_request req; swupdate_prepare_req(&req); req.len = strlen(mp->file_name); - req.info = mp->file_name; + strncpy(req.info, mp->file_name, sizeof(req.info) - 1); + req.source = SOURCE_WEBSERVER; fus->fd = ipc_inst_start_ext(SOURCE_WEBSERVER, &req, sizeof(req)); if (fus->fd < 0) { mg_http_send_error(nc, 500, "Failed to queue command"); diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index db82ac8..5373db5 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -1843,8 +1843,8 @@ static server_op_res_t server_activation_ipc(ipc_message *msg) update_state_t update_state = STATE_NOT_AVAILABLE; struct json_object *json_root; - json_root = server_tokenize_msg(msg->data.instmsg.buf, - sizeof(msg->data.instmsg.buf)); + json_root = server_tokenize_msg(msg->data.procmsg.buf, + sizeof(msg->data.procmsg.buf)); if (!json_root) return SERVER_EERR; @@ -1942,7 +1942,7 @@ static server_op_res_t server_activation_ipc(ipc_message *msg) } } - msg->data.instmsg.len = 0; + msg->data.procmsg.len = 0; cleanup: free(details); @@ -1956,8 +1956,8 @@ static server_op_res_t server_configuration_ipc(ipc_message *msg) unsigned int polling; json_object *json_data; - json_root = server_tokenize_msg(msg->data.instmsg.buf, - sizeof(msg->data.instmsg.buf)); + json_root = server_tokenize_msg(msg->data.procmsg.buf, + sizeof(msg->data.procmsg.buf)); if (!json_root) return SERVER_EERR; @@ -1979,7 +1979,7 @@ server_op_res_t server_ipc(ipc_message *msg) { server_op_res_t result = SERVER_OK; - switch (msg->data.instmsg.cmd) { + switch (msg->data.procmsg.cmd) { case CMD_ACTIVATION: result = server_activation_ipc(msg); break; @@ -1996,7 +1996,7 @@ server_op_res_t server_ipc(ipc_message *msg) } else msg->type = ACK; - msg->data.instmsg.len = 0; + msg->data.procmsg.len = 0; return SERVER_OK; } diff --git a/suricatta/suricatta.c b/suricatta/suricatta.c index e5f8cc4..9e07efb 100644 --- a/suricatta/suricatta.c +++ b/suricatta/suricatta.c @@ -46,8 +46,8 @@ static server_op_res_t suricatta_enable(ipc_message *msg) struct json_object *json_root; json_object *json_data; - json_root = server_tokenize_msg(msg->data.instmsg.buf, - sizeof(msg->data.instmsg.buf)); + json_root = server_tokenize_msg(msg->data.procmsg.buf, + sizeof(msg->data.procmsg.buf)); if (!json_root) { msg->type = NACK; ERROR("Wrong JSON message, see documentation"); @@ -92,7 +92,7 @@ static server_op_res_t suricatta_ipc(int fd, time_t *seconds) if (ret != sizeof(msg)) return SERVER_EERR; - switch (msg.data.instmsg.cmd) { + switch (msg.data.procmsg.cmd) { case CMD_ENABLE: result = suricatta_enable(&msg); /* diff --git a/tools/swupdate-hawkbitcfg.c b/tools/swupdate-hawkbitcfg.c index 3ccc24c..2e5a332 100644 --- a/tools/swupdate-hawkbitcfg.c +++ b/tools/swupdate-hawkbitcfg.c @@ -47,16 +47,16 @@ static void send_msg(ipc_message *msg) { int rc; - fprintf(stdout, "Sending: '%s'", msg->data.instmsg.buf); + fprintf(stdout, "Sending: '%s'", msg->data.procmsg.buf); rc = ipc_send_cmd(msg); fprintf(stdout, " returned %d\n", rc); if (rc == 0) { fprintf(stdout, "Server returns %s\n", (msg->type == ACK) ? "ACK" : "NACK"); - if (msg->data.instmsg.len > 0) { + if (msg->data.procmsg.len > 0) { fprintf(stdout, "Returned message: %s\n", - msg->data.instmsg.buf); + msg->data.procmsg.buf); } } } @@ -80,11 +80,11 @@ int main(int argc, char *argv[]) { } memset(&msg, 0, sizeof(msg)); - msg.data.instmsg.source = SOURCE_SURICATTA; + msg.data.procmsg.source = SOURCE_SURICATTA; msg.type = SWUPDATE_SUBPROCESS; - size = sizeof(msg.data.instmsg.buf); - buf = msg.data.instmsg.buf; + size = sizeof(msg.data.procmsg.buf); + buf = msg.data.procmsg.buf; /* Process options with getopt */ while ((c = getopt_long(argc, argv, "p:edh", @@ -92,12 +92,12 @@ int main(int argc, char *argv[]) { switch (c) { case 'p': opt_p = 1; - msg.data.instmsg.cmd = CMD_CONFIG; + msg.data.procmsg.cmd = CMD_CONFIG; polling_time = strtoul(optarg, NULL, 10); break; case 'e': case 'd': - msg.data.instmsg.cmd = CMD_ENABLE; + msg.data.procmsg.cmd = CMD_ENABLE; opt_e = 1; enable = (c == 'e'); break; @@ -121,12 +121,12 @@ int main(int argc, char *argv[]) { */ if (opt_p) { snprintf(buf, size, "{ \"polling\" : \"%lu\"}", polling_time); - msg.data.instmsg.len = strnlen(buf, size); + msg.data.procmsg.len = strnlen(buf, size); send_msg(&msg); } if (opt_e) { snprintf(buf, size, "{ \"enable\" : %s}", enable ? "true" : "false"); - msg.data.instmsg.len = strnlen(buf, size); + msg.data.procmsg.len = strnlen(buf, size); send_msg(&msg); } diff --git a/tools/swupdate-sendtohawkbit.c b/tools/swupdate-sendtohawkbit.c index 0c65ce4..3701fb9 100644 --- a/tools/swupdate-sendtohawkbit.c +++ b/tools/swupdate-sendtohawkbit.c @@ -43,12 +43,12 @@ int main(int argc, char *argv[]) { } memset(&msg, 0, sizeof(msg)); - msg.data.instmsg.source = SOURCE_SURICATTA; - msg.data.instmsg.cmd = CMD_ACTIVATION; + msg.data.procmsg.source = SOURCE_SURICATTA; + msg.data.procmsg.cmd = CMD_ACTIVATION; msg.type = SWUPDATE_SUBPROCESS; - size = sizeof(msg.data.instmsg.buf); - buf = msg.data.instmsg.buf; + size = sizeof(msg.data.procmsg.buf); + buf = msg.data.procmsg.buf; /* * Build a json string with the command line parameters @@ -91,8 +91,8 @@ int main(int argc, char *argv[]) { else written = snprintf(buf, size, "}"); - fprintf(stdout, "Sending: '%s'", msg.data.instmsg.buf); - msg.data.instmsg.len = strnlen(msg.data.instmsg.buf, sizeof(msg.data.instmsg.buf)); + fprintf(stdout, "Sending: '%s'", msg.data.procmsg.buf); + msg.data.procmsg.len = strnlen(msg.data.procmsg.buf, sizeof(msg.data.procmsg.buf)); rc = ipc_send_cmd(&msg);