@@ -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);
@@ -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);
@@ -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)) {
@@ -15,6 +15,7 @@
* headers are not exported.
*/
+#include <stdbool.h>
#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
@@ -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 */
};
@@ -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;
@@ -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);
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
+#include <stdbool.h>
#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);
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 <sbabic@denx.de> --- 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(-)