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=1683307475; x=1685899475; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=mNKvQDDOS3nU+QgGutXKMtHw+5+UneNh703DuQYIznY=; b=IG9/w/lp9lih2hh9wNbdcOcdFXMJm9bUMyUG+VbXUk+nng94GyBuR55XZO2xQObdmU K9DrvF7nkOZ7yCz1K5D4y2FYfLEgtEqh83p25QUE01Kl7w1wZ5yIcxQeoDsLC+zfXtT7 gBvuzBIHJBOB0R8WWBKBI7vi2IyPlKJqn1sJj3rNH3sRbSnvRFXDqdiYyuwAb0P9+MeT 1Dg3RquG1JFoRHtySDBTeV4EBX9AFtdgw1BNn83Ih2v4BoL+FxLnPogOD7RfR0x75CPS RHjuN+Wv/osJojp+MkkON6wPWfcJbO0MjTcQXfYn8XfnJMrjqy9KTrkSHaaX5WLv1ROh s2Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683307475; x=1685899475; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mNKvQDDOS3nU+QgGutXKMtHw+5+UneNh703DuQYIznY=; b=GbSY6ph+yDFcCDJTh/GTpwUNB47j2xutSh4c1VL56B/89kzbkMXDE9leZ9KNfR0qMu RIOZ48Z5unaEGJ/c+JpWvUXvgNM0ShZQCMJJgvvgn40pf3Gq1zoIAD6OxAbQnsMCvxd/ kriNj8zu1eBPfjf7paI4B9TQFxf2l8S18JRNOzqaj/fhsq3rUGAjjUDIOk2lCWBDMEI9 IHsDkO7EFmO4MB6HnXnSPEQO8+Iw3h4PCXpcRauAS0TCJZ7r08oEgXCKTfAYJ+sOdXWX RQWZ23IGXfq2IJnhg55bN+6SbEGwxvyEQMjM6NL01C4rWtZvo/rV9MfMJkxP2ueB+dcw MKRg== X-Gm-Message-State: AC+VfDxkFBw2eZXb5Bqm+/aAGgfEv31KgvUEoLLl4yKV8aBULuv1aiNE 5izk149lc3q5FIdqn6jw42OyIEIYi+I= X-Google-Smtp-Source: ACHHUZ6bvF8yEpj6zBXB4sIisSWqugd2sPjXHW4h+OKeNbjSOXYFHSHrkM6YJnlNHKnR+TKZR2XvXg== X-Received: by 2002:adf:f4cf:0:b0:307:5091:5b96 with SMTP id h15-20020adff4cf000000b0030750915b96mr3982214wrp.22.1683307475635; Fri, 05 May 2023 10:24:35 -0700 (PDT) Date: Fri, 5 May 2023 19:24:31 +0200 From: Alexey Gladkov To: make-initrd@lists.altlinux.org Message-ID: References: <6b444ed922286eb3df8f5322b1bddf9c55753eb8.1683200226.git.gladkov.alexey@gmail.com> <6868e911-b66b-431c-1164-f45158396dfa@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6868e911-b66b-431c-1164-f45158396dfa@gmail.com> 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: Fri, 05 May 2023 17:24:38 -0000 Archived-At: List-Archive: On Fri, May 05, 2023 at 08:21:25AM +0300, Leonid Krivoshein wrote: > > On 5/4/23 16:42, Alexey Gladkov wrote: > > [...] > > diff --git a/datasrc/ueventd/queue-processor.c b/datasrc/ueventd/queue-processor.c > > new file mode 100644 > > index 00000000..ab5e03e4 > > --- /dev/null > > +++ b/datasrc/ueventd/queue-processor.c > > @@ -0,0 +1,116 @@ > > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > > + > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "ueventd.h" > > + > > [...] > > +void move_files(char *srcdir, char *dstdir) > > +{ > > + struct dirent *ent; > > + int srcfd, dstfd; > > + > > + if ((srcfd = open(srcdir, O_RDONLY | O_CLOEXEC)) < 0) > > + fatal("open: %s: %m", srcdir); > > + > > + errno = 0; > > + if ((dstfd = open(dstdir, O_RDONLY | O_CLOEXEC)) < 0) { > > + if (errno == ENOENT) { > > open() тоже прерываемый примитив, но его ты оборачивать не стал. Так > задумано? Нет, это я пропустил просто. > > + if (mkdir(dstdir, 0755) < 0) > > + fatal("mkdir: %s: %m", dstdir); > > + dstfd = open(dstdir, O_RDONLY | O_CLOEXEC); > > + } > > + if (dstfd < 0) > > + fatal("open: %s: %m", dstdir); > > + } > > + > > + DIR *d = fdopendir(srcfd); > > + if (!d) > > + fatal("fdopendir: %m"); > > + > > + while ((ent = xreaddir(d, srcdir)) != NULL) { > > + if (ent->d_name[0] != '.' && ent->d_type == DT_REG && > > + renameat(srcfd, ent->d_name, dstfd, ent->d_name) < 0) > > + fatal("rename `%s/%s' -> `%s/%s': %m", srcdir, ent->d_name, dstdir, ent->d_name); > > + } > > + > > + closedir(d); > > + close(dstfd); > > Возможно тут и нет ошибки, но srcfd будет закрыт только при завершении > программы, а что насчёт повторного вызова функции с такой же srcdir или > такое невозможно? Нет, srcfd будет закрыт в closedir. https://git.altlinux.org/gears/g/glibc.git?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/closedir.c#l30 > > +} > > [...] > > > -- > WBR, Leonid Krivoshein. > _______________________________________________ > Make-initrd mailing list > Make-initrd@lists.altlinux.org > https://lists.altlinux.org/mailman/listinfo/make-initrd -- Rgrds, legion