Back to index

glibc  2.9
nscd_setup_thread.c
Go to the documentation of this file.
00001 /* Setup of nscd worker threads.  Linux verison.
00002    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published
00008    by the Free Software Foundation; version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software Foundation,
00018    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00019 
00020 #include <string.h>
00021 #include <unistd.h>
00022 #include <nscd.h>
00023 #include <sysdep.h>
00024 
00025 
00026 int
00027 setup_thread (struct database_dyn *db)
00028 {
00029 #ifdef __NR_set_tid_address
00030   /* Only supported when NPTL is used.  */
00031   char buf[100];
00032   if (confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof (buf)) >= sizeof (buf)
00033       || strncmp (buf, "NPTL", 4) != 0)
00034     return 0;
00035 
00036   /* Do not try this at home, kids.  We play with the SETTID address
00037      even thought the process is multi-threaded.  This can only work
00038      since none of the threads ever terminates.  */
00039   INTERNAL_SYSCALL_DECL (err);
00040   int r = INTERNAL_SYSCALL (set_tid_address, err, 1,
00041                          &db->head->nscd_certainly_running);
00042   if (!INTERNAL_SYSCALL_ERROR_P (r, err))
00043     /* We know the kernel can reset this field when nscd terminates.
00044        So, set the field to a nonzero value which indicates that nscd
00045        is certainly running and clients can skip the test.  */
00046     return db->head->nscd_certainly_running = 1;
00047 #endif
00048 
00049   return 0;
00050 }