~ubuntu-branches/debian/experimental/distcc/experimental

« back to all changes in this revision

Viewing changes to .pc/r732_distccmon-gnome-client-list.patch/source/src/clirpc.c

  • Committer: Package Import Robot
  • Author(s): Daniel Hartwig
  • Date: 2012-05-05 17:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20120505172418-d5821mf4ys0vvh2o
Tags: 3.1-5
* new maintainer (Closes: #664497)
* update Standards-Version to 3.9.3:
  - debian/distcc.init.d: start action exits successfully if daemon
    is already running [9.3.2]; postinst will succeed on upgrades in
    this case also (Closes: #620773, LP: #822887)
* switch to dpkg-source 3.0 (quilt) format
* remove Build-Depends: dpatch
* add Build-Depends: autotools-dev
* debian/rules:
  - use debhelper compat level 9
  - reduce to "dh $@" style
  - fixes FTBFS caused by previous build-arch target (Closes: #666383)
  - enabled bindnow hardening (no PIE yet, it causes build failure)
* debian/control:
  - added Homepage field
  - distcc: description starts lowercase
* debian/distcc.config:
  - renamed from debian/config
  - use "set -e"
  - include missing #DEBHELPER# token
* debian/distcc.init.d:
  - added stop levels 0, 6
  - unset TMPDIR before starting the daemon to avoid problems with
    root's value for this being unwritable by the distccd user; to
    provide distccd with a sensible TMPDIR put it in /etc/default/distcc
    (Closes: #514556)
* debian/distcc.postinst:
  - use "set -e" instead of "#!/bin/sh -e"
  - drop extra calls to "sed ... /etc/default/distcc" for every field
    that only removed whitespace which would be removed anyway when
    updating the fields
  - always create distccd user if it does not exist (Closes: #548053)
* debian/distccmon-gnome.menu:
  - changed title to "distcc monitor"
  - dropped incorrect hint tag
* debian/patches:
  - 06_set-pythonpath-securely.patch: contains fix for #605168 which
    was previously applied directly to the source
  - 07_preferred-user.patch: starting the daemon as root causes it to
    change user, which should be to "distccd" in Debian
  - 08_gnome-data-public-dirs.patch: install desktop and icon files for
    distccmon-gnome /usr/share/applications and /usr/share/pixmaps
    respectively (LP: #512288)
  - 09_rename-pump.patch: rename the "pump" command to "distcc-pump" in
    all references such as help text, man pages, etc. (Closes: #594083)
  - 10_consecutive-preprocessor-options.patch: correctly count
    preprocessor options (Closes: #626926)
  - 11_lsdistcc-man.patch: add man page for lsdistcc utility
* debian/watch:
  - added remote watch file
* source/config.{guess,sub}:
  - update with autotools-dev during build instead of directly patching
    the source tree
* use dpkg triggers to dynamically generate/update compiler links
  based on the ccache packaging.  Thanks to Daniel Schaal
  (Closes: #651670)
* cherry-pick upstream fixes for IPv6 support (Closes: #452835):
  - r650_ipv6-zeroconf.patch: IPv6 patch for Zeroconf and IPv6 literals
    in hosts file (Closes: #481951, LP: #593047)
  - r673_zeroconf-nodups.patch: remove duplicate hosts from the Zeroconf
    list (LP: #809534)
  - r678_distcc-v6-acl-2.patch: IPv6 support for access control
* cherry-pick other upstream fixes:
  - r732_distccmon-gnome.patch: avoid client list growing indefinitely
    (LP: #521165)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- c-file-style: "java"; indent-tabs-mode: nil; tab-width: 4; fill-column: 78 -*-
 
2
 *
 
3
 * distcc -- A simple distributed compiler system
 
4
 *
 
5
 * Copyright (C) 2002, 2003, 2004 by Martin Pool <mbp@samba.org>
 
6
 * Copyright 2007 Google Inc.
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU General Public License
 
10
 * as published by the Free Software Foundation; either version 2
 
11
 * of the License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 
21
 * USA.
 
22
 */
 
23
 
 
24
#include <config.h>
 
25
 
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <unistd.h>
 
29
#include <string.h>
 
30
#include <fcntl.h>
 
31
#include <errno.h>
 
32
 
 
33
#include <sys/stat.h>
 
34
#include <sys/types.h>
 
35
#include <sys/wait.h>
 
36
 
 
37
#include "distcc.h"
 
38
#include "trace.h"
 
39
#include "exec.h"
 
40
#include "rpc.h"
 
41
#include "exitcode.h"
 
42
#include "util.h"
 
43
#include "clinet.h"
 
44
#include "bulk.h"
 
45
#include "hosts.h"
 
46
#include "state.h"
 
47
#include "include_server_if.h"
 
48
#include "emaillog.h"
 
49
 
 
50
/**
 
51
 * @file
 
52
 *
 
53
 * @brief Client-side RPC functions.
 
54
 **/
 
55
 
 
56
/*
 
57
 * Transmit header for whole request.
 
58
 */
 
59
int dcc_x_req_header(int fd,
 
60
                     enum dcc_protover protover)
 
61
{
 
62
     return dcc_x_token_int(fd, "DIST", protover);
 
63
}
 
64
 
 
65
 
 
66
 
 
67
/**
 
68
 * Transmit an argv array.
 
69
 **/
 
70
int dcc_x_argv(int fd, char **argv)
 
71
{
 
72
    int i;
 
73
    int ret;
 
74
    int argc;
 
75
 
 
76
    argc = dcc_argv_len(argv);
 
77
 
 
78
    if (dcc_x_token_int(fd, "ARGC", (unsigned) argc))
 
79
        return EXIT_PROTOCOL_ERROR;
 
80
 
 
81
    for (i = 0; i < argc; i++) {
 
82
        if ((ret = dcc_x_token_string(fd, "ARGV", argv[i])))
 
83
            return ret;
 
84
    }
 
85
 
 
86
    return 0;
 
87
}
 
88
 
 
89
/**
 
90
 * Transmit the current working directory
 
91
 */
 
92
int dcc_x_cwd(int fd)
 
93
{
 
94
    int ret;
 
95
    char cwd[MAXPATHLEN + 1];
 
96
    char * cwd_ret;
 
97
    cwd_ret = getcwd(cwd, MAXPATHLEN);
 
98
    if (cwd_ret == NULL) {
 
99
        return 0;
 
100
    }
 
101
    ret = dcc_x_token_string(fd, "CDIR", cwd);
 
102
    return ret;
 
103
}
 
104
 
 
105
/**
 
106
 * Read the "DONE" token from the network that introduces a response.
 
107
 **/
 
108
int dcc_r_result_header(int ifd,
 
109
                        enum dcc_protover expect_ver)
 
110
{
 
111
    unsigned vers;
 
112
    int ret;
 
113
 
 
114
    if ((ret = dcc_r_token_int(ifd, "DONE", &vers)))
 
115
        rs_log_error("server provided no answer. "
 
116
                     "Is the server configured to allow access from your IP"
 
117
                     " address? Does the server have the compiler installed?"
 
118
                     " Is the server configured to access the compiler?");
 
119
        return ret;
 
120
 
 
121
    if (vers != expect_ver) {
 
122
        rs_log_error("got version %d not %d in response from server",
 
123
                     vers, expect_ver);
 
124
        return EXIT_PROTOCOL_ERROR;
 
125
    }
 
126
 
 
127
    rs_trace("got response header");
 
128
 
 
129
    return 0;
 
130
}
 
131
 
 
132
 
 
133
int dcc_r_cc_status(int ifd, int *status)
 
134
{
 
135
    unsigned u_status;
 
136
    int ret;
 
137
 
 
138
    ret = dcc_r_token_int(ifd, "STAT", &u_status);
 
139
    *status = u_status;
 
140
    return ret;
 
141
}
 
142
 
 
143
 
 
144
/**
 
145
 * The second half of the client protocol: retrieve all results from the server.
 
146
 **/
 
147
int dcc_retrieve_results(int net_fd,
 
148
                         int *status,
 
149
                         const char *output_fname,
 
150
                         const char *deps_fname,
 
151
                         const char *server_stderr_fname,
 
152
                         struct dcc_hostdef *host)
 
153
{
 
154
    unsigned len;
 
155
    int ret;
 
156
    unsigned o_len;
 
157
 
 
158
    if ((ret = dcc_r_result_header(net_fd, host->protover)))
 
159
        return ret;
 
160
 
 
161
    /* We've started to see the response, so the server is done
 
162
     * compiling. */
 
163
    dcc_note_state(DCC_PHASE_RECEIVE, NULL, NULL);
 
164
 
 
165
    if ((ret = dcc_r_cc_status(net_fd, status)))
 
166
        return ret;
 
167
 
 
168
    if ((ret = dcc_r_token_int(net_fd, "SERR", &len)))
 
169
        return ret;
 
170
 
 
171
    /* Save the server-side errors into a file. This way, we can
 
172
       decide later whether we want to report them to the user
 
173
       or not. We don't want to report them to the user if
 
174
       we are going to redo the compilation locally, because then
 
175
       the local errors are going to appear.
 
176
       Always put the server-side errors in the email we will
 
177
       send to the maintainers, though.
 
178
    */
 
179
 
 
180
    if ((ret = dcc_r_file(net_fd, server_stderr_fname, len, host->compr)))
 
181
        return ret;
 
182
 
 
183
    if (dcc_add_file_to_log_email("server-side stderr", server_stderr_fname))
 
184
        return ret;
 
185
 
 
186
    if ((ret = dcc_r_token_int(net_fd, "SOUT", &len))
 
187
        || (ret = dcc_r_bulk(STDOUT_FILENO, net_fd, len, host->compr))
 
188
        || (ret = dcc_r_token_int(net_fd, "DOTO", &o_len)))
 
189
        return ret;
 
190
 
 
191
 
 
192
    /* If the compiler succeeded, then we always retrieve the result,
 
193
     * even if it's 0 bytes.  */
 
194
    if (*status == 0) {
 
195
        if ((ret = dcc_r_file_timed(net_fd, output_fname, o_len, host->compr)))
 
196
            return ret;
 
197
        if (host->cpp_where == DCC_CPP_ON_SERVER) {
 
198
            if ((ret = dcc_r_token_int(net_fd, "DOTD", &len) == 0)
 
199
                && deps_fname != NULL) {
 
200
                ret = dcc_r_file_timed(net_fd, deps_fname, len, host->compr);
 
201
                return ret;
 
202
            }
 
203
        }
 
204
    } else if (o_len != 0) {
 
205
        rs_log_error("remote compiler failed but also returned output: "
 
206
                     "I don't know what to do");
 
207
    }
 
208
 
 
209
    return 0;
 
210
}
 
211
 
 
212
/* points_to must be at least MAXPATHLEN + 1 long */
 
213
int dcc_read_link(const char* fname, char *points_to)
 
214
{
 
215
    int len;
 
216
    if ((len = readlink(fname, points_to, MAXPATHLEN)) == -1) {
 
217
        rs_log_error("readlink '%s' failed: %s", fname, strerror(errno));
 
218
        return EXIT_IO_ERROR;
 
219
    }
 
220
    points_to[len] = '\0';
 
221
    return 0;
 
222
}
 
223
 
 
224
int dcc_is_link(const char *fname, int *is_link)
 
225
{
 
226
    struct stat buf;
 
227
 
 
228
    if (lstat(fname, &buf) == -1) {
 
229
        rs_log_error("stat '%s' failed: %s", fname, strerror(errno));
 
230
        return EXIT_IO_ERROR;
 
231
    }
 
232
 
 
233
    *is_link = S_ISLNK(buf.st_mode);
 
234
    return 0;
 
235
}
 
236
 
 
237
/* Send to @p ofd @p n_files whose names are in @p fnames.
 
238
 * @fnames must be null-terminated.
 
239
 * The names can be coming from the include server, so
 
240
 * we consult dcc_get_original_fname to get the real names.
 
241
 * Always uses lzo compression.
 
242
 */
 
243
/* TODO: This code is highly specific to DCC_VER_3; it assumes
 
244
   lzo compression is on, and that the include server has
 
245
   actually compressed the files. */
 
246
int dcc_x_many_files(int ofd,
 
247
                     unsigned int n_files,
 
248
                     char **fnames)
 
249
{
 
250
    int ret;
 
251
    char link_points_to[MAXPATHLEN + 1];
 
252
    int is_link;
 
253
    const char *fname;
 
254
    char *original_fname;
 
255
 
 
256
    dcc_x_token_int(ofd, "NFIL", n_files);
 
257
 
 
258
    for (; *fnames != NULL; ++fnames) {
 
259
        fname = *fnames;
 
260
        ret = dcc_get_original_fname(fname, &original_fname);
 
261
        if (ret) return ret;
 
262
 
 
263
        if ((ret = dcc_is_link(fname, &is_link))) {
 
264
            return ret;
 
265
        }
 
266
 
 
267
        if (is_link) {
 
268
            if ((ret = dcc_read_link(fname, link_points_to)) ||
 
269
                (ret = dcc_x_token_string(ofd, "NAME", original_fname)) ||
 
270
                (ret = dcc_x_token_string(ofd, "LINK", link_points_to))) {
 
271
                    return ret;
 
272
            }
 
273
        } else {
 
274
            ret = dcc_x_token_string(ofd, "NAME", original_fname);
 
275
            if (ret) return ret;
 
276
            /* File should be compressed already.
 
277
               If we ever support non-compressed server-side-cpp,
 
278
               we should have some checks here and then uncompress
 
279
               the file if it is compressed. */
 
280
            ret = dcc_x_file(ofd, fname, "FILE", DCC_COMPRESS_NONE,
 
281
                             NULL);
 
282
            if (ret) return ret;
 
283
        }
 
284
    }
 
285
    return 0;
 
286
}