Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 80219 | Differences between
and this patch

Collapse All | Expand All

(-) (-26 / +593 lines)
Line  Link Here
-- configure.ac
Lines 57-63 Link Here
57
	AC_HELP_STRING([--enable-rfc2553], [use getaddrinfo, getnameinfo, etc]),
57
	AC_HELP_STRING([--enable-rfc2553], [use getaddrinfo, getnameinfo, etc]),
58
        AC_DEFINE(ENABLE_RFC2553,1,[Use getaddrinfo(), getnameinfo(), etc]))
58
        AC_DEFINE(ENABLE_RFC2553,1,[Use getaddrinfo(), getnameinfo(), etc]))
59
59
60
61
AC_ARG_WITH(gnome,
60
AC_ARG_WITH(gnome,
62
        AC_HELP_STRING([--with-gnome], [build GNOME-based monitor]),
61
        AC_HELP_STRING([--with-gnome], [build GNOME-based monitor]),
63
        [GNOME_BIN=distccmon-gnome
62
        [GNOME_BIN=distccmon-gnome
Lines 262-274 Link Here
262
    AC_MSG_RESULT(no)
261
    AC_MSG_RESULT(no)
263
fi
262
fi
264
263
264
########################################################################
265
# Check for OpenSLP
266
AC_ARG_ENABLE(slp, [  --enable-slp            find hosts via slp],  with_slp=$enableval, with_slp=no)
267
if test "$with_slp" = "yes"; then
268
AC_MSG_CHECKING(for SLP support)
269
save_slptest_LIBS="$LIBS"
270
save_slptest_LDFLAGS="$LDFLAGS"
271
save_slptest_CPPFLAGS="$CPPFLAGS"
272
LDFLAGS="$all_libraries $LDFLAGS"
273
CPPFLAGS="$CPPFLAGS $all_includes"
274
LIBS="-lslp"
275
AC_TRY_LINK(   [
276
                       #include <slp.h>
277
               ],[
278
                       SLPOpen(0, SLP_FALSE, (SLPHandle*) 0);
279
               ],[
280
                       AC_DEFINE(WITH_SLP,1,[Define if SLP is avaible and enabled])
281
                       LIB_SLP="-lslp"
282
		       SLP_BIN=distccenv
283
                       BUILD_SLP='$(slp_OBJS)'
284
                       AC_MSG_RESULT(yes)
285
               ],[
286
                       AC_MSG_ERROR(no)
287
])
288
CPPFLAGS=$save_slptest_CPPFLAGS
289
LDFLAGS=$save_slptest_LDFLAGS
290
LIBS=$save_slptest_LIBS
291
fi
292
AC_SUBST(LIB_SLP)
293
265
294
266
295
267
########################################################################
296
########################################################################
268
# Check for types
297
# Check for types
269
AC_TYPE_SIGNAL
298
AC_TYPE_SIGNAL
270
299
271
272
########################################################################
300
########################################################################
273
# Checks for library functions, using libraries discovered above
301
# Checks for library functions, using libraries discovered above
274
CPPFLAGS="$CPPFLAGS -I$srcdir/src"
302
CPPFLAGS="$CPPFLAGS -I$srcdir/src"
Lines 353-358 Link Here
353
AC_SUBST(CPPFLAGS)
381
AC_SUBST(CPPFLAGS)
354
AC_SUBST(BUILD_POPT)
382
AC_SUBST(BUILD_POPT)
355
AC_SUBST(GNOME_BIN)
383
AC_SUBST(GNOME_BIN)
384
AC_SUBST(SLP_BIN)
385
AC_SUBST(BUILD_SLP)
356
dnl AC_DEFINE_UNQUOTED(PACKAGE, $PACKAGE, [Package name])
386
dnl AC_DEFINE_UNQUOTED(PACKAGE, $PACKAGE, [Package name])
357
dnl AC_DEFINE_UNQUOTED(VERSION, $VERSION, [Package version])
387
dnl AC_DEFINE_UNQUOTED(VERSION, $VERSION, [Package version])
358
AC_DEFINE_UNQUOTED(GNU_HOST, ["$host"], [Your gnu-style host triple])
388
AC_DEFINE_UNQUOTED(GNU_HOST, ["$host"], [Your gnu-style host triple])
359
-- Makefile.in
Lines 62-68 Link Here
62
GNOME_CFLAGS = @GNOME_CFLAGS@
62
GNOME_CFLAGS = @GNOME_CFLAGS@
63
GNOME_LIBS = @GNOME_LIBS@
63
GNOME_LIBS = @GNOME_LIBS@
64
64
65
LIBS = @LIBS@
65
LIBS = @LIBS@ @LIB_SLP@
66
66
67
DESTDIR =
67
DESTDIR =
68
68
Lines 84-89 Link Here
84
	$(MEN)							\
84
	$(MEN)							\
85
	$(pkgdoc_DOCS)						\
85
	$(pkgdoc_DOCS)						\
86
	$(example_DOCS)						\
86
	$(example_DOCS)						\
87
	$(slp_EXTRA) $(slp_SRC) $(slp_HEADERS)				\
87
	$(popt_EXTRA) $(popt_SRC) $(popt_HEADERS)		\
88
	$(popt_EXTRA) $(popt_SRC) $(popt_HEADERS)		\
88
	$(SRC) $(HEADERS)					\
89
	$(SRC) $(HEADERS)					\
89
	$(test_SOURCE)						\
90
	$(test_SOURCE)						\
Lines 175-180 Link Here
175
	src/safeguard.o src/snprintf.o src/timeval.o			\
176
	src/safeguard.o src/snprintf.o src/timeval.o			\
176
	lzo/minilzo.o
177
	lzo/minilzo.o
177
178
179
distccenv_obj = src/distccenv.o src/cc_version.o
180
178
distcc_obj = src/backoff.o						\
181
distcc_obj = src/backoff.o						\
179
	src/climasq.o src/clinet.o src/clirpc.o				\
182
	src/climasq.o src/clinet.o src/clirpc.o				\
180
	src/compile.o src/cpp.o						\
183
	src/compile.o src/cpp.o						\
Lines 192-198 Link Here
192
	src/ncpus.o							\
195
	src/ncpus.o							\
193
	src/prefork.o							\
196
	src/prefork.o							\
194
	src/serve.o src/setuid.o src/srvnet.o src/srvrpc.o		\
197
	src/serve.o src/setuid.o src/srvnet.o src/srvrpc.o		\
195
	$(common_obj) @BUILD_POPT@
198
	$(common_obj) @BUILD_POPT@ @BUILD_SLP@
196
199
197
# Objects that need to be linked in to build monitors
200
# Objects that need to be linked in to build monitors
198
mon_obj =								\
201
mon_obj =								\
Lines 224-230 Link Here
224
	src/cleanup.c							\
227
	src/cleanup.c							\
225
	src/climasq.c src/clinet.c src/clirpc.c src/compile.c		\
228
	src/climasq.c src/clinet.c src/clirpc.c src/compile.c		\
226
	src/compress.c src/cpp.c					\
229
	src/compress.c src/cpp.c					\
227
	src/daemon.c src/distcc.c src/dsignal.c				\
230
	src/daemon.c src/distcc.c src/dsignal.c src/register_slp.c	\
228
	src/dopt.c src/dparent.c src/exec.c src/filename.c		\
231
	src/dopt.c src/dparent.c src/exec.c src/filename.c		\
229
	src/h_argvtostr.c						\
232
	src/h_argvtostr.c						\
230
	src/h_exten.c src/h_hosts.c src/h_issource.c src/h_parsemask.c	\
233
	src/h_exten.c src/h_hosts.c src/h_issource.c src/h_parsemask.c	\
Lines 265-270 Link Here
265
gnome_data = gnome/distccmon-gnome-icon.png	\
268
gnome_data = gnome/distccmon-gnome-icon.png	\
266
	gnome/distccmon-gnome.desktop
269
	gnome/distccmon-gnome.desktop
267
270
271
slp_OBJS=src/register_slp.o src/cc_version.o
272
slp_SRC=src/register_slp.c src/cc_version.c
273
slp_HEADERS = src/register_slp.h src/cc_version.h
274
slp_EXTRA = README.slp
275
268
popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
276
popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
269
	popt/popthelp.o popt/poptparse.o
277
	popt/popthelp.o popt/poptparse.o
270
278
Lines 292-298 Link Here
292
	distcc@EXEEXT@ \
300
	distcc@EXEEXT@ \
293
	distccd@EXEEXT@ \
301
	distccd@EXEEXT@ \
294
	distccmon-text@EXEEXT@ \
302
	distccmon-text@EXEEXT@ \
295
	@GNOME_BIN@ 
303
	@GNOME_BIN@ \
304
	@SLP_BIN@ 
296
305
297
check_PROGRAMS = \
306
check_PROGRAMS = \
298
	h_exten@EXEEXT@ \
307
	h_exten@EXEEXT@ \
Lines 333-338 Link Here
333
distcc@EXEEXT@: $(distcc_obj)
342
distcc@EXEEXT@: $(distcc_obj)
334
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(distcc_obj) $(LIBS)
343
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(distcc_obj) $(LIBS)
335
344
345
distccenv@EXEEXT@: $(distccenv_obj)
346
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(distccenv_obj) $(LIBS)
347
336
distccd@EXEEXT@: $(distccd_obj)
348
distccd@EXEEXT@: $(distccd_obj)
337
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(distccd_obj) $(LIBS)	
349
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(distccd_obj) $(LIBS)	
338
350
339
-- README.slp
Line 0 Link Here
0
-- src/cc_version.c
1
#
2
# SLP support in distcc
3
#
4
5
It is enough to start the SLP server and distcc server, if you have 
6
compiled distccd with SLP support. You can simply use distcc as compiler
7
afterwards.
8
9
NOTE: SLP support is only used, when distccd runs as daemon, not when
10
      running via inetd or xinetd !
11
12
The distcc frontend cache SLP results inside the $HOME/.distcc.slp.cache
13
file. This file gets update every 3 minutes (hardcoded for now).
14
15
Alternative you can set the enviroment once via distccenv. A bash user
16
might simply do to set $DISTCC_HOSTS with
17
18
  eval `distccenv`
19
20
A distcc service url looks like
21
22
 service:distccd.$IDENTITY
23
24
The identity is usually set based on the used compiler at build time 
25
of distcc and the used system architecture.
26
However there is no check which checks the installed compiler, since it
27
is not known how it is called at distccd startup time.
28
29
You can set the IDENTIY during distccd startup via the --slp-identy=$IDENTIY
30
switch. You need to set the $DISTCC_IDENTITY enviroment variable to the
31
same value afterwards inside your enviroment (or during distccenv run).
32
33
There is some very basic load balancing code. You can enable it via
34
35
  export DISTCC_LOAD_BALANCE=1
36
37
in your compile enviroment. It is not active, if $DISTCC_HOSTS is set.
38
39
Have fun, adrian.
40
Line 0 Link Here
0
-- src/cc_version.h
1
/* -*- c-file-style: "java"; indent-tabs-mode: nil -*-
2
 *
3
 * distcc -- A simple distributed compiler system
4
 *
5
 * Copyright (C) 2003 by Adrian Schroeter <adrian@suse.de>
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License as
9
 * published by the Free Software Foundation; either version 2 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
 * USA
21
 */
22
23
#include <stdlib.h>
24
#include <string.h>
25
#include <stdio.h>
26
#include <sys/utsname.h>
27
#include "cc_version.h"
28
#include "config.h"
29
30
char *used_compiler_version(void)
31
{
32
    char *compiler     = NULL;
33
    char *architecture = NULL;
34
    char *ret;
35
    int len;
36
37
    /* The enviroment is always right ... */
38
    if ( getenv("DISTCC_IDENTIFY") )
39
	return getenv("DISTCC_IDENTIFY"); 
40
41
    /* do we really want a runtime check here ? */
42
    /* it would be worse performance wise for the distcc frontend ... */
43
44
    /* default compiler based on distcc build time */
45
#ifdef __GNUC__
46
#ifdef __GNUC_MINOR__
47
#ifdef __GNUC_PATCHLEVEL__
48
    compiler = (char*) malloc( 33 );
49
    snprintf( compiler, 32, "gcc-%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ );
50
#endif
51
#endif
52
#endif
53
54
#ifdef GNU_HOST
55
    architecture = strdup(GNU_HOST);
56
    {
57
       char *p;
58
       p = strstr( architecture, "-" );
59
       if (p){
60
         *p = '\0';
61
         /* unify all different ia32 systems */
62
         p = architecture;
63
         if ( p[0] == 'i' && p[2] == '8' && p[3] == '6' && p[4] == '\0' )
64
           p[1] = '3';
65
       }
66
    }
67
#endif
68
69
    if ( compiler == NULL ){
70
       /* we use the system release, this is unreleated to the compiler
71
          version, but better than default ... */
72
       struct utsname t;
73
       if ( !uname( &t ) )
74
          compiler = t.release;
75
    }
76
    if ( architecture == NULL ){
77
       struct utsname t;
78
       if ( !uname( &t ) )
79
          architecture = t.machine;
80
    }
81
82
    /* fallback values */
83
    if ( compiler == NULL )
84
       compiler = strdup("default");
85
    if ( architecture == NULL )
86
       architecture = strdup("default");
87
88
    len = strlen(compiler) + 1 + strlen(architecture) + 1;
89
    ret = (char*) malloc(len + 1);
90
    snprintf( ret, len, "%s-%s", compiler, architecture );
91
    return ret;
92
}
93
Line 0 Link Here
0
-- src/config.h.in
1
2
char *used_compiler_version(void);
3
Lines 260-265 Link Here
260
/* Use GTK+ */
260
/* Use GTK+ */
261
#undef WITH_GTK
261
#undef WITH_GTK
262
262
263
/* Use SLP */
264
#undef WITH_SLP
265
263
/* Define to `__inline__' or `__inline' if that's what the C compiler
266
/* Define to `__inline__' or `__inline' if that's what the C compiler
264
   calls it, or to nothing if 'inline' is not supported under any name.  */
267
   calls it, or to nothing if 'inline' is not supported under any name.  */
265
#ifndef __cplusplus
268
#ifndef __cplusplus
266
-- src/distccenv.c
Line 0 Link Here
0
-- src/dopt.c
1
2
#include "config.h"
3
4
#ifndef WITH_SLP
5
#error distccenv needs SLP atm. 
6
#endif
7
8
#include <stdlib.h>
9
#include <stdio.h>
10
#include <string.h>
11
12
#include "register_slp.h"
13
14
#define BUFFER 1024
15
16
char compiler[BUFFER + 1];
17
FILE *out;
18
19
#define MAX_HOSTS 256
20
struct dcc_host{
21
  char *url;
22
  int  jobs;
23
  float speed;
24
  float load;
25
  long value;
26
};
27
struct dcc_host hosts[MAX_HOSTS];
28
int host_count = 0;
29
30
int slp_calls = 0;
31
int load_balancing = 0;
32
33
void dump_result(void);
34
SLPBoolean myAttrCallback(SLPHandle phslp, char* attrlist,
35
                          SLPError errcode, void* cookie );
36
SLPBoolean MySLPSrvURLCallback( SLPHandle phslp, const char* srvurl,
37
                              unsigned short lifetime, SLPError errcode,
38
                              void* cookie );
39
40
void dump_result(void)
41
{
42
  int h, j, max_jobs = 0;
43
  float avg_speed = 0, avg_load = 0;
44
45
  if ( host_count == 0 )
46
     exit(-1);
47
48
  if ( !out )
49
     printf( "DISTCC_HOSTS=\"" );
50
51
  if ( load_balancing )
52
  {
53
     for ( h = 0; h<host_count; h++ ){
54
        avg_speed += hosts[h].speed;
55
        avg_load  += hosts[h].load;
56
     }
57
     avg_speed /= host_count;
58
     avg_load /= host_count;
59
     
60
     for ( h = 0; h<host_count; h++ ){
61
        hosts[h].value = hosts[h].jobs
62
                         * ( hosts[h].speed / avg_speed );
63
#if 0
64
// load might be misleading, so we only care about bogomips atm
65
// beside of architectures with random bogomips values (like s390) 
66
// this should work so far now.
67
                         * ( avg_load / hosts[h].load );
68
#endif
69
        if ( max_jobs < hosts[h].value )
70
           max_jobs = hosts[h].value;
71
     }
72
  }
73
74
  for ( j = 0; j<(load_balancing?max_jobs:1); j++ ){
75
     for ( h = 0; h<host_count; h++ ){
76
        if ( !load_balancing || j < hosts[h].value ){
77
           if ( out ){
78
              fputs( hosts[h].url, out );
79
              fputs( "\n", out );
80
           }else{
81
              printf( "%s ", hosts[h].url );
82
           }
83
        }
84
     }
85
  }
86
87
  if ( out )
88
    fclose( out );
89
  else
90
    printf( "\"\n" );
91
  exit(0);
92
}
93
94
SLPBoolean myAttrCallback(SLPHandle phslp,
95
                        char* attrlist,
96
                        SLPError errcode,
97
                        void* cookie )
98
{
99
    phslp = phslp;
100
    struct dcc_host *_host = &(hosts[(long)cookie]);
101
102
    if(attrlist && errcode == SLP_OK)
103
    {
104
	char *p;
105
106
        p = strstr( attrlist, "(maxjobs=" );
107
	if ( p )
108
	   _host->jobs  = atoi( p + strlen("(maxjobs=") );
109
110
        p = strstr( attrlist, "(bogomips=" );
111
	if ( p )
112
	   _host->speed = atol( p + strlen("(bogomips=") );
113
114
        p = strstr( attrlist, "(load=" );
115
	if ( p )
116
	   _host->load  = atol( p + strlen("(load=") );
117
    }
118
119
    return SLP_FALSE;
120
}
121
122
SLPBoolean MySLPSrvURLCallback( SLPHandle phslp,
123
                              const char* srvurl,
124
                              unsigned short lifetime,
125
                              SLPError errcode,
126
                              void* cookie )
127
{
128
  phslp = phslp; lifetime = lifetime; cookie = cookie;
129
130
  if ( host_count >= MAX_HOSTS || !srvurl
131
       || strncmp( compiler, srvurl, strlen(compiler) ) ) 
132
     return SLP_TRUE;
133
134
  if(errcode == SLP_OK || errcode == SLP_LAST_CALL) 
135
  {
136
     hosts[host_count].url   = strdup((char*)(strlen(compiler) + srvurl + 3));
137
     hosts[host_count].jobs  = -1;
138
     hosts[host_count].speed = -1;
139
     host_count++;
140
  }
141
142
  return SLP_TRUE;
143
}
144
145
int main( int argc, char *argv[] )
146
{
147
  long h;
148
  SLPHandle phslp;
149
  SLPError result;
150
  char *p;
151
152
  out = 0;
153
154
  p = getenv("DISTCC_LOAD_BALANCE");
155
  if ( p && (!strcmp( "1", p)||!strncmp( "y", p, 1)) )
156
     load_balancing = 1;
157
 
158
  if ( argc > 2 && !strcmp(argv[1], "--file" ) )
159
     out = fopen( argv[2], "w" );
160
161
  snprintf( compiler, BUFFER, "service:distccd.%s", used_compiler_version() );
162
163
  result = SLPOpen( NULL, SLP_FALSE, &phslp);
164
  if (result != SLP_OK) {
165
     fprintf( stderr, "SLPOpen failed !   Aborting ... " );
166
     exit( -1 );
167
  } else {
168
     result = SLPFindSrvs( phslp,
169
                           compiler,
170
                           "", // TODO: Scope selector
171
                           "", // all services
172
                           MySLPSrvURLCallback,
173
                           0 );
174
     if (result != SLP_OK){
175
        fprintf( stderr, "unable to query for services !  Aborting .." );
176
        exit(-1);
177
     }
178
179
     if ( load_balancing )
180
     {
181
        for ( h = 0; h < host_count; h++ )
182
        {
183
           char buf[BUFFER+1];
184
           snprintf( buf, BUFFER, "%s://%s", compiler, hosts[h].url );
185
           result = SLPFindAttrs(phslp,
186
                                buf,
187
                                "",
188
                                "maxjobs,bogomips,load",
189
                                myAttrCallback,
190
                                (void*)h);
191
           if(result != SLP_OK)
192
           {
193
               printf("unable to request SLP attributes: %i\n",result);
194
               exit(-1);
195
           }
196
        }
197
     }else
198
        dump_result();
199
200
     SLPClose( phslp );
201
  }
202
203
  dump_result();
204
  return 0;
205
}
Lines 50-55 Link Here
50
#include "setuid.h"
50
#include "setuid.h"
51
#include "access.h"
51
#include "access.h"
52
52
53
#ifdef WITH_SLP
54
#include "register_slp.h"
55
#endif
56
53
int opt_niceness = 5;           /* default */
57
int opt_niceness = 5;           /* default */
54
58
55
/**
59
/**
Lines 92-97 Link Here
92
96
93
const char *arg_pid_file = NULL;
97
const char *arg_pid_file = NULL;
94
const char *arg_log_file = NULL;
98
const char *arg_log_file = NULL;
99
const char *compiler_version = NULL;
95
100
96
/* Enumeration values for options that don't have single-letter name.  These
101
/* Enumeration values for options that don't have single-letter name.  These
97
 * must be numerically above all the ascii letters. */
102
 * must be numerically above all the ascii letters. */
Lines 123-128 Link Here
123
    { "verbose", 0,      POPT_ARG_NONE, 0, 'v', 0, 0 },
128
    { "verbose", 0,      POPT_ARG_NONE, 0, 'v', 0, 0 },
124
    { "version", 0,      POPT_ARG_NONE, 0, 'V', 0, 0 },
129
    { "version", 0,      POPT_ARG_NONE, 0, 'V', 0, 0 },
125
    { "wizard", 'W',     POPT_ARG_NONE, 0, 'W', 0, 0 },
130
    { "wizard", 'W',     POPT_ARG_NONE, 0, 'W', 0, 0 },
131
#ifdef WITH_SLP
132
    { "slp-identy", 0,   POPT_ARG_STRING, &compiler_version, 0, 0, 0 },
133
#endif
126
    { 0, 0, 0, 0, 0, 0, 0 }
134
    { 0, 0, 0, 0, 0, 0, 0 }
127
};
135
};
128
136
Lines 157-162 Link Here
157
"  Mode of operation:\n"
165
"  Mode of operation:\n"
158
"    --inetd                    serve client connected to stdin\n"
166
"    --inetd                    serve client connected to stdin\n"
159
"    --daemon                   bind and listen on socket\n"
167
"    --daemon                   bind and listen on socket\n"
168
#ifdef WITH_SLP
169
"  SLP Identification:\n"
170
"    --slp-identy=STRING        to identify the provided compiler\n"
171
#endif
160
"\n"
172
"\n"
161
"distccd runs either from inetd or as a standalone daemon to compile\n"
173
"distccd runs either from inetd or as a standalone daemon to compile\n"
162
"files submitted by the distcc client.\n"
174
"files submitted by the distcc client.\n"
Lines 253-258 Link Here
253
        }
265
        }
254
    }
