Re: [PATCH v3 4/9] index-helper: new daemon for caching index and related stuff
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Jul 30, 2014, 10:39 UTC
- Message-ID
- <CACsJy8Bngi8-eMSvNAPmT4_o4A_f1dq-Hs+dC7FNiVHNmoL7+g@mail.gmail.com>
- In-Reply-To
- <CAPig+cTDxTpo53WhfkQbt8EuY15Ttj1NHbh2Do-TKYq2xVvP+g@mail.gmail.com>
On Wed, Jul 30, 2014 at 3:08 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 13 quoted lines
>> +static void share_index(struct index_state *istate, struct index_shm *is)
>> +{
>> + void *new_mmap;
>> + if (istate->mmap_size <= 20 ||
>> + hashcmp(istate->sha1,
>> + (unsigned char *)istate->mmap + istate->mmap_size - 20) ||
>> + !hashcmp(istate->sha1, is->sha1) ||
>> + git_shm_map(O_CREAT | O_EXCL | O_RDWR, 0700, istate->mmap_size,
>> + &new_mmap, PROT_READ | PROT_WRITE, MAP_SHARED,
>> + "git-index-%s", sha1_to_hex(istate->sha1)) < 0)
>
> Do any of these failure conditions deserve a diagnostic message to let
> the user know that there was a problem?Hmm.. diagnostic messages are a problem already. This most likely runs as a daemon, nowhere to print to. But if running on foreground, some messages would help.
Show 11 quoted lines
>> +static int try_shm(struct index_state *istate)
>> +{
>> + void *new_mmap = NULL;
>> + size_t old_size = istate->mmap_size;
>
> Is old_size needed? Can you not simply reference istate->mmap_size
> directly each place old_size is mentioned?
>
>> + ssize_t new_length;
>
> Nit: 'size' vs. 'length' inconsistency in variable name choices.Leftovers after many iterations. Will fix.
Show 9 quoted lines
>> +#define SHM_PATH_LEN 72 /* we don't create very long paths.. */
>> +
>> +ssize_t git_shm_map(int oflag, int perm, ssize_t length, void **mmap,
>> + int prot, int flags, const char *fmt, ...)
>> +{
>> + va_list ap;
>> + char path[SHM_PATH_LEN];
>
> Is there a reason to avoid strbuf here?Laziness (which is ironic as I'm working on patches to clean up fixed size buffers)
-- Duy