From 0bd21201f254f5d040d88af9a99198109899d2d8 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Mon, 30 Sep 2013 21:16:54 +0200
Subject: Convert existing patch to git patchset.


diff --git a/Makefile.in b/Makefile.in
index 073482e..2759efa 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -554,7 +554,7 @@ distccmon-gnome@EXEEXT@: $(mon_obj) $(gnome_obj)
 
 # The include-server is a python app, so we use Python's build system.  We pass
 # the distcc version, the source location, the CPP flags (for location of the
-# includes), and the build location.
+# includes), LD flags and the build location.
 include-server:
 	if test -z "$(INCLUDESERVER_PYTHON)"; then	\
 	  echo "Not building $@: No suitable python found"; \
@@ -564,6 +564,7 @@ include-server:
 	  SRCDIR="$(srcdir)"                            \
 	  CFLAGS="$(CFLAGS) $(PYTHON_CFLAGS)"           \
 	  CPPFLAGS="$(CPPFLAGS)"                        \
+	  LDFLAGS="$(LDFLAGS)"                        \
 	  $(INCLUDESERVER_PYTHON) "$(srcdir)/include_server/setup.py" \
 	      build 					\
 	        --build-base="$(include_server_builddir)"  \
diff --git a/configure.ac b/configure.ac
index 757dbe3..8456596 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,9 +329,12 @@ AC_CHECK_TYPES([in_port_t, in_addr_t], , ,
 # only looks in /etc/hosts), so we only look for -lsocket if we need
 # it.
 AC_SEARCH_LIBS(gethostent, [nsl])
-AC_SEARCH_LIBS(setsockopt, [socket])
+AC_SEARCH_LIBS(setsockopt, [socket network])
 AC_SEARCH_LIBS(hstrerror, [resolv])
 AC_SEARCH_LIBS(inet_aton, [resolv])
+AC_SEARCH_LIBS(strsep, [bsd])
+AC_SEARCH_LIBS(wait3, [bsd])
+AC_SEARCH_LIBS(wait4, [bsd])
 
 if test x"$with_included_popt" != x"yes"  && test x"$with_included_popt" != xno
 then
@@ -379,6 +382,7 @@ AC_CHECK_FUNCS([snprintf vsnprintf vasprintf asprintf getcwd getwd mkdtemp])
 AC_CHECK_FUNCS([getrusage strsignal gettimeofday])
 AC_CHECK_FUNCS([getaddrinfo getnameinfo inet_ntop inet_ntoa])
 AC_CHECK_FUNCS([strndup strsep mmap strlcpy])
+AC_CHECK_FUNCS([nice])
 
 AC_CHECK_FUNCS([getloadavg])
 
@@ -471,6 +475,8 @@ AC_CHECK_MEMBER([struct sockaddr_storage.ss_family],
     AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, [define if you have struct sockaddr_storage]),,
     [#include <sys/socket.h>])
 
+AC_CHECK_MEMBERS([struct rusage.ru_minflt, struct rusage.ru_majflt])
+
 AC_ARG_WITH(avahi,
         AC_HELP_STRING([--without-avahi], [build without avahi]))
 
diff --git a/src/daemon.c b/src/daemon.c
index 5b06971..cdfd452 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -172,15 +172,19 @@ int main(int argc, char *argv[])
     if ((ret = dcc_set_lifetime()) != 0)
         dcc_exit(ret);
 
+#ifdef HAVE_NICE
     /* do this before giving away root */
     if (nice(opt_niceness) == -1) {
         rs_log_warning("nice %d failed: %s", opt_niceness,
                        strerror(errno));
         /* continue anyhow */
     }
+#endif
 
+#ifndef __HAIKU__
     if ((ret = dcc_discard_root()) != 0)
         dcc_exit(ret);
+#endif
 
     /* Discard privileges before opening log so that if it's created, it has
      * the right ownership. */
diff --git a/src/exec.c b/src/exec.c
index 8d2df86..bd92d4f 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -488,12 +488,19 @@ int dcc_collect_child(const char *what, pid_t pid,
          * critique_status(). */
         rs_trace("%s child %ld terminated with status %#x",
                  what, (long) ret_pid, *wait_status);
+#if defined HAVE_RUSAGE_RU_MINFLT && defined HAVE_RUSAGE_RU_MAJFLT
         rs_log_info("%s times: user %ld.%06lds, system %ld.%06lds, "
                     "%ld minflt, %ld majflt",
                     what,
                     ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
                     ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec,
                     ru.ru_minflt, ru.ru_majflt);
+#else
+        rs_log_info("%s times: user %ld.%06lds, system %ld.%06lds",
+                    what,
+                    ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
+                    ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
+#endif
 
         return 0;
     }
-- 
1.8.3.4


From c7121172e07205189fe1b10e49ab0256863ba1a2 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Tue, 1 Oct 2013 17:26:29 +0200
Subject: C89 fixes for gcc2 compatibility


diff --git a/src/compile.c b/src/compile.c
index 2fc60b7..15bc8ad 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -89,6 +89,8 @@ int dcc_discrepancy_filename(char **filename)
         return 0;
     } else if (str_endswith(include_server_port_suffix,
                             include_server_port)) {
+		int slash_pos;
+
         /* We're going to make a longer string from include_server_port: one
          * that replaces include_server_port_suffix with discrepancy_suffix. */
         int delta = strlen(discrepancy_suffix) -
@@ -100,7 +102,7 @@ int dcc_discrepancy_filename(char **filename)
             return EXIT_OUT_OF_MEMORY;
         }
         strcpy(*filename, include_server_port);
-        int slash_pos = strlen(include_server_port)
+        slash_pos = strlen(include_server_port)
                         - strlen(include_server_port_suffix);
         /* Because include_server_port_suffix is a suffix of include_server_port
          * we expect to find a '/' at slash_pos in filename. */
@@ -119,8 +121,9 @@ int dcc_discrepancy_filename(char **filename)
  **/
 static int dcc_read_number_discrepancies(const char *discrepancy_filename)
 {
-    if (!discrepancy_filename) return 0;
     struct stat stat_record;
+
+    if (!discrepancy_filename) return 0;
     if (stat(discrepancy_filename, &stat_record) == 0) {
         size_t size = stat_record.st_size;
         /* Does size fit in an 'int'? */
diff --git a/src/emaillog.c b/src/emaillog.c
index fdb5e37..971e229 100644
--- a/src/emaillog.c
+++ b/src/emaillog.c
@@ -107,12 +107,13 @@ int dcc_add_file_to_log_email(const char *description,
 void dcc_maybe_send_email(void) {
   int child_pid = 0;
   const char *whom_to_blame;
+  char *will_send_message_to;
+  char *cant_send_message_to;
+
   if ((whom_to_blame = getenv("DISTCC_EMAILLOG_WHOM_TO_BLAME"))
       == NULL) {
     whom_to_blame = dcc_emaillog_whom_to_blame;
   }
-  char *will_send_message_to;
-  char *cant_send_message_to;
 
   if (should_send_email == 0) return;
   if (never_send_email) return;
diff --git a/src/lsdistcc.c b/src/lsdistcc.c
index 2cbca66..50f10c8 100644
--- a/src/lsdistcc.c
+++ b/src/lsdistcc.c
@@ -920,6 +920,8 @@ int detect_distcc_servers(const char **argv, int argc, int opti,
     const char *default_format = DEFAULT_FORMAT;
     const char **sformat = &default_format;
     const char *domain_name;
+    struct rlimit rlim = {0, 0};
+
     if (opt_domain) {
         if (dcc_get_dns_domain(&domain_name)) {
                 fprintf(stderr, "Can't get domain name\n");
@@ -942,7 +944,6 @@ int detect_distcc_servers(const char **argv, int argc, int opti,
      * We'll ideally use n + 2 fds in our poll loop, so ask for n + 10
      * fds total.
      */
-    struct rlimit rlim = {0, 0};
     getrlimit(RLIMIT_NOFILE, &rlim);
     if (rlim.rlim_cur < (rlim_t)n + 10) {
         rlim.rlim_cur = (rlim_t)n + 10;
-- 
1.8.3.4