266
    }
255
267
268
#ifdef WITH_SLP
269
    if ( compiler_version == NULL )
270
       compiler_version = used_compiler_version();
271
#endif
272
256
    poptFreeContext(po);
273
    poptFreeContext(po);
257
    return 0;
274
    return 0;
258
275
259
-- src/dopt.h
Lines 20-25 Link Here
20
 * USA
20
 * USA
21
 */
21
 */
22
22
23
#include "config.h"
23
24
24
/* dopt.c */
25
/* dopt.c */
25
extern struct dcc_allow_list *opt_allowed;
26
extern struct dcc_allow_list *opt_allowed;
Lines 38-40 Link Here
38
extern int opt_lifetime;
39
extern int opt_lifetime;
39
extern char *opt_listen_addr;
40
extern char *opt_listen_addr;
40
extern int opt_niceness;
41
extern int opt_niceness;
41
-- src/dparent.c
42
#ifdef WITH_SLP
43
extern const char *compiler_version;
44
#endif
Lines 71-76 Link Here
71
#include "srvnet.h"
71
#include "srvnet.h"
72
#include "types.h"
72
#include "types.h"
73
#include "daemon.h"
73
#include "daemon.h"
74
#if WITH_SLP
75
#include "register_slp.h"
76
#endif
74
77
75
static int dcc_start_server_child(int listen_fd, int accept_fd, struct sockaddr *,
78
static int dcc_start_server_child(int listen_fd, int accept_fd, struct sockaddr *,
76
                                  int);
79
                                  int);
