Re: [PATCH] uuidd: add cont_clock persistence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Karel,


> On 4. Jan 2024, at 13:12, Karel Zak <kzak@xxxxxxxxxx> wrote:
> 
> On Fri, Dec 15, 2023 at 11:18:29PM +0100, Michael Trapp wrote:
>> cont_clock requires a correct time setup and therefore it
>> must be possible to detect a step back between uuidd starts.
>> ...
>> + enum { fd_init = -2, fd_error = -1 };
> 
> In the code (below) the enum items seems like variables, a little bit
> confusing. It would be better use upper-case, STATE_FD_INIT, STATE_FD_ERROR.
>> + static int state_fd = fd_init;
>> ...
>> + if (state_fd == fd_error)

Makes sense and will be fixed.

>> ...
>> + save_umask = umask(0);
>> + state_fd = open(LIBUUID_CLOCK_CONT_FILE, O_RDWR|O_CREAT|O_CLOEXEC, 0660);
>> + (void) umask(save_umask);
>> + if (state_fd == fd_error)
>> + return -1;
>> +
>> + state_f = fdopen(state_fd, "r+" UL_CLOEXECSTR);
>> + if (!state_f)
>> + goto error;
> 
> Seems it duplicates code from get_clock(), what about introduce a generic
> 
>    state_fd_init(LIBUUID_CLOCK_CONT_FILE, &state_fd, &state_f);
> 
> and use the same in get_clock() for LIBUUID_CLOCK_FILE?

That’s the case for the initialization with open()/fdopen().
I’ll move this into the new function state_fd_init().

>> + if (fstat(state_fd, &st))
>> + goto error;
>> +
>> + if (st.st_size) {
>> + rewind(state_f);
>> + if (fscanf(state_f, "cont: %lu\n", &last_clock_reg) != 1)
>> + goto error;
>> + } else
>> + last_clock_reg = clock_reg;
> 
> For LIBUUID_CLOCK_FILE we use flock(), I guess it's unnecessary for
> LIBUUID_CLOCK_CONT_FILE as we assume only one uuidd instance, right?

That’s correct, based on the check in uuidd.c, there can't be multiple instances.



Michael








[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux