From patchwork Tue Aug 7 08:42:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 954411 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:4864:20::137; helo=mail-lf1-x137.google.com; envelope-from=swupdate+bncbdnkrafg44krbbvxuxnqkgqeqa6eyfq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Y1U5NYfi"; dkim-atps=neutral Received: from mail-lf1-x137.google.com (mail-lf1-x137.google.com [IPv6:2a00:1450:4864:20::137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41l7Ly1HFdz9rxx for ; Tue, 7 Aug 2018 18:42:49 +1000 (AEST) Received: by mail-lf1-x137.google.com with SMTP id a136-v6sf2744325lfa.4 for ; Tue, 07 Aug 2018 01:42:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1533631366; cv=pass; d=google.com; s=arc-20160816; b=jVyun8q6Lfj2N/YDrGN+UBNgJLTrG0z8BidJugeeErIgTIRck/33RvY37ub67OYiJZ nGZJpSTtMbyeS9xud3+Yipi9lTg+hphYmSAY6TsBPxHJV+W0vYaHwLfkGWonfHdjwPtf 2wjvVhKY2jRcRsWYuTH2mAOXP7WH/f7cBZltk/oYtMrW13opHjqMl2XSD+Bm8EHt+GCb KE+qK//soia/qB3W3btl0jJy+J5ZM+9qRhq4MnwHKI9K5/LjkuUyjpHyJH5IkcFYiwbQ 4n69wjh92kfDb5iBzue84ydMNBBRAPke8IfyuVmJ6leUfjlKpkY+Le5h531rBDrdHond x8Jw== 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=bWQ9bar5eixJv3EfNpQCljYMHn4nW6A3ubO4tJfrCDY=; b=SSVL2DETg5cVAIK3Ee/xzID2ZUm3PISEzaNED6gaB7Z6H7Ve5bBCn8uHATe4jop3n9 pn+vWh+ZrkT3g5Aln86UGV1eGYWGPkkUf6PnreER1UPAayY4JoA+uEfe9mgBLPLvBz1E jWGGT1a8yvp4jh9VezTeBGfPhzukPHsNV80ZTnLhqlREoSd+zzcSQISSOmVucCE74Pq0 YWIJ4IjtBPxPVWQF2mvvpqw0MvhqTNDbxJk1aairp0CcOtmDWqcUDzud9OyRjpHWRivW ajeP45uuzTZb0ArwnS5p+k535TsC7GEBlf0KY/CP73Oq72cBY4AJjHVaSIDoD+5UhJ5U vSDQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lj9sJmQP; spf=pass (google.com: domain of angelo@amarulasolutions.com designates 2a00:1450:4864:20::544 as permitted sender) smtp.mailfrom=angelo@amarulasolutions.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=bWQ9bar5eixJv3EfNpQCljYMHn4nW6A3ubO4tJfrCDY=; b=Y1U5NYfiddGrZsKnsuBdWobS1wWK5HhMPY2j6YIl3PYQwmaWK4xCET4YDj8IvtxpPO nUHafG/UwPS+DGFnNqq5L6Kteb7ADzsUsVYlhx400pyZghmX9Dtq7Lxi4uKfFp1rNV8c QzCqiTQyfM4vGZNBfsHFXDvxx5y0xoUEIaRP6Y5zHhK2Ig1wx1RpHOFe5JOa5uQ3RQae ECSrSf4M0nAV3sYMTX/Xt84R4SGALp6tWiUDsD38uI0AdYskT5P5PutvykEwzsBjBBRu XfI26/Yy1aTCEtmw/IGjmSXDKefexpmY2sPa7/v24BEs2r25WMU2rE3tejN8HzgDUYf/ RbKQ== 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=bWQ9bar5eixJv3EfNpQCljYMHn4nW6A3ubO4tJfrCDY=; b=X8FDpWNhLisFtIwS01Vea0vSlTHvqbhC4yd8TPwCX3irP2dIZ2rJhOy8Ylivxvjobf hv0KIww9tNGyNUA47jeWWVdP5xYh8Gv/jX81RCrL9EI7/NmZv0EfH5zGDwCZc5ygKjvO v213nTiaPqmm56ClZAxCNcdt+39LhzWzZnFwEux5eur9jDLCoDqJgXLz6qeMIzlIfUiC C+DqTjNocqm6/Uohmb6X/i6IR8ws7d/c4iHWcBx1Hgv8kkgprD3p5/xYxpJalhqBdB3h TuI1C6hE6vnz9zCuE5a5XQ+WOzCIIiZ/RUfgnWBamaf0KpxkJWIbuGQAuV3Dtgdu/TtA bqVA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOUpUlHlBaV+hLlGkSs7upfJ0BuY9xGJR0J1GbK1C3qNILMkuky81kYv aEyRWn/xK9i1kTK+bmNRQ0Y= X-Google-Smtp-Source: AAOMgpfuGg+HNvC9bf/t/eZ60gMXy963XibkjT+B1xObCkhavSojsrJ7fs4rK0u1vpFQtREj+LS4JA== X-Received: by 2002:a19:c111:: with SMTP id r17-v6mr112432lff.6.1533631366267; Tue, 07 Aug 2018 01:42:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:3308:: with SMTP id d8-v6ls102814ljc.11.gmail; Tue, 07 Aug 2018 01:42:45 -0700 (PDT) X-Received: by 2002:a2e:850e:: with SMTP id j14-v6mr1000872lji.30.1533631365723; Tue, 07 Aug 2018 01:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533631365; cv=none; d=google.com; s=arc-20160816; b=nmXsxmP9kFUDJsEdw6oouLG2pgY5AWkyjgZF6BSrOXwsxjz30gvgJJ4R9kt/dHonJr N5cNMj+g08QNs8wbVMxG/Y12+0YB65kqNRqE31D4BFaRH53OWBhCCKqPb5hb3DjKkgB6 ZCX7FHilc4E3EFLCvG++2FwCsJiElp/bcNHtkU75fhoDyWsCyVyaxV7bMdeCxlnnHcz1 kHymLmwlWVhnhd7CrdvcOnpy03AlmJyY4R/B/rikrgD0tTxQv6+g2QLA2cgzT8ZjDaik mu4+yZcBORep2QcoDi4DX69NKUwDowi5zz2jf5q0Hvpw0JUTRYH0qfPAy4QNYSrY53zj C09w== 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:dkim-signature :arc-authentication-results; bh=LhikpZBev7R/Qvk5C3LbKXLNbe3evCF9q5dBjlqsels=; b=NFPd9CdcEh8WNVTwYenqmKBVH83WLiE6ECyINyrXKO26BQW61tIl9BNJYvCkS1iKw6 +vxAOQWBy4XmsGwNt3U1BGKGvypq2JjyIyjPf0tKzMVjYUjS6BvIpAVs+IKojddlSgvl DZi61MR/yUruhzFBOCPLuVTIJ7Sz+MxRnI1X3QNFmLoUSXqAjCkKKiIE9F88pszO5eFR NEeErqbhGgK8jRPH6dHe1GTtXWryhyZTraY0nxNw1klde9Tez0aFhlfG/IkssF+RmYlu 1YoIsod3aH4duCOV/QwufsM0nN3DhIgpD7ivJBBCF4DNKxqTqz6JsubALK0R/4D0qvDo MaJg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lj9sJmQP; spf=pass (google.com: domain of angelo@amarulasolutions.com designates 2a00:1450:4864:20::544 as permitted sender) smtp.mailfrom=angelo@amarulasolutions.com Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com. [2a00:1450:4864:20::544]) by gmr-mx.google.com with ESMTPS id n1-v6si22722ljg.0.2018.08.07.01.42.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Aug 2018 01:42:45 -0700 (PDT) Received-SPF: pass (google.com: domain of angelo@amarulasolutions.com designates 2a00:1450:4864:20::544 as permitted sender) client-ip=2a00:1450:4864:20::544; Received: by mail-ed1-x544.google.com with SMTP id h1-v6so6514442eds.1 for ; Tue, 07 Aug 2018 01:42:45 -0700 (PDT) X-Received: by 2002:a50:b5a5:: with SMTP id a34-v6mr21406872ede.88.1533631364656; Tue, 07 Aug 2018 01:42:44 -0700 (PDT) Received: from localhost.localdomain ([89.202.204.147]) by smtp.gmail.com with ESMTPSA id h8-v6sm444967edi.68.2018.08.07.01.42.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Aug 2018 01:42:44 -0700 (PDT) From: Angelo Compagnucci To: swupdate@googlegroups.com Cc: Angelo Compagnucci Subject: [swupdate] [PATCH] core: create path for a file if path doesn't exists Date: Tue, 7 Aug 2018 10:42:40 +0200 Message-Id: <1533631360-23581-1-git-send-email-angelo@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 X-Original-Sender: angelo@amarulasolutions.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lj9sJmQP; spf=pass (google.com: domain of angelo@amarulasolutions.com designates 2a00:1450:4864:20::544 as permitted sender) smtp.mailfrom=angelo@amarulasolutions.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: , Actually, when a path for a file is missing, swupdate will crash cause it relies on existing paths. Changing this to create first the directory tree needed by a file then writing it. Signed-off-by: Angelo Compagnucci --- core/util.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/util.c b/core/util.c index b8910e0..092f5d5 100644 --- a/core/util.c +++ b/core/util.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "swupdate.h" #include "util.h" #include "generated/autoconf.h" @@ -130,13 +131,36 @@ void freeargs (char **argv) } } +static int mkpath(char *dir, mode_t mode) +{ + if (!dir) { + errno = EINVAL; + return 1; + } + + if (strlen(dir) == 1 && dir[0] == '/') + return 0; + + mkpath(dirname(strdupa(dir)), mode); + + if (mkdir(dir, mode) == -1) { + if (errno != EEXIST) + return 1; + } + return 0; +} + int openfileoutput(const char *filename) { int fdout; + fdout = mkpath(dirname(strdupa(filename)), 0755); + if (fdout < 0) + ERROR("I cannot create path %s: %s\n", filename, strerror(errno)); + fdout = open(filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR ); if (fdout < 0) - ERROR("I cannot open %s %d\n", filename, errno); + ERROR("I cannot open %s: %s\n", filename, strerror(errno)); return fdout; }