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=1684105691; x=1686697691; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=9N4FrMS6Dt0ibQNrefQWllR6Cx45PqDtEgdihnB27ME=; b=dXxfyPwZMxakh+zz9vyXqDwcyioXXcGcXuGWj69SBUEqQ2MeqH/M4+0e86J2xnnSVA b2CPNWc09gG439zbQKL7jyAHLKxYT22gjBSDMsQdUORu5QXlKE2FiRJV8/rlsaSakpdl mZZl0leK7xq32368e8v60/gK98DxT7HWMNXEGrWnkJU8wIshUoWnbpmIJWiQzHucrXAY sJbhHwz0KIWT5YqlKDZFu/CxKz6loH0+ZdX+o26eBUnpZN6pgxyuPpYlJw9Nl3sh+PLv MB2aIeQsit9vpzC/q9a8q2NC2sxbdTijg2d1JHlL4WO5f4KjcxLRSUQYO5kEcRJFUggU 9AfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684105691; x=1686697691; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9N4FrMS6Dt0ibQNrefQWllR6Cx45PqDtEgdihnB27ME=; b=FeeJtsSCc+PII/9FouEg99UVvzeQIumhcQtMZz5bJdia0mHpeonA1gVeUMoSengJwp SP8ANYdU4Q2cROEPVB/Rs1L9U/7Jp7YJBPu4oiwQSWzbnYP8bmafJZ1+DGLLd0FnAGoi QsIfncI3JVsPfKBGpLmJZuMAwQypwDK2lTRLtV7MvB6OWFEku8O4tALliilXNPzC2CKf WUz+e7l4q2qLxxHuYfcykp2VhHvVFmrgtQAkEd2Hey7TPs65Q7fqQthkjvCbvIMzIgeP 0k6ge/0u+gHUR6gfDYDkhIHUjG3penoJqkM0QFleSoAHZgJeTxKSCNXKn+N3lJlQ9rAe +b3A== X-Gm-Message-State: AC+VfDz3ivUT20Ea8KzvR7iVfajipMbexyVzZ8WBrNIsZHcF8H9pKCcu w77eGWYCPllMFjm7Nyy8hma8Lv3Df8s= X-Google-Smtp-Source: ACHHUZ5VmBIba/QI4/pKhBoDIK03FmWQF9m95SFjDIzsu8XGq0YcnUy0zbC0pGEpsQ2+lV5J1kt7lg== X-Received: by 2002:a05:6808:1289:b0:395:f659:6181 with SMTP id a9-20020a056808128900b00395f6596181mr2063139oiw.55.1684105691146; Sun, 14 May 2023 16:08:11 -0700 (PDT) Message-ID: Date: Mon, 15 May 2023 02:08:09 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.10.0 Content-Language: ru, en-US To: make-initrd@lists.altlinux.org References: <6b444ed922286eb3df8f5322b1bddf9c55753eb8.1683200226.git.gladkov.alexey@gmail.com> From: Leonid Krivoshein In-Reply-To: <6b444ed922286eb3df8f5322b1bddf9c55753eb8.1683200226.git.gladkov.alexey@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [make-initrd] [PATCH 1/3] Reimplement ueventd 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: Sun, 14 May 2023 23:08:14 -0000 Archived-At: List-Archive: Тут ошибок нет, но есть над чем позудеть.)) On 5/4/23 16:42, Alexey Gladkov wrote: > [...] > diff --git a/datasrc/ueventd/path.c b/datasrc/ueventd/path.c > new file mode 100644 > index 00000000..7880ad5c > --- /dev/null > +++ b/datasrc/ueventd/path.c > @@ -0,0 +1,80 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > + > +#include > +#include > +#include > +#include > + > +#include "ueventd.h" > + > +int is_dot_dir(struct dirent *ent) > +{ > + return (ent->d_type == DT_DIR && > + (ent->d_name[0] == '.' && (ent->d_name[1] == '\0' || > + (ent->d_name[1] == '.' && ent->d_name[2] == '\0') ))); > +} > + > +DIR *xopendir(const char *path) > +{ > + DIR *dir = opendir(path); > + if (!dir) > + fatal("opendir: %s: %m", path); > + return dir; > +} > + > + > +struct dirent *xreaddir(DIR *d, const char *path) > +{ > + struct dirent *ent; > + > + errno = 0; > + ent = readdir(d); > + if (!ent) { > + if (!errno) > + return NULL; Создавать этот NULL дольше, чем вернуть готовый ent. Я бы поменял условие на if (!ent && errno) fatal(...); Получится даже короче и читабельней. > + fatal("readdir: %s: %m", path); > + } > + return ent; > +} > + > +int empty_directory(const char *path) > +{ > + struct dirent *ent; > + int is_empty = 1; > + DIR *d = xopendir(path); > + > + while ((ent = xreaddir(d, path)) != NULL) { > + if (ent->d_name[0] != '.') { > + is_empty = 0; > + break; > + } > + } > + closedir(d); > + > + return is_empty; > +} Назначение функции по имени кажется двусмысленным и можно обойтись без этой переменной в стеке, даже немного сократив код: int is_dir_empty(const char *path) {         struct dirent *ent;         DIR *d = xopendir(path);         while ((ent = xreaddir(d, path)) != NULL) {                 if (ent->d_name[0] != '.') {                         closedir(d);                         return 0;                 }         }         closedir(d);         return -1; } Не помню, какую задачу решает этот минус, но кажется правильней для логического значения. > + > +ssize_t read_retry(int fd, void *buf, size_t count) > +{ > + return TEMP_FAILURE_RETRY(read(fd, buf, count)); > +} > + > +ssize_t write_retry(int fd, const void *buf, size_t count) > +{ > + return TEMP_FAILURE_RETRY(write(fd, buf, count)); > +} > + > +ssize_t write_loop(int fd, const char *buffer, size_t count) > +{ > + ssize_t offset = 0; > + > + while (count > 0) { > + ssize_t block = write_retry(fd, &buffer[offset], count); > + > + if (block <= 0) > + return offset ? : block; Первый раз встречаю в такой нотации. Перед двоеточием имеется ввиду тоже offset? > + offset += block; > + count -= (size_t) block; > + } > + return offset; > +} > [...] -- WBR, Leonid Krivoshein.