~ubuntu-branches/ubuntu/karmic/sbuild/karmic-proposed

« back to all changes in this revision

Viewing changes to lib/Sbuild/Chroot.pm

  • Committer: Bazaar Package Importer
  • Author(s): Roger Leigh, Roger Leigh
  • Date: 2009-05-19 22:16:46 UTC
  • mfrom: (8.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090519221646-iyxt2sohtaxtwgjr
Tags: 0.58.4-1
[ Roger Leigh ]
* New release. 
* sbuild:
  - A $purge_build_deps configuration option, and --purge-deps
    command-line option have been added to control build-dependency
    removal (Closes: #528312).
  - Use the isin function from the Sbuild module (Closes: #529470).
    Thanks to Gustavo Noronha Silva for spotting this.
* Sbuild:
  - Use Filesys::Df (libfilesys-df-perl) in place of invoking /bin/df
    and parsing its output.  This is more robust and efficient, and
    works whatever the user environment (Closes: #509133).

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        'CHROOT' => 1,
64
64
        'PRIORITY' => 0,
65
65
        'DIR' => '/',
 
66
        'SETSID' => 0,
66
67
        'STREAMIN' => undef,
67
68
        'STREAMOUT' => undef,
68
69
        'STREAMERR' => undef});
143
144
    return 1;
144
145
}
145
146
 
 
147
sub get_option {
 
148
    my $self = shift;
 
149
    my $options = shift;
 
150
    my $option = shift;
 
151
 
 
152
    my $value = undef;
 
153
    $value = $self->get('Defaults')->{$option} if
 
154
        (defined($self->get('Defaults')) &&
 
155
         defined($self->get('Defaults')->{$option}));
 
156
    $value = $options->{$option} if
 
157
        (defined($options) &&
 
158
         defined($options->{$option}));
 
159
 
 
160
    return $value;
 
161
}
 
162
 
146
163
sub strip_chroot_path {
147
164
    my $self = shift;
148
165
    my $path = shift;
189
206
    } elsif ($pid == 0) { # child
190
207
        if (!defined $options->{'PIPE'} ||
191
208
            $options->{'PIPE'} ne 'out') { # redirect stdin
192
 
            my $in = undef;
193
 
            $in = $self->get('Defaults')->{'STREAMIN'} if
194
 
                (defined($self->get('Defaults')) &&
195
 
                 defined($self->get('Defaults')->{'STREAMIN'}));
196
 
            $in = $options->{'STREAMIN'} if defined($options->{'STREAMIN'});
 
209
            my $in = $self->get_option($options, 'STREAMIN');
197
210
            if (defined($in) && $in && \*STDIN != $in) {
198
211
                open(STDIN, '<&', $in)
199
212
                    or warn "Can't redirect stdin\n";
200
213
            }
201
214
        } else { # redirect stdout
202
 
            my $out = undef;
203
 
            $out = $self->get('Defaults')->{'STREAMOUT'} if
204
 
                (defined($self->get('Defaults')) &&
205
 
                 defined($self->get('Defaults')->{'STREAMOUT'}));
206
 
            $out = $options->{'STREAMOUT'} if defined($options->{'STREAMOUT'});
 
215
            my $out = $self->get_option($options, 'STREAMOUT');
207
216
            if (defined($out) && $out && \*STDOUT != $out) {
208
217
                open(STDOUT, '>&', $out)
209
218
                    or warn "Can't redirect stdout\n";
210
219
            }
211
220
        }
212
221
        # redirect stderr
213
 
        my $err = undef;
214
 
        $err = $self->get('Defaults')->{'STREAMERR'} if
215
 
            (defined($self->get('Defaults')) &&
216
 
             defined($self->get('Defaults')->{'STREAMERR'}));
217
 
        $err = $options->{'STREAMERR'} if defined($options->{'STREAMERR'});
 
222
        my $err = $self->get_option($options, 'STREAMERR');
218
223
        if (defined($err) && $err && \*STDERR != $err) {
219
224
            open(STDERR, '>&', $err)
220
225
                or warn "Can't redirect stderr\n";
221
226
        }
222
227
 
 
228
        my $setsid = $self->get_option($options, 'SETSID');
 
229
        setsid() if defined($setsid) && $setsid;
 
230
 
223
231
        $self->exec_command($options);
224
232
    }
225
233
 
245
253
        warn "Cannot fork: $!\n";
246
254
    } elsif ($pid == 0) { # child
247
255
        # redirect stdout
248
 
        my $in = undef;
249
 
        $in = $self->get('Defaults')->{'STREAMIN'} if
250
 
            (defined($self->get('Defaults')) &&
251
 
             defined($self->get('Defaults')->{'STREAMIN'}));
252
 
        $in = $options->{'STREAMIN'} if defined($options->{'STREAMIN'});
 
256
        my $in = $self->get_option($options, 'STREAMIN');
253
257
        if (defined($in) && $in && \*STDIN != $in) {
254
258
            open(STDIN, '<&', $in)
255
259
                or warn "Can't redirect stdin\n";
256
260
        }
257
261
        # redirect stdout
258
 
        my $out = undef;
259
 
        $out = $self->get('Defaults')->{'STREAMOUT'} if
260
 
            (defined($self->get('Defaults')) &&
261
 
             defined($self->get('Defaults')->{'STREAMOUT'}));
262
 
        $out = $options->{'STREAMOUT'} if defined($options->{'STREAMOUT'});
 
262
        my $out = $self->get_option($options, 'STREAMOUT');
263
263
        if (defined($out) && $out && \*STDOUT != $out) {
264
264
            open(STDOUT, '>&', $out)
265
265
                or warn "Can't redirect stdout\n";
266
266
        }
267
267
        # redirect stderr
268
 
        my $err = undef;
269
 
        $err = $self->get('Defaults')->{'STREAMERR'} if
270
 
            (defined($self->get('Defaults')) &&
271
 
             defined($self->get('Defaults')->{'STREAMERR'}));
272
 
        $err = $options->{'STREAMERR'} if defined($options->{'STREAMERR'});
 
268
        my $err = $self->get_option($options, 'STREAMERR');
273
269
        if (defined($err) && $err && \*STDERR != $err) {
274
270
            open(STDERR, '>&', $err)
275
271
                or warn "Can't redirect stderr\n";
276
272
        }
277
273
 
 
274
        my $setsid = $self->get_option($options, 'SETSID');
 
275
        setsid() if defined($setsid) && $setsid;
 
276
 
278
277
        $self->exec_command($options);
279
278
    }