Lines 137-142 Link Here
137
     * not.  */
140
     * not.  */
138
    dcc_master_pid = getpid();
141
    dcc_master_pid = getpid();
139
142
143
#ifdef WITH_SLP
144
    register_slp();
145
#endif
146
140
    if (opt_no_fork) {
147
    if (opt_no_fork) {
141
        dcc_log_daemon_started("non-forking daemon");   
148
        dcc_log_daemon_started("non-forking daemon");   
142
        dcc_nofork_parent(listen_fd);
149
        dcc_nofork_parent(listen_fd);
143
-- src/hosts.c
Lines 85-90 Link Here
85
#include <stdio.h>
85
#include <stdio.h>
86
#include <stdlib.h>
86
#include <stdlib.h>
87
#include <unistd.h>
87
#include <unistd.h>
88
#include <sys/types.h>
89
#include <sys/stat.h>
88
#include <string.h>
90
#include <string.h>
89
#include <errno.h>
91
#include <errno.h>
90
#include <time.h>
92
#include <time.h>
Lines 162-168 Link Here
162
        rs_trace("not reading %s: %s", path, strerror(errno));
164
        rs_trace("not reading %s: %s", path, strerror(errno));
163
        free(path);
165
        free(path);
164
    }
166
    }
165
    
167
168
#ifdef WITH_SLP    
169
    if ((home = getenv("HOME")) != NULL) {
170
        struct stat fst;
171
        
172
        asprintf(&path, "%s/.distcc.slp.cache", home);
173
        /* the refresh rate of SLP cache is hardcoded to 5 minutes for now */
174
        if ( stat (path, &fst) || fst.st_mtime < time (0) - 60*5 ) { 
175
	    unlink( path );
176
	    /* sure, we could implement the SLP query also via a function
177
               call, but we would need to wait here anyway ... */
178
	    execlp("distccenv", "distccenv", "--file", path, 0 );
179
        }
180
        if (access(path, R_OK) == 0) {
181
            ret = dcc_parse_hosts_file(path, ret_list, ret_nhosts);
182
            free(path);
183
            return ret;
184
        } else {
185
            rs_trace("not reading %s: %s", path, strerror(errno));
186
            free(path);
187
        }
188
    }
