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=1684742253; x=1687334253; 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=xgimQUS2m0+hc1gsn7wSG9GFEgYn1YDQAMvIFEOFSf0=; b=ihPjWMerWo7fHTyxqOuYRGh6lUOj1O4W7EIQDL7nxI4WlwuT0yMmx3BnXF3enTVkPK x1P5g8aaInwK/mix+NQ8REE1qBCYlbPtGMq4GI4YL3noCOJ9w9z3C4t7Hs9+sjUCxt+U ZncMq0bpK8w9QSbNWTaI3PGlDiCo2bGp4XBjKHwZ7YOCVb+t/GgihbYAERwZCu/Y6EuB TwgI81+Z333ZHm1Fl61Db98h2uh7MNA+994ZI4eubRcrozUQaVsIuIm2UKyxzUyiKs06 1RogRvSQPvAoNuXXQIdxBjXBwoM4gcwqUda/B5wJmKACRmNNyKDrWjBb4zoqoy8EyJx2 PE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684742253; x=1687334253; 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=xgimQUS2m0+hc1gsn7wSG9GFEgYn1YDQAMvIFEOFSf0=; b=J+G4WuzwFAAjAo58fPBTajSfVDhRIXvlb7A5YapGV5P3/3RNGRBzCTaUnvd2WkVKVW 9iwjtOC0mnmZCgQ0Waqo0xYxr6DxApABwHTd61wxI8eCl83gif00qwH4k8BOHYV/Sv+l TWTwR/mrF/QVoCVgB2u1eHlV+8+Zd0bOHILhsSgPX5jJncT11bKPqbWJGg8QDUQuSLxW OMm9qQmAJDZj45BrdEkmS45gIv+oKm050G5W1o/WepgCLBQ2vLUIi0xSjzywUnh/dMtM tFT2C37J/zlv/Fk7kJisp+1EJsMqvR2chklGLZe9em50x+buXSeN3DkugOAhL1VdwPk8 wrXQ== X-Gm-Message-State: AC+VfDyXPflopjYRuvjy70HmI7GHcsKd6ZTni26HAEGmyVOdprXlOEmb npBsbkbME5coodhzO3c6KmDwppSj//M= X-Google-Smtp-Source: ACHHUZ6p2FkZGLmA5Cn3fKsB95TKhxRDvjlqvaVkgxsb7f+RYlT2sdLZvwWvC+V0It9YAtYWiTQTlg== X-Received: by 2002:adf:f28a:0:b0:309:42f3:4c3a with SMTP id k10-20020adff28a000000b0030942f34c3amr7750285wro.32.1684742253018; Mon, 22 May 2023 00:57:33 -0700 (PDT) From: Alexey Gladkov To: make-initrd@lists.altlinux.org Date: Mon, 22 May 2023 09:57:23 +0200 Message-Id: <20230522075723.486638-2-gladkov.alexey@gmail.com> X-Mailer: git-send-email 2.33.8 In-Reply-To: <6258d160-9ffc-30de-abda-d6aec405559a@gmail.com> References: <6258d160-9ffc-30de-abda-d6aec405559a@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [make-initrd] [PATCH 2/2] 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 07:57:37 -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 --- Makefile.in | 2 +- datasrc/libinitramfs/memory.c | 3 ++- datasrc/libinitramfs/rd/memory.h | 6 +++--- datasrc/ueventd/queue-processor.c | 10 +++------- datasrc/ueventd/ueventd.c | 11 +++-------- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Makefile.in b/Makefile.in index 45053fa0..4d133964 100644 --- a/Makefile.in +++ b/Makefile.in @@ -138,7 +138,7 @@ PATH = $(CURDIR)/$(dest_sbindir):$(CURDIR)/$(dest_bindir):$(shell echo $$PATH) CFLAGS = @CFLAGS@ \ -Wall -Wextra -W -Wshadow -Wcast-align \ -Wwrite-strings -Wconversion -Waggregate-return -Wstrict-prototypes \ - -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn \ + -Wmissing-prototypes -Wmissing-declarations \ -Wmissing-format-attribute -Wredundant-decls -Wdisabled-optimization \ -Wno-pointer-arith \ -Werror=shadow -Werror=missing-prototypes -Werror=implicit-function-declaration diff --git a/datasrc/libinitramfs/memory.c b/datasrc/libinitramfs/memory.c index ea0d292e..f884dd21 100644 --- a/datasrc/libinitramfs/memory.c +++ b/datasrc/libinitramfs/memory.c @@ -27,8 +27,9 @@ 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 = NULL; va_list arg; va_start(arg, fmt); diff --git a/datasrc/libinitramfs/rd/memory.h b/datasrc/libinitramfs/rd/memory.h index 415e8394..6694f212 100644 --- a/datasrc/libinitramfs/rd/memory.h +++ b/datasrc/libinitramfs/rd/memory.h @@ -5,8 +5,8 @@ #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