summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2008-05-04 10:15:05 +0000
committerArthur de Jong <arthur@arthurdejong.org>2008-05-04 10:15:05 +0000
commit35e494074414dab26a46ab7e7d6ffece6e348425 (patch)
treeb203ff3daca640c604037ece8513d667e7aa1897
parent29ff03a6428f3845cc1db1aa742534379a74a333 (diff)
make number of threads configurable with the threads keyword
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@725 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--man/nss-ldapd.conf.5.xml18
-rw-r--r--nslcd/cfg.c9
-rw-r--r--nslcd/cfg.h2
-rw-r--r--nslcd/nslcd.c16
4 files changed, 39 insertions, 6 deletions
diff --git a/man/nss-ldapd.conf.5.xml b/man/nss-ldapd.conf.5.xml
index 1542263..2b9343e 100644
--- a/man/nss-ldapd.conf.5.xml
+++ b/man/nss-ldapd.conf.5.xml
@@ -68,6 +68,24 @@
<refsect1 id="options">
<title>Options</title>
+ <refsect2 id='runtime_options'>
+ <title>Runtime options</title>
+ <variablelist>
+
+ <varlistentry>
+ <term><option>threads</option> <emphasis remap="I">NUM</emphasis></term>
+ <listitem>
+ <para>
+ Specifies the number of threads to start that can handle requests
+ and perform <acronym>LDAP</acronym> queries.
+ The default is to start 5 threads.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+ </refsect2>
+
<refsect2 id='general_connection_options'>
<title>General connection options</title>
<variablelist>
diff --git a/nslcd/cfg.c b/nslcd/cfg.c
index a884e98..d1eb5b0 100644
--- a/nslcd/cfg.c
+++ b/nslcd/cfg.c
@@ -62,6 +62,7 @@ static void cfg_defaults(struct ldap_config *cfg)
{
int i;
memset(cfg,0,sizeof(struct ldap_config));
+ cfg->ldc_threads=5;
for (i=0;i<(NSS_LDAP_CONFIG_URI_MAX+1);i++)
{
cfg->ldc_uris[i].uri=NULL;
@@ -589,8 +590,14 @@ static void cfg_read(const char *filename,struct ldap_config *cfg)
/* get keyword from line and ignore empty lines */
if (get_token(&line,keyword,sizeof(keyword))==NULL)
continue;
+ /* runtime options */
+ if (strcasecmp(keyword,"threads")==0)
+ {
+ get_int(filename,lnr,keyword,&line,&cfg->ldc_threads);
+ get_eol(filename,lnr,keyword,&line);
+ }
/* general connection options */
- if (strcasecmp(keyword,"uri")==0)
+ else if (strcasecmp(keyword,"uri")==0)
{
check_argumentcount(filename,lnr,keyword,(line!=NULL)&&(*line!='\0'));
while (get_token(&line,token,sizeof(token))!=NULL)
diff --git a/nslcd/cfg.h b/nslcd/cfg.h
index 20ddb30..a67657a 100644
--- a/nslcd/cfg.h
+++ b/nslcd/cfg.h
@@ -66,6 +66,8 @@ struct myldap_uri
struct ldap_config
{
+ /* the number of threads to start */
+ int ldc_threads;
/* NULL terminated list of URIs */
struct myldap_uri ldc_uris[NSS_LDAP_CONFIG_URI_MAX+1];
/* protocol version */
diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c
index 9ead273..5ec2961 100644
--- a/nslcd/nslcd.c
+++ b/nslcd/nslcd.c
@@ -82,8 +82,7 @@ static volatile int nslcd_exitsignal=0;
static int nslcd_serversocket=-1;
/* thread ids of all running threads */
-#define NUM_THREADS 5
-static pthread_t nslcd_threads[NUM_THREADS];
+static pthread_t *nslcd_threads;
/* display version information */
static void display_version(FILE *fp)
@@ -215,7 +214,7 @@ static RETSIGTYPE sigexit_handler(int signum)
int i;
nslcd_exitsignal=signum;
/* cancel all running threads */
- for (i=0;i<NUM_THREADS;i++)
+ for (i=0;i<nslcd_cfg->ldc_threads;i++)
if (pthread_cancel(nslcd_threads[i]))
{
/* TODO: figure out if we can actually log from within a signal handler */
@@ -595,7 +594,13 @@ int main(int argc,char *argv[])
/* TODO: install signal handlers for reloading configuration */
log_log(LOG_INFO,"accepting connections");
/* start worker threads */
- for (i=0;i<NUM_THREADS;i++)
+ nslcd_threads=(pthread_t *)malloc(nslcd_cfg->ldc_threads*sizeof(pthread_t));
+ if (nslcd_threads==NULL)
+ {
+ log_log(LOG_CRIT,"main(): malloc() failed to allocate memory");
+ exit(EXIT_FAILURE);
+ }
+ for (i=0;i<nslcd_cfg->ldc_threads;i++)
{
if (pthread_create(&nslcd_threads[i],NULL,worker,NULL))
{
@@ -610,7 +615,7 @@ int main(int argc,char *argv[])
to do general house keeping things (e.g. checking signals etc) */
/* it is also better to always do thread_cancel() here instead of in the signal
handler */
- for (i=0;i<NUM_THREADS;i++)
+ for (i=0;i<nslcd_cfg->ldc_threads;i++)
{
if (pthread_join(nslcd_threads[i],NULL))
{
@@ -618,6 +623,7 @@ int main(int argc,char *argv[])
exit(EXIT_FAILURE);
}
}
+ free(nslcd_threads);
/* print something about received signals */
if (nslcd_exitsignal!=0)
{