0

I have tried to use kv_t to store some data without success. I have also tried to the examples forum.c & kv.c. forum.c hangs when trying to create the second Forum thread while kv.c crashes.s.

When I have 1 item added to the kv, kv_do will succeed. After adding the second item, trying to call kv_do will result in an infinite loop and the data doesn`t seem valid too.

#include "stdio.h"
int list_threads(kv_item *item, xbuf_t *reply)
{
  Thread *thread = (Thread*)item->val;

  xbuf_t thread_li;
  xbuf_init(&thread_li);

  //using sprintf-like formatting
  xbuf_xcat(&thread_li, 
  "<li>"
   "<a href='/?forum_simple/act=t/id=%llu'>%s</a> (%lu)"
  "</li>",
  thread->id, thread->title.ptr, thread->posts.nbr_items
  );

  char *pos = (char*)xbuf_findstr(reply, "<!--tpl-->");
  if (pos) xbuf_insert(reply, pos, thread_li.len, thread_li.ptr);
  printf("-----------listing threads------\n");
  xbuf_free(&thread_li);

  return 1;
}

The code above is from forum.c. trying after creating the first forum Thread, trying to create the second one will hang because the list_threads function if invoked infinitely. the ---------listing threads----------- is getting printed on the terminal infinitely

DcCarter
  • 1
  • 1

1 Answers1

0

Another user recently reported (see "newest" G-WAN questions) a crash with kv_do and it seems to be related to the atomic primitives implementation rather than about the kv code.

A workaround will be issued once the problem has been isolated.

Gil
  • 3,279
  • 1
  • 15
  • 25
  • Has this problem been addressed yet @Gil? – Nagi Apr 03 '17 at 03:53
  • Not in the close future: programs on Linux became even more a hurdle to maintain than on Microsoft Windows. At this time, we just can't afford to cope with these constant gratuitous incompatibilities. – Gil Apr 04 '17 at 07:08
  • In that case, could you share your working environment that guarantee kv_do to be working? (kernel version, may be gcc version also?) – Nagi Apr 05 '17 at 07:27
  • TWD's custom Linux kernel and a stripped-down Linux usermode environment. All (including G-WAN) compiled with TWD's LIBC. – Gil Apr 06 '17 at 13:38
  • a year later and seems like the libc bug that broke kv_do is still there. One interesting thing though, is that I've successfully run G-WAN under Windows, via its newly introduced [Linux subsystem](https://learn.microsoft.com/en-us/windows/wsl/install-win10) The behaviour is exactly the same as with native Linux, including the trouble with kv_do! – Nagi Jul 23 '18 at 14:27