From patchwork Fri Sep 8 13:45:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 811603 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::238; helo=mail-lf0-x238.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbhf7zlgqkgqe3xao3jq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="kqFf4kJ4"; dkim-atps=neutral Received: from mail-lf0-x238.google.com (mail-lf0-x238.google.com [IPv6:2a00:1450:4010:c07::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 3xpdv54G2Xz9sBd for ; Fri, 8 Sep 2017 23:48:17 +1000 (AEST) Received: by mail-lf0-x238.google.com with SMTP id 80sf396646lfy.11 for ; Fri, 08 Sep 2017 06:48:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1504878493; cv=pass; d=google.com; s=arc-20160816; b=v0awOKM5qUMHUNxLoLxgMIvHNa81443BDtsSDLhfBiTQFy+W90wgxpi2gsOqA+vFGS L3dvJ16q5SuBENuVgcwlSPTuk3guBPRIT0/avs8WpafrXCJmOLeOv6/NO8qSTFpmjGmp vVYVoWWGNcN5GL65eRkawHMHxDs+ap2sVhQHMvdABoMeA/zPahB3F+aNy6W/KBlezPIQ 3mfPS3mC2QhyOCYLPMMzNSwzKK5pjmEFVgvWsP/EirRqYoIIb9l4YoDgysoaLN5EPb0s nxVN8X7dFKukqEOYZ8+jP3zSWLGIj6whADZ2dtn3SCRjdP7Bvdu1CErVSNWRL1vtG5MB tfRg== 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=XYTOuDIjEY5lCx6F4mCaKcdJyEVNX/fcOuorxv0qcSE=; b=jKkWaAjttxKy6V8glfmzcrszdwDGUeLql9k7/sJLDy7ye/fRfn+fT/5E1rPEsf47o9 18AabB62PxkJaW2y/X1wjhkTqMoBqmrfcBzFXS7vwytRKohTEKtzjJi+q0kvxt0bYEJ+ H3kDDrOo9r75HL3UWwYEIdNUmbOld4/+vusgvDphFrHFcxA5r2zUIVLlLedlAfcDOB9K fp35slgXp6eN45OkHSo10WZbjo8x1KvtYRS6C7RR9DNJ3zYhA62srr1k1ZLYPX+TFjfB XAp2LI+ssAtT3J7i2F8hr/8UI6IVolEiwxdhagd8mM2bWpS5T+Yez5tCKbnIupGL4Bhz Lztg== 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 :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=XYTOuDIjEY5lCx6F4mCaKcdJyEVNX/fcOuorxv0qcSE=; b=kqFf4kJ4breis4wf/UnhnSKtwRBRODb1Z8dfwEfIZS8GMAyzPGB0HBUnHlyDse7RZ9 hA/nRBLXEZjhl+WooyHjL9Lvm7OdPbWcFtsMe3PGKHRjphYpyLXtBDKB+m6CN5slnAAB RKPLXARWg3MIIU8ydEURbnUyMMvHP9WfutEBN4uoMS1jc8EXyYuiM/24x2hLqcyUlbwD zI3KJSC7a0SgE7WFr5WrEPe8QCflibNrQsgkTMf1FzUaLiwI5objWpCTI0rsKFJeCJZV 1iCV3KCNxex/sLmG2Z//B1seVuIjvVLXiC5ukD/WMYH39t90XSyUTehpv4uzQRhLjMoJ QdCg== 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=XYTOuDIjEY5lCx6F4mCaKcdJyEVNX/fcOuorxv0qcSE=; b=Fqg0idjUXcv0O792Ew7R8A9SQJxhd/WO0/b2jRToWz+sRflXtha97jFRFEJK8EzgUm nOsqubqyGf0krWNB+OUgFzr4JLlNTxjAsHfS8rm3vW6mZ0ce9kW0MoiNsqCGJnkIKsLI lrWktckQHRUHc1A27MJQ1T0PdSRwcDymfZDC3aP18mQd+OmNcxJjq4s69ZpKf+AVeOPR PCLAkGL9pIDnd8VgOa2ZkM0jwQ7IQ9QG+MBOpJGfUUTN1E9rvJBMVi6Cns4+0ylhVYd3 uxuGH4g7Ribajs6BvcOHIXA5C7LrijqKesgmAU3GpZStCr4wmKyO6JyQl1huUW2j4KQe amPg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AHPjjUhi/N7KM/1pc9Adyag+etfArgFIaTO8LtNARukCGYh3zTMumcOV 0w/kcT65LYGdzA== X-Google-Smtp-Source: AOwi7QBRlIXZcHsQGJPnBAUctnyp/p86sBqxcze1vmoLYyR1sA/E2P9KeYaT2vzSvkZODSxwyCwHZQ== X-Received: by 10.46.22.9 with SMTP id w9mr4973ljd.9.1504878492979; Fri, 08 Sep 2017 06:48:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.25.166.8 with SMTP id p8ls17309lfe.23.gmail; Fri, 08 Sep 2017 06:48:12 -0700 (PDT) X-Received: by 10.46.86.74 with SMTP id k71mr240771ljb.0.1504878492530; Fri, 08 Sep 2017 06:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504878492; cv=none; d=google.com; s=arc-20160816; b=L03+37vtEYaq/GO4wYVloYgcS4LzjEmNLygPHth14Mt3YYsnogVSC/Xm44L/yAOTXv SrYCHuGY+JxsMJpelIWakMsCkG4RiU9y52Plw7XMkuiLvFOLpvpggXbQIkn/dHtuqye3 apcjjF7acLXaWJytDjGmPtCr56uBlB6OUYSqs6iRzfFnIs/4NRx0lsvfkFK4FqmkS71+ aAI6O5E60+VeKKP0p+kuGWWvHLJZreG22YWidGgIiKkI3C1AYzUAmg4TObBLNDS5WlxN RC7+hMQP6yYWReAp0Jk/gjgTHbmaK728alGytWv5p0b6lg2kR3TaWjjck6PksdGt4qry IyoQ== 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=POesLmUtky4nmGZMdwD7wEtIaooRKPOUQKGOZiqDdUA=; b=H3CGYoUmn9Hw/4uP7V/RDSS3Dp8rhWg8ZfBxHqA/RTO6u0g71qz45X3wZTsecucHSJ AXosnz52va6GeVld94mukvjFWxz5Ie1grqgD62Aod7AYgxQVtIKZ59Al9BKPZT79tC+b j3E/qtsh2R9l2D1+wqMYZ5G+kYHBVNz0UXdZb3yitVsqIwbx9T2z8HB03Oe88JA7QcT9 q4UWiFxiL0UvcVeXLDDOKXAtZrUJZdvHwEo2KuGY5rwS8e0DgI7lqVQHGiAE71l4OQc1 IOpILfTqh3uaPs4zLFxWYiLW6w6sQ9KKT/T0lIJUbnyRykh+E0z2yOmj6Z2zREOCRCus wS+g== 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 200si286505wmj.0.2017.09.08.06.48.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 06:48:12 -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 mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id v88DmCE4000486 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 8 Sep 2017 15:48:12 +0200 Received: from MD1KR9XC.ad001.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id v88DmBKk021896; Fri, 8 Sep 2017 15:48:11 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 1/3] tmpdir: introduce get_tmpdir() respecting TMPDIR Date: Fri, 8 Sep 2017 15:45:45 +0200 Message-Id: <20170908134547.9170-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.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: , Introduce a get_tmpdir() method that is to be used instead of the #define'd TMPDIR hard-coded to /tmp so that SWUpdate respects the TMPDIR environment variable or, if it is unset, falls back to /tmp as sane default and current behavior. Signed-off-by: Christian Storm --- core/util.c | 23 +++++++++++++++++++++++ include/util.h | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/util.c b/core/util.c index b714f29..fe2a657 100644 --- a/core/util.c +++ b/core/util.c @@ -52,6 +52,29 @@ char *sdup(const char *str) { return p; } +static char* TMPDIR = NULL; + +const char* get_tmpdir(void) +{ + if (TMPDIR != NULL) { + return TMPDIR; + } + + char *env_tmpdir = getenv("TMPDIR"); + if (env_tmpdir == NULL) { + TMPDIR = (char*)"/tmp/"; + return TMPDIR; + } + + if (env_tmpdir[strlen(env_tmpdir)] == '/') { + TMPDIR = env_tmpdir; + return TMPDIR; + } + + asprintf(&TMPDIR, "%s/", env_tmpdir); + return TMPDIR; +} + static int countargc(char *args, char **argv) { int count = 0; diff --git a/include/util.h b/include/util.h index 70a0acc..9fb7860 100644 --- a/include/util.h +++ b/include/util.h @@ -112,7 +112,6 @@ typedef void (*notifier) (RECOVERY_STATUS status, int level, const char *msg); #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#define TMPDIR "/tmp/" #define LG_16 4 #define FROM_HEX(f) from_ascii (f, sizeof f, LG_16) @@ -196,5 +195,6 @@ static inline int decompress_image(int __attribute__ ((__unused__))infile, } #endif +const char* get_tmpdir(void); #endif