[PATCH 1/3] gen_uuid.c: Ignore return values from fcntl()

Gedare Bloom gedare at rtems.org
Wed Mar 31 16:48:55 UTC 2021


On Wed, Mar 31, 2021 at 10:35 AM Joel Sherrill <joel at rtems.org> wrote:
>
>
>
> On Wed, Mar 31, 2021 at 11:13 AM Gedare Bloom <gedare at rtems.org> wrote:
>>
>> On Wed, Mar 31, 2021 at 9:16 AM Ryan Long <ryan.long at oarcorp.com> wrote:
>> >
>> > CID 1049146: Unchecked return value from library in get_clock().
>> > CID 1049147: Unchecked return value from library in get_random_fd().
>> >
>> > Closes #4280
>> > ---
>> >  cpukit/libmisc/uuid/gen_uuid.c | 8 ++++++++
>> >  1 file changed, 8 insertions(+)
>> >
>> > diff --git a/cpukit/libmisc/uuid/gen_uuid.c b/cpukit/libmisc/uuid/gen_uuid.c
>> > index 3ca75a0..9cd763d 100644
>> > --- a/cpukit/libmisc/uuid/gen_uuid.c
>> > +++ b/cpukit/libmisc/uuid/gen_uuid.c
>> > @@ -164,8 +164,13 @@ static int get_random_fd(void)
>> >                         fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
>> >                 if (fd >= 0) {
>> >                         i = fcntl(fd, F_GETFD);
>> > +                       #ifdef __rtems__
>> > +                       if (i >= 0)
>> > +                               (void) fcntl(fd, F_SETFD, i | FD_CLOEXEC);
>> > +                       #else
>> >                         if (i >= 0)
>> >                                 fcntl(fd, F_SETFD, i | FD_CLOEXEC);
>> > +                       #endif
>> You could do the same thing here as you did below, just put the #ifdef
>> after the if (i>=0)
>>
>> The upstream is
>> https://github.com/karelzak/util-linux/blob/master/libuuid/src/gen_uuid.c
>> I wonder if we should update?
>
>
> Are you sure that's the master? That's not what the README in the directory says.
>
> I'm not opposed to updating the code in the directory but I want to make sure it
> comes from the right place.
>
OK, I see there is
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/tree/lib/uuid
and there is the util-linux. I don't know how they are related and
whether they have forked from each other.

You're right, the e2fsprogs is the right upstream. I think they have
diverged, and it seems that the util-linux is more cactive and more
likely to be maintained into the future.

https://github.com/karelzak/util-linux/commits/master/libuuid/src
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/log/lib/uuid

That's as far down the Linux ecosystem rabbit hole I want to go.

> And do we have any tests to ensure it works if it builds? This wasn't included
> in the last coverage I uploaded but I can ask Alex to turn it on.
>
IDK anything about that either.

>>
>> >                 }
>> >  #endif
>> >                 srand((getpid() << ((sizeof(pid_t)*CHAR_BIT)>>1)) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
>> > @@ -426,6 +431,9 @@ try_again:
>> >                 }
>> >                 rewind(state_f);
>> >                 fl.l_type = F_UNLCK;
>> > +       #ifdef __rtems__
>> > +               (void)
>> > +       #endif
>> >                 fcntl(state_fd, F_SETLK, &fl);
>> >         }
>> >
>> > --
>> > 1.8.3.1
>> >
>> > _______________________________________________
>> > devel mailing list
>> > devel at rtems.org
>> > http://lists.rtems.org/mailman/listinfo/devel
>> _______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list