Blame sysdeps/unix/sysv/linux/nscd_setup_thread.c

Packit 6c4009
/* Setup of nscd worker threads.  Linux verison.
Packit 6c4009
   Copyright (C) 2004-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
Packit 6c4009
Packit 6c4009
   This program is free software; you can redistribute it and/or modify
Packit 6c4009
   it under the terms of the GNU General Public License as published
Packit 6c4009
   by the Free Software Foundation; version 2 of the License, or
Packit 6c4009
   (at your option) any later version.
Packit 6c4009
Packit 6c4009
   This program is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 6c4009
   GNU General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU General Public License
Packit 6c4009
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <nscd.h>
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
setup_thread (struct database_dyn *db)
Packit 6c4009
{
Packit 6c4009
#ifdef __NR_set_tid_address
Packit 6c4009
  /* Only supported when NPTL is used.  */
Packit 6c4009
  char buf[100];
Packit 6c4009
  if (confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof (buf)) >= sizeof (buf)
Packit 6c4009
      || strncmp (buf, "NPTL", 4) != 0)
Packit 6c4009
    return 0;
Packit 6c4009
Packit 6c4009
  /* Do not try this at home, kids.  We play with the SETTID address
Packit 6c4009
     even thought the process is multi-threaded.  This can only work
Packit 6c4009
     since none of the threads ever terminates.  */
Packit 6c4009
  INTERNAL_SYSCALL_DECL (err);
Packit 6c4009
  int r = INTERNAL_SYSCALL (set_tid_address, err, 1,
Packit 6c4009
			    &db->head->nscd_certainly_running);
Packit 6c4009
  if (!INTERNAL_SYSCALL_ERROR_P (r, err))
Packit 6c4009
    /* We know the kernel can reset this field when nscd terminates.
Packit 6c4009
       So, set the field to a nonzero value which indicates that nscd
Packit 6c4009
       is certainly running and clients can skip the test.  */
Packit 6c4009
    return db->head->nscd_certainly_running = 1;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}