--- distcc-2.0.1/src/hosts.c.old Wed Oct 9 08:58:04 2002 +++ distcc-2.0.1/src/hosts.c Wed Oct 9 09:16:14 2002 @@ -72,6 +72,9 @@ #include #include #include +#include +#include +#include #include "distcc.h" #include "trace.h" @@ -107,9 +110,45 @@ char *where; where = getenv("DISTCC_HOSTS"); - if (!where) { - rs_log_warning("$DISTCC_HOSTS is not defined; can't distribute work"); - return EXIT_BAD_HOSTSPEC; + if (!where) { + char *filename; + int file; + char buffer[4096]; + int readcount; + char *listbuf=0; + int listbufsize=4096; + int listbuflen=0; + int parseresult; + + listbuf = malloc(4096); + + filename = getenv("DISTCC_HOSTS_FILE"); + if (!filename) + { + rs_log_warning("$DISTCC_HOSTS or $DISTCC_HOSTS_FILE not defined;" + " can't distribute work"); + return 1; + } + file = open(filename, O_RDONLY); + + while ((readcount = read(file, buffer, 4096)) > 0) + { + if (readcount+listbuflen > listbufsize) + { + char *temp; + temp = malloc(readcount+listbuflen); + memcpy(temp, listbuf, listbuflen); + free(listbuf); + listbuf = temp; + listbufsize = readcount+listbuflen; + } + memcpy(listbuf+listbuflen, buffer, readcount); + } + close(file); + /* ok, I've read the file, now have it parsed */ + parseresult = dcc_parse_hosts(listbuf, ret_list, ret_nhosts); + free(listbuf); + return parseresult; } return dcc_parse_hosts(where, ret_list, ret_nhosts); @@ -296,7 +335,7 @@ if (*ret_nhosts) { return 0; } else { - rs_log_warning("$DISTCC_HOSTS is empty; can't distribute work"); + rs_log_warning("$DISTCC_HOSTS or $DISTCC_HOSTS_FILE is empty; can't distribute work"); return EXIT_BAD_HOSTSPEC; } }