^src/util\.c$
^src/xend_internal\.c$
^src/util-lib\.c$
+^qemud/qemud.c$
^gnulib/
+Tue Jan 20 16:59:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
+
+ Make error reporting threadsafe by avoiding strerror()
+ * autobuild.sh: Set mingw compile warnings to fail compile
+ * configure.in: Check for strerror_r
+ * po/POTFILES.in: Add src/xen_unified.c
+ * src/virterror.c, src/virterror_internal.h,
+ src/libvirt_private.syms: Add virReportSystemErrorFull and
+ virReportOOMErrorFull convenience functions
+ * src/domain_conf.c, src/lxc_container.c, src/lxc_controller.c,
+ src/lxc_driver.c, src/network_conf.c, src/network_driver.c,
+ src/nodeinfo.c, src/qemu_driver.c, src/remote_internal.c,
+ src/storage_backend.c, src/storage_backend_disk.c,
+ src/storage_backend_fs.c, src/storage_backend_iscsi.c,
+ src/storage_backend_logical.c, src/storage_conf.c,
+ src/storage_driver.c, src/test.c, src/uml_driver.c,
+ src/util.c, src/xen_inotify.c, src/xen_internal.c,
+ src/xen_unified.c, src/xend_internal.c, src/xm_internal.c:
+ Remove use of strerror when reporting errors, in favour
+ of virReportSystemError() and virReportOOMError()
+
Tue Jan 20 17:17:11 CET 2009 Daniel Veillard <veillard@redhat.com>
* src/qemu_driver.c: remove a warning when printing a file offset
--build=$(uname -m)-pc-linux \
--host=i686-pc-mingw32 \
--prefix="$AUTOBUILD_INSTALL_ROOT/i686-pc-mingw32/sys-root/mingw" \
+ --enable-compile-warnings=error \
--without-sasl \
--without-avahi \
--without-polkit \
dnl Availability of various common functions (non-fatal if missing).
AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid])
+dnl Availability of various not common threadsafe functions
+AC_CHECK_FUNCS([strerror_r])
+
dnl Availability of various common headers (non-fatal if missing).
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/utsname.h sys/wait.h winsock2.h sched.h termios.h sys/poll.h syslog.h])
src/network_driver.c
src/node_device.c
src/node_device_conf.c
+src/nodeinfo.c
src/openvz_conf.c
src/openvz_driver.c
src/proxy_internal.c
src/virterror.c
src/xen_inotify.c
src/xen_internal.c
+src/xen_unified.c
src/xend_internal.c
src/xm_internal.c
src/xml.c
#include "buf.h"
#include "c-ctype.h"
+#define VIR_FROM_THIS VIR_FROM_DOMAIN
+
VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
"qemu",
"kqemu",
int err;
if ((err = virUUIDGenerate(def->uuid))) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to generate UUID: %s"),
- strerror(err));
+ "%s", _("Failed to generate UUID"));
goto error;
}
} else {
goto cleanup;
if ((err = virFileMakePath(configDir))) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create config directory %s: %s"),
- configDir, strerror(err));
+ virReportSystemError(conn, errno,
+ _("cannot create config directory '%s'"),
+ configDir);
goto cleanup;
}
if ((fd = open(configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR )) < 0) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create config file %s: %s"),
- configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot create config file '%s'"),
+ configFile);
goto cleanup;
}
towrite = strlen(xml);
if (safewrite(fd, xml, towrite) < 0) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot write config file %s: %s"),
- configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot write config file '%s'"),
+ configFile);
goto cleanup;
}
if (close(fd) < 0) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot save config file %s: %s"),
- configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot save config file '%s'"),
+ configFile);
goto cleanup;
}
if (!(dir = opendir(configDir))) {
if (errno == ENOENT)
return 0;
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to open dir '%s': %s"),
- configDir, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failed to open dir '%s'"),
+ configDir);
return -1;
}
if (unlink(configFile) < 0 &&
errno != ENOENT) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot remove config for %s: %s"),
- dom->def->name, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot remove config %s"),
+ configFile);
goto cleanup;
}
virReportErrorHelper;
virErrorMsg;
virRaiseError;
+virReportSystemErrorFull;
+virReportOOMErrorFull;
# xml.h
#include "memory.h"
#include "veth.h"
+#define VIR_FROM_THIS VIR_FROM_LXC
+
/*
* GLibc headers are behind the kernel, so we define these
* constants if they're not present already.
int open_max, i;
if (setsid() < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("setsid failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("setsid failed"));
goto cleanup;
}
if (ioctl(ttyfd, TIOCSCTTY, NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("ioctl(TIOCSTTY) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("ioctl(TIOCSTTY) failed"));
goto cleanup;
}
close(i);
if (dup2(ttyfd, 0) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("dup2(stdin) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("dup2(stdin) failed"));
goto cleanup;
}
if (dup2(ttyfd, 1) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("dup2(stdout) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("dup2(stdout) failed"));
goto cleanup;
}
if (dup2(ttyfd, 2) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("dup2(stderr) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("dup2(stderr) failed"));
goto cleanup;
}
writeCount = safewrite(control, &msg, sizeof(msg));
if (writeCount != sizeof(msg)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("unable to send container continue message: %s"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("unable to send container continue message"));
goto error_out;
}
readLen = saferead(control, &msg, sizeof(msg));
if (readLen != sizeof(msg) ||
msg != LXC_CONTINUE_MSG) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to read the container continue message: %s"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("Failed to read the container continue message"));
return -1;
}
close(control);
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
{
+ int rc;
char *oldroot;
/* First step is to ensure the new root itself is
a mount point */
if (mount(root->src, root->src, NULL, MS_BIND, NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to bind new root %s: %s"),
- root->src, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to bind new root %s"),
+ root->src);
return -1;
}
if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) {
- lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(NULL);
return -1;
}
- if (virFileMakePath(oldroot) < 0) {
+ if ((rc = virFileMakePath(oldroot)) < 0) {
VIR_FREE(oldroot);
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create %s: %s"),
- oldroot, strerror(errno));
+ virReportSystemError(NULL, rc,
+ _("failed to create %s"),
+ oldroot);
return -1;
}
* this and will soon be unmounted completely */
if (pivot_root(root->src, oldroot) < 0) {
VIR_FREE(oldroot);
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to pivot root %s to %s: %s"),
- oldroot, root->src, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to pivot root %s to %s"),
+ oldroot, root->src);
return -1;
}
VIR_FREE(oldroot);
static int lxcContainerPopulateDevices(void)
{
int i;
+ int rc;
const struct {
int maj;
int min;
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_URANDOM, 0666, "/dev/urandom" },
};
- if (virFileMakePath("/dev") < 0 ||
- mount("none", "/dev", "tmpfs", 0, NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to mount /dev tmpfs for container: %s"),
- strerror(errno));
+ if ((rc = virFileMakePath("/dev")) < 0) {
+ virReportSystemError(NULL, rc, "%s",
+ _("cannot create /dev/"));
+ return -1;
+ }
+ if (mount("none", "/dev", "tmpfs", 0, NULL) < 0) {
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to mount /dev tmpfs"));
return -1;
}
/* Move old devpts into container, since we have to
XXX This sucks, we need to figure out how to get our
own private devpts for isolation
*/
- if (virFileMakePath("/dev/pts") < 0 ||
- mount("/.oldroot/dev/pts", "/dev/pts", NULL,
+ if ((rc = virFileMakePath("/dev/pts") < 0)) {
+ virReportSystemError(NULL, rc, "%s",
+ _("cannot create /dev/pts"));
+ return -1;
+ }
+ if (mount("/.oldroot/dev/pts", "/dev/pts", NULL,
MS_MOVE, NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to move /dev/pts into container: %s"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to move /dev/pts into container"));
return -1;
}
dev_t dev = makedev(devs[i].maj, devs[i].min);
if (mknod(devs[i].path, 0, dev) < 0 ||
chmod(devs[i].path, devs[i].mode)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to make device %s: %s"),
- devs[i].path, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to make device %s"),
+ devs[i].path);
return -1;
}
}
return -1;
}
- if (virFileMakePath(vmDef->fss[i]->dst) < 0 ||
- mount(src, vmDef->fss[i]->dst, NULL, MS_BIND, NULL) < 0) {
+ if (virFileMakePath(vmDef->fss[i]->dst) < 0) {
+ virReportSystemError(NULL, errno,
+ _("failed to create %s"),
+ vmDef->fss[i]->dst);
VIR_FREE(src);
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to mount %s at %s for container: %s"),
- vmDef->fss[i]->src, vmDef->fss[i]->dst, strerror(errno));
+ return -1;
+ }
+ if (mount(src, vmDef->fss[i]->dst, NULL, MS_BIND, NULL) < 0) {
+ VIR_FREE(src);
+ virReportSystemError(NULL, errno,
+ _("failed to mount %s at %s"),
+ vmDef->fss[i]->src,
+ vmDef->fss[i]->dst);
return -1;
}
VIR_FREE(src);
int i;
if (!(procmnt = setmntent("/proc/mounts", "r"))) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to read /proc/mounts: %s"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to read /proc/mounts"));
return -1;
}
while ((mntent = getmntent(procmnt)) != NULL) {
for (i = 0 ; i < nmounts ; i++) {
if (umount(mounts[i]) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to unmount %s: %s"),
- mounts[i], strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to unmount '%s'"),
+ mounts[i]);
return -1;
}
VIR_FREE(mounts[i]);
if (virFileMakePath("/proc") < 0 ||
mount("none", "/proc", "proc", 0, NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to mount /proc for container: %s"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to mount /proc"));
return -1;
}
NULL,
MS_BIND,
NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to mount %s at %s for container: %s"),
- vmDef->fss[i]->src, vmDef->fss[i]->dst, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to mount %s at %s"),
+ vmDef->fss[i]->src,
+ vmDef->fss[i]->dst);
return -1;
}
}
/* mount /proc */
if (mount("lxcproc", "/proc", "proc", 0, NULL) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to mount /proc for container: %s"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to mount /proc"));
return -1;
}
ttyfd = open(argv->ttyPath, O_RDWR|O_NOCTTY);
if (ttyfd < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("open(%s) failed: %s"), argv->ttyPath, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to open %s"),
+ argv->ttyPath);
return -1;
}
DEBUG("clone() returned, %d", pid);
if (pid < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("clone() failed, %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to run clone container"));
return -1;
}
#include "util.h"
#include "cgroup.h"
+#define VIR_FROM_THIS VIR_FROM_LXC
+
struct cgroup_device_policy {
char type;
int major;
rc = virCgroupAddTask(cgroup, getpid());
out:
if (rc != 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to set lxc resources: %s\n"), strerror(-rc));
+ virReportSystemError(NULL, -rc, "%s",
+ _("Failed to set lxc resources"));
virCgroupRemove(cgroup);
}
struct sockaddr_un addr;
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create server socket %s: %s"),
- sockpath, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to create server socket '%s'"),
+ sockpath);
goto error;
}
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to bind server socket %s: %s"),
- sockpath, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to bind server socket '%s'"),
+ sockpath);
goto error;
}
if (listen(fd, 30 /* backlog */ ) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to listen server socket %s: %s"),
- sockpath, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("failed to listen server socket %s"),
+ sockpath);
goto error;
}
goto cleanup;
}
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("read of fd %d failed: %s"), readFd, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("read of fd %d failed"),
+ readFd);
goto cleanup;
}
if (1 != (safewrite(writeFd, buf, 1))) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("write to fd %d failed: %s"), writeFd, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("write to fd %d failed"),
+ writeFd);
goto cleanup;
}
/* create the epoll fild descriptor */
epollFd = epoll_create(2);
if (0 > epollFd) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_create(2) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_create(2) failed"));
goto cleanup;
}
epollEvent.events = EPOLLIN|EPOLLET; /* edge triggered */
epollEvent.data.fd = appPty;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, appPty, &epollEvent)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_ctl(appPty) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_ctl(appPty) failed"));
goto cleanup;
}
epollEvent.data.fd = contPty;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, contPty, &epollEvent)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_ctl(contPty) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_ctl(contPty) failed"));
goto cleanup;
}
epollEvent.events = EPOLLIN;
epollEvent.data.fd = monitor;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, monitor, &epollEvent)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_ctl(contPty) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_ctl(contPty) failed"));
goto cleanup;
}
epollEvent.events = EPOLLHUP;
epollEvent.data.fd = client;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_ctl(contPty) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_ctl(contPty) failed"));
goto cleanup;
}
epollEvent.events = EPOLLHUP;
epollEvent.data.fd = client;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_ctl(contPty) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_ctl(contPty) failed"));
goto cleanup;
}
} else if (client != -1 && epollEvent.data.fd == client) {
if (0 > epoll_ctl(epollFd, EPOLL_CTL_DEL, client, &epollEvent)) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_ctl(contPty) failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_ctl(contPty) failed"));
goto cleanup;
}
close(client);
}
/* error */
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("epoll_wait() failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("epoll_wait() failed"));
goto cleanup;
}
pid_t container = -1;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("sockpair failed: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("sockpair failed"));
goto cleanup;
}
if (virFileOpenTty(&containerPty,
&containerPtyPath,
0) < 0) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to allocate tty: %s"), strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("failed to allocate tty"));
goto cleanup;
}
case 'n':
if ((name = strdup(optarg)) == NULL) {
- fprintf(stderr, "%s", strerror(errno));
+ virReportOOMError(NULL);
goto cleanup;
}
break;
case 'v':
if (VIR_REALLOC_N(veths, nveths+1) < 0) {
- fprintf(stderr, "cannot allocate veths %s", strerror(errno));
+ virReportOOMError(NULL);
goto cleanup;
}
if ((veths[nveths++] = strdup(optarg)) == NULL) {
- fprintf(stderr, "cannot allocate veth name %s", strerror(errno));
+ virReportOOMError(NULL);
goto cleanup;
}
break;
if (pid > 0) {
if ((rc = virFileWritePid(LXC_STATE_DIR, name, pid)) != 0) {
- fprintf(stderr, _("Unable to write pid file: %s\n"),
- strerror(rc));
+ virReportSystemError(NULL, rc,
+ _("Unable to write pid file '%s/%s.pid'"),
+ LXC_STATE_DIR, name);
_exit(1);
}
/* Don't hold onto any cwd we inherit from libvirtd either */
if (chdir("/") < 0) {
- fprintf(stderr, _("Unable to change to root dir: %s\n"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("Unable to change to root dir"));
goto cleanup;
}
if (setsid() < 0) {
- fprintf(stderr, _("Unable to become session leader: %s\n"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("Unable to become session leader"));
goto cleanup;
}
}
/* Accept initial client which is the libvirtd daemon */
if ((client = accept(monitor, NULL, 0)) < 0) {
- fprintf(stderr, _("Failed connection from LXC driver: %s\n"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s",
+ _("Failed connection from LXC driver"));
goto cleanup;
}
#include "cgroup.h"
+#define VIR_FROM_THIS VIR_FROM_LXC
+
static int lxcStartup(void);
static int lxcShutdown(void);
static lxc_driver_t *lxc_driver = NULL;
; /* empty */
if ((waitRc != vm->pid) && (errno != ECHILD)) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("waitpid failed to wait for container %d: %d %s"),
- vm->pid, waitRc, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("waitpid failed to wait for container %d: %d"),
+ vm->pid, waitRc);
}
rc = 0;
}
if (0 != (rc = brAddInterface(brctl, bridge, parentVeth))) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add %s device to %s: %s"),
- parentVeth,
- bridge,
- strerror(rc));
+ virReportSystemError(conn, rc,
+ _("failed to add %s device to %s"),
+ parentVeth, bridge);
goto error_exit;
}
if (0 != (rc = vethInterfaceUpOrDown(parentVeth, 1))) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to enable parent ns veth device: %d"), rc);
+ virReportSystemError(conn, rc, "%s",
+ _("failed to enable parent ns veth device"));
goto error_exit;
}
}
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create client socket: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("failed to create client socket"));
goto error;
}
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to connect to client socket: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("failed to connect to client socket"));
goto error;
}
if (kill(vm->pid, signum) < 0) {
if (errno != ESRCH) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to kill pid %d: %s"),
- vm->pid, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to kill pid %d"),
+ vm->pid);
return -1;
}
}
*/
while ((rc = waitpid(child, &status, 0) == -1) && errno == EINTR);
if (rc == -1) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot wait for '%s': %s"),
- largv[0], strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot wait for '%s'"),
+ largv[0]);
goto cleanup;
}
unsigned int nveths = 0;
char **veths = NULL;
- if (virFileMakePath(driver->logDir) < 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot create log directory %s: %s"),
- driver->logDir, strerror(rc));
+ if ((rc = virFileMakePath(driver->logDir)) < 0) {
+ virReportSystemError(conn, rc,
+ _("cannot create log directory '%s'"),
+ driver->logDir);
return -1;
}
/* open parent tty */
if (virFileOpenTty(&parentTty, &parentTtyPath, 1) < 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to allocate tty: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("failed to allocate tty"));
goto cleanup;
}
if (vm->def->console &&
if ((logfd = open(logfile, O_WRONLY | O_TRUNC | O_CREAT,
S_IRUSR|S_IWUSR)) < 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to open %s: %s"), logfile,
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to open '%s'"),
+ logfile);
goto cleanup;
}
/* And get its pid */
if ((rc = virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) != 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to read pid file %s/%s.pid: %s"),
- driver->stateDir, vm->def->name, strerror(rc));
+ virReportSystemError(conn, rc,
+ _("Failed to read pid file %s/%s.pid"),
+ driver->stateDir, vm->def->name);
rc = -1;
goto cleanup;
}
int min;
int rev;
- if (uname(&ver) != 0) {
- lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
- _("uname(): %s"), strerror(errno));
- return -1;
- }
+ uname(&ver);
if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
#include "buf.h"
#include "c-ctype.h"
+#define VIR_FROM_THIS VIR_FROM_NETWORK
+
VIR_ENUM_DECL(virNetworkForward)
VIR_ENUM_IMPL(virNetworkForward,
int err;
if ((err = virUUIDGenerate(def->uuid))) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to generate UUID: %s"), strerror(err));
+ "%s", _("Failed to generate UUID"));
goto error;
}
} else {
goto cleanup;
if ((err = virFileMakePath(configDir))) {
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create config directory %s: %s"),
- configDir, strerror(err));
+ virReportSystemError(conn, err,
+ _("cannot create config directory '%s'"),
+ configDir);
goto cleanup;
}
if ((err = virFileMakePath(autostartDir))) {
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create autostart directory %s: %s"),
- autostartDir, strerror(err));
+ virReportSystemError(conn, err,
+ _("cannot create autostart directory '%s'"),
+ autostartDir);
goto cleanup;
}
if ((fd = open(net->configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR )) < 0) {
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create config file %s: %s"),
- net->configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot create config file '%s'"),
+ net->configFile);
goto cleanup;
}
towrite = strlen(xml);
if (safewrite(fd, xml, towrite) < 0) {
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot write config file %s: %s"),
- net->configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot write config file '%s'"),
+ net->configFile);
goto cleanup;
}
if (close(fd) < 0) {
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot save config file %s: %s"),
- net->configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot save config file '%s'"),
+ net->configFile);
goto cleanup;
}
if (!(dir = opendir(configDir))) {
if (errno == ENOENT)
return 0;
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to open dir '%s': %s"),
- configDir, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failed to open dir '%s'"),
+ configDir);
return -1;
}
unlink(net->autostartLink);
if (unlink(net->configFile) < 0) {
- virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot remove config for %s: %s"),
- net->def->name, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot remove config file '%s'"),
+ net->configFile);
return -1;
}
#include "iptables.h"
#include "bridge.h"
+
+#define VIR_FROM_THIS VIR_FROM_NETWORK
+
/* Main driver state */
struct network_driver {
virMutex lock;
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow forwarding from '%s' : %s\n"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow forwarding from '%s'"),
+ network->def->bridge);
goto masqerr1;
}
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow forwarding to '%s' : %s\n"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow forwarding to '%s'"),
+ network->def->bridge);
goto masqerr2;
}
if ((err = iptablesAddForwardMasquerade(driver->iptables,
network->def->network,
network->def->forwardDev))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to enable masquerading : %s\n"),
- strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to enable masquerading to '%s'\n"),
+ network->def->forwardDev ? network->def->forwardDev : NULL);
goto masqerr3;
}
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow routing from '%s' : %s\n"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow routing from '%s'"),
+ network->def->bridge);
goto routeerr1;
}
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow routing to '%s' : %s\n"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow routing to '%s'"),
+ network->def->bridge);
goto routeerr2;
}
/* allow DHCP requests through to dnsmasq */
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 67))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow DHCP requests from '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow DHCP requests from '%s'"),
+ network->def->bridge);
goto err1;
}
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 67))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow DHCP requests from '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow DHCP requests from '%s'"),
+ network->def->bridge);
goto err2;
}
/* allow DNS requests through to dnsmasq */
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 53))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow DNS requests from '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow DNS requests from '%s'"),
+ network->def->bridge);
goto err3;
}
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 53))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow DNS requests from '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow DNS requests from '%s'"),
+ network->def->bridge);
goto err4;
}
/* Catch all rules to block forwarding to/from bridges */
if ((err = iptablesAddForwardRejectOut(driver->iptables, network->def->bridge))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to block outbound traffic from '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to block outbound traffic from '%s'"),
+ network->def->bridge);
goto err5;
}
if ((err = iptablesAddForwardRejectIn(driver->iptables, network->def->bridge))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to block inbound traffic to '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to block inbound traffic to '%s'"),
+ network->def->bridge);
goto err6;
}
/* Allow traffic between guests on the same bridge */
if ((err = iptablesAddForwardAllowCross(driver->iptables, network->def->bridge))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to add iptables rule to allow cross bridge traffic on '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to add iptables rule to allow cross bridge traffic on '%s'"),
+ network->def->bridge);
goto err7;
}
}
if (!driver->brctl && (err = brInit(&driver->brctl))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize bridge support: %s"), strerror(err));
+ virReportSystemError(conn, err, "%s",
+ _("cannot initialize bridge support"));
return -1;
}
if ((err = brAddBridge(driver->brctl, &network->def->bridge))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot create bridge '%s' : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("cannot create bridge '%s'"),
+ network->def->bridge);
return -1;
}
if (network->def->ipAddress &&
(err = brSetInetAddress(driver->brctl, network->def->bridge, network->def->ipAddress))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot set IP address on bridge '%s' to '%s' : %s"),
- network->def->bridge, network->def->ipAddress, strerror(err));
+ virReportSystemError(conn, err,
+ _("cannot set IP address on bridge '%s' to '%s'"),
+ network->def->bridge, network->def->ipAddress);
goto err_delbr;
}
if (network->def->netmask &&
(err = brSetInetNetmask(driver->brctl, network->def->bridge, network->def->netmask))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot set netmask on bridge '%s' to '%s' : %s"),
- network->def->bridge, network->def->netmask, strerror(err));
+ virReportSystemError(conn, err,
+ _("cannot set netmask on bridge '%s' to '%s'"),
+ network->def->bridge, network->def->netmask);
goto err_delbr;
}
if (network->def->ipAddress &&
(err = brSetInterfaceUp(driver->brctl, network->def->bridge, 1))) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to bring the bridge '%s' up : %s"),
- network->def->bridge, strerror(err));
+ virReportSystemError(conn, err,
+ _("failed to bring the bridge '%s' up"),
+ network->def->bridge);
goto err_delbr;
}
if (network->def->forwardType != VIR_NETWORK_FORWARD_NONE &&
!networkEnableIpForwarding()) {
- networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to enable IP forwarding : %s"), strerror(err));
+ virReportSystemError(conn, errno, "%s",
+ _("failed to enable IP forwarding"));
goto err_delbr2;
}
int err;
if ((err = virFileMakePath(driver->networkAutostartDir))) {
- networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
- _("cannot create autostart directory %s: %s"),
- driver->networkAutostartDir, strerror(err));
+ virReportSystemError(net->conn, errno,
+ _("cannot create autostart directory '%s'"),
+ driver->networkAutostartDir);
goto cleanup;
}
if (symlink(network->configFile, network->autostartLink) < 0) {
- networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
- _("Failed to create symlink '%s' to '%s': %s"),
- network->autostartLink, network->configFile, strerror(errno));
+ virReportSystemError(net->conn, errno,
+ _("Failed to create symlink '%s' to '%s'"),
+ network->autostartLink, network->configFile);
goto cleanup;
}
} else {
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
- _("Failed to delete symlink '%s': %s"),
- network->autostartLink, strerror(errno));
+ virReportSystemError(net->conn, errno,
+ _("Failed to delete symlink '%s'"),
+ network->autostartLink);
goto cleanup;
}
}
#include "util.h"
#include "virterror_internal.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
#ifdef __linux__
#define CPUINFO_PATH "/proc/cpuinfo"
#ifdef HAVE_UNAME
struct utsname info;
- if (uname(&info) < 0) {
- virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
- VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "cannot extract machine type %s", strerror(errno));
- return -1;
- }
+ uname(&info);
+
strncpy(nodeinfo->model, info.machine, sizeof(nodeinfo->model)-1);
nodeinfo->model[sizeof(nodeinfo->model)-1] = '\0';
int ret;
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
if (!cpuinfo) {
- virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
- VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "cannot open %s %s", CPUINFO_PATH, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open %s"), CPUINFO_PATH);
return -1;
}
ret = linuxNodeInfoCPUPopulate(conn, cpuinfo, nodeinfo);
#include "uuid.h"
#include "domain_conf.h"
+#define VIR_FROM_THIS VIR_FROM_QEMU
+
/* For storing short-lived temporary files. */
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
if ((ret = snprintf(logfile, sizeof(logfile), "%s/%s.log", logDir, name))
< 0 || ret >= sizeof(logfile)) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to build logfile name %s/%s.log"),
- logDir, name);
+ virReportOOMError(conn);
return -1;
}
else
logmode |= O_APPEND;
if ((fd = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create logfile %s: %s"),
- logfile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to create logfile %s"),
+ logfile);
return -1;
}
if (qemudSetCloseExec(fd) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Unable to set VM logfile close-on-exec flag %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("Unable to set VM logfile close-on-exec flag"));
close(fd);
return -1;
}
continue;
if (errno != EAGAIN) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failure while reading %s startup output: %s"),
- what, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failure while reading %s startup output"),
+ what);
return -1;
}
return -1;
} else if (ret == -1) {
if (errno != EINTR) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failure while reading %s startup output: %s"),
- what, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failure while reading %s startup output"),
+ what);
return -1;
}
} else {
for (i = 0 ; i < vm->nvcpupids ; i++) {
if (sched_setaffinity(vm->vcpupids[i],
sizeof(mask), &mask) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to set CPU affinity %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("failed to set CPU affinity"));
return -1;
}
}
}
if (virFileMakePath(driver->logDir) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot create log directory %s: %s"),
- driver->logDir, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot create log directory %s"),
+ driver->logDir);
return -1;
}
* in a sub-process so its hard to feed back a useful error
*/
if (stat(emulator, &sb) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Cannot find QEMU binary %s: %s"),
- emulator,
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Cannot find QEMU binary %s"),
+ emulator);
return -1;
}
}
if (close(fd) < 0) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- _("unable to save file %s %s"),
- path, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("unable to save file %s"),
+ path);
goto cleanup;
}
fd = -1;
if (vm->vcpupids != NULL) {
if (sched_setaffinity(vm->vcpupids[vcpu], sizeof(mask), &mask) < 0) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
- _("cannot set affinity: %s"), strerror(errno));
+ virReportSystemError(dom->conn, errno, "%s",
+ _("cannot set affinity"));
goto cleanup;
}
} else {
CPU_ZERO(&mask);
if (sched_getaffinity(vm->vcpupids[v], sizeof(mask), &mask) < 0) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
- _("cannot get affinity: %s"), strerror(errno));
+ virReportSystemError(dom->conn, errno, "%s",
+ _("cannot get affinity"));
goto cleanup;
}
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot create autostart directory %s: %s"),
- driver->autostartDir, strerror(err));
+ virReportSystemError(dom->conn, err,
+ _("cannot create autostart directory %s"),
+ driver->autostartDir);
goto cleanup;
}
if (symlink(configFile, autostartLink) < 0) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to create symlink '%s to '%s': %s"),
- autostartLink, configFile, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("Failed to create symlink '%s to '%s'"),
+ autostartLink, configFile);
goto cleanup;
}
} else {
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to delete symlink '%s': %s"),
- autostartLink, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("Failed to delete symlink '%s'"),
+ autostartLink);
goto cleanup;
}
}
#include "util.h"
#include "event.h"
+#define VIR_FROM_THIS VIR_FROM_REMOTE
+
#ifdef WIN32
#define pipe(fds) _pipe(fds,4096, _O_BINARY)
#endif
}
freeaddrinfo (res);
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to connect to '%s': %s"),
- priv->hostname, strerror (saved_errno));
+ virReportSystemError(conn, saved_errno,
+ _("unable to connect to '%s'"),
+ priv->hostname);
goto failed;
tcp_connected:
uid_t uid = getuid();
if (!(pw = getpwuid(uid))) {
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to lookup user '%d': %s"),
- uid, strerror (errno));
+ virReportSystemError(conn, errno,
+ _("unable to lookup user '%d'"),
+ uid);
goto failed;
}
autostart_retry:
priv->sock = socket (AF_UNIX, SOCK_STREAM, 0);
if (priv->sock == -1) {
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to create socket %s"),
- strerror (errno));
+ virReportSystemError(conn, errno, "%s",
+ _("unable to create socket"));
goto failed;
}
if (connect (priv->sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
goto autostart_retry;
}
}
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to connect to '%s': %s"),
- sockname, strerror (errno));
+ virReportSystemError(conn, errno,
+ _("unable to connect to '%s'"),
+ sockname);
goto failed;
}
* to faff around with two file descriptors (a la 'pipe(2)').
*/
if (socketpair (PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to create socket pair %s"),
- strerror (errno));
+ virReportSystemError(conn, errno, "%s",
+ _("unable to create socket pair"));
goto failed;
}
} /* switch (transport) */
if (virSetNonBlock(priv->sock) < 0) {
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to make socket non-blocking %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("unable to make socket non-blocking"));
goto failed;
}
if (pipe(wakeupFD) < 0) {
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("unable to make pipe %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("unable to make pipe"));
goto failed;
}
priv->wakeupReadFD = wakeupFD[0];
{
struct stat sb;
if (stat(file, &sb) < 0) {
- errorf(conn, VIR_ERR_RPC,
- _("Cannot access %s '%s': %s (%d)"),
- type, file, strerror(errno), errno);
+ virReportSystemError(conn, errno,
+ _("Cannot access %s '%s'"),
+ type, file);
return -1;
}
return 0;
}
if ((now = time(NULL)) == ((time_t)-1)) {
- errorf (conn, VIR_ERR_SYSTEM_ERROR,
- _("cannot get current time: %s"),
- strerror (errno));
+ virReportSystemError(conn, errno, "%s",
+ _("cannot get current time"));
return -1;
}
/* Get local address in form IPADDR:PORT */
salen = sizeof(sa);
if (getsockname(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
- virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
- VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- _("failed to get sock address %d (%s)"),
- errno, strerror(errno));
+ virReportSystemError(in_open ? NULL : conn, errno, "%s",
+ _("failed to get sock address"));
goto cleanup;
}
if ((localAddr = addrToString(&sa, salen)) == NULL)
/* Get remote address in form IPADDR:PORT */
salen = sizeof(sa);
if (getpeername(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
- virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
- VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- _("failed to get peer address %d (%s)"),
- errno, strerror(errno));
+ virReportSystemError(in_open ? NULL : conn, errno, "%s",
+ _("failed to get peer address"));
goto cleanup;
}
if ((remoteAddr = addrToString(&sa, salen)) == NULL)
if (errno == EWOULDBLOCK)
return 0;
- error (in_open ? NULL : conn,
- VIR_ERR_SYSTEM_ERROR, strerror (errno));
+ virReportSystemError(in_open ? NULL : conn, errno,
+ "%s", _("cannot send data"));
return -1;
}
if (errno == EWOULDBLOCK)
return 0;
- errorf (in_open ? NULL : conn,
- VIR_ERR_SYSTEM_ERROR,
- _("failed to read from socket %s"),
- strerror (errno));
+ virReportSystemError(in_open ? NULL : conn, errno,
+ "%s", _("cannot recv data"));
} else {
errorf (in_open ? NULL : conn,
VIR_ERR_SYSTEM_ERROR,
#endif
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
static virStorageBackendPtr backends[] = {
#if WITH_STORAGE_DIR
&virStorageBackendDirectory,
int ret, fd;
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot open volume '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open volume '%s'"),
+ vol->target.path);
return -1;
}
#endif
if (fstat(fd, &sb) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot stat file '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot stat file '%s'"),
+ vol->target.path);
return -1;
}
*/
end = lseek(fd, 0, SEEK_END);
if (end == (off_t)-1) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot seek to end of file '%s':%s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot seek to end of file '%s'"),
+ vol->target.path);
return -1;
}
vol->allocation = end;
start = lseek(fd, 0, SEEK_SET);
if (start < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot seek to beginning of file '%s':%s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot seek to beginning of file '%s'"),
+ vol->target.path);
return -1;
}
bytes = saferead(fd, buffer, sizeof(buffer));
if (bytes < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read beginning of file '%s':%s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read beginning of file '%s'"),
+ vol->target.path);
return -1;
}
#if HAVE_SELINUX
if (fgetfilecon(fd, &filecon) == -1) {
if (errno != ENODATA && errno != ENOTSUP) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot get file context of %s: %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot get file context of '%s'"),
+ vol->target.path);
return -1;
} else {
vol->target.perms.label = NULL;
} else {
vol->target.perms.label = strdup(filecon);
if (vol->target.perms.label == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("context"));
+ virReportOOMError(conn);
return -1;
}
freecon(filecon);
usleep(100 * 1000);
goto reopen;
}
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read dir %s: %s"),
- pool->def->target.path,
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read dir '%s'"),
+ pool->def->target.path);
return NULL;
}
if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) +
1 + strlen(dent->d_name) + 1) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
+ virReportOOMError(conn);
closedir(dh);
return NULL;
}
stablepath = strdup(devpath);
if (stablepath == NULL)
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("dup path"));
+ virReportOOMError(conn);
return stablepath;
}
/* Compile all regular expressions */
if (VIR_ALLOC_N(reg, nregex) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("regex"));
+ virReportOOMError(conn);
return -1;
}
/* Storage for matched variables */
if (VIR_ALLOC_N(groups, totgroups) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("regex groups"));
+ virReportOOMError(conn);
goto cleanup;
}
if (VIR_ALLOC_N(vars, maxvars+1) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("regex groups"));
+ virReportOOMError(conn);
goto cleanup;
}
line[vars[j+1].rm_eo] = '\0';
if ((groups[ngroup++] =
strdup(line + vars[j+1].rm_so)) == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("regex groups"));
+ virReportOOMError(conn);
goto cleanup;
}
}
return -1;
if (err == -1) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to wait for command: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to wait for command '%s'"),
+ prog[0]);
return -1;
} else {
if (WIFEXITED(exitstatus)) {
return -1;
if (VIR_ALLOC_N(v, n_columns) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("n_columns too large"));
+ virReportOOMError(conn);
return -1;
}
for (i = 0; i < n_columns; i++)
if (feof (fp))
err = 0;
else
- virStorageReportError (conn, VIR_ERR_INTERNAL_ERROR,
- _("read error: %s"), strerror (errno));
+ virReportSystemError(conn, errno,
+ _("read error on pipe to '%s'"), prog[0]);
cleanup:
for (i = 0; i < n_columns; i++)
return -1;
if (w_err == -1) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to wait for command: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to wait for command '%s'"),
+ prog[0]);
return -1;
} else {
if (WIFEXITED(exitstatus)) {
#include "util.h"
#include "memory.h"
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
#define PARTHELPER BINDIR "/libvirt_parthelper"
static int
if (vol == NULL) {
if (VIR_ALLOC(vol) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
+ virReportOOMError(conn);
return -1;
}
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
+ virReportOOMError(conn);
virStorageVolDefFree(vol);
return -1;
}
*/
tmp = strrchr(groups[0], '/');
if ((vol->name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
+ virReportOOMError(conn);
return -1;
}
}
if (vol->target.path == NULL) {
if ((devpath = strdup(groups[0])) == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
+ virReportOOMError(conn);
return -1;
}
if (vol->key == NULL) {
/* XXX base off a unique key of the underlying disk */
if ((vol->key = strdup(vol->target.path)) == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
+ virReportOOMError(conn);
return -1;
}
}
if (vol->source.extents == NULL) {
if (VIR_ALLOC(vol->source.extents) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("volume extents"));
+ virReportOOMError(conn);
return -1;
}
vol->source.nextent = 1;
if ((vol->source.extents[0].path =
strdup(pool->def->source.devices[0].path)) == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
+ virReportOOMError(conn);
return -1;
}
}
if ((n = readlink(vol->target.path, devpath, sizeof(devpath))) < 0 &&
errno != EINVAL) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Couldn't read volume target path '%s'. %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Couldn't read volume target path '%s'"),
+ vol->target.path);
return -1;
} else if (n <= 0) {
strncpy(devpath, vol->target.path, PATH_MAX);
*/
};
+#define VIR_FROM_THIS VIR_FROM_STORAGE
int len, i, ret;
if ((fd = open(def->target.path, O_RDONLY)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot open volume '%s': %s"),
- def->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open volume '%s'"),
+ def->target.path);
return -1;
}
}
if ((len = read(fd, head, sizeof(head))) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read header '%s': %s"),
- def->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read header '%s'"),
+ def->target.path);
close(fd);
return -1;
}
}
if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources));
xpath_ctxt = xmlXPathNewContext(doc);
if (xpath_ctxt == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xpath_ctxt"));
+ virReportOOMError(conn);
goto cleanup;
}
retval = virStoragePoolSourceListFormat(conn, &state.list);
if (retval == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("retval"));
+ virReportOOMError(conn);
goto cleanup;
}
struct mntent *ent;
if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read %s: %s"),
- _PATH_MOUNTED, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read mount list '%s'"),
+ _PATH_MOUNTED);
return -1;
}
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
1 + strlen(pool->def->source.dir) + 1) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
+ virReportOOMError(conn);
return -1;
}
strcpy(src, pool->def->source.host.name);
strcat(src, pool->def->source.dir);
} else {
if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
+ virReportOOMError(conn);
return -1;
}
}
virStoragePoolObjPtr pool,
unsigned int flags ATTRIBUTE_UNUSED)
{
- if (virFileMakePath(pool->def->target.path) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create path '%s': %s"),
- pool->def->target.path, strerror(errno));
+ int err;
+ if ((err = virFileMakePath(pool->def->target.path)) < 0) {
+ virReportSystemError(conn, err,
+ _("cannot create path '%s'"),
+ pool->def->target.path);
return -1;
}
virStorageVolDefPtr vol = NULL;
if (!(dir = opendir(pool->def->target.path))) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot open path '%s': %s"),
- pool->def->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open path '%s'"),
+ pool->def->target.path);
goto cleanup;
}
if (statvfs(pool->def->target.path, &sb) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot statvfs path '%s': %s"),
- pool->def->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot statvfs path '%s'"),
+ pool->def->target.path);
return -1;
}
pool->def->capacity = ((unsigned long long)sb.f_frsize *
return 0;
no_memory:
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
/* fallthrough */
cleanup:
/* XXX delete all vols first ? */
if (unlink(pool->def->target.path) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot unlink path '%s': %s"),
- pool->def->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot unlink path '%s'"),
+ pool->def->target.path);
return -1;
}
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
1 + strlen(vol->name) + 1) < 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
+ virReportOOMError(conn);
return -1;
}
vol->type = VIR_STORAGE_VOL_FILE;
strcat(vol->target.path, vol->name);
vol->key = strdup(vol->target.path);
if (vol->key == NULL) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("storage vol key"));
+ virReportOOMError(conn);
return -1;
}
if (vol->target.format == VIR_STORAGE_VOL_FILE_RAW) {
if ((fd = open(vol->target.path, O_RDWR | O_CREAT | O_EXCL,
vol->target.perms.mode)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create path '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot create path '%s'"),
+ vol->target.path);
return -1;
}
if (bytes > remain)
bytes = remain;
if ((bytes = safewrite(fd, zeros, bytes)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot fill file '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot fill file '%s'"),
+ vol->target.path);
unlink(vol->target.path);
close(fd);
return -1;
/* Now seek to final size, possibly making the file sparse */
if (ftruncate(fd, vol->capacity) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot extend file '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot extend file '%s'"),
+ vol->target.path);
unlink(vol->target.path);
close(fd);
return -1;
}
} else if (vol->target.format == VIR_STORAGE_VOL_FILE_DIR) {
if (mkdir(vol->target.path, vol->target.perms.mode) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create path '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot create path '%s'"),
+ vol->target.path);
return -1;
}
if ((fd = open(vol->target.path, O_RDWR)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read path '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read path '%s'"),
+ vol->target.path);
return -1;
}
} else {
}
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read path '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read path '%s'"),
+ vol->target.path);
unlink(vol->target.path);
return -1;
}
}
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read path '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read path '%s'"),
+ vol->target.path);
unlink(vol->target.path);
return -1;
}
/* We can only chown/grp if root */
if (getuid() == 0) {
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot set file owner '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot set file owner '%s'"),
+ vol->target.path);
unlink(vol->target.path);
close(fd);
return -1;
}
}
if (fchmod(fd, vol->target.perms.mode) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot set file mode '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot set file mode '%s'"),
+ vol->target.path);
unlink(vol->target.path);
close(fd);
return -1;
}
if (close(fd) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot close file '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot close file '%s'"),
+ vol->target.path);
unlink(vol->target.path);
return -1;
}
if (unlink(vol->target.path) < 0) {
/* Silently ignore failures where the vol has already gone away */
if (errno != ENOENT) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot unlink file '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot unlink file '%s'"),
+ vol->target.path);
return -1;
}
}
#include "util.h"
#include "memory.h"
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
+
static int
virStorageBackendISCSITargetIP(virConnectPtr conn,
const char *hostname,
usleep(100 * 1000);
goto reopen;
}
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot open %s: %s"),
- devpath, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open '%s'"),
+ devpath);
goto cleanup;
}
sysdir = opendir(sysfs_path);
if (sysdir == NULL) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to opendir sysfs path %s: %s"),
- sysfs_path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failed to opendir sysfs path '%s'"),
+ sysfs_path);
return -1;
}
while ((sys_dirent = readdir(sysdir))) {
n = scandir(sysfs_path, &namelist, notdotdir, versionsort);
if (n <= 0) {
/* we didn't find any reasonable entries; return failure */
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to find any LUNs for session %s: %s"),
- session, strerror(errno));
-
+ virReportSystemError(conn, errno,
+ _("Failed to find any LUNs for session '%s'"),
+ session);
return -1;
}
sysdir = opendir(sysfs_path);
if (sysdir == NULL) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to opendir sysfs path %s: %s"),
- sysfs_path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failed to opendir sysfs path '%s'"),
+ sysfs_path);
retval = -1;
goto namelist_cleanup;
}
host, bus, target, lun);
sysdir = opendir(sysfs_path);
if (sysdir == NULL) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to opendir sysfs path %s: %s"),
- sysfs_path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failed to opendir sysfs path '%s'"),
+ sysfs_path);
retval = -1;
goto namelist_cleanup;
}
#include "util.h"
#include "memory.h"
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
#define PV_BLANK_SECTOR_SIZE 512
* rather than trying to figure out if we're a disk or partition
*/
if ((fd = open(pool->def->source.devices[i].path, O_WRONLY)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot open device %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open device '%s'"),
+ pool->def->source.devices[i].path);
goto cleanup;
}
if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot clear device header %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot clear device header of '%s'"),
+ pool->def->source.devices[i].path);
close(fd);
goto cleanup;
}
if (close(fd) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot close device %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot close device '%s'"),
+ pool->def->source.devices[i].path);
goto cleanup;
}
pvargv[1] = pool->def->source.devices[i].path;
if (virRun(conn, pvargv, NULL) < 0) {
error = -1;
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot remove PV device %s: %s"),
- pool->def->source.devices[i].path,
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot remove PV device '%s'"),
+ pool->def->source.devices[i].path);
break;
}
}
return -1;
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot read path '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read path '%s'"),
+ vol->target.path);
goto cleanup;
}
/* We can only chown/grp if root */
if (getuid() == 0) {
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot set file owner '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot set file owner '%s'"),
+ vol->target.path);
goto cleanup;
}
}
if (fchmod(fd, vol->target.perms.mode) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot set file mode '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot set file mode '%s'"),
+ vol->target.path);
goto cleanup;
}
if (close(fd) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot close file '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot close file '%s'"),
+ vol->target.path);
goto cleanup;
}
fd = -1;
/* Fill in data about this new vol */
if (virStorageBackendLogicalFindLVs(conn, pool, vol) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot find newly created volume '%s': %s"),
- vol->target.path, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot find newly created volume '%s'"),
+ vol->target.path);
goto cleanup;
}
#include "util.h"
#include "memory.h"
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
/* Work around broken limits.h on debian etch */
#if defined __GNUC__ && defined _GCC_LIMITS_H_ && ! defined ULLONG_MAX
# define ULLONG_MAX ULONG_LONG_MAX
char path[PATH_MAX];
if ((err = virFileMakePath(driver->configDir))) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create config directory %s: %s"),
- driver->configDir, strerror(err));
+ virStorageReportError(conn, err,
+ _("cannot create config directory %s"),
+ driver->configDir);
return -1;
}
if ((fd = open(pool->configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR )) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create config file %s: %s"),
- pool->configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot create config file %s"),
+ pool->configFile);
goto cleanup;
}
towrite = strlen(xml);
if (safewrite(fd, xml, towrite) != towrite) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot write config file %s: %s"),
- pool->configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot write config file %s"),
+ pool->configFile);
goto cleanup;
}
if (close(fd) < 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot save config file %s: %s"),
- pool->configFile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot save config file %s"),
+ pool->configFile);
goto cleanup;
}
#include "memory.h"
#include "storage_backend.h"
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
#define storageLog(msg...) fprintf(stderr, msg)
static virStorageDriverStatePtr driverState;
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
virStoragePoolObjUnlock(driver->pools.objs[i]);
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("names"));
+ virReportOOMError(conn);
goto cleanup;
}
got++;
if (!virStoragePoolObjIsActive(driver->pools.objs[i])) {
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
virStoragePoolObjUnlock(driver->pools.objs[i]);
- virStorageReportError(conn, VIR_ERR_NO_MEMORY,
- "%s", _("names"));
+ virReportOOMError(conn);
goto cleanup;
}
got++;
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create autostart directory %s: %s"),
- driver->autostartDir, strerror(err));
+ virReportSystemError(obj->conn, err,
+ _("cannot create autostart directory %s"),
+ driver->autostartDir);
goto cleanup;
}
if (symlink(pool->configFile, pool->autostartLink) < 0) {
- virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to create symlink '%s' to '%s': %s"),
- pool->autostartLink, pool->configFile,
- strerror(errno));
+ virReportSystemError(obj->conn, errno,
+ _("Failed to create symlink '%s' to '%s'"),
+ pool->autostartLink, pool->configFile);
goto cleanup;
}
} else {
if (unlink(pool->autostartLink) < 0 &&
errno != ENOENT && errno != ENOTDIR) {
- virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to delete symlink '%s': %s"),
- pool->autostartLink, strerror(errno));
+ virReportSystemError(obj->conn, errno,
+ _("Failed to delete symlink '%s'"),
+ pool->autostartLink);
goto cleanup;
}
}
for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) {
if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) {
- virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY,
- "%s", _("name"));
+ virReportOOMError(obj->conn);
goto cleanup;
}
}
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) {
- virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(obj->conn);
goto cleanup;
}
ret = strdup(vol->target.path);
if (ret == NULL)
- virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
+ virReportOOMError(obj->conn);
cleanup:
if (pool)
#include "xml.h"
#include "threads.h"
+#define VIR_FROM_THIS VIR_FROM_TEST
+
#define MAX_CPUS 128
struct _testCell {
return caps;
no_memory:
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
virCapabilitiesFree(caps);
return NULL;
}
static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull);
static const unsigned long long defaultPoolAlloc = 0;
-static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool);
+static int testStoragePoolObjSetDefaults(virConnectPtr conn, virStoragePoolObjPtr pool);
static int testOpenDefault(virConnectPtr conn) {
int u;
virStoragePoolObjPtr poolobj = NULL;
if (VIR_ALLOC(privconn) < 0) {
- testError(conn, VIR_ERR_NO_MEMORY, "testConn");
+ virReportOOMError(conn);
return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&privconn->lock) < 0) {
conn->privateData = privconn;
if (gettimeofday(&tv, NULL) < 0) {
- testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("getting time of day"));
+ virReportSystemError(conn, errno,
+ "%s", _("getting time of day"));
goto error;
}
goto error;
}
- if (testStoragePoolObjSetDefaults(poolobj) == -1) {
+ if (testStoragePoolObjSetDefaults(conn, poolobj) == -1) {
virStoragePoolObjUnlock(poolobj);
goto error;
}
virDomainObjPtr dom;
testConnPtr privconn;
if (VIR_ALLOC(privconn) < 0) {
- testError(NULL, VIR_ERR_NO_MEMORY, "testConn");
+ virReportOOMError(conn);
return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&privconn->lock) < 0) {
goto error;
if ((fd = open(file, O_RDONLY)) < 0) {
- testError(NULL, VIR_ERR_INTERNAL_ERROR,
- _("loading host definition file '%s': %s"),
- file, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("loading host definition file '%s'"),
+ file);
goto error;
}
goto error;
}
- if (testStoragePoolObjSetDefaults(pool) == -1) {
+ if (testStoragePoolObjSetDefaults(conn, pool) == -1) {
virStoragePoolObjUnlock(pool);
goto error;
}
result = virGetHostname();
if (result == NULL) {
- testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
- strerror (errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot lookup hostname"));
return NULL;
}
/* Caller frees this string. */
char *xml;
testDriverLock(privconn);
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL)
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
testDriverUnlock(privconn);
return xml;
}
xml = testDomainDumpXML(domain, 0);
if (xml == NULL) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("saving domain '%s' failed to allocate space for metadata: %s"),
- domain->name, strerror(errno));
+ virReportSystemError(domain->conn, errno,
+ _("saving domain '%s' failed to allocate space for metadata"),
+ domain->name);
goto cleanup;
}
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("saving domain '%s' to '%s': open failed: %s"),
- domain->name, path, strerror(errno));
+ virReportSystemError(domain->conn, errno,
+ _("saving domain '%s' to '%s': open failed"),
+ domain->name, path);
goto cleanup;
}
len = strlen(xml);
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("saving domain '%s' to '%s': write failed: %s"),
- domain->name, path, strerror(errno));
+ virReportSystemError(domain->conn, errno,
+ _("saving domain '%s' to '%s': write failed"),
+ domain->name, path);
goto cleanup;
}
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("saving domain '%s' to '%s': write failed: %s"),
- domain->name, path, strerror(errno));
+ virReportSystemError(domain->conn, errno,
+ _("saving domain '%s' to '%s': write failed"),
+ domain->name, path);
goto cleanup;
}
if (safewrite(fd, xml, len) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("saving domain '%s' to '%s': write failed: %s"),
- domain->name, path, strerror(errno));
+ virReportSystemError(domain->conn, errno,
+ _("saving domain '%s' to '%s': write failed"),
+ domain->name, path);
goto cleanup;
}
if (close(fd) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("saving domain '%s' to '%s': write failed: %s"),
- domain->name, path, strerror(errno));
+ virReportSystemError(domain->conn, errno,
+ _("saving domain '%s' to '%s': write failed"),
+ domain->name, path);
goto cleanup;
}
fd = -1;
int ret = -1;
if ((fd = open(path, O_RDONLY)) < 0) {
- testError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot read domain image"));
+ virReportSystemError(conn, errno,
+ _("cannot read domain image '%s'"),
+ path);
goto cleanup;
}
- if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
- testError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("incomplete save header"));
+ if (saferead(fd, magic, sizeof(magic)) != sizeof(magic)) {
+ virReportSystemError(conn, errno,
+ _("incomplete save header in '%s'"),
+ path);
goto cleanup;
}
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
"%s", _("mismatched header magic"));
goto cleanup;
}
- if (read(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
- testError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to read metadata length"));
+ if (saferead(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
+ virReportSystemError(conn, errno,
+ _("failed to read metadata length in '%s'"),
+ path);
goto cleanup;
}
if (len < 1 || len > 8192) {
goto cleanup;
}
if (VIR_ALLOC_N(xml, len+1) < 0) {
- testError(conn, VIR_ERR_NO_MEMORY, "xml");
+ virReportOOMError(conn);
goto cleanup;
}
- if (read(fd, xml, len) != len) {
- testError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("incomplete metdata"));
+ if (saferead(fd, xml, len) != len) {
+ virReportSystemError(conn, errno,
+ _("incomplete metdata in '%s'"), path);
goto cleanup;
}
xml[len] = '\0';
}
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("domain '%s' coredump: failed to open %s: %s"),
- domain->name, to, strerror (errno));
+ virReportSystemError(domain->conn, errno,
+ _("domain '%s' coredump: failed to open %s"),
+ domain->name, to);
goto cleanup;
}
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("domain '%s' coredump: failed to write header to %s: %s"),
- domain->name, to, strerror (errno));
+ virReportSystemError(domain->conn, errno,
+ _("domain '%s' coredump: failed to write header to %s"),
+ domain->name, to);
goto cleanup;
}
if (close(fd) < 0) {
- testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- _("domain '%s' coredump: write failed: %s: %s"),
- domain->name, to, strerror (errno));
+ virReportSystemError(domain->conn, errno,
+ _("domain '%s' coredump: write failed: %s"),
+ domain->name, to);
goto cleanup;
}
privdom->state = VIR_DOMAIN_SHUTOFF;
static char *testGetOSType(virDomainPtr dom) {
char *ret = strdup("linux");
if (!ret)
- testError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(dom->conn);
return ret;
}
return n;
no_memory:
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
for (n = 0 ; n < maxnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
*nparams = 1;
type = strdup("fair");
if (!type)
- testError(domain->conn, VIR_ERR_NO_MEMORY, "schedular");
+ virReportOOMError(domain->conn);
return type;
}
return n;
no_memory:
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
return n;
no_memory:
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
if (privnet->def->bridge &&
!(bridge = strdup(privnet->def->bridge))) {
- testError(network->conn, VIR_ERR_NO_MEMORY, "network");
+ virReportOOMError(network->conn);
goto cleanup;
}
* Storage Driver routines
*/
-static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) {
+static int testStoragePoolObjSetDefaults(virConnectPtr conn,
+ virStoragePoolObjPtr pool) {
pool->def->capacity = defaultPoolCap;
pool->def->allocation = defaultPoolAlloc;
pool->configFile = strdup("\0");
if (!pool->configFile) {
- testError(NULL, VIR_ERR_NO_MEMORY, "configFile");
+ virReportOOMError(conn);
return -1;
}
return n;
no_memory:
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
return n;
no_memory:
- testError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
}
def = NULL;
- if (testStoragePoolObjSetDefaults(pool) == -1) {
+ if (testStoragePoolObjSetDefaults(conn, pool) == -1) {
virStoragePoolObjRemove(&privconn->pools, pool);
pool = NULL;
goto cleanup;
}
def = NULL;
- if (testStoragePoolObjSetDefaults(pool) == -1) {
+ if (testStoragePoolObjSetDefaults(conn, pool) == -1) {
virStoragePoolObjRemove(&privconn->pools, pool);
pool = NULL;
goto cleanup;
for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) {
if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
- testError(pool->conn, VIR_ERR_NO_MEMORY, "%s", _("name"));
+ virReportOOMError(pool->conn);
goto cleanup;
}
}
if (VIR_REALLOC_N(privpool->volumes.objs,
privpool->volumes.count+1) < 0) {
- testError(pool->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(pool->conn);
goto cleanup;
}
if (VIR_ALLOC_N(privvol->target.path,
strlen(privpool->def->target.path) +
1 + strlen(privvol->name) + 1) < 0) {
- testError(pool->conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
+ virReportOOMError(pool->conn);
goto cleanup;
}
strcat(privvol->target.path, privvol->name);
privvol->key = strdup(privvol->target.path);
if (privvol->key == NULL) {
- testError(pool->conn, VIR_ERR_INTERNAL_ERROR, "%s",
- _("storage vol key"));
+ virReportOOMError(pool->conn);
goto cleanup;
}
ret = strdup(privvol->target.path);
if (ret == NULL)
- testError(vol->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
+ virReportOOMError(vol->conn);
cleanup:
if (privpool)
#include "datatypes.h"
#include "logging.h"
+#define VIR_FROM_THIS VIR_FROM_UML
+
/* For storing short-lived temporary files. */
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
char *res = NULL;
int retries = 0;
if (virAsprintf(&cmd, "config %s%d", dev, def->dstPort) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
requery:
if (STRPREFIX(res, "pts:")) {
VIR_FREE(def->data.file.path);
if ((def->data.file.path = strdup(res + 4)) == NULL) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
VIR_FREE(res);
VIR_FREE(cmd);
return -1;
vm->pid = -1;
if (virAsprintf(&pidfile, "%s/%s/pid",
driver->monitorDir, vm->def->name) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
cleanup:
if (rc != 0)
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to read pid: %s: %s"),
- pidfile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to read pid: %s"),
+ pidfile);
VIR_FREE(pidfile);
return rc;
}
if (virAsprintf(&sockname, "%s/%s/mconsole",
driver->monitorDir, vm->def->name) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
}
if ((vm->monitor = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot open socket %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot open socket"));
return -1;
}
memset(addr.sun_path, 0, sizeof addr.sun_path);
sprintf(addr.sun_path + 1, "%u", getpid());
if (bind(vm->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot bind socket %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot bind socket"));
close(vm->monitor);
vm->monitor = -1;
return -1;
req.version = MONITOR_VERSION;
req.length = strlen(cmd);
if (req.length > (MONITOR_BUFLEN-1)) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot send too long command %s: %s"),
- cmd, strerror(EINVAL));
+ virReportSystemError(conn, EINVAL,
+ _("cannot send too long command %s (%d bytes)"),
+ cmd, req.length);
return -1;
}
strncpy(req.data, cmd, req.length);
if (sendto(vm->monitor, &req, sizeof req, 0,
(struct sockaddr *)&addr, sizeof addr) != (sizeof req)) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot send command %s: %s"),
- cmd, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot send command %s"),
+ cmd);
return -1;
}
addrlen = sizeof(addr);
if (recvfrom(vm->monitor, &res, sizeof res, 0,
(struct sockaddr *)&addr, &addrlen) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot read reply %s: %s"),
- cmd, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read reply %s"),
+ cmd);
goto error;
}
if (VIR_REALLOC_N(retdata, retlen + res.length) < 0) {
- umlReportError(conn, NULL, NULL,
- VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
goto error;
}
memcpy(retdata + retlen, res.data, res.length);
* in a sub-process so its hard to feed back a useful error
*/
if (stat(vm->def->os.kernel, &sb) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Cannot find UML kernel %s: %s"),
- vm->def->os.kernel, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Cannot find UML kernel %s"),
+ vm->def->os.kernel);
return -1;
}
if (virFileMakePath(driver->logDir) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot create log directory %s"),
- driver->logDir);
+ virReportSystemError(conn, errno,
+ _("cannot create log directory %s"),
+ driver->logDir);
return -1;
}
if (virAsprintf(&logfile, "%s/%s.log",
driver->logDir, vm->def->name) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
if ((logfd = open(logfile, O_CREAT | O_TRUNC | O_WRONLY,
S_IRUSR | S_IWUSR)) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create logfile %s: %s"),
- logfile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to create logfile %s"),
+ logfile);
VIR_FREE(logfile);
return -1;
}
VIR_FREE(logfile);
if (umlSetCloseExec(logfd) < 0) {
- umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Unable to set VM logfile close-on-exec flag %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("Unable to set VM logfile close-on-exec flag"));
close(logfd);
return -1;
}
} else {
conn->uri = xmlParseURI(uid ? "uml:///session" : "uml:///system");
if (!conn->uri) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,NULL);
+ virReportOOMError(conn);
return VIR_DRV_OPEN_ERROR;
}
}
umlDriverLock(driver);
if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL)
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
- "%s", _("failed to allocate space for capabilities support"));
+ virReportOOMError(conn);
umlDriverUnlock(driver);
return xml;
result = virGetHostname();
if (result == NULL) {
- umlReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot lookup hostname"));
return NULL;
}
/* Caller frees this string. */
}
if (!(type = strdup(vm->def->os.type)))
- umlReportError(dom->conn, dom, NULL, VIR_ERR_NO_MEMORY,
- "%s", _("failed to allocate space for ostype"));
+ virReportOOMError(dom->conn);
cleanup:
if (vm)
virDomainObjLock(driver->domains.objs[i]);
if (!virDomainIsActive(driver->domains.objs[i])) {
if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) {
- umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
- "%s", _("failed to allocate space for VM name string"));
+ virReportOOMError(conn);
virDomainObjUnlock(driver->domains.objs[i]);
goto cleanup;
}
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot create autostart directory %s: %s"),
- driver->autostartDir, strerror(err));
+ virReportSystemError(dom->conn, err,
+ _("cannot create autostart directory %s"),
+ driver->autostartDir);
goto cleanup;
}
if (symlink(configFile, autostartLink) < 0) {
- umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to create symlink '%s to '%s': %s"),
- autostartLink, configFile, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("Failed to create symlink '%s to '%s'"),
+ autostartLink, configFile);
goto cleanup;
}
} else {
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to delete symlink '%s': %s"),
- autostartLink, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("Failed to delete symlink '%s'"),
+ autostartLink);
goto cleanup;
}
}
/* The path is correct, now try to open it and get its size. */
fd = open (path, O_RDONLY);
if (fd == -1) {
- umlReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError(dom->conn, errno,
+ _("cannot open %s"), path);
goto cleanup;
}
*/
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
saferead (fd, buffer, size) == (ssize_t) -1) {
- umlReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError(dom->conn, errno,
+ _("cannot read %s"), path);
goto cleanup;
}
#define virLog(msg...) fprintf(stderr, msg)
+#define VIR_FROM_THIS VIR_FROM_NONE
#define ReportError(conn, code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
*/
sigfillset(&newmask);
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot block signals: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot block signals"));
return -1;
}
if ((null = open("/dev/null", O_RDONLY)) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot open %s: %s"),
- "/dev/null", strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot open %s"),
+ "/dev/null");
goto cleanup;
}
if (outfd != NULL) {
if (*outfd == -1) {
if (pipe(pipeout) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create pipe: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot create pipe"));
goto cleanup;
}
if ((flags & VIR_EXEC_NONBLOCK) &&
virSetNonBlock(pipeout[0]) == -1) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to set non-blocking file descriptor flag"));
+ virReportSystemError(conn, errno,
+ "%s", _("Failed to set non-blocking file descriptor flag"));
goto cleanup;
}
if (virSetCloseExec(pipeout[0]) == -1) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to set close-on-exec file descriptor flag"));
+ virReportSystemError(conn, errno,
+ "%s", _("Failed to set close-on-exec file descriptor flag"));
goto cleanup;
}
if (errfd != NULL) {
if (*errfd == -1) {
if (pipe(pipeerr) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to create pipe: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("Failed to create pipe"));
goto cleanup;
}
if ((flags & VIR_EXEC_NONBLOCK) &&
virSetNonBlock(pipeerr[0]) == -1) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to set non-blocking file descriptor flag"));
+ virReportSystemError(conn, errno,
+ "%s", _("Failed to set non-blocking file descriptor flag"));
goto cleanup;
}
if (virSetCloseExec(pipeerr[0]) == -1) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to set close-on-exec file descriptor flag"));
+ virReportSystemError(conn, errno,
+ "%s", _("Failed to set close-on-exec file descriptor flag"));
goto cleanup;
}
}
if ((pid = fork()) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot fork child process: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot fork child process"));
goto cleanup;
}
/* Restore our original signal mask now child is safely
running */
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot unblock signals: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot unblock signals"));
return -1;
}
and don't want to propagate that to children */
sigemptyset(&newmask);
if (pthread_sigmask(SIG_SETMASK, &newmask, NULL) != 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot unblock signals: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot unblock signals"));
return -1;
}
if (flags & VIR_EXEC_DAEMON) {
if (setsid() < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot become session leader: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot become session leader"));
_exit(1);
}
if (chdir("/") < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot change to root directory: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot change to root directory: %s"));
_exit(1);
}
pid = fork();
if (pid < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot fork child process: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot fork child process"));
_exit(1);
}
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to setup stdin file handle: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("failed to setup stdin file handle"));
_exit(1);
}
if (childout > 0 &&
dup2(childout, STDOUT_FILENO) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to setup stdout file handle: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("failed to setup stdout file handle"));
_exit(1);
}
if (childerr > 0 &&
dup2(childerr, STDERR_FILENO) < 0) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to setup stderr file handle: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("failed to setup stderr file handle"));
_exit(1);
}
else
execvp(argv[0], (char **) argv);
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot execute binary '%s': %s"),
- argv[0], strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot execute binary %s"),
+ argv[0]);
_exit(1);
continue;
pollerr:
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("poll error: %s"), strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("poll error"));
goto error;
}
while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
errno == EINTR);
if (waitret == -1) {
- ReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot wait for '%s': %s"),
- argv[0], strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot wait for '%s'"),
+ argv[0]);
goto error;
}
if (status == NULL) {
errno = EINVAL;
if (WIFEXITED(exitstatus) && WEXITSTATUS(exitstatus) != 0) {
-
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("'%s' exited with non-zero status %d and "
"signal %d: %s"), argv_str,
#include "logging.h"
#include "memory.h"
#include "threads.h"
+#include "util.h"
virThreadLocal virLastErr;
void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
const char *filename ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED,
- long long linenr ATTRIBUTE_UNUSED,
+ size_t linenr ATTRIBUTE_UNUSED,
const char *fmt, ...)
{
va_list args;
virerr, errorMessage, NULL, -1, -1, virerr, errorMessage);
}
+
+
+void virReportSystemErrorFull(virConnectPtr conn,
+ int domcode,
+ int theerrno,
+ const char *filename ATTRIBUTE_UNUSED,
+ const char *funcname ATTRIBUTE_UNUSED,
+ size_t linenr ATTRIBUTE_UNUSED,
+ const char *fmt, ...)
+{
+ va_list args;
+ char errorMessage[1024];
+ char systemError[1024];
+ char *theerrnostr;
+ const char *virerr;
+ char *combined = NULL;
+
+#ifdef HAVE_STRERROR_R
+#ifdef __USE_GNU
+ /* Annoying linux specific API contract */
+ theerrnostr = strerror_r(theerrno, systemError, sizeof(systemError));
+#else
+ strerror_r(theerrno, systemError, sizeof(systemError));
+ theerrnostr = systemError;
+#endif
+#else
+ /* Mingw lacks strerror_r() and its strerror() is definitely not
+ * threadsafe, so safest option is to just print the raw errno
+ * value - we can at least reliably & safely look it up in the
+ * header files for debug purposes
+ */
+ snprintf(systemError, sizeof(systemError), "errno=%d", theerrno);
+ theerrnostr = systemError;
+#endif
+
+ if (fmt) {
+ va_start(args, fmt);
+ vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args);
+ va_end(args);
+ } else {
+ errorMessage[0] = '\0';
+ }
+
+ if (virAsprintf(&combined, "%s: %s", errorMessage, theerrnostr) < 0)
+ combined = theerrnostr; /* OOM, so lets just pass the strerror info as best effort */
+
+ virerr = virErrorMsg(VIR_ERR_SYSTEM_ERROR, (errorMessage[0] ? errorMessage : NULL));
+ virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR,
+ virerr, errorMessage, NULL, -1, -1, virerr, errorMessage);
+}
+
+
+void virReportOOMErrorFull(virConnectPtr conn,
+ int domcode,
+ const char *filename ATTRIBUTE_UNUSED,
+ const char *funcname ATTRIBUTE_UNUSED,
+ size_t linenr ATTRIBUTE_UNUSED)
+{
+ const char *virerr;
+
+ virerr = virErrorMsg(VIR_ERR_NO_MEMORY, NULL);
+ virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
+ virerr, NULL, NULL, -1, -1, virerr, NULL);
+}
void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
const char *filename ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED,
- long long linenr ATTRIBUTE_UNUSED,
+ size_t linenr ATTRIBUTE_UNUSED,
const char *fmt, ...)
ATTRIBUTE_FORMAT(printf, 7, 8);
+void virReportSystemErrorFull(virConnectPtr conn,
+ int domcode,
+ int theerrno,
+ const char *filename,
+ const char *funcname,
+ size_t linenr,
+ const char *fmt, ...)
+ ATTRIBUTE_FORMAT(printf, 7, 8);
+
+#define virReportSystemError(conn, theerrno, fmt,...) \
+ virReportSystemErrorFull((conn), \
+ VIR_FROM_THIS, \
+ (theerrno), \
+ __FILE__, __FUNCTION__, __LINE__, \
+ (fmt), __VA_ARGS__)
+
+void virReportOOMErrorFull(virConnectPtr conn,
+ int domcode,
+ const char *filename,
+ const char *funcname,
+ size_t linenr);
+
+#define virReportOOMError(conn) \
+ virReportOOMErrorFull((conn), VIR_FROM_THIS, \
+ __FILE__, __FUNCTION__, __LINE__)
+
void virSetGlobalError(void);
void virSetConnError(virConnectPtr conn);
#include "xm_internal.h" /* for xenXMDomainConfigParse */
+#define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY
+
#define virXenInotifyError(conn, code, fmt...) \
virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
}
/* populate initial list */
- if (!(dh = opendir(configDir))) {
- virXenInotifyError (NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", strerror(errno));
+ if (!(dh = opendir(configDir))) {
+ virReportSystemError(NULL, errno,
+ _("cannot open directory: %s"),
+ configDir);
return -1;
}
while ((ent = readdir(dh))) {
#include "capabilities.h"
#include "memory.h"
+#define VIR_FROM_THIS VIR_FROM_XEN
+
/*
* so far there is 2 versions of the structures usable for doing
* hypervisor calls.
cpuinfo = fopen ("/proc/cpuinfo", "r");
if (cpuinfo == NULL) {
if (errno != ENOENT) {
- virXenError (conn, VIR_ERR_SYSTEM_ERROR,
- "/proc/cpuinfo: %s", strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read file %s"),
+ "/proc/cpuinfo");
return NULL;
}
}
if (capabilities == NULL) {
if (errno != ENOENT) {
fclose(cpuinfo);
- virXenError (conn, VIR_ERR_SYSTEM_ERROR,
- "/sys/hypervisor/properties/capabilities: %s",
- strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read file %s"),
+ "/sys/hypervisor/properties/capabilities");
return NULL;
}
}
#include "util.h"
#include "memory.h"
+#define VIR_FROM_THIS VIR_FROM_XEN
+
static int
xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info);
static int
result = virGetHostname();
if (result == NULL) {
- xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot lookup hostname"));
return NULL;
}
/* Caller frees this string. */
/* required for cpumap_t */
#include <xen/dom0_ops.h>
+#define VIR_FROM_THIS VIR_FROM_XEND
+
#ifndef PROXY
/*
if (uri_in == NULL) {
r = gethostname (hostname, HOST_NAME_MAX+1);
if (r == -1) {
- virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
- _("gethostname failed: %s"), strerror (errno));
+ virReportSystemError(dconn, errno,
+ _("unable to resolve name %s"), hostname);
return -1;
}
*uri_out = strdup (hostname);
if (*uri_out == NULL) {
- virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
- _("failed to strdup hostname: %s"), strerror (errno));
+ virReportOOMError(dconn);
return -1;
}
}
/* The path is correct, now try to open it and get its size. */
fd = open (path, O_RDONLY);
if (fd == -1) {
- virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
- _("failed to open for reading: %s: %s"),
- path, strerror (errno));
+ virReportSystemError(domain->conn, errno,
+ _("failed to open for reading: %s"),
+ path);
goto cleanup;
}
*/
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
saferead (fd, buffer, size) == (ssize_t) -1) {
- virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
- _("failed to lseek or read from file: %s: %s"),
- path, strerror (errno));
+ virReportSystemError(domain->conn, errno,
+ _("failed to lseek or read from file: %s"),
+ path);
goto cleanup;
}
#include "memory.h"
#include "logging.h"
+#define VIR_FROM_THIS VIR_FROM_XENXM
#ifdef WITH_RHEL5_API
#define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 0
}
if (!(*value = strdup(val->str))) {
- xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
/* Get modified time */
if ((stat(filename, &st) < 0)) {
- xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot stat %s: %s"), filename, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot stat: %s"),
+ filename);
return -1;
}
} else { /* Completely new entry */
newborn = 1;
if (VIR_ALLOC(entry) < 0) {
- xenXMError (conn, VIR_ERR_NO_MEMORY, "%s", strerror(errno));
+ virReportOOMError(conn);
return -1;
}
memcpy(entry->filename, filename, PATH_MAX);
int ret = -1;
if (now == ((time_t)-1)) {
- xenXMError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
+ virReportSystemError(conn, errno,
+ "%s", _("cannot get time of day"));
return (-1);
}
/* Process the files in the config dir */
if (!(dh = opendir(configDir))) {
- xenXMError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
+ virReportSystemError(conn, errno,
+ _("cannot read directory %s"),
+ configDir);
return (-1);
}
return def;
no_memory:
- xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
/* fallthrough */
cleanup:
virDomainGraphicsDefFree(graphics);
}
if (virBufferError(&mapbuf)) {
- xenXMError(domain->conn, VIR_ERR_NO_MEMORY, "%s", _("allocate buffer"));
+ virReportOOMError(domain->conn);
return -1;
}
mapstr = virBufferContentAndReset(&mapbuf);
if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
- xenXMError(domain->conn, VIR_ERR_NO_MEMORY, "%s", _("allocate buffer"));
+ virReportOOMError(domain->conn);
goto cleanup;
}
if (virDomainCpuSetParse(domain->conn,
virBufferAddLit(&buf, ",w");
if (virBufferError(&buf)) {
- xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
return -1;
}
if (VIR_ALLOC(val) < 0) {
- xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
goto cleanup;
}
net->model);
if (VIR_ALLOC(val) < 0) {
- xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
goto cleanup;
}
return conf;
no_memory:
- xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(conn);
cleanup:
virConfFreeValue(diskVal);
goto error;
if (VIR_ALLOC(entry) < 0) {
- xenXMError(conn, VIR_ERR_NO_MEMORY, "%s", _("config"));
+ virReportOOMError(conn);
goto error;
}
case VIR_DOMAIN_DEVICE_DISK:
{
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
- xenXMError(domain->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(domain->conn);
goto cleanup;
}
def->disks[def->ndisks++] = dev->data.disk;
case VIR_DOMAIN_DEVICE_NET:
{
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
- xenXMError(domain->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(domain->conn);
goto cleanup;
}
def->nets[def->nnets++] = dev->data.net;
int ret = -1;
if (!linkname || !config) {
- xenXMError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(dom->conn);
goto cleanup;
}
*autostart = virFileLinkPointsTo(linkname, config);
if (*autostart < 0) {
- xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to check autostart link %s: %s"),
- linkname, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("cannot check link %s points to config %s"),
+ linkname, config);
goto cleanup;
}
int ret = -1;
if (!linkname || !config) {
- xenXMError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
+ virReportOOMError(dom->conn);
goto cleanup;
}
if (autostart) {
if (symlink(config, linkname) < 0 &&
errno != EEXIST) {
- xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to create link %s: %s"),
- linkname, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("failed to create link %s to %s"),
+ config, linkname);
goto cleanup;
}
} else {
if (unlink(linkname) < 0 &&
errno != ENOENT) {
- xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR,
- _("failed to remove link %s: %s"),
- linkname, strerror(errno));
+ virReportSystemError(dom->conn, errno,
+ _("failed to remove link %s"),
+ linkname);
goto cleanup;
}
}