~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
#
# Author: Daniel Silverstone <daniel.silverstone@canonical.com>

# Buildd Slave tool to scan a chroot in case any processes are underneath it

## This script uses bashisms, must be run under bash

# Expects build id as arg 1, makes build-id to contain the build

# Needs SUDO to be set to a sudo instance for passwordless access

SUDO=/usr/bin/sudo
BUILDID="$1"
REALHOME=$(cd $HOME && pwd -P)

set -e

exec 2>&1

[ $(id -u) = "0" ] || exec $SUDO $0 "$REALHOME/build-$BUILDID/chroot-autobuild"

echo "Scanning for processes to kill in build $BUILDID..."

PREFIX="$BUILDID"
FOUND=0

for ROOT in /proc/*/root; do
    LINK=$(readlink $ROOT)
    if [ "x$LINK" != "x" ]; then
	if [ "x${LINK:0:${#PREFIX}}" = "x$PREFIX" ]; then
	    # this process is in the chroot...
	    PID=$(basename $(dirname "$ROOT"))
	    kill -9 "$PID"
	    FOUND=1
	fi
    fi
done

if [ "x$FOUND" = "x1" ]; then
  exec $0 $1
fi