]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add a helper function, new_ipc
authorMasatake YAMATO <yamato@redhat.com>
Sat, 4 Mar 2023 04:37:20 +0000 (13:37 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 18 May 2023 18:27:27 +0000 (03:27 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-fifo.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index aea143c7e5eb2c150a6ecad34ee87fc37dbd71da..704bc06da4cae969132ec949f6b390d019dd4d2a 100644 (file)
@@ -107,6 +107,7 @@ static bool fifo_is_suitable_ipc(struct ipc *ipc, struct file *file)
 static const struct ipc_class *fifo_get_ipc_class(struct file *file __attribute__((__unused__)))
 {
        static const struct ipc_class fifo_ipc_class = {
+               .size = sizeof(struct fifo_ipc),
                .get_hash = fifo_get_hash,
                .is_suitable_ipc = fifo_is_suitable_ipc,
                .free = NULL,
@@ -125,10 +126,7 @@ static void fifo_initialize_content(struct file *file)
        if (ipc)
                goto link;
 
-       ipc = xmalloc(sizeof(struct fifo_ipc));
-       ipc->class = fifo_get_ipc_class(file);
-       INIT_LIST_HEAD(&ipc->endpoints);
-       INIT_LIST_HEAD(&ipc->ipcs);
+       ipc = new_ipc(fifo_get_ipc_class(file));
        ((struct fifo_ipc *)ipc)->ino = file->stat.st_ino;
 
        hash = fifo_get_hash(file);
index 6d7fd13f3ce82e28f98b3a42025ebf517daffcfd..cdfe311b9d2e22b73cf770d26444084f54a9f4a5 100644 (file)
@@ -1062,6 +1062,15 @@ static void finalize_ipc_table(void)
                list_free(&ipc_table.tables[i], struct ipc, ipcs, free_ipc);
 }
 
+struct ipc *new_ipc(const struct ipc_class *class)
+{
+       struct ipc *ipc = xcalloc(1, class->size);
+       ipc->class = class;
+       INIT_LIST_HEAD(&ipc->endpoints);
+       INIT_LIST_HEAD(&ipc->ipcs);
+       return ipc;
+}
+
 struct ipc *get_ipc(struct file *file)
 {
        int slot;
index aec2c7a57ed932fe57efae292cba019fb7130523..5a1cc9891b5cf96a3cf21968629681dfe75a6d1c 100644 (file)
@@ -203,11 +203,13 @@ struct ipc_endpoint {
 };
 
 struct ipc_class {
+       size_t size;
        unsigned int (*get_hash)(struct file *file);
        bool (*is_suitable_ipc)(struct ipc *ipc, struct file *file);
        void (*free)(struct ipc *ipc);
 };
 
+struct ipc *new_ipc(const struct ipc_class *class);
 struct ipc *get_ipc(struct file *file);
 void add_ipc(struct ipc *ipc, unsigned int hash);