diff --git a/man/distccd.1 b/man/distccd.1 index f8452e18..41596d81 100644 --- a/man/distccd.1 +++ b/man/distccd.1 @@ -215,6 +215,8 @@ DNS Service Discovery (DNS-SD). This allows distcc clients on the local network to access this distccd server without explicitly listing its host name or IP address in their distcc host list: the distcc clients can just use "+zeroconf" in their distcc host lists. +Can optionally use -j parameter to specify the maximum number of jobs +that this server can process concurrently. .B This option is only available if distccd was compiled with .B Avahi support enabled. .TP diff --git a/src/dparent.c b/src/dparent.c index 77a4ac5c..f8dc5340 100644 --- a/src/dparent.c +++ b/src/dparent.c @@ -141,7 +141,7 @@ int dcc_standalone_server(void) #ifdef HAVE_AVAHI /* Zeroconf registration */ if (opt_zeroconf) { - if (!(avahi = dcc_zeroconf_register((uint16_t) arg_port, n_cpus))) + if (!(avahi = dcc_zeroconf_register((uint16_t) arg_port, n_cpus, dcc_max_kids))) return EXIT_CONNECT_FAILED; } #endif diff --git a/src/zeroconf-reg.c b/src/zeroconf-reg.c index 8511315e..cfe00b31 100644 --- a/src/zeroconf-reg.c +++ b/src/zeroconf-reg.c @@ -52,6 +52,7 @@ struct context { AvahiEntryGroup *group; uint16_t port; int n_cpus; + int n_jobs; }; static void publish_reply(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata); @@ -73,9 +74,10 @@ static void register_stuff(struct context *ctx) { } if (avahi_entry_group_is_empty(ctx->group)) { - char cpus[32], machine[64] = "cc_machine=", version[64] = "cc_version=", *m, *v; + char cpus[32], jobs[32], machine[64] = "cc_machine=", version[64] = "cc_version=", *m, *v; snprintf(cpus, sizeof(cpus), "cpus=%i", ctx->n_cpus); + snprintf(jobs, sizeof(jobs), "jobs=%i", ctx->n_jobs); v = dcc_get_gcc_version(version+11, sizeof(version)-11); m = dcc_get_gcc_machine(machine+11, sizeof(machine)-11); @@ -93,6 +95,7 @@ static void register_stuff(struct context *ctx) { ctx->port, "txtvers=1", cpus, + jobs, "distcc="PACKAGE_VERSION, "gnuhost="GNU_HOST, v ? version : NULL, @@ -222,8 +225,8 @@ static void client_callback(AvahiClient *client, AvahiClientState state, void *u } } -/* register a distcc service in DNS-SD/mDNS with the given port and number of CPUs */ -void* dcc_zeroconf_register(uint16_t port, int n_cpus) { +/* register a distcc service in DNS-SD/mDNS with the given port, number of CPUs, and maximum concurrent jobs */ +void* dcc_zeroconf_register(uint16_t port, int n_cpus, int n_jobs) { struct context *ctx = NULL; char service[256] = "distcc@"; int error; @@ -235,6 +238,7 @@ void* dcc_zeroconf_register(uint16_t port, int n_cpus) { ctx->threaded_poll = NULL; ctx->port = port; ctx->n_cpus = n_cpus; + ctx->n_jobs = n_jobs; /* Prepare service name */ gethostname(service+7, sizeof(service)-8); diff --git a/src/zeroconf.c b/src/zeroconf.c index 652cc1d1..a06a2358 100644 --- a/src/zeroconf.c +++ b/src/zeroconf.c @@ -77,6 +77,7 @@ struct host { AvahiAddress address; uint16_t port; int n_cpus; + int n_jobs; AvahiServiceResolver *resolver; }; @@ -163,9 +164,9 @@ static int write_hosts(struct daemon_data *d) { /* Not yet fully resolved */ continue; if (h->address.proto == AVAHI_PROTO_INET6) - snprintf(t, sizeof(t), "[%s]:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, d->n_slots * h->n_cpus); + snprintf(t, sizeof(t), "[%s]:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, h->n_jobs); else - snprintf(t, sizeof(t), "%s:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, d->n_slots * h->n_cpus); + snprintf(t, sizeof(t), "%s:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, h->n_jobs); if (dcc_writex(d->fd, t, strlen(t)) != 0) { rs_log_crit("write() failed: %s\n", strerror(errno)); @@ -276,6 +277,21 @@ static void resolve_reply( avahi_free(value); } + /* Look for the number of jobs in TXT RRs, and if not found, then set n_jobs = 4 * n_cpus */ + for (i = txt; i; i = i->next) { + char *key, *value; + + if (avahi_string_list_get_pair(i, &key, &value, NULL) < 0) + continue; + + if (!strcmp(key, "jobs")) + if ((h->n_jobs = atoi(value)) <= 0) + h->n_jobs = 4 * h->n_cpus; + + avahi_free(key); + avahi_free(value); + } + h->address = *a; h->port = port; @@ -350,6 +366,7 @@ static void browse_reply( h->protocol = protocol; h->next = d->hosts; h->n_cpus = 1; + h->n_jobs = 4; d->hosts = h; } diff --git a/src/zeroconf.h b/src/zeroconf.h index a1526598..ea1f807f 100644 --- a/src/zeroconf.h +++ b/src/zeroconf.h @@ -25,7 +25,7 @@ int dcc_zeroconf_add_hosts(struct dcc_hostdef **re_list, int *ret_nhosts, int slots, struct dcc_hostdef **ret_prev); -void *dcc_zeroconf_register(uint16_t port, int n_cpus); +void *dcc_zeroconf_register(uint16_t port, int n_cpus, int n_jobs); int dcc_zeroconf_unregister(void*); char* dcc_get_gcc_version(char *s, size_t nbytes);