From patchwork Mon Jun 8 16:17:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Nicholson X-Patchwork-Id: 6566631 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0CD119F2F4 for ; Mon, 8 Jun 2015 16:18:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0672020425 for ; Mon, 8 Jun 2015 16:18:12 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id AE0892041D for ; Mon, 8 Jun 2015 16:18:10 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6AC9F260718; Mon, 8 Jun 2015 18:18:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 38446260474; Mon, 8 Jun 2015 18:18:01 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 35D972604C7; Mon, 8 Jun 2015 18:18:00 +0200 (CEST) Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) by alsa0.perex.cz (Postfix) with ESMTP id 0F575260442 for ; Mon, 8 Jun 2015 18:17:53 +0200 (CEST) Received: by qkhq76 with SMTP id q76so80421346qkh.2 for ; Mon, 08 Jun 2015 09:17:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-type:mime-version:content-transfer-encoding; bh=zR3bClniK6dRQDGq89/K94L6C1WLAzeOjX1L8qn1jHU=; b=GqCrQISt8DCH1X4Oyp5bgXLvulzNs3Uo5+AxAR4l2Xc/KhMheQua51ucrDYODXG0Vi 3sUCX2Px9i3/mea6HP8wLKvtXdSu5P5ax5+uQLbqoIOJxOOYb8Sm1649nUy1CYM6j27F 1qH4bJj6MZwu86HHpxxWeEF2PflbDOkcpEwy6Tv5ifec/kKyk6VvWdTZ7bmM3Hh8iDdi zy1wZdnp14Tz5y2aBqsO4wWLICs7eW9dJC96rDZV0wT+7Kzpykl0S7ToYbU1UXTTC4PE jnX9w1qHKutnWClXTFwwRmprWwvKzORVG1LVirYEoCf864YAK7s65by0q7uwKLbaDzn4 hsWQ== X-Gm-Message-State: ALoCoQlXceQFlnJKLgIzLDSsgGI/B/k4+B+TD79T18BX2oxjyuTbfkjBRAJEfePIDeHBYLVdcDFT X-Received: by 10.140.218.198 with SMTP id o189mr20977254qhb.47.1433780272367; Mon, 08 Jun 2015 09:17:52 -0700 (PDT) Received: from [10.0.64.114] ([204.28.125.50]) by mx.google.com with ESMTPSA id q7sm1399269qkh.35.2015.06.08.09.17.50 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 09:17:51 -0700 (PDT) Message-ID: <1433780269.8893.5.camel@midnight> From: Dan Nicholson To: Takashi Iwai Date: Mon, 08 Jun 2015 09:17:49 -0700 In-Reply-To: References: <1433541647-300-1-git-send-email-nicholson@endlessm.com> X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH] alsactl: Try to create state file directory X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 2015-06-08 at 15:22 +0200, Takashi Iwai wrote: > At Mon, 08 Jun 2015 15:03:21 +0200, > Takashi Iwai wrote: > > > > At Mon, 8 Jun 2015 05:52:18 -0700, > > Dan Nicholson wrote: > > > > > > On Jun 8, 2015 4:38 AM, "Takashi Iwai" wrote: > > > > > > > > At Fri, 5 Jun 2015 15:00:47 -0700, > > > > Dan Nicholson wrote: > > > > > > > > > > Try to create the directory for the state file when saving so we don't > > > > > depend on it being created ahead of time. This only checks for failures > > > > > on existing directories and doesn't try to create the leading > > > > > directories or workaround any other errors. This should catch the common > > > > > case where /var/lib exists, but /var/lib/alsa doesn't. > > > > > > > > I don't think it's the role of alsactl. It saves a file on the > > > > certain directory. If it doesn't exist, it's a failure of the > > > > installed package. > > > > > > Sure, that's understandable, but there's a couple reasons I think this is > > > helpful addition. > > > > > > First, if no path is supplied, store will save to /var/lib/alsa. So, it's > > > not as of the user has supplied a path it didn't setup correctly. It would > > > be nice if alsactl worked out of the box without additional integration by > > > packagers. > > > > For that, a safer way would be to create /var/lib/alsa in the > > installation.'s Sure, as I said, we can do that if necessary. It's just another custom thing to maintain, and I think it would be nice if alsactl could manage this on its own. > > > Second, my real motivation for fixing this is to support stateless type of > > > systems that come with a clean /var. At Endless we're using ostree. The OS > > > is composed by Debian packages, and indeed alsa-utils is setup to create > > > /var/lib/alsa on install. However, to use the same OS snapshot for all > > > users, the contents of /var are stripped since they represent local system > > > state. We can certainly add a method for creating the directory at runtime, > > > but we believe it's more robust to have the program manage its own state as > > > much as possible. > > > > Why not specifying the proper directory via alsactl -f option for > > user? > > Also, your patch seems to care only the top directory. For example, > if alsactl is configured to use /var/lib/alsa/more/deep/dir, it won't > work. Here's another version that creates all leading directories. From e1f75388682ad662dd5bdbb057d12b00e0aa80a8 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Fri, 5 Jun 2015 14:39:15 -0700 Subject: [PATCH] alsactl: Try to create state file directory Try to create the directory for the state file when saving so we don't depend on it being created ahead of time. This only checks for failures on existing directories. This should catch the common case where /var/lib exists, but /var/lib/alsa doesn't. Signed-off-by: Dan Nicholson --- v3: Create all leading directories alsactl/state.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) int err; @@ -1561,6 +1599,9 @@ int save_state(const char *file, const char *cardname) } strcpy(nfile, file); strcat(nfile, ".new"); + err = create_directories(file); + if (err < 0) + goto out; lock_fd = state_lock(file, 10); if (lock_fd < 0) { err = lock_fd; diff --git a/alsactl/state.c b/alsactl/state.c index 3908ec4..10b3567 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include #include "alsactl.h" @@ -1536,6 +1539,41 @@ static int set_controls(int card, snd_config_t *top, int doit) return err; } +static int create_directories(const char *file) +{ + int err = 0; + char *filedir, *cur; + + filedir = strdup(file); + if (filedir == NULL) { + error("Not enough memory..."); + err = -ENOMEM; + goto out; + } + + cur = filedir; + /* skip leading /s */ + while (*cur && *cur == '/') + cur++; + while ((cur = strchr(cur, '/')) != NULL) { + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + + *cur = '\0'; + if (mkdir(filedir, mode) != 0 && errno != EEXIST) { + error("Could not create directory %s: %s", + filedir, strerror(errno)); + err = -errno; + goto out; + } + /* restore path element */ + *cur++ = '/'; + } + +out: + free(filedir); + return err; +} + int save_state(const char *file, const char *cardname) {