From patchwork Thu Jun 28 05:33:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 935942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::23a; helo=mail-lf0-x23a.google.com; envelope-from=swupdate+bncbcxploxj6ikrbo7g2hmqkgqeqiz3pwy@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.b="AkzpyzQg"; dkim-atps=neutral Received: from mail-lf0-x23a.google.com (mail-lf0-x23a.google.com [IPv6:2a00:1450:4010:c07::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41GT3N0CGqz9ryt for ; Thu, 28 Jun 2018 15:33:51 +1000 (AEST) Received: by mail-lf0-x23a.google.com with SMTP id l136-v6sf1166192lfg.3 for ; Wed, 27 Jun 2018 22:33:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1530164029; cv=pass; d=google.com; s=arc-20160816; b=KBXh/JzAvOUJ58YopMU1LU+S2Ff15OD8//AnwJyyS7ia4E9zqPbk3d6g+h9JTA3Ogo PSUuBdq0NEhQ2puIHPga3nu/eX0Gvhx4zG7H8KDCRSp2v9475/+0gesfRRMKXxCupDBc CdkHkMJRrWsIYzT5TDoarRSOb5q7ehPu/7HIKSaPflsHcGjHPx55B4CRcKwcxnj43oAf /JhE23BxIIsjNUCQSjIT5BLaGumRPGG4zV0DnwElA7CVv7ppaQBwwMyPBQ6QnDPj3J2Q eaTnrAflZPCsjT88ADC76EP0N/d3Aa23acZ2FdIxX80hVpv52Hxy+nEo+b1NBKlvVJ7q a/jg== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=cL6W1uxyTqUns/BIH4+tM7ADN7yJdMnNz94lxbTy3os=; b=EbHY6Hpk4cITDqmyLI/P/wUK5su6kZVxP4dp4E777Ji2rEaq0dgi6DG7qAVTiygvTb oifuad/rdrwM3NAW1PA4fSqNab+9TnNepdLd/3s0QEVLqEG60APHEqVwA67MKl+8cO2i H27D9kO9I7ModebXkJXak6OvJR50iewmuwIKV1oLImrXURXpHlqN5NWqPygoh3sOwogm BCurDGJEjKTZ2ES24hJABmwxn4siU05Bw+0O6QQiIpa67A0f6XBSu5KFlAIyoqnaNqjN fqsCwXP5UOf0grYICb5jyYH4h71ZJebBa0pWEK92B6rzrWjqOlAofsuUegd54CXveP85 jpug== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 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:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=cL6W1uxyTqUns/BIH4+tM7ADN7yJdMnNz94lxbTy3os=; b=AkzpyzQg7qJm/qLqPaibV/YeFQMuqABja1yG9Bo6Hd2g+Uar+LrX5bRswrPbjt2KmI D54nrM9I97VdnMCgZdF/mDS8DhSpf+0SAOdgrRz1DjgfXs7mUm56b1talNPJyhRVbZ1T Zqe9v+Izc3Zf9+aEhGzmeaPnIbqz0gpaXZi7aGUnOkOKe1KD1ANdDa4HyCusvU2vFRMw 3pIMtdhgxgMhvj9jG7p/h3PZM7Wvv5PQIz/yMw2AfPnf5vxylm7kWoJGZAFaxgI9SbM+ EdVe4YLSZ1b5xW0v+DER4Xm9Sj0SbBgnApOzBs6CzLUw/oKuNskLsO+zkGPF3gVtkh24 jTzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id: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=cL6W1uxyTqUns/BIH4+tM7ADN7yJdMnNz94lxbTy3os=; b=ioKwgGUlcJi1i6N0EwdyHsYrJ+ZMuCmNh4PHZzmTa6yQoJGMARDMWXlO0lZS6soljT R7Z3TniwN9Zjc5hBN9hwjEnH7CsLLopRNofzq+Lq5yNwmiHVYlmRXYkhVg83KxdwY/d+ 9PaM2fr26+1uO60T0vstJVptbRid6n1V4VMHM6jjrni1BHZpPZmTjn8pd1ggoN899big 51QWoXKChy2P/bta7BTiJzQEwbuGXf7gxZ+gA7ELnTiNyxP3aF94/bGGpq4XJf1cWR/S DJgXt1PPyRWk9KIjo7JieRLN7oQ0xkBOBXtOasC0FdK0N7/G/Kp0tCBWiQauwyqEiPWQ YgJQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: APt69E11mT6vZSOpvUo8FXL/uigD8uJ7cVgkDXBx23I03abREKxv9Vo+ r4UPPAxJC+utLsoDPc09wQ4= X-Google-Smtp-Source: ADUXVKLYzG8HpEufIqpNcQ0mnr9c8/h9f/JO1S4DjsaakB7IdvcduyAvW9v1K9L6naA4lPynPA2EkQ== X-Received: by 2002:a2e:9f12:: with SMTP id u18-v6mr38362ljk.7.1530164029154; Wed, 27 Jun 2018 22:33:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:240b:: with SMTP id k11-v6ls884230ljk.14.gmail; Wed, 27 Jun 2018 22:33:47 -0700 (PDT) X-Received: by 2002:a2e:83cf:: with SMTP id s15-v6mr471982ljh.28.1530164027590; Wed, 27 Jun 2018 22:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530164027; cv=none; d=google.com; s=arc-20160816; b=hFEN6raiwh9iAOsK9nxQ3TwoizjaHNV8QKZLQJZ1ntMoYvNxgsxL88xqkzjkCKKdsa rK11dQGAEKFvcg+JYEF1ybHT+QzxH7wBnaQ2gTyTxjFIBihpMM86sbHHEobfIlP6nU4w aVwnWIjp8nYQqGOAjX9/+CJ+afCHSMIyRIdrQJNiHjhlK7Db84/AQ4dhi3SKnHg5opB3 i6Jdwv2hMGLOFFkqaIMKS9UaEvMR/Rwf26fDDRzWOeMzbC4cUfXKlwvt4UuamnO7C5T4 Fg6yAY3JQsUqg2N8Tz1wuPRB2CDo2+BFH31XKxxsJF4mP66Q2gNlv9Zoe7/2CRvnaXgV Oeyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=6EzyCA/x/fBoFE2CJF9MnxHVRS663CmXmqkAGcKIz5k=; b=cvWxuLCZlhuv+EwkRVpz0MHW9fkc1oKX67yHvb62uW3QigGfwxfToCZ+p/pfFt+hnS StV3KiqaFvs078KjYVEWhFIG3HIb6HJLRb/K0/6z8YVdWYXPk0Qy3egbw8kfK3sNxmx9 pDAuTWqW/Rj56k2yPbGHsj9KZMCzqc1AQVBTDaQ0SIGfAZ4knhFyQh5J/h0qnpnQA33o GfqoOWBMNdsjArb3GxVofHf0qOxRDaOEGX7DsGj2/gtOxlLSE/0tRJVWjuQWllSEgtPF 9k4ajSvoY8uy/sZCw/mgO4eC9Hmv4XJlDm/TMjNa9zffyJ70pZFvux21/zXUpSj8h0BV DHtQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 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. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id k22-v6si227725ljg.0.2018.06.27.22.33.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 22:33:47 -0700 (PDT) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 41GT3G6YHJz1qvnv; Thu, 28 Jun 2018 07:33:46 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 41GT3G6JlCz1r3ld; Thu, 28 Jun 2018 07:33:46 +0200 (CEST) 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 SW3iFqYdf3kM; Thu, 28 Jun 2018 07:33:45 +0200 (CEST) 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; Thu, 28 Jun 2018 07:33:45 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 60C934540463; Thu, 28 Jun 2018 07:33:45 +0200 (CEST) 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 VqU6hibnGWIl; Thu, 28 Jun 2018 07:33:43 +0200 (CEST) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id F1BE74540441; Thu, 28 Jun 2018 07:33:42 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] Allow to override the dry-run flag by each install Date: Thu, 28 Jun 2018 07:33:41 +0200 Message-Id: <1530164021-5929-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 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 dryrun flag is set global as command line parameter, but there are use cases where it is desired to set it for each install request. In fact, the install can be first checked using the dryrun flag, and if it was successfully, a normal install is run. This does not apply when the SWU is local and SWUpdate works in one shot, because the dryrun flag can be passed as command line parameter and SWUpdate terminates after its execution. Signed-off-by: Stefano Babic --- corelib/channel_curl.c | 3 ++- corelib/network_thread.c | 10 ++++++++++ corelib/stream_interface.c | 6 ++++++ include/network_ipc.h | 6 ++++-- include/util.h | 1 + ipc/network_ipc.c | 10 +++++----- mongoose/mongoose_interface.c | 4 ++-- tools/client.c | 3 ++- 8 files changed, 32 insertions(+), 11 deletions(-) diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 8077f15..3b6cdb2 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -761,7 +761,8 @@ channel_op_res_t channel_get_file(channel_t *this, void *data) for (int retries = 3; retries >= 0; retries--) { file_handle = ipc_inst_start_ext(channel_data->source, channel_data->info == NULL ? 0 : strlen(channel_data->info), - channel_data->info); + channel_data->info, + false /*no dryrun */); if (file_handle > 0) break; sleep(1); diff --git a/corelib/network_thread.c b/corelib/network_thread.c index e7d0fa2..22d0b67 100644 --- a/corelib/network_thread.c +++ b/corelib/network_thread.c @@ -339,11 +339,21 @@ void *network_thread (void *data) break; case REQ_INSTALL: + case REQ_INSTALL_DRYRUN: TRACE("Incoming network request: processing..."); if (instp->status == IDLE) { instp->fd = ctrlconnfd; instp->source = msg.data.instmsg.source; instp->len = min(msg.data.instmsg.len, sizeof(instp->info)); + + /* + * Communicate if a dryrun is asked and set it + */ + if (msg.type == REQ_INSTALL_DRYRUN) + instp->dry_run = 1; + else + instp->dry_run = 0; + memcpy(instp->info, msg.data.instmsg.buf, instp->len); diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c index 267944f..d9375c1 100644 --- a/corelib/stream_interface.c +++ b/corelib/stream_interface.c @@ -334,6 +334,12 @@ void *network_initializer(void *data) notify(START, RECOVERY_NO_ERROR, INFOLEVEL, "Software Update started !"); /* + * Check if the dryrun flag is overwrittn + */ + if (inst.dry_run) + software->globals.dry_run = 1; + + /* * Check if the stream should be saved */ if (strlen(software->output)) { diff --git a/include/network_ipc.h b/include/network_ipc.h index fd90b1e..ea997b8 100644 --- a/include/network_ipc.h +++ b/include/network_ipc.h @@ -15,6 +15,7 @@ * headers are not exported. */ +#include #include "swupdate_status.h" #define IPC_MAGIC 0x14052001 @@ -26,6 +27,7 @@ typedef enum { GET_STATUS, POST_UPDATE, SWUPDATE_SUBPROCESS, + REQ_INSTALL_DRYRUN, } msgtype; enum { @@ -60,7 +62,7 @@ typedef struct { } ipc_message; int ipc_inst_start(void); -int ipc_inst_start_ext(sourcetype source, size_t len, const char *info); +int ipc_inst_start_ext(sourcetype source, size_t len, const char *info, bool dryrun); int ipc_send_data(int connfd, char *buf, int size); void ipc_end(int connfd); int ipc_get_status(ipc_message *msg); @@ -73,6 +75,6 @@ typedef int (*terminated)(RECOVERY_STATUS status); int ipc_wait_for_complete(getstatus callback); int swupdate_image_write(char *buf, int size); int swupdate_async_start(writedata wr_func, getstatus status_func, - terminated end_func); + terminated end_func, bool dryrun); #endif diff --git a/include/util.h b/include/util.h index f36fa92..48dc538 100644 --- a/include/util.h +++ b/include/util.h @@ -56,6 +56,7 @@ struct installer { 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 */ char info[2048]; /* info */ }; diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c index 37bb124..4cfe2f3 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -144,7 +144,7 @@ int ipc_get_status(ipc_message *msg) return ret; } -int ipc_inst_start_ext(sourcetype source, size_t len, const char *buf) +int ipc_inst_start_ext(sourcetype source, size_t len, const char *buf, bool dryrun) { int connfd; ipc_message msg; @@ -160,7 +160,7 @@ int ipc_inst_start_ext(sourcetype source, size_t len, const char *buf) * Command is request to install */ msg.magic = IPC_MAGIC; - msg.type = REQ_INSTALL; + msg.type = (!dryrun) ? REQ_INSTALL : REQ_INSTALL_DRYRUN; /* * Pass data from interface originating @@ -202,7 +202,7 @@ int ipc_inst_start_ext(sourcetype source, size_t len, const char *buf) */ int ipc_inst_start(void) { - return ipc_inst_start_ext(SOURCE_UNKNOWN, 0, NULL); + return ipc_inst_start_ext(SOURCE_UNKNOWN, 0, NULL, false); } /* @@ -347,7 +347,7 @@ static pthread_t start_ipc_thread(void *(* start_routine) (void *), void *arg) * Only one running request is accepted */ int swupdate_async_start(writedata wr_func, getstatus status_func, - terminated end_func) + terminated end_func, bool dryrun) { struct async_lib *rq; int connfd; @@ -361,7 +361,7 @@ int swupdate_async_start(writedata wr_func, getstatus status_func, rq->get = status_func; rq->end = end_func; - connfd = ipc_inst_start(); + connfd = ipc_inst_start_ext(SOURCE_UNKNOWN, 0, NULL, dryrun); if (connfd < 0) return connfd; diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 65e7a08..2521b30 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -313,7 +313,7 @@ static void upload_handler_v1(struct mg_connection *nc, int ev, void *p) return; } - fd = ipc_inst_start_ext(SOURCE_WEBSERVER, filename->len, filename->p); + fd = ipc_inst_start_ext(SOURCE_WEBSERVER, filename->len, filename->p, false); ipc_send_data(fd, (char *) hm->body.p, hm->body.len); ipc_end(fd); @@ -385,7 +385,7 @@ static void upload_handler(struct mg_connection *nc, int ev, void *p) break; } - fus->fd = ipc_inst_start_ext(SOURCE_WEBSERVER, strlen(mp->file_name), mp->file_name); + fus->fd = ipc_inst_start_ext(SOURCE_WEBSERVER, strlen(mp->file_name), mp->file_name, false); if (fus->fd < 0) { mg_http_send_error(nc, 500, "Failed to queue command"); free(fus); diff --git a/tools/client.c b/tools/client.c index d172b7c..1a59d97 100644 --- a/tools/client.c +++ b/tools/client.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "network_ipc.h" static void usage(void) { @@ -102,7 +103,7 @@ static int send_file(const char* filename) { /* synchronize with a mutex */ pthread_mutex_lock(&mymutex); rc = swupdate_async_start(readimage, printstatus, - end); + end, false); if (rc) printf("swupdate_async_start returns %d\n", rc);