~ubuntu-branches/ubuntu/natty/libvirt/natty-security

« back to all changes in this revision

Viewing changes to tests/testutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-02-23 09:05:46 UTC
  • mfrom: (1.2.8 upstream) (3.4.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110223090546-4pwmrrt7h51hr3l3
Tags: 0.8.8-1ubuntu1
* Resynchronize and merge from Debian unstable. Remaining changes:
  - debian/patches:
    * 9000-delayed_iff_up_bridge.patch
    * 9001-dont_clobber_existing_bridges.patch
    * 9002-better_default_uri_virsh.patch
    * 9003-better-default-arch.patch
    * 9004-libvirtd-group-name.patch
    * 9005-increase-unix-socket-timeout.patch
    * 9006-default-config-test-case.patch
    * 9007-fix-daemon-conf-ftbfs.patch
    * 9011-move-ebtables-script.patch
    * 9014-skip-nodeinfotest.patch
    * 9020-lp545795.patch
    * 9021-fix-uint64_t.patch
  - debian/patches/series:
    * Disable qemu-disable-network.diff.patch
  - debian/control:
    * set ubuntu maintainer
    * Build-Depends:
      - swap libxen to libxen3, qemu to qemu-kvm, and open-iscsi to
        open-iscsi-utils in Build-Depends
      - remove virtualbox Build-Depends
      - add libxml2 and libapparmor-dev Build-Depends
    * convert Vcs-Git to Xs-Debian-Vcs-Git
    * libvirt-bin Depends: move netcat-openbsd, bridge-utils, dnsmasq-base
      (>= 2.46-1), and iptables from Recommends to Depends
    * libvirt-bin Recommends: move qemu to Suggests
    * libvirt-bin Suggests: add apparmor
    * libvirt0 Recommands: move lvm2 to Suggests
  - keep debian/libvirt-bin.apport
  - keep debian/libvirt-bin.cron.daily
  - debian/libvirt-bin.dirs:
    * add apparmor, cron.daily, and apport dirs
  - debian/libvirt-bin.examples:
    * add debian/libvirt-suspendonreboot
  - debian/libvirt-bin.install:
    * add /etc/apparmor.d files
    * add apport hook
  - debian/libvirt-bin.manpages:
    * add debian/libvirt-migrate-qemu-disks.1
  - debian/libvirt-bin.postinst:
    * replace libvirt groupname with libvirtd
    * add each admin user to libvirtd group
    * call apparmor_parser on usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
    * call 'libvirt-migrate-qemu-disks -a' after
      libvirt-bin has started if migrating from
      older than 0.8.3-1ubuntu1
  - debian/libvirt-bin.postrm:
    * replace libvirt groupname with libvirtd
    * remove usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
  - keep added files under debian/:
    * libvirt-bin.upstart
    * libvirt-migrate-qemu-disks
    * libvirt-migrate-qemu-disks.1
    * libvirt-suspendonreboot
    * apparmor profiles
  - debian/README.Debian:
    * add 'Apparmor Profile' section
    * add 'Disk migration' section
  - debian/rules:
    * don't build with vbox since virtualbox-ose is in universe
    * add --with-apparmor to DEB_CONFIGURE_EXTRA_FLAGS
    * set DEB_DH_INSTALLINIT_ARGS to '--upstart-only'
    * set DEB_MAKE_CHECK_TARGET to 'check'
    * remove unneeded binary-install/libvirt-bin:: and clean::
      sections (they only deal with sysvinit stuff)
    * add build/libvirt-bin:: section to install
      - apparmor files
      - apport hooks
      - libvirt-migrate-qemu-disks
* The following Ubuntu packaging changes occurred during the divergence
  between Debian and Ubuntu. These changes are not new, but included here
  for completeness: (0.8.5-0ubuntu1 - 0.8.5-0ubuntu5):
  - Have upstart job source /etc/default/libvirt-bin.  This is only a
    temporary fix until upstart provides proper default override support
    through /etc/init/libvirt-bin.override (or any other mechanism).
    (LP: 708172)
  - debian/apparmor/usr.sbin.libvirtd: use PUx instead of Ux for executables
    (LP: 573315)
  - Rebuild with python 2.7 as the python default.
  - debian/libvirt-bin.cron.daily: use shell globbing to enumerate xml files.
    Based on patch thanks to Henryk Plötz (LP: 655176)
* Dropped the following patches included/fixed upstream:
  - 9010-dont-disable-ipv6.patch
  - 9022-build-cleanup-declaration-of-xen-tests.patch
  - 9023-vah-require-uuid.patch
  - 9009-autodetect-nc-params.patch
    * rolled into Debian's
      Autodetect-if-the-remote-nc-command-supports-the-q-o.patch
* Updated the following patches:
  - 9011-move-ebtables-script.patch:
    * LOCALSTATEDIR is defined in configmake.h
  - 9000-9006: added DEP-3 tags
  - 9002-better_default_uri_virsh.patch: updated (context changed)
* New patches:
  - 9022-drop-booton-when-kernel-specified.patch (LP: #720426)
  - 9023-fix-lxc-console-hangup.patch (LP: #668369)
  - 9024-skip-broken-commandtest.patch
* debian/patches/series:
  - don't apply Disable-CHECKSUM-rule.patch: our iptables can do this
  - don't apply Debian-specific Debianize-libvirt-guests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * testutils.c: basic test utils
3
3
 *
4
 
 * Copyright (C) 2005-2010 Red Hat, Inc.
 
4
 * Copyright (C) 2005-2011 Red Hat, Inc.
5
5
 *
6
6
 * See COPYING.LIB for the License of this software
7
7
 *
44
44
 
45
45
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
46
46
#define DIFF_MSEC(T, U)                                 \
47
 
    ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
 
47
    ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
48
48
      ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
49
49
 
 
50
#include "files.h"
 
51
 
50
52
static unsigned int testDebug = -1;
51
53
static unsigned int testVerbose = -1;
52
54
 
124
126
 
125
127
        if (ts)
126
128
            GETTIMEOFDAY(&before);
 
129
 
127
130
        virResetLastError();
128
 
        if ((ret = body(data)) != 0)
 
131
        ret = body(data);
 
132
        virErrorPtr err = virGetLastError();
 
133
        if (err) {
 
134
            if (virTestGetVerbose() || virTestGetDebug())
 
135
                virDispatchError(NULL);
 
136
        }
 
137
 
 
138
        if (ret != 0) {
129
139
            break;
130
 
        virErrorPtr err = virGetLastError();
131
 
        if (err)
132
 
            virDispatchError(NULL);
133
 
        if (ts) {
 
140
        }
 
141
 
 
142
        if (ts) {
134
143
            GETTIMEOFDAY(&after);
135
144
            ts[i] = DIFF_MSEC(&after, &before);
136
145
        }
164
173
/* Read FILE into buffer BUF of length BUFLEN.
165
174
   Upon any failure, or if FILE appears to contain more than BUFLEN bytes,
166
175
   diagnose it and return -1, but don't bother trying to preserve errno.
167
 
   Otherwise, return the number of bytes read (and copied into BUF).  */
 
176
   Otherwise, return the number of bytes copied into BUF. */
168
177
int virtTestLoadFile(const char *file,
169
178
                     char **buf,
170
179
                     int buflen) {
171
180
    FILE *fp = fopen(file, "r");
172
181
    struct stat st;
 
182
    char *tmp = *buf;
 
183
    int len, tmplen = buflen;
173
184
 
174
185
    if (!fp) {
175
186
        fprintf (stderr, "%s: failed to open: %s\n", file, strerror(errno));
178
189
 
179
190
    if (fstat(fileno(fp), &st) < 0) {
180
191
        fprintf (stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
181
 
        fclose(fp);
 
192
        VIR_FORCE_FCLOSE(fp);
182
193
        return -1;
183
194
    }
184
195
 
185
196
    if (st.st_size > (buflen-1)) {
186
197
        fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
187
 
        fclose(fp);
 
198
        VIR_FORCE_FCLOSE(fp);
188
199
        return -1;
189
200
    }
190
201
 
 
202
    (*buf)[0] = '\0';
191
203
    if (st.st_size) {
192
 
        if (fread(*buf, st.st_size, 1, fp) != 1) {
 
204
        /* read the file line by line */
 
205
        while (fgets(tmp, tmplen, fp) != NULL) {
 
206
            len = strlen(tmp);
 
207
            /* remove trailing backslash-newline pair */
 
208
            if (len >= 2 && tmp[len-2] == '\\' && tmp[len-1] == '\n') {
 
209
                len -= 2;
 
210
                tmp[len] = '\0';
 
211
            }
 
212
            /* advance the temporary buffer pointer */
 
213
            tmp += len;
 
214
            tmplen -= len;
 
215
        }
 
216
        if (ferror(fp)) {
193
217
            fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
194
 
            fclose(fp);
 
218
            VIR_FORCE_FCLOSE(fp);
195
219
            return -1;
196
220
        }
197
221
    }
198
 
    (*buf)[st.st_size] = '\0';
199
222
 
200
 
    fclose(fp);
201
 
    return st.st_size;
 
223
    VIR_FORCE_FCLOSE(fp);
 
224
    return strlen(*buf);
202
225
}
203
226
 
204
227
#ifndef WIN32
222
245
    open_max = sysconf (_SC_OPEN_MAX);
223
246
    for (i = 0; i < open_max; i++) {
224
247
        if (i != stdinfd &&
225
 
            i != pipefd)
226
 
            close(i);
 
248
            i != pipefd) {
 
249
            int tmpfd = i;
 
250
            VIR_FORCE_CLOSE(tmpfd);
 
251
        }
227
252
    }
228
253
 
229
254
    if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
237
262
    execve(argv[0], (char *const*)argv, (char *const*)env);
238
263
 
239
264
 cleanup:
240
 
    if (stdinfd != -1)
241
 
        close(stdinfd);
 
265
    VIR_FORCE_CLOSE(stdinfd);
242
266
}
243
267
 
244
268
int virtTestCaptureProgramOutput(const char *const argv[],
252
276
    int pid = fork();
253
277
    switch (pid) {
254
278
    case 0:
255
 
        close(pipefd[0]);
 
279
        VIR_FORCE_CLOSE(pipefd[0]);
256
280
        virtTestCaptureProgramExecChild(argv, pipefd[1]);
257
281
 
258
 
        close(pipefd[1]);
 
282
        VIR_FORCE_CLOSE(pipefd[1]);
259
283
        _exit(1);
260
284
 
261
285
    case -1:
267
291
            int ret = -1;
268
292
            int want = buflen-1;
269
293
 
270
 
            close(pipefd[1]);
 
294
            VIR_FORCE_CLOSE(pipefd[1]);
271
295
 
272
296
            while (want) {
273
297
                if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
275
299
                got += ret;
276
300
                want -= ret;
277
301
            }
278
 
            close(pipefd[0]);
 
302
            VIR_FORCE_CLOSE(pipefd[0]);
279
303
 
280
304
            if (!ret)
281
305
                (*buf)[got] = '\0';