[{"id":1770068,"web_url":"http://patchwork.ozlabs.org/comment/1770068/","msgid":"<a455aa4c-1fb9-d112-0077-c46581463e05@denx.de>","list_archive_url":null,"date":"2017-09-18T10:36:21","subject":"Re: [swupdate] [PATCH] core: unlink socket files on normal\n\ttermination","submitter":{"id":5771,"url":"http://patchwork.ozlabs.org/api/people/5771/","name":"Stefano Babic","email":"sbabic@denx.de"},"content":"On 15/09/2017 13:40, Christian Storm wrote:\n> Currently, the socket files are (re)created on SWUpdate\n> starting but are not unlinked on SWUpdate exiting. Leverage\n> atexit() and a SIGTERM handler to cleanup socket files on\n> normal program termination.\n> \n> Signed-off-by: Christian Storm <christian.storm@siemens.com>\n> ---\n>  core/swupdate.c           | 14 ++++++++++++++\n>  corelib/network_thread.c  | 10 ++++++++++\n>  corelib/progress_thread.c | 10 ++++++++++\n>  3 files changed, 34 insertions(+)\n> \n> diff --git a/core/swupdate.c b/core/swupdate.c\n> index 3057000..e35289e 100644\n> --- a/core/swupdate.c\n> +++ b/core/swupdate.c\n> @@ -483,6 +483,11 @@ static int read_processes_settings(void *settings, void *data)\n>  \treturn 0;\n>  }\n>  \n> +static void sigterm_handler(int __attribute__ ((__unused__)) signum)\n> +{\n> +\tpthread_cancel(network_daemon);\n> +}\n> +\n>  int main(int argc, char **argv)\n>  {\n>  \tint c;\n> @@ -859,6 +864,15 @@ int main(int argc, char **argv)\n>  \t\t}\n>  \t}\n>  \n> +\t/*\n> +\t * Install a handler for SIGTERM that cancels\n> +\t * the network_daemon thread to allow atexit()\n> +\t * registered functions to run.\n> +\t */\n> +\tmemset(&sa, 0, sizeof(sa));\n> +\tsa.sa_handler = sigterm_handler;\n> +\tsigaction(SIGTERM, &sa, NULL);\n> +\n>  \t/*\n>  \t * Go into supervisor loop\n>  \t */\n> diff --git a/corelib/network_thread.c b/corelib/network_thread.c\n> index 6c34614..5ed516e 100644\n> --- a/corelib/network_thread.c\n> +++ b/corelib/network_thread.c\n> @@ -171,6 +171,11 @@ static void empty_pipe(int fd)\n>  \t} while (1);\n>  }\n>  \n> +static void unlink_socket(void)\n> +{\n> +\tunlink((char*)CONFIG_SOCKET_CTRL_PATH);\n> +}\n> +\n>  void *network_thread (void *data)\n>  {\n>  \tstruct installer *instp = (struct installer *)data;\n> @@ -200,6 +205,11 @@ void *network_thread (void *data)\n>  \t\texit(2);\n>  \t}\n>  \n> +\tif (atexit(unlink_socket) != 0) {\n> +\t\tTRACE(\"Cannot setup socket cleanup on exit, %s won't be unlinked.\",\n> +\t\t\t  (char*)CONFIG_SOCKET_CTRL_PATH);\n> +\t}\n> +\n>  \tdo {\n>  \t\tclilen = sizeof(cliaddr);\n>  \t\tif ( (ctrlconnfd = accept(ctrllisten, (struct sockaddr *) &cliaddr, &clilen)) < 0) {\n> diff --git a/corelib/progress_thread.c b/corelib/progress_thread.c\n> index 14d4735..e0a11fe 100644\n> --- a/corelib/progress_thread.c\n> +++ b/corelib/progress_thread.c\n> @@ -183,6 +183,11 @@ void swupdate_progress_done(const char *info)\n>  \tpthread_mutex_unlock(&prbar->lock);\n>  }\n>  \n> +static void unlink_socket(void)\n> +{\n> +\tunlink((char*)CONFIG_SOCKET_PROGRESS_PATH);\n> +}\n> +\n>  void *progress_bar_thread (void __attribute__ ((__unused__)) *data)\n>  {\n>  \tint listen, connfd;\n> @@ -201,6 +206,11 @@ void *progress_bar_thread (void __attribute__ ((__unused__)) *data)\n>  \t\texit(2);\n>  \t}\n>  \n> +\tif (atexit(unlink_socket) != 0) {\n> +\t\tTRACE(\"Cannot setup socket cleanup on exit, %s won't be unlinked.\",\n> +\t\t\t  (char*)CONFIG_SOCKET_PROGRESS_PATH);\n> +\t}\n> +\n>  \tdo {\n>  \t\tclilen = sizeof(cliaddr);\n>  \t\tif ( (connfd = accept(listen, (struct sockaddr *) &cliaddr, &clilen)) < 0) {\n> \n\nApplied to -master, thanks !\n\nBest regards,\nStefano Babic","headers":{"Return-Path":"<swupdate+bncBAABBKOD73GQKGQEM3LN4PI@googlegroups.com>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=googlegroups.com\n\t(client-ip=2a00:1450:4010:c07::239;\n\thelo=mail-lf0-x239.google.com;\n\tenvelope-from=swupdate+bncbaabbkod73gqkgqem3ln4pi@googlegroups.com;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=googlegroups.com header.i=@googlegroups.com\n\theader.b=\"h+wdNut5\"; dkim-atps=neutral"],"Received":["from mail-lf0-x239.google.com (mail-lf0-x239.google.com\n\t[IPv6:2a00:1450:4010:c07::239])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xwj984NzXz9s78\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 20:36:28 +1000 (AEST)","by mail-lf0-x239.google.com with SMTP id c8sf10184lfe.21\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 03:36:28 -0700 (PDT)","by 10.46.76.9 with SMTP id z9ls793034lja.24.gmail; Mon, 18 Sep 2017\n\t03:36:25 -0700 (PDT)","from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9])\n\tby gmr-mx.google.com with ESMTPS id\n\tm74si458565wma.0.2017.09.18.03.36.25\n\tfor <swupdate@googlegroups.com>\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 18 Sep 2017 03:36:25 -0700 (PDT)","from frontend01.mail.m-online.net (unknown [192.168.8.182])\n\tby mail-out.m-online.net (Postfix) with ESMTP id 3xwj950w4nz1rLG1;\n\tMon, 18 Sep 2017 12:36:25 +0200 (CEST)","from localhost (dynscan1.mnet-online.de [192.168.6.70])\n\tby mail.m-online.net (Postfix) with ESMTP id 3xwj950L4sz1qqkW;\n\tMon, 18 Sep 2017 12:36:25 +0200 (CEST)","from mail.mnet-online.de ([192.168.8.182])\n\tby localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new,\n\tport 10024)\n\twith ESMTP id eru--Kp8UeyQ; Mon, 18 Sep 2017 12:36:24 +0200 (CEST)","from babic.homelinux.org\n\t(host-88-217-136-221.customer.m-online.net [88.217.136.221])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby mail.mnet-online.de (Postfix) with ESMTPS;\n\tMon, 18 Sep 2017 12:36:24 +0200 (CEST)","from localhost (mail.babic.homelinux.org [127.0.0.1])\n\tby babic.homelinux.org (Postfix) with ESMTP id B6596454058B;\n\tMon, 18 Sep 2017 12:36:23 +0200 (CEST)","from babic.homelinux.org ([127.0.0.1])\n\tby localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new,\n\tport 10024)\n\twith ESMTP id stlP2Pgen24N; Mon, 18 Sep 2017 12:36:21 +0200 (CEST)","from [192.168.178.132] (papero.fritz.box [192.168.178.132])\n\tby babic.homelinux.org (Postfix) with ESMTP id 5F1AC454057C;\n\tMon, 18 Sep 2017 12:36:21 +0200 (CEST)"],"ARC-Seal":["i=2; a=rsa-sha256; t=1505730985; cv=pass;\n\td=google.com; s=arc-20160816;\n\tb=ned8D7nRytQa+4KKP8IJFjhTRoxf5meWu/mKy5Jy3aWcCVBYgSwrAexyFiQMCV3pi9\n\tG1LCd55SkjwXiGSLIC0SHXPBQawO1Y3Ynuqw6im6zqSCilWPfV/j4XnqMj3PD3Opsp/T\n\thH3CTZePjxEe1LDvooIT/ux0/Y/bULqjfmbU0g74phfZHlOxlnLmL2OcS+fwWOJlQKO+\n\thvRcKq9OlhFCjMb/RYoSAZt4FCdixbQc9uAowzOiP5GATVsKy0ESm3j07ZdXydzwQk79\n\t/5lRWZc+m0lgG5d+rjBNYochFo8Tc1bYgBVnHnh6G7A1EsP3kRxnyYRCHX0RfsVuRixI\n\t7X4w==","i=1; a=rsa-sha256; t=1505730985; cv=none;\n\td=google.com; s=arc-20160816;\n\tb=mYcs3Tcwnz39mBxHtXrsQbE9V/gZcSdj3W4mjuwvEldK2wlhDm9YZ9oXyi0ToXazPs\n\t3U3084CzbBb33evx8XOGMhGJhlbmATsP6Ap2pji9rFNIBnVZHqhBeovP3y92A87l8/zi\n\txQGq+5BDz6ntS0O0TtHQ9eVQkFgV23CVRoM5Zu4vfskYh7lpof8Z2qb3Ri8EIJxPvEN6\n\t3ZdogvRkOdnre9wv+0TPpVRiFCkD8MMRpWQmDXZbdHaE9dKq2Gu2lbL5tA8mmV5vq7cf\n\t19DdOF3Ih+DfrCOk7qGzvL1eN/RCcfj3FtyN1kUv1sRjBzcFBJKd9UeyDDLyuxqz/nFi\n\tjglg=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20160816; \n\th=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n\t:list-id:mailing-list:precedence:content-language:in-reply-to\n\t:mime-version:user-agent:date:message-id:from:references:to:subject\n\t:arc-authentication-results:arc-message-signature:sender\n\t:dkim-signature:arc-authentication-results;\n\tbh=WPgsnvcxUosdZhRVN1y2Tsx2axeGkxXliDuiaZ2nKzM=;\n\tb=XhLLPjUqbJ9E7fV5mMbO6QPLv41oB/iYMWevu9Sj4uz0my+CS1brX0OLc3eLEKxM2b\n\tGJTdVdvYdtRq07wLMl7YuaoxEBioKaeuh8hFzVk/Yn5FmeGIPzaLAZHVLfSmuZx/Rj9F\n\tbL/zFsdntoJykjSSkWUQflLtWKDyDDyi/2fJMwFbuk9jqwiqkoiVkZatuJiOP6inxd5m\n\tUv6EnqnxkBQI0pq7pFhqVPDKCa4R8X3ZLMolTX/gHww9bUZnGRX9LyS7q2XiHRJ3DWBs\n\tsK858vEkw3rnv6w6NbNDi9UaTVytUwN/qqNYgVDvepSnTPnAmJzINby/dQhpT/o6JuCV\n\thzMg==","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20160816; \n\th=content-transfer-encoding:content-language:in-reply-to:mime-version\n\t:user-agent:date:message-id:from:references:to:subject\n\t:arc-authentication-results;\n\tbh=rdHPpLpkFkJak8cca7pVclkf6JTHWhuYXBdanlhGXik=;\n\tb=dV9qZx3KAlUgPIhZhVLUZmrkhcPDgdxgh1hoXa98g3vfFA6HxMPuFU0lz/A5ojGcLY\n\tqpookfx8BAI1ZWdVO4ZVQ05wRMbDl3BOTSQA1IVCJXtv+K+VR4Ef/kCDk7kQDL/oLlxf\n\t4dFRfB71f3OX3UvzMU/w6SBuyhb8tsUZx+xOR5QTW4Yfejwv68MBGaZvSwxkodFNkEQA\n\tzCxpFyDGPc69MU6diCGkQQMyKsutEW79LBpP7nHo5WgMgJ9Kc5QZqb5V8B96r06DHEjl\n\tjIMmkMLMr1NkE8QXx1YBEtJGyNQTnUBG8ArF6tEO2muvv+jUDrJ1K8ELM6q9yRezi33h\n\tBkYg=="],"ARC-Authentication-Results":["i=2; gmr-mx.google.com;\n\tspf=neutral (google.com: 212.18.0.9 is neither permitted nor denied\n\tby best guess record for domain of sbabic@denx.de)\n\tsmtp.mailfrom=sbabic@denx.de","i=1; gmr-mx.google.com;\n\tspf=neutral (google.com: 212.18.0.9 is neither permitted nor denied\n\tby best guess record for domain of sbabic@denx.de)\n\tsmtp.mailfrom=sbabic@denx.de"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=googlegroups.com; s=20161025;\n\th=sender:subject:to:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:x-original-sender\n\t:x-original-authentication-results:precedence:mailing-list:list-id\n\t:list-post:list-help:list-archive:list-subscribe:list-unsubscribe;\n\tbh=WPgsnvcxUosdZhRVN1y2Tsx2axeGkxXliDuiaZ2nKzM=;\n\tb=h+wdNut5TL3c/WT89SGnZTKRT8yohGYsSk8bUZFVmpxqZgFQBI6p0ZHOukCmGi7UVx\n\tw7AV6b0s6GKBp1FESZvUSbnB5cV+WOUY39wIn365EwgcbjPLq4wlXaqpr2brDoCSeeoF\n\tbzufOCTT4+U5sF4e0ZCoFcKpNx9j7zqzVaFigatyE2p8GR+QYayzegUM19P++76/xedx\n\t5B0qpMHwi/EGeaXm3mU+ZWj67OM4WXmS/ohnVMSZjAVAUs913eC8F6VcoQrEkk+OWLGc\n\tpqO27JWx0XQQ2hup5euiWnTzrsaYXzwI/4kOrBp05FAkcqCnbRnB/GvN4MeM8U8LB4Re\n\tu+VA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=sender:x-gm-message-state:subject:to:references:from:message-id\n\t:date:user-agent:mime-version:in-reply-to:content-language\n\t:x-original-sender:x-original-authentication-results:precedence\n\t:mailing-list:list-id:x-spam-checked-in-group:list-post:list-help\n\t:list-archive:list-subscribe:list-unsubscribe;\n\tbh=WPgsnvcxUosdZhRVN1y2Tsx2axeGkxXliDuiaZ2nKzM=;\n\tb=HdYgvrGNkxkQeDzAP9f8DBCjuzmqDRnIJW877Y3/KNZcGrJdS0fnx63JyoMTUnpPl8\n\t8K0WbplV/HE513ubM7LVlAsSiHpRbyVJgzGOoUa8+H1qa60pVHAy6udERDKeFPMEMkjf\n\tAcv7KHHUK8CCTcOw2/ZcbgHbFhUbQZlfCXNQ0/6iKL0Tjwl1zGKq8FvpuXrfryIbV0rZ\n\tzkCGwTqMakr2HZVJaeTeX5AuPrUtC7+2drBUnrh+fuiZbAuPDt2SL2QXvJhkmNp5f/sV\n\tFVtvj8xuxH7mM299gbdVqNU0TQ/oVyRRCSf6D5TG4SbLXRU0q18xl7C343PiEJVh9CvZ\n\tN0NA==","Sender":"swupdate@googlegroups.com","X-Gm-Message-State":"AHPjjUgDt9y+Yd8KOFuutAtOqQiaJVyHlX5HPFxAADTfNdUflXxkc2YB\n\tZLi0tNsv7JxX9A==","X-Google-Smtp-Source":"AOwi7QC7dvF+vljy6dZcpYItGx5TfyeZIiYKeTaBRAfQYy+ndo6Z5BJEw5HP+u7ET4IQ8ItvE4KYTg==","X-Received":["by 10.25.84.148 with SMTP id b20mr19352lfl.12.1505730985726;\n\tMon, 18 Sep 2017 03:36:25 -0700 (PDT)","by 10.46.16.8 with SMTP id j8mr2710481lje.18.1505730985349;\n\tMon, 18 Sep 2017 03:36:25 -0700 (PDT)"],"X-BeenThere":"swupdate@googlegroups.com","Received-SPF":"neutral (google.com: 212.18.0.9 is neither permitted nor\n\tdenied by best guess record for domain of sbabic@denx.de)\n\tclient-ip=212.18.0.9; ","X-Virus-Scanned":["amavisd-new at mnet-online.de","Debian amavisd-new at babic.homelinux.org"],"Subject":"Re: [swupdate] [PATCH] core: unlink socket files on normal\n\ttermination","To":"Christian Storm <christian.storm@siemens.com>, swupdate@googlegroups.com","References":"<20170915114030.25138-1-christian.storm@siemens.com>","From":"Stefano Babic <sbabic@denx.de>","Message-ID":"<a455aa4c-1fb9-d112-0077-c46581463e05@denx.de>","Date":"Mon, 18 Sep 2017 12:36:21 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170915114030.25138-1-christian.storm@siemens.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Language":"de-DE","X-Original-Sender":"sbabic@denx.de","X-Original-Authentication-Results":"gmr-mx.google.com;       spf=neutral\n\t(google.com: 212.18.0.9 is neither permitted nor denied by best guess\n\trecord\n\tfor domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de","Precedence":"list","Mailing-list":"list swupdate@googlegroups.com;\n\tcontact swupdate+owners@googlegroups.com","List-ID":"<swupdate.googlegroups.com>","X-Spam-Checked-In-Group":"swupdate@googlegroups.com","X-Google-Group-Id":"605343134186","List-Post":"<https://groups.google.com/group/swupdate/post>,\n\t<mailto:swupdate@googlegroups.com>","List-Help":"<https://groups.google.com/support/>,\n\t<mailto:swupdate+help@googlegroups.com>","List-Archive":"<https://groups.google.com/group/swupdate","List-Subscribe":"<https://groups.google.com/group/swupdate/subscribe>,\n\t<mailto:swupdate+subscribe@googlegroups.com>","List-Unsubscribe":"<mailto:googlegroups-manage+605343134186+unsubscribe@googlegroups.com>,\n\t<https://groups.google.com/group/swupdate/subscribe>"}}]