Make-initrd development discussion
 help / color / mirror / Atom feed
From: Alexey Gladkov <gladkov.alexey@gmail.com>
To: make-initrd@lists.altlinux.org
Subject: [make-initrd] [PATCH 2/2] ueventd: Change interface rd_asprintf_or_die
Date: Mon, 22 May 2023 09:57:23 +0200
Message-ID: <20230522075723.486638-2-gladkov.alexey@gmail.com> (raw)
In-Reply-To: <6258d160-9ffc-30de-abda-d6aec405559a@gmail.com>

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 <gladkov.alexey@gmail.com>
---
 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 <stdlib.h>
 
-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



  parent reply	other threads:[~2023-05-22  7:57 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 13:42 [make-initrd] [PATCH 0/3] Reimplement ueventd Alexey Gladkov
2023-05-04 13:42 ` [make-initrd] [PATCH 1/3] " Alexey Gladkov
2023-05-05  3:08   ` Leonid Krivoshein
2023-05-05 17:02     ` Alexey Gladkov
2023-05-05  4:03   ` Leonid Krivoshein
2023-05-05 17:16     ` Alexey Gladkov
2023-05-05  5:21   ` Leonid Krivoshein
2023-05-05 17:24     ` Alexey Gladkov
2023-05-14 20:12   ` Leonid Krivoshein
2023-05-14 20:45     ` Alexey Gladkov
2023-05-14 20:57   ` Leonid Krivoshein
2023-05-15  8:52     ` Alexey Gladkov
2023-05-14 23:08   ` Leonid Krivoshein
2023-05-15  9:05     ` Alexey Gladkov
2023-05-15  0:47   ` Leonid Krivoshein
2023-05-15  9:12     ` Alexey Gladkov
2023-05-15  4:38   ` Leonid Krivoshein
2023-05-15 10:43     ` Alexey Gladkov
2023-05-18  6:39         ` Leonid Krivoshein
2023-05-18  7:05           ` Alexey Gladkov
2023-05-20  9:00   ` Leonid Krivoshein
2023-05-20 13:18     ` Alexey Gladkov
2023-05-20 15:17       ` Vladimir D. Seleznev
2023-05-20 17:23       ` Leonid Krivoshein
2023-05-20 18:51         ` Alexey Gladkov
2023-05-21  8:53         ` [make-initrd] [PATCH] ueventd: Don't use a epoll timeout when it's not needed Alexey Gladkov
2023-05-22  4:46           ` Leonid Krivoshein
2023-05-22  7:54             ` Alexey Gladkov
2023-05-22  9:19               ` Alexey Gladkov
2023-05-22  7:57             ` [make-initrd] [PATCH 1/2] ueventd: Fix memory leak Alexey Gladkov
2023-05-22  7:57             ` Alexey Gladkov [this message]
2023-05-22  9:36               ` [make-initrd] [PATCH v2] ueventd: Change interface rd_asprintf_or_die Alexey Gladkov
2023-05-20 16:37     ` [make-initrd] [PATCH 1/3] ueventd: Simplify call of the queue handler Alexey Gladkov
2023-05-20 16:37     ` [make-initrd] [PATCH 2/3] ueventd: Rename fd_list to fd_handler_list Alexey Gladkov
2023-05-20 16:37     ` [make-initrd] [PATCH 3/3] ueventd: Drop obsolete declarations Alexey Gladkov
2023-05-04 13:42 ` [make-initrd] [PATCH 2/3] Replace polld by uevent queue Alexey Gladkov
2023-05-04 13:42 ` [make-initrd] [PATCH 3/3] feature/kickstart: Reset rootdelay timer after kickstart Alexey Gladkov
2023-05-06 19:45 ` [make-initrd] ueventd: Add a prefix to the logging functions to avoid name collisions Alexey Gladkov
2023-05-06 19:45 ` [make-initrd] ueventd: Allow to configure the log destination Alexey Gladkov
2023-05-06 19:45 ` [make-initrd] ueventd: Pass the program name when initializing the logger Alexey Gladkov
2023-05-06 19:45 ` [make-initrd] ueventd: Rewrite logging function to make it more atomic Alexey Gladkov
2023-05-07 12:48 ` [make-initrd] [PATCH 0/3] Reimplement ueventd Alexey Gladkov
2023-05-13 11:50 ` Alexey Gladkov
2023-05-14 20:15   ` Leonid Krivoshein
2023-05-14 20:49     ` Alexey Gladkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522075723.486638-2-gladkov.alexey@gmail.com \
    --to=gladkov.alexey@gmail.com \
    --cc=make-initrd@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Make-initrd development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \
		make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com
	public-inbox-index make-initrd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.make-initrd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git