From patchwork Thu Sep 28 11:09:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 819540 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:c0c::23f; helo=mail-wr0-x23f.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbcnswphakgqegdiw6sq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="dQBFqAU7"; dkim-atps=neutral Received: from mail-wr0-x23f.google.com (mail-wr0-x23f.google.com [IPv6:2a00:1450:400c:c0c::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y2sTp180qz9tXv for ; Thu, 28 Sep 2017 21:12:12 +1000 (AEST) Received: by mail-wr0-x23f.google.com with SMTP id z39sf478325wrb.4 for ; Thu, 28 Sep 2017 04:12:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1506597129; cv=pass; d=google.com; s=arc-20160816; b=gOx3YInBoHMwts3uaukENnlEVtMc+htkbeC7ERvjfWWzJZDylEyOFqvFTnGuSt0Stf Db0NPByDWYdZJ5qQUBjAS1m54DoGuMXTDxqFU49Z/+KY5BnLum27iDoauCP7SkIThpox jsbFDMgGM5oCxRlMOK5G7Jam/iGELwUdT8rsXSZon6WFJRGe/Dcvkoe8Bna4qwgC23oG /X6b9dAGZI3rK4B2TQGM2ePHmam+VX/r4nySGgG1I7fCLJZFESOQsifZDxQF4iWj+yvT oRAbqYINgGqPxsmn2kcytWVypXn4eu5NI2p78AMSv5WvHf4ElrmwWQj6/IjHYP7evBv5 4+ng== 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=3INjaRvwzyhgh6Tajx1Lh7FqKTbhfndN/+SOOf7SQaE=; b=ZrFPFuuw9ytUZON7JH4Wu/IQJrvB/ZFXKlBlIiLV+M9iUY98yTJLNtZqiRv6SEkQpY VoZ2I45oR1vt//+6HhKYf7lYTVHfqT+TEOcR0dqVFythztNvRiHTfqxxLf6dEY7HzbSb /QF2USn65usabXOVPnEVND+/OcA7z7F43R0/r0nPE43itiFBK7p62BjJREWUHtCDM1tO YCzewMk10t6ftRK+fbs609vmNCGucjVUxttu3dCNtKk8A8WlIWyhz2gJX7Tn16AA9dZ3 rq4a6AwRKVWhGD7IQJSR1jZDRXIPLPFIpCK2hIVmUci1fmyzEy4v7dTg80dNbaWy3hzS Qllw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.28 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 :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=3INjaRvwzyhgh6Tajx1Lh7FqKTbhfndN/+SOOf7SQaE=; b=dQBFqAU7NKXnNKNHE/+YcA9lmie/TES8Y2Mc0KrT6+GTcXmfuH9AzeGzm5KhYBOl6r jlj4gZzQYqRXDt/4Xu73sGglOAf7gAGCVfkoCWQxS2KKRtokYyeykq8Irt4Kp/YuEE4w SK8Jw72S4OWpgaHDyfCxVl/d07VpRgJX5Hak5ynG8mdPgSj+tUteWi5mfelc+5Bm+hTF tY8fn/eWZmtXEWtix4SgjNawVukOLlrrzxkH0fEAUB/OBSfxlLne6+GvVoOA5iPMix5v WBjrZSckKgwuY+nY/01S1BIqA4lxhuJVgy2cLu21TDwgEXG82xtiLCxR0hbAlXsnHJbT 895Q== 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=3INjaRvwzyhgh6Tajx1Lh7FqKTbhfndN/+SOOf7SQaE=; b=BTFz5sih8xEnhVAKxt0B82TS4seyEfThNVnTdsgXIKJ/u4FOa4+ZJcTKYLbASW/2Zm J6MhxZw7nLN9BbT/NMMo5bsv3UcFjZulWkLSIHYanN0gkzzwnfPAfYammr/4vxh/JjXt tHNYJ9QdFts0CgeDEoCLKcFOi1YrlF0s8HW75t8Rm0IsL9CWdvLPR5au26cb2nhD87H4 tFES5OyK7lhPMuAfS0dWDjyfcl+144VGUbch4aPeuXeXpb/eBrGOvLns3T+EPlTXOdPq BqmALWkSoU/24zYGxfZq7GcMTIlnX6KI7t/UD/K68NLrlJB6GtF2+aloVPgXHGjjUuuH EWtA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaXHuDt14a2saaTaCt+j3OWWM4g/NynhMJqHsBHrOqlbm4iNhdO9 raNNCC2vhMgjqNAWyHbT9Is= X-Google-Smtp-Source: AOwi7QD7/f0OsFxWdZPxisH/Iz3M1M5LdoxMN0jny44i6mKdHeDzAw0QUiy8PfntB8kop2nqJLM0jQ== X-Received: by 10.28.23.11 with SMTP id 11mr3706wmx.27.1506597129783; Thu, 28 Sep 2017 04:12:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.9.5 with SMTP id 5ls18114wmj.2.canary-gmail; Thu, 28 Sep 2017 04:12:09 -0700 (PDT) X-Received: by 10.223.130.234 with SMTP id 97mr471490wrc.5.1506597129051; Thu, 28 Sep 2017 04:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506597128; cv=none; d=google.com; s=arc-20160816; b=pZgdqPI4PCItzpXSm9bZNLqiQ6EmF3cGfemP1E0UXMcVnIVhrpSjEaD+IhxpD3PadI f3WHy8q9S8AyUR1RREGc4+6WAj2UBfZE08sfYJKQYsrpDP2XwnCRMC3fs7tEeRyNa3gC CynBC/VC1Ov2EHrPWYk+L83WA2v6LvtTFtuDplAGEwowkOTxmKEjRhs3vQ7KWAlihfTi ViKlDQDiachoqd4MCU2xmtWxDErvxE1djkEK/REDKfQWasjd9G9IEQ+6/qwvbq2tHnCa g7rL8YRT15wk1bR78/h/mTxuvpWfpMVu5J60+9WbME7+4fcfnFlFSzx8b+baLBuxApe+ A5Zw== 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=akOQUahCstiS4r/BdNFG9hoK+eR9MoBje3gsq8gANNM=; b=ahzEymF0Hev+x53KtKseFPRZ8engb5WHdPXZsKn66sLw3DVwgRMJp1oQRh+uaC/i+b H4xtN6KjnrHnSsZ+6DL2kSJcvkv359LSPX14pvUUWgwCwd+gzVvJDvpFxzXQKLt8bhrh 0SbZxBaOx9mt/ft5A+VfUbi/Y+WzysZHMJFuws+nbECmJiih5pReK30Rn90BX9l8D9Tl YTQSzD4fIgffOYoyNL9R8I8pzyVumaFv27DX9/FQ/vdqmZBPKfrkQu6uooDo2R4vGV3+ ZmJQRrMeOE0HagehYvQ7pVJgwmkAEnrRWnluzT2LMWu5nBOMUIr4Yy/5E9GgIKXOvyd1 IVfQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.28 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id 200si220004wmj.0.2017.09.28.04.12.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Sep 2017 04:12:08 -0700 (PDT) Received-SPF: neutral (google.com: 192.35.17.28 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) client-ip=192.35.17.28; Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id v8SBC8Mc030989 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Sep 2017 13:12:08 +0200 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id v8SBC88A010579; Thu, 28 Sep 2017 13:12:08 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH] core: unlink temp directories on normal termination Date: Thu, 28 Sep 2017 13:09:10 +0200 Message-Id: <20170928110910.29088-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.14.1 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 192.35.17.28 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: , Remove the temporary directories $TMPDIR/SCRIPTS_DIR_SUFFIX and $TMPDIR/DATADST_DIR_SUFFIX on normal program termination. Signed-off-by: Christian Storm --- core/swupdate.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/swupdate.c b/core/swupdate.c index 52e0a3f..b490871 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "bsdqueue.h" #include "cpiohdr.h" @@ -406,6 +407,30 @@ static void create_directory(const char* path) { mkdir(dpath, 0777); } +static int _remove_directory_cb(const char *fpath, const struct stat *sb, + int typeflag, struct FTW *ftwbuf) +{ + (void)sb; + (void)typeflag; + (void)ftwbuf; + return remove(fpath); +} + +static int remove_directory(const char* path) +{ + char* dpath = alloca(strlen(get_tmpdir())+strlen(path)+1); + sprintf(dpath, "%s%s", get_tmpdir(), path); + return nftw(dpath, _remove_directory_cb, 64, FTW_DEPTH | FTW_PHYS); +} + +static void swupdate_cleanup(void) +{ +#ifndef CONFIG_NOCLEANUP + remove_directory(SCRIPTS_DIR_SUFFIX); + remove_directory(DATADST_DIR_SUFFIX); +#endif +} + static void swupdate_init(struct swupdate_cfg *sw) { /* Initialize internal tree to store configuration */ @@ -422,6 +447,10 @@ static void swupdate_init(struct swupdate_cfg *sw) create_directory(SCRIPTS_DIR_SUFFIX); create_directory(DATADST_DIR_SUFFIX); + if (atexit(swupdate_cleanup) != 0) { + TRACE("Cannot setup SWUpdate cleanup on exit"); + } + #ifdef CONFIG_MTD mtd_init(); ubi_init();