From patchwork Wed Sep 6 07:23:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 810413 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:400c:c09::238; helo=mail-wm0-x238.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbewgx3gqkgqekq6bnfy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Zbgb+fsb"; dkim-atps=neutral Received: from mail-wm0-x238.google.com (mail-wm0-x238.google.com [IPv6:2a00:1450:400c:c09::238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xnFW92lyMz9t3f for ; Wed, 6 Sep 2017 17:26:12 +1000 (AEST) Received: by mail-wm0-x238.google.com with SMTP id x17sf922966wmd.0 for ; Wed, 06 Sep 2017 00:26:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1504682770; cv=pass; d=google.com; s=arc-20160816; b=LCQS3M1r7NZCSbMYNLHOdCzAcazyPhNzx4zrXl6pukSf1IYzmTzJo/avq5EGr4473Q PDbhR+W4gWtbypkP6F04Y/z44HQJVvv7nn9tp2J5H0P9IkmCK64WU/qntxas4CzgOxQx iGROD7eURIZOhn4k4kcmAcccGlhpFXGFrjnzXOs05VYmWw6iBjMdEgUva+5CvqZrO7lq URw6yRmv9E53bihJgwT31eYbhBaPozJY5mlGcCb7mZfBmViwvRAa+UmMeCJ66Afhj48/ 5YNSVVECUu0OZZFEHvWjP+0KRl9jQPJMn+Te2T1Hln9b5qT3wUTwYh5guYkKLLjZSSYT BLSQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=MeTjrxj1AKrnkYR26CyBZ/87oWV/nTx0Yg6j3D1TeOc=; b=tsk9/w7gDijejT6FuB6aKnvLdvjF2mh+7X92YkIxLZWnXMCcM2Lx24I2d+OLgfsqNC ExoSis3jwnDXVpgRyanxfa4m//J7fTR8OH7skV09eIEAXVn9BbDPuOjmqp2FwkDNwtAP FaCBwqRIHx66/+nxJLYi4UPuJTIeLAHLSOB2MTCzHUkYhfIb8KSjh7ZCd+0khRq1vZ6P K1mKnYSr5lHPwh3GKiyarbyBcbNjvoWsd5JOB0UTQllsUc9Iiu72J4vgY8ZkARsaFVih iSDyxnwybxdJ7paq7/mZqain1OMPX8QNkZ3a/VPFQqNA3sxFTO8hcbu5uDIMfgWWb+kp Hnsw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.14 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com 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:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=MeTjrxj1AKrnkYR26CyBZ/87oWV/nTx0Yg6j3D1TeOc=; b=Zbgb+fsb9GWV9hPeI/CsPktxhu+SJDebZ1aKYckQErOV+cck9u3gIY6eRYyHnLvNMX 3g2jhpxaF6YFDrYWXcyluxL//ZRJLjw+rdeIm0Ed/7JjS6HuIZaClYnulUnjtkvd9l9J 3EC3cDGZxicI8MwUWCvpODDWjWdsQcdv4hnSu0Plfdkn8C7F3FpIloeJ7WohKLYAP7c5 m+TCNPlpj1nfYlXwW5fOtTT5OjLQVElKSEc+W/9+ooXkC8dNpyZIiKoowngvL8W22+sc R2Cb/+6U1aXqm3BuJvE1Ym4bH8GfG064L6C1UonKmOLZaHGx9wK4bZILTdqdFmli4enA Ou8w== 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:in-reply-to:references: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=MeTjrxj1AKrnkYR26CyBZ/87oWV/nTx0Yg6j3D1TeOc=; b=ReQimyOruVwpM4Q3JDX5+Ah9+/0e3b9QWcyTH9LHp7sTCGxgKmISq8PY9BT3PqJkVM 5z4CA6FtfQ4imOyeOIWnDf2fjCIt+qvdtA5+K/TqJ3/qTiiqfDS5RRfMdfsL+i67Lc0L WOLeGweLnp0A9rJaR9E79kmp2JPh2wz3D6Sr/KNPbWFOOCWl2XhkSHh+Bp2iBtEKvivg qCdDGoPaCt9vfvBwfM7N0fra+gkeF2LZz4Bg5WjXG4h7o429AkVoQ2TQ9lXiXslHcsdg E2DMtTcjyhSymTa4qd5JLnieBG0MMUjx9+dFGNFjRJaPqonKIkxOVt+R+L/W6khh+6tZ gQ8w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AHPjjUihZSb+K2KPtzcBP186rvVwY/yOfbnT4Dk2KSUst2rLWhYtIz4x c0VjDVxF4abg1Q== X-Google-Smtp-Source: ADKCNb76C2ElHGC25739RQHirK6WkhlQ2holEwhbY+i9fffGvO3AX1jOBDBi3UPrEk7dE8ZkETLXdw== X-Received: by 10.28.60.133 with SMTP id j127mr1277wma.27.1504682770369; Wed, 06 Sep 2017 00:26:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.214.213 with SMTP id n204ls2185731wmg.25.canary-gmail; Wed, 06 Sep 2017 00:26:09 -0700 (PDT) X-Received: by 10.223.138.151 with SMTP id y23mr82928wry.21.1504682769902; Wed, 06 Sep 2017 00:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504682769; cv=none; d=google.com; s=arc-20160816; b=LOg6yN/ggUweNk7AEzRwiGwkK5MxZL7MmKJlHJFGnL1cLQzRdV324+sNhj+m7uTNrQ HV1cE2rUVXZ+r3yTQk1KCb7+U+lprgSzLnrdxyEy3LoIFvzUNG72wkGzDtz6wl6fFEZ2 S/nmvGPV+FJfCszIKVLRJUr8rRmTDjGKcrU+frcfZhjA1h01pKbxsWjQdKJp0B0vlCtv L11Y1DkpDUzheFz/x/J4YcMFXVXImEjr5GLNaof+aEW7uyAPcHfjccyRqPcHUQ9f+vhW WaIbinSRTTopP0L358JErdSomYfOXMKlc9+v9JO9chgGO56wtiAZO5wvPPPpDooSmIaO Yisw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9x+7GUkHRq1R0Ib7j1ZTntFZ/Oobl4p1Jy/xDnciGGA=; b=XIkNjMp34gr4TdcETeKbgbq6I7B9tZ0aZ1JdnbCSk1mTFdVVgOLs2FmpQqv8NExgYe d1QhGi4yK4ijOyRIQtm8tyPlKVgGJqCDrNUE08tD1bfc40/NqSFA95RWZsCrQZttz5fB n0xPBcQLMpipwzDb/Xd8LehrMMMZpP8d0YjDuZugDXZ0wPLu7L55F6PLH6crAwAfuY10 v5PcClOdv3kHdjaBz2NTGlJeoRFpnmYj68x5mP2INGc1mYTXxcuscSSi4lrTBNgo7rGo e5y1kPNO5+y3obI5VYyKSW5gllb8oGgYXY+e1cRFIigLXqlUij/rHrA9W69unTxSJDRR +Erg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.14 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id l133si45065wmb.3.2017.09.06.00.26.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 00:26:09 -0700 (PDT) Received-SPF: neutral (google.com: 192.35.17.14 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) client-ip=192.35.17.14; Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id v867Q9m8021208 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 6 Sep 2017 09:26:09 +0200 Received: from MD1KR9XC.ad001.siemens.net ([139.25.69.251]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id v867Q9gP028166; Wed, 6 Sep 2017 09:26:09 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 6/6] socket split: adapt tools Date: Wed, 6 Sep 2017 09:23:24 +0200 Message-Id: <20170906072324.15734-6-christian.storm@siemens.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170906072324.15734-1-christian.storm@siemens.com> References: <20170906072324.15734-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 192.35.17.14 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com 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: , Adapt the tool executables to use the introduced progress_ipc{.c,.h} and to respect a --socket command line switch to point them to the socket location in case the configuration deviates from the default. Signed-off-by: Christian Storm --- tools/hawkbitcfg.c | 32 ++++++++++++++++++++++++++--- tools/progress.c | 52 +++++++++-------------------------------------- tools/sendtohawkbit.c | 56 +++++++++++++++++++++++++++++++++++---------------- 3 files changed, 77 insertions(+), 63 deletions(-) diff --git a/tools/hawkbitcfg.c b/tools/hawkbitcfg.c index b6c2122..6f0bc54 100644 --- a/tools/hawkbitcfg.c +++ b/tools/hawkbitcfg.c @@ -32,12 +32,19 @@ #include #include #include +#include #include "network_ipc.h" static void usage(char *program) { - printf("%s ..\n", program); + printf("%s [-s ] ..\n", program); } +static struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"socket", required_argument, NULL, 's'}, + {NULL, 0, NULL, 0} +}; + /* * Simple example, it does nothing but calling the library */ @@ -47,7 +54,26 @@ int main(int argc, char *argv[]) { size_t size; char *buf; - if (argc < 2) { + int c; + + while ((c = getopt_long(argc, argv, "hs:", + long_options, NULL)) != EOF) { + switch (c) { + case 's': + SOCKET_CTRL_PATH = strdup(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + usage(argv[0]); + exit(1); + break; + } + } + + if ((argc - optind) < 1) { usage(argv[0]); exit(1); } @@ -67,7 +93,7 @@ int main(int argc, char *argv[]) { * case of failure */ - snprintf(buf, size, "{ \"polling\" : \"%lu\"}", strtoul(argv[1], NULL, 10)); + snprintf(buf, size, "{ \"polling\" : \"%lu\"}", strtoul(argv[optind], NULL, 10)); fprintf(stdout, "Sending: '%s'", msg.data.instmsg.buf); diff --git a/tools/progress.c b/tools/progress.c index fe9f8ef..4db0b22 100644 --- a/tools/progress.c +++ b/tools/progress.c @@ -36,7 +36,7 @@ #include #include -#include +#include #define PSPLASH_MSG_SIZE 64 @@ -76,6 +76,7 @@ static struct option long_options[] = { {"reboot", no_argument, NULL, 'r'}, {"wait", no_argument, NULL, 'w'}, {"color", no_argument, NULL, 'c'}, + {"socket", required_argument, NULL, 's'}, {NULL, 0, NULL, 0} }; @@ -89,6 +90,7 @@ static void usage(char *programname) " -r, --reboot : reboot after a successful update\n" " -w, --wait : wait for a connection with SWUpdate\n" " -p, --psplash : send info to the psplash process\n" + " -s, --socket : path to progress IPC socket\n" " -h, --help : print this help and exit\n" ); } @@ -177,45 +179,10 @@ static void psplash_progress(char *pipe, struct progress_msg *pmsg) free(buf); } -static int connect_to_swupdate(int reconnect) -{ - struct sockaddr_un servaddr; - int fd, ret; - - /* - * The thread read from swupdate progress thread - * and forward messages to psplash - */ - fd = socket(AF_LOCAL, SOCK_STREAM, 0); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sun_family = AF_LOCAL; - strcpy(servaddr.sun_path, SOCKET_PROGRESS_PATH); - - fprintf(stdout, "Trying to connect to SWUpdate...\n"); - - /* Connection to SWUpdate */ - do { - ret = connect(fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); - if (ret == 0) - break; - if (!reconnect) { - fprintf(stderr, "no communication with swupdate\n"); - exit(1); - } - - usleep(10000); - } while (1); - - fprintf(stdout, "Connected\n"); - - return fd; -} - int main(int argc, char **argv) { int connfd; struct progress_msg msg; - int ret; const char *tmpdir; char psplash_pipe_path[256]; int psplash_ok = 0; @@ -231,7 +198,7 @@ int main(int argc, char **argv) RECOVERY_STATUS status = IDLE; /* Update Status (Running, Failure) */ /* Process options with getopt */ - while ((c = getopt_long(argc, argv, "cwprh", + while ((c = getopt_long(argc, argv, "cwprhs:", long_options, NULL)) != EOF) { switch (c) { case 'c': @@ -246,6 +213,9 @@ int main(int argc, char **argv) case 'r': opt_r = 1; break; + case 's': + SOCKET_PROGRESS_PATH = strdup(optarg); + break; case 'h': usage(argv[0]); exit(0); @@ -266,14 +236,10 @@ int main(int argc, char **argv) connfd = -1; while (1) { if (connfd < 0) { - connfd = connect_to_swupdate(opt_w); + connfd = progress_ipc_connect(opt_w); } - ret = read(connfd, &msg, sizeof(msg)); - if (ret != sizeof(msg)) { - fprintf(stdout, "Connection closing..\n"); - close(connfd); - connfd = -1; + if (progress_ipc_receive(&connfd, &msg) == -1) { continue; } diff --git a/tools/sendtohawkbit.c b/tools/sendtohawkbit.c index c866507..2f8e34b 100644 --- a/tools/sendtohawkbit.c +++ b/tools/sendtohawkbit.c @@ -32,15 +32,22 @@ #include #include #include +#include #include "network_ipc.h" static void usage(char *program) { - printf("%s ..\n", program); + printf("%s [-s ] ..\n", program); } int fd; int verbose = 1; +static struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"socket", required_argument, NULL, 's'}, + {NULL, 0, NULL, 0} +}; + /* * Simple example, it does nothing but calling the library */ @@ -49,8 +56,26 @@ int main(int argc, char *argv[]) { ipc_message msg; size_t size; char *buf; + int c; + + while ((c = getopt_long(argc, argv, "hs:", + long_options, NULL)) != EOF) { + switch (c) { + case 's': + SOCKET_CTRL_PATH = strdup(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + usage(argv[0]); + exit(1); + break; + } + } - if (argc < 3) { + if ((argc - optind) < 2) { usage(argv[0]); exit(1); } @@ -69,26 +94,23 @@ int main(int argc, char *argv[]) { * An error or a NACK is returned in * case of failure */ - for (i = 1; i < argc; i++) { - switch (i) { - case 1: + for (i = optind; i < argc; i++) { + if (i == optind) { written = snprintf(buf, size, "{ \"id\" : \"%lu\"", strtoul(argv[i], NULL, 10)); - break; - case 2: + } else + if (i == optind+1) { written = snprintf(buf, size, ", \"status\" : \"%s\"", argv[i]); - break; - case 3: + } else + if (i == optind+2) { written = snprintf(buf, size, ",\"finished\" : \"%s\"", argv[i]); - break; - case 4: + } else + if (i == optind+3) { written = snprintf(buf, size, ",\"execution\" : \"%s\"", argv[i]); - break; - case 5: + } else + if (i == optind+4) { written = snprintf(buf, size, ",\"details\" : [ \"%s\"", argv[i]); - break; - default: + } else { written = snprintf(buf, size, ",\"%s\"", argv[i]); - break; } buf += written; @@ -98,7 +120,7 @@ int main(int argc, char *argv[]) { break; } - if (i > 4) + if (i > optind+4) written = snprintf(buf, size, "]}"); else written = snprintf(buf, size, "}");