189
#endif
190
166
    /* FIXME: Clearer message? */
191
    /* FIXME: Clearer message? */
167
    rs_log_warning("no hostlist is set; can't distribute work");
192
    rs_log_warning("no hostlist is set; can't distribute work");
168
193
169
-- src/register_slp.c
Line 0 Link Here
0
-- src/register_slp.h
1
/* -*- c-file-style: "java"; indent-tabs-mode: nil -*-
2
 *
3
 * distcc -- A simple distributed compiler system
4
 *
5
 * Copyright (C) 2003 by Adrian Schroeter <adrian@suse.de>
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License as
9
 * published by the Free Software Foundation; either version 2 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
 * USA
21
 */
22
23
#include "register_slp.h"
24
25
#ifdef WITH_SLP
26
#include <stdlib.h>
27
#include <string.h>
28
#include <signal.h>
29
#include <unistd.h>
30
#include <stdio.h>
31
#include <sys/utsname.h>
32
#include "dopt.h"
33
#include "trace.h"
34
#include "cc_version.h"
35
36
extern int dcc_max_kids;
37
38
void mySLPRegReport(SLPHandle hslp, SLPError errcode, void *cookie)
39
{
40
    hslp = hslp; cookie = cookie;
41
    if (errcode)
42
       rs_log_warning( "SLP (de)registration error" );
43
}
44
45
void refresh_slp(void)
46
{
47
      register_slp();
48
}
49
50
void register_slp(void)
51
{
52
      SLPHandle phslp;
53
      SLPError result;
54
      struct sigaction act, oact;
55
      /* TODO: make it a config option */
56
      /* hardcode it to 5 minutes now, because we use also the load
57
         from last 5 minutes */
58
      int slp_timeout = 60 * 3;
59
60
      /* do not bomb the slp server with wrong configuration */
61
      if ( slp_timeout < 120 )
62
        slp_timeout = 120 ;
63
      if ( slp_timeout > SLP_LIFETIME_MAXIMUM )
64
         slp_timeout = SLP_LIFETIME_MAXIMUM;
65
66
      result = SLPOpen( 0, SLP_FALSE, &phslp);
67
      if (result != SLP_OK)
68
         rs_log_warning( "SLPOpen failed" );
69
      else {
70
         char hostname[1024];
71
         char SLPServiceUrl[2048];
72
         char SLPattributes[2048];
73
         long load = -1, bogomips = 0;
74
         FILE *proc;
75
76
         gethostname( hostname, 1023 );
77
         /* Linux specific part, no idea how to do this in general */
78
         proc = fopen( "/proc/cpuinfo", "r" );
79
         if ( proc ){
80
           while( !feof(proc) ) {
81
               long b = 0;
82
               int ret;
83
               ret = fscanf( proc, "bogomips        : %ld", &b );
84
               if ( ret < 0 )
85
                  break;
86
               if ( ret )
87
                  bogomips += b;
88
               fseek( proc, 1L, SEEK_CUR );
89
           }
90
           fclose( proc );
91
         }
92
93
         proc = fopen( "/proc/loadavg", "r" );
94
         if ( proc ){
95
           fscanf( proc, "%*d.%*d %ld.%*d %*s %*s %*s", &load );
96
           fclose( proc );
97
         }
98
	 if ( !bogomips ) bogomips = 1;
99
	 load += 1;
100
101
         snprintf( SLPServiceUrl, 1023, "service:distccd.%s://%s:%i", compiler_version, hostname, arg_port );
102
         snprintf( SLPattributes, 1023, "(maxjobs=%d),(bogomips=%ld),(load=%ld)", dcc_max_kids, bogomips, load );
103
104
         result = SLPReg( phslp,
105
                          SLPServiceUrl,
106
                          slp_timeout,
107
                          0,
108
                          SLPattributes,
109
                          SLP_TRUE,
110
                          mySLPRegReport,
111
                          0 );
112
113
         if (result != SLP_OK)
114
            rs_log_warning( "unable to register SLP service" );
115
         SLPClose( phslp );
116
117
         /* sigalarm is also used in inetd mode, but we should never
118
            use SLP in inetd mode anyway ...                         */
119
         act.sa_handler = refresh_slp;
120
         if (0 != sigaction(SIGALRM, &act, &oact))
121
             rs_log_warning("Error establishing signal handler for SLP");
122
         alarm(slp_timeout - 15);
123
      }
124
}
125
#endif
126
127
Line 0 Link Here
0
-- src/setuid.c
1
2
#include "config.h"
3
4
#ifdef WITH_SLP
5
6
#include <slp.h>
7
8
void  register_slp(void);
9
char* used_compiler_version(void);
10
11
void refresh_slp(void);
12
void mySLPRegReport(SLPHandle hslp, SLPError errcode, void *cookie);
13
14
#endif
15
Lines 108-118 Link Here
108
     * permanently discard privileges: both the real and effective uid are
