From patchwork Fri Jun 5 22:00:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Nicholson X-Patchwork-Id: 6558291 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 B27DB9F1C1 for ; Fri, 5 Jun 2015 22:01:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E4920207D3 for ; Fri, 5 Jun 2015 22:01:17 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id A2DF3205DB for ; Fri, 5 Jun 2015 22:01:15 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 180F9266962; Sat, 6 Jun 2015 00:01:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: 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 E3F42266943; Sat, 6 Jun 2015 00:01:04 +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 A9B85266950; Sat, 6 Jun 2015 00:01:04 +0200 (CEST) Received: from mail-qc0-f171.google.com (mail-qc0-f171.google.com [209.85.216.171]) by alsa0.perex.cz (Postfix) with ESMTP id 7B829266938 for ; Sat, 6 Jun 2015 00:00:57 +0200 (CEST) Received: by qcxw10 with SMTP id w10so35071921qcx.3 for ; Fri, 05 Jun 2015 15:00:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=SY8HttgtqPkEA04gVSNFGGYDqcyHvArET4LTSRd/n3Q=; b=EncffSqVRuHDKXLyn+jqW6nBqK5CuZAeDQQLdSqmh/p7EybUhpysWYRzgYYa/l2rTe TgcJa2QPwiy8xhFIbDIxgBwA3WjtFkGi9oK6pVibUgp7yjd1/mu9TsJRO5y1wWdUH8vY IpafeIdfqGMdSzg4+nC0tMP1ccAhbehx8G13ydy546R9raNJ8mKbnIqDZLfuPq/itHfV 1hsbyNFGPHnw4gIML13BrCNRBCWBGpj0mcBrgH7VhNnAeuZY3EYahCyJxB9AQYql7D6I Tt4fgzWyw4+X7/F5VTMXiy8Gf4dOJwtFKjlCFFVHFMGPRQljDBLymL/hCy6It9PYsjso NEbA== X-Gm-Message-State: ALoCoQmNzjofkr9e2ek4PW26MOnFoY80WMFshlL2tiGuwtJ22kQNm5dA0wZBJRtasdrNBLT1bnTe X-Received: by 10.229.185.68 with SMTP id cn4mr6988824qcb.12.1433541656502; Fri, 05 Jun 2015 15:00:56 -0700 (PDT) Received: from midnight.endlessm-sf.com ([204.28.125.50]) by mx.google.com with ESMTPSA id e104sm4576599qgd.29.2015.06.05.15.00.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 15:00:55 -0700 (PDT) From: Dan Nicholson To: alsa-devel@alsa-project.org Date: Fri, 5 Jun 2015 15:00:47 -0700 Message-Id: <1433541647-300-1-git-send-email-nicholson@endlessm.com> X-Mailer: git-send-email 1.9.3 Subject: [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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Dan Nicholson --- alsactl/state.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/alsactl/state.c b/alsactl/state.c index 3908ec4..8ca3d6e 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include #include "alsactl.h" @@ -1544,6 +1547,7 @@ int save_state(const char *file, const char *cardname) snd_output_t *out; int stdio; char *nfile = NULL; + char *filedir = NULL; int lock_fd = -EINVAL; err = snd_config_top(&config); @@ -1553,6 +1557,9 @@ int save_state(const char *file, const char *cardname) } stdio = !strcmp(file, "-"); if (!stdio) { + char *tmp; + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + nfile = malloc(strlen(file) + 5); if (nfile == NULL) { error("No enough memory..."); @@ -1561,6 +1568,21 @@ int save_state(const char *file, const char *cardname) } strcpy(nfile, file); strcat(nfile, ".new"); + filedir = strdup(file); + if (filedir == NULL) { + error("Not enough memory..."); + err = -ENOMEM; + goto out; + } + tmp = strrchr(filedir, '/'); + if (tmp && tmp != filedir) { + *tmp = '\0'; + if (mkdir(filedir, mode) != 0 && errno != EEXIST) { + error("Could not create directory %s: %s", + filedir, strerror(errno)); + goto out; + } + } lock_fd = state_lock(file, 10); if (lock_fd < 0) { err = lock_fd; @@ -1640,6 +1662,7 @@ out: if (!stdio && lock_fd >= 0) state_unlock(lock_fd, file); free(nfile); + free(filedir); snd_config_delete(config); snd_config_update_free_global(); return err;