280
279
 
315
314
 
316
315
    $self->get_command_internal($options);
317
316
 
318
 
    debug("COMMAND: ", join(" ", @{$options->{'COMMAND'}}), "\n");
319
 
    debug("INTCOMMAND: ", join(" ", @{$options->{'INTCOMMAND'}}), "\n");
320
 
    debug("EXPCOMMAND: ", join(" ", @{$options->{'EXPCOMMAND'}}), "\n");
321
 
 
322
317
    $self->log_command($options);
323
318
 
324
319
    my $dir = $options->{'CHDIR'};
325
320
    my $command = $options->{'EXPCOMMAND'};
326
321
 
 
322
    my $program = $command->[0];
 
323
    $program = $options->{'PROGRAM'} if defined($options->{'PROGRAM'});
 
324
 
327
325
    my $chrootenv = $self->get('Defaults')->{'ENV'};
328
326
    foreach (keys %$chrootenv) {
329
327
        $ENV{$_} = $chrootenv->{$_};
334
332
        $ENV{$_} = $commandenv->{$_};
335
333
    }
336
334
 
 
335
    debug("PROGRAM: $program\n");
 
336
    debug("COMMAND: ", join(" ", @{$options->{'COMMAND'}}), "\n");
 
337
    debug("INTCOMMAND: ", join(" ", @{$options->{'INTCOMMAND'}}), "\n");
 
338
    debug("EXPCOMMAND: ", join(" ", @{$options->{'EXPCOMMAND'}}), "\n");
 
339
 
337
340
    debug("Environment set:\n");
338
341
    foreach (sort keys %ENV) {
339
342
        debug("  $_=$ENV{$_}\n");
345
348
    }
346
349
 
347
350
    debug("Running command: ", join(" ", @$command), "\n");
348
 
    exec @$command;
 
351
    exec { $program } @$command;
349
352
    die "Failed to exec: $command->[0]: $!";
350
353
}
351
354