Skip to content

syscall flood on every time*() function call

rim requested to merge rozhuk-im/glib:gtimezone into master

truss show that GTK app do many times:

27100: openat(AT_FDCWD,"/etc/localtime",O_RDONLY,00) = 114 (0x72)
27100: fstat(114,{ mode=-r--r--r-- ,inode=1845941,size=1518,blksize=32768 }) = 0 (0x0)
27100: mmap(0x0,1518,PROT_READ,MAP_PRIVATE,114,0x0) = 34458873856 (0x805e8b000)
27100: close(114)				 = 0 (0x0)
27100: munmap(0x805e8b000,1518)			 = 0 (0x0)

I found article: set-environment-variable-save-thousands-of-system-calls and try to set: env TZ=":/etc/localtime" truss -fD geany or env TZ="Europe/Moscow" truss -fD geany without success.

I discovered that glib time zone cache is does not work properly:

GDateTime *
g_date_time_new_from_unix_local (gint64 t)
  GDateTime *datetime;
  GTimeZone *local;

  local = g_time_zone_new_local ();
  datetime = g_date_time_new_from_unix (local, t);
  g_time_zone_unref (local);

  return datetime;

GTimeZone *
g_time_zone_new_local (void)
  return g_time_zone_new (getenv ("TZ"));

g_time_zone_new() load and add time zone to cache if arg is not NULL. g_time_zone_unref() - remove time zone from cache. As you can see time zone in most cases removed from cache after short time.

Patch keep zone pointer with ref=1 and for g_time_zone_ref() for time zone getenv ("TZ") and UTC. After apply patch even without set TZ env var no more syscall flood happen.

FreeBSD ports BUG 240517

Edited by Jeff Fortin

Merge request reports