From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684748225; x=1687340225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eyCr/nAnQbFrRLdKJYGT3R8h+LPdWWPHq/Wb2N3Ndv4=; b=JasGBazp+2XNhlJR2oIZNl7hzWH5/Z3jG1A6bn0uAzIUGGd9yc0wJQ3pjOx3HfNMp+ YVGNBIog4L1lEZEB7Ms0vE+FCPmr6wJZSyWFlnXUmDqyBoCzbkBoC5Bl+UbNJ3WlbZA7 iElD92dSuj06YZCa9Qrd3KPlejn/VX7EiHuA8IBvP//9CvIidMIxp9M0Hwkp2rKetTaI hvIIOJixp1WPrCcE8wmGsHWOViy7uBWyVtgHkt22CzPsRCMp1b+fu68CsLoKVbooGvoO eQkfh72ItIR3Xi2tLSazIxCiZJVW4EJlujMrmH1SbHjzhcTAc2Bv3SPDLVV8Ub4Z3Meh x75w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684748225; x=1687340225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eyCr/nAnQbFrRLdKJYGT3R8h+LPdWWPHq/Wb2N3Ndv4=; b=EvLRdCgni4MhXlg2Sq0wI/zOa8eDtCumlF3+dhCNLs/bUtpUJQx0Qf2wHlr+XasGl6 FVvaIgmIEsr+XV7nZpPj2dY1cNUuAojybTvLV+wXtpQb9DZyvVijoU6FoC6WHsXJNaFM ZP2l2MHENPyOdofAHyGX6ZbF2az4u/5/6nunwy/wd7mrrutPJc4RMaCZIlCsCbcZNsgR zecBKmFNw0Dn5FchqhOteMes33ePGE25fTVnZWggJj3tqdUqe4qem2XaufZVqMOr2puL Zt24LLFO4VeIFvMR5YN2Jio5EP/XNHKU5gc4r7uR1UkqN9lOwXPgZfnP5NhS0IRcHr/p JGkA== X-Gm-Message-State: AC+VfDwr+CcHt0wmW2gSHwdSXfji1ELFOdA7TqNk7ZDSYp6pMXYpG0QN m/lYEukZNZ5onp9TL7xMTVmUSZ79TcM= X-Google-Smtp-Source: ACHHUZ5/yLXht/nhXqRhOHDHUJURwP5pIwFIOepFC+HKLYSc3wQi8SaxbAOcj0HPxNXE6XV4cMhNGg== X-Received: by 2002:a05:600c:2312:b0:3f6:832:aae7 with SMTP id 18-20020a05600c231200b003f60832aae7mr159072wmo.25.1684748224989; Mon, 22 May 2023 02:37:04 -0700 (PDT) From: Alexey Gladkov To: make-initrd@lists.altlinux.org Date: Mon, 22 May 2023 11:36:55 +0200 Message-Id: <20230522093655.505529-1-gladkov.alexey@gmail.com> X-Mailer: git-send-email 2.33.8 In-Reply-To: <20230522075723.486638-2-gladkov.alexey@gmail.com> References: <20230522075723.486638-2-gladkov.alexey@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [make-initrd] [PATCH v2] ueventd: Change interface rd_asprintf_or_die X-BeenThere: make-initrd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: make-initrd@lists.altlinux.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 May 2023 09:37:08 -0000 Archived-At: List-Archive: There is no need to pass a pointer for the result to rd_asprintf_or_die because the error check is inside the function and the function cannot fail. Signed-off-by: Alexey Gladkov --- datasrc/libinitramfs/memory.c | 7 ++++--- datasrc/libinitramfs/rd/memory.h | 7 ++++--- datasrc/ueventd/queue-processor.c | 10 +++------- datasrc/ueventd/ueventd.c | 11 +++-------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/datasrc/libinitramfs/memory.c b/datasrc/libinitramfs/memory.c index ea0d292e..cd6a19f7 100644 --- a/datasrc/libinitramfs/memory.c +++ b/datasrc/libinitramfs/memory.c @@ -27,14 +27,15 @@ void *rd_malloc_or_die(size_t size) return r; } -char *rd_asprintf_or_die(char **ptr, const char *fmt, ...) +char *rd_asprintf_or_die(const char *fmt, ...) { + char *ptr; va_list arg; va_start(arg, fmt); - if (vasprintf(ptr, fmt, arg) < 0) + if (vasprintf(&ptr, fmt, arg) < 0) rd_fatal("vasprintf: %m"); va_end(arg); - return *ptr; + return ptr; } diff --git a/datasrc/libinitramfs/rd/memory.h b/datasrc/libinitramfs/rd/memory.h index 415e8394..b8c82909 100644 --- a/datasrc/libinitramfs/rd/memory.h +++ b/datasrc/libinitramfs/rd/memory.h @@ -5,8 +5,9 @@ #include -void *rd_calloc_or_die(size_t nmemb, size_t size) __attribute__((alloc_size(1, 2))); -void *rd_malloc_or_die(size_t size) __attribute__((alloc_size(1))); -char *rd_asprintf_or_die(char **ptr, const char *fmt, ...) __attribute__((nonnull(1, 2),format(printf, 2, 3))); +void *rd_calloc_or_die(size_t nmemb, size_t size) __attribute__((alloc_size(1, 2),returns_nonnull,warn_unused_result)); +void *rd_malloc_or_die(size_t size) __attribute__((alloc_size(1),returns_nonnull,warn_unused_result)); +char *rd_asprintf_or_die(const char *fmt, ...) __attribute__((nonnull(1),format(printf, 1, 2),returns_nonnull, + warn_unused_result)); #endif /* __RD_MEMORY_H__ */ diff --git a/datasrc/ueventd/queue-processor.c b/datasrc/ueventd/queue-processor.c index 908492a7..8b13a1c9 100644 --- a/datasrc/ueventd/queue-processor.c +++ b/datasrc/ueventd/queue-processor.c @@ -92,15 +92,11 @@ void process_events(struct watch *queue) { rd_info("%s: session=%lu: processing events", queue->q_name, session); - char *numenv; - - rd_asprintf_or_die(&numenv, "SESSION=%lu", session); + char *numenv = rd_asprintf_or_die("SESSION=%lu", session); putenv(numenv); - char *srcdir, *dstdir; - - rd_asprintf_or_die(&srcdir, "%s/%s", filter_dir, queue->q_name); - rd_asprintf_or_die(&dstdir, "%s/%s", uevent_dir, queue->q_name); + char *srcdir = rd_asprintf_or_die("%s/%s", filter_dir, queue->q_name); + char *dstdir = rd_asprintf_or_die("%s/%s", uevent_dir, queue->q_name); move_files(srcdir, dstdir); diff --git a/datasrc/ueventd/ueventd.c b/datasrc/ueventd/ueventd.c index c2c23ba3..414c3f51 100644 --- a/datasrc/ueventd/ueventd.c +++ b/datasrc/ueventd/ueventd.c @@ -99,9 +99,8 @@ int watch_path(int inotifyfd, const char *dir, const char *name, uint32_t mask, { struct stat st; struct watch *new = NULL; - char *path; - rd_asprintf_or_die(&path, "%s/%s", dir, name); + char *path = rd_asprintf_or_die("%s/%s", dir, name); int wfd = add_queue_dir(inotifyfd, path, mask); if (wfd < 0) { @@ -173,9 +172,7 @@ int unwatch_path(int inotifyfd, ino_t ino) void watch_pauses(int inotifyfd) { - char *path; - - rd_asprintf_or_die(&path, "%s/queue/pause", uevent_confdb); + char *path = rd_asprintf_or_die("%s/queue/pause", uevent_confdb); if (watch_path(inotifyfd, path, ".", EV_PAUSE_MASK, F_PAUSE_DIR) < 0) exit(EXIT_FAILURE); @@ -187,9 +184,7 @@ void apply_pause(void) { struct watch *p; DIR *dir; - char *path; - - rd_asprintf_or_die(&path, "%s/queue/pause", uevent_confdb); + char *path = rd_asprintf_or_die("%s/queue/pause", uevent_confdb); dir = xopendir(path); pause_all = 0; -- 2.33.8