[PATCH v10 1/5] PID namespace translation support

Dmitry V. Levin ldv at altlinux.org
Sat Aug 22 21:06:26 UTC 2020


On Sat, Aug 22, 2020 at 10:56:05PM +0200, Ákos Uzonyi wrote:
> On Sat, 22 Aug 2020 at 21:50, Dmitry V. Levin <ldv at altlinux.org> wrote:
> > On Sat, Aug 22, 2020 at 09:37:55PM +0200, Ákos Uzonyi wrote:
> > > On Sat, 22 Aug 2020 at 19:52, Dmitry V. Levin <ldv at altlinux.org> wrote:
> > > > On Wed, Aug 19, 2020 at 08:16:33PM +0200, Ákos Uzonyi wrote:
> > > > [...]
> > > > > +static uint64_t *
> > > > > +trie_get_node(struct trie *t, uint64_t key, bool auto_create)
> > > > > +{
> > > > > +     void **cur_node = &(t->data);
> > > > > +
> > > > > +     if (t->key_size < 64 && key > (uint64_t) 1 << t->key_size)
> > > > > +             return NULL;
> > > > > +
> > > > > +     for (uint8_t cur_depth = 0; cur_depth <= t->max_depth; cur_depth++) {
> > > > > +             uint8_t offs = trie_get_node_bit_offs(t, cur_depth);
> > > > > +             uint8_t sz = trie_get_node_size(t, cur_depth);
> > > > > +
> > > > > +             if (!*cur_node) {
> > > > > +                     if (!auto_create)
> > > > > +                             return NULL;
> > > > > +
> > > > > +                     if (cur_depth == t->max_depth)
> > > > > +                             *cur_node = trie_create_data_block(t);
> > > > > +                     else
> > > > > +                             *cur_node = calloc(1 << sz, 1);
> > > > > +
> > > > > +                     if (!*cur_node) {
> > > > > +                             fprintf(stderr, "Out of memory");
> > > > > +                             exit(1);
> > > > > +                     }
> > > >
> > > > This should rather be error_msg_and_die("Out of memory");
> > > >
> > > > Or better use xcalloc instead of calloc here and in
> > > > trie_create_data_block.
> > >
> > > The problem is, trie.c is linked to the strace code and to the test
> > > suite code too, so we can't use these functions (they do not exist in
> > > the test environment). Originally xcalloc was used here, but when I
> > > created the trie test, I replaced it with the code above.
> > > fprintf(sterr); exit(1) seems to be fine, as this is used in
> > > error_msg_and_die, and error_msg_and fail too.
> >
> > First of all, I don't like the very idea of a mere test affecting the way
> > how the main code is implemented.
> 
> Yes, I agree, it was an ugly hack from me to replace xcalloc this way.
> 
> > If xcalloc is needed in a test, why not add it to the test?
> 
> OK, I'll add it. Is it OK if I copy xmalloc.c and xmalloc.h to tests/
> (with necessary modifications like replacing
> error_msg_and_die with error_msg_and_fail), and add them to libtests_a_SOURCES?

There is no need to do anything with xmalloc.h as its directory is already
in the search path of header files for tests.

With regards to xmalloc.c, I suppose you can create e.g.
tests/xmalloc_for_tests.c containing
#define error_msg_and_die error_msg_and_fail
#include "xmalloc.c"


-- 
ldv


More information about the Strace-devel mailing list