108
     * permanently discard privileges: both the real and effective uid are
109
     * set. */
109
     * set. */
110
110
111
    if (setuid(uid)) {
112
        rs_log_error("setuid(%d) failed: %s", (int) uid, strerror(errno));
113
        return EXIT_SETUID_FAILED;
114
    }
115
116
    if (setgid(gid)) {
111
    if (setgid(gid)) {
117
        rs_log_error("setgid(%d) failed: %s", (int) gid, strerror(errno));
112
        rs_log_error("setgid(%d) failed: %s", (int) gid, strerror(errno));
118
        return EXIT_SETUID_FAILED;
113
        return EXIT_SETUID_FAILED;
Lines 128-133 Link Here
128
    }
123
    }
129
#endif
124
#endif
130
125
126
    if (setuid(uid)) {
127
        rs_log_error("setuid(%d) failed: %s", (int) uid, strerror(errno));
128
        return EXIT_SETUID_FAILED;
129
    }
130
131
    if (getuid() == 0  ||  geteuid() == 0) {
131
    if (getuid() == 0  ||  geteuid() == 0) {
132
        rs_log_crit("still have root privileges after trying to discard them!");
132
        rs_log_crit("still have root privileges after trying to discard them!");
133
        return EXIT_SETUID_FAILED;
133
        return EXIT_SETUID_FAILED;

Return to bug 80219