Remove lots of stack-allocated buffers.
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
int
libxlDriverConfigInit(libxlDriverConfigPtr cfg)
{
- char ebuf[1024];
unsigned int free_mem;
if (virFileMakePath(cfg->logDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create log dir '%s': %s"),
cfg->logDir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return -1;
}
{
libxlDriverConfigPtr cfg;
g_autofree char *driverConf = NULL;
- char ebuf[1024];
bool autostart = true;
if (root != NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create state dir '%s': %s"),
cfg->stateDir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto error;
}
if (virFileMakePath(cfg->libDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create lib dir '%s': %s"),
cfg->libDir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto error;
}
if (virFileMakePath(cfg->saveDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create save dir '%s': %s"),
cfg->saveDir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto error;
}
if (virFileMakePath(cfg->autoDumpDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create dump dir '%s': %s"),
cfg->autoDumpDir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto error;
}
if (virFileMakePath(cfg->channelDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create channel dir '%s': %s"),
cfg->channelDir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto error;
}
char timestamp[VIR_TIME_STRING_BUFLEN];
char *message = NULL;
char *start, *end;
- char ebuf[1024];
VIR_DEBUG("libvirt_vmessage: context='%s' format='%s'", context, format);
fprintf(logFile, "%s", message);
if (errnoval >= 0)
- fprintf(logFile, ": %s", virStrerror(errnoval, ebuf, sizeof(ebuf)));
+ fprintf(logFile, ": %s", g_strerror(errnoval));
fputc('\n', logFile);
fflush(logFile);
char *path = NULL;
FILE *logFile = NULL;
char *domidstr = NULL;
- char ebuf[1024];
path = g_strdup_printf("%s/%s.log", logger->logDir, name);
domidstr = g_strdup_printf("%d", id);
if (!(logFile = fopen(path, "a"))) {
VIR_WARN("Failed to open log file %s: %s",
- path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ path, g_strerror(errno));
goto cleanup;
}
ignore_value(virHashAddEntry(logger->files, domidstr, logFile));
old_umask = umask(077);
VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
if (virFileMakePath(run_dir) < 0) {
- char ebuf[1024];
VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
ret = VIR_LOCK_DAEMON_ERR_RUNDIR;
umask(old_umask);
goto cleanup;
};
if (godaemon) {
- char ebuf[1024];
-
if (chdir("/") < 0) {
VIR_ERROR(_("cannot change to root directory: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
if ((statuswrite = virLockDaemonForkIntoBackground(argv[0])) < 0) {
VIR_ERROR(_("Failed to fork as daemon: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
}
old_umask = umask(077);
VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
if (virFileMakePath(run_dir) < 0) {
- char ebuf[1024];
VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
ret = VIR_LOG_DAEMON_ERR_RUNDIR;
umask(old_umask);
goto cleanup;
};
if (godaemon) {
- char ebuf[1024];
-
if (chdir("/") < 0) {
VIR_ERROR(_("cannot change to root directory: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
if ((statuswrite = virLogDaemonForkIntoBackground(argv[0])) < 0) {
VIR_ERROR(_("Failed to fork as daemon: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
}
for (i = 0; i < nmounts; i++) {
VIR_DEBUG("Umount %s", mounts[i]);
if (umount(mounts[i]) < 0) {
- char ebuf[1024];
failedUmount = mounts[i];
saveErrno = errno;
VIR_WARN("Failed to unmount '%s', trying to detach subtree '%s': %s",
failedUmount, mounts[nmounts-1],
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
break;
}
}
lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg,
virDomainObjPtr vm)
{
- char ebuf[1024];
char *file = NULL;
file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_WARN("Failed to remove domain XML for %s: %s",
- vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+ vm->def->name, g_strerror(errno));
VIR_FREE(file);
}
if (safewrite(logfd, timestamp, strlen(timestamp)) < 0 ||
safewrite(logfd, START_POSTFIX, strlen(START_POSTFIX)) < 0) {
VIR_WARN("Unable to write timestamp to logfile: %s",
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
}
VIR_FREE(timestamp);
virCommandWriteArgLog(cmd, logfd);
if ((pos = lseek(logfd, 0, SEEK_END)) < 0)
VIR_WARN("Unable to seek to end of logfile: %s",
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
VIR_DEBUG("Launching container");
virCommandRawStatus(cmd);
if (errno == ESRCH) {
ret = 0;
} else {
- char ebuf[1024];
VIR_WARN("Failed to terminate %s process %d "
"for network '%s' with SIG%s: %s",
daemonName, pid, networkName, signame,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
}
return ret;
}
}
if (stat(qemuCaps->binary, &sb) < 0) {
- char ebuf[1024];
VIR_DEBUG("Failed to stat QEMU binary '%s': %s",
qemuCaps->binary,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return false;
}
} while (*tapfd < 0 && errno == EINTR);
if (*tapfd < 0) {
- char ebuf[1024];
char *errstr = NULL;
if (!(cmdstr = virCommandToString(cmd, false)))
virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s: failed to communicate with bridge helper: %s%s"),
- cmdstr, virStrerror(errno, ebuf, sizeof(ebuf)),
+ cmdstr, g_strerror(errno),
NULLSTR_EMPTY(errstr));
VIR_FREE(errstr);
goto cleanup;
qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
- char ebuf[1024];
g_autofree char *file = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_WARN("Failed to remove domain XML for %s: %s",
- vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+ vm->def->name, g_strerror(errno));
if (priv->pidfile &&
unlink(priv->pidfile) < 0 &&
errno != ENOENT)
VIR_WARN("Failed to remove PID file for %s: %s",
- vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+ vm->def->name, g_strerror(errno));
}
virDomainObjEndAPI(&proc->vm);
if (proc->pid != 0) {
- char ebuf[1024];
-
VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid);
if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH)
VIR_ERROR(_("Failed to kill process %lld: %s"),
(long long)proc->pid,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
proc->pid = 0;
}
VIR_FORCE_CLOSE(statuspipe[0]);
if (ret != 1) {
- char ebuf[1024];
-
fprintf(stderr,
_("%s: error: unable to determine if daemon is "
"running: %s\n"), argv0,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
exit(EXIT_FAILURE);
} else if (status != 0) {
fprintf(stderr,
NULLSTR(sock_file_adm));
if (godaemon) {
- char ebuf[1024];
-
if (chdir("/") < 0) {
VIR_ERROR(_("cannot change to root directory: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
if ((statuswrite = daemonForkIntoBackground(argv[0])) < 0) {
VIR_ERROR(_("Failed to fork as daemon: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
}
old_umask = umask(077);
VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
if (virFileMakePath(run_dir) < 0) {
- char ebuf[1024];
VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
ret = VIR_DAEMON_ERR_RUNDIR;
goto cleanup;
}
return;
for (i = 0; i < (*state)->nfds; i++) {
- char ebuf[1024];
const char *path = (*state)->paths[i];
int fd = (*state)->fds[i];
* happen on VIR_CLOSE() anyway. But let's play it nice. */
if (virFileUnlock(fd, METADATA_OFFSET, METADATA_LEN) < 0) {
VIR_WARN("Unable to unlock fd %d path %s: %s",
- fd, path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ fd, path, g_strerror(errno));
}
if (VIR_CLOSE(fd) < 0) {
VIR_WARN("Unable to close fd %d path %s: %s",
- fd, path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ fd, path, g_strerror(errno));
}
}
struct stat buf;
security_context_t fcon = NULL;
char *newpath = NULL;
- char ebuf[1024];
int rc;
int ret = -1;
if (virFileResolveLink(path, &newpath) < 0) {
VIR_WARN("cannot resolve symlink %s: %s", path,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
if (!recall || rc == -2) {
if (stat(newpath, &buf) != 0) {
VIR_WARN("cannot stat %s: %s", newpath,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
goto cleanup;
}
if (autostartLink && unlink(autostartLink) < 0 &&
errno != ENOENT && errno != ENOTDIR) {
- char ebuf[1024];
VIR_ERROR(_("Failed to delete autostart link '%s': %s"),
- autostartLink, virStrerror(errno, ebuf, sizeof(ebuf)));
+ autostartLink, g_strerror(errno));
}
event = virStoragePoolEventLifecycleNew(def->name,
VIR_WARN("Unknown audit record type %d", type);
else if (audit_log_user_message(auditfd, record_types[type], str, NULL,
clientaddr, clienttty, success) < 0) {
- char ebuf[1024];
VIR_WARN("Failed to send audit message %s: %s",
- NULLSTR(str), virStrerror(errno, ebuf, sizeof(ebuf)));
+ NULLSTR(str), g_strerror(errno));
}
}
#endif
}
if (ioError) {
- char ebuf[1024];
VIR_WARN("Unable to write command %s args to logfile: %s",
- cmd->args[0], virStrerror(ioError, ebuf, sizeof(ebuf)));
+ cmd->args[0], g_strerror(ioError));
}
}
if (!(flags & VIR_FILE_CLOSE_IGNORE_EBADF))
VIR_WARN("Tried to close invalid fd %d", *fdptr);
} else {
- char ebuf[1024] G_GNUC_UNUSED;
VIR_DEBUG("Failed to close fd %d: %s",
- *fdptr, virStrerror(errno, ebuf, sizeof(ebuf)));
+ *fdptr, g_strerror(errno));
}
} else {
VIR_DEBUG("Closed fd %d", *fdptr);
unsigned int version = 0;
if (virFileReadHeaderQuiet(CPUINFO_PATH, 4096, &outbuf) < 0) {
- char ebuf[1024];
VIR_DEBUG("Failed to read microcode version from %s: %s",
- CPUINFO_PATH, virStrerror(errno, ebuf, sizeof(ebuf)));
+ CPUINFO_PATH, g_strerror(errno));
return 0;
}
uint64_t *msr)
{
VIR_AUTOCLOSE fd = -1;
- char ebuf[1024];
*msr = 0;
if ((fd = open(MSR_DEVICE, O_RDONLY)) < 0) {
VIR_DEBUG("Unable to open %s: %s",
- MSR_DEVICE, virStrerror(errno, ebuf, sizeof(ebuf)));
+ MSR_DEVICE, g_strerror(errno));
} else {
int rc = pread(fd, msr, sizeof(*msr), index);
}
VIR_DEBUG("Cannot read MSR 0x%lx from %s: %s",
- index, MSR_DEVICE, virStrerror(errno, ebuf, sizeof(ebuf)));
+ index, MSR_DEVICE, g_strerror(errno));
}
VIR_DEBUG("Falling back to KVM ioctl");
} else {
if (unlink(res->path) < 0 &&
errno != ENOENT) {
- char ebuf[1024];
VIR_WARN("Failed to unlink resource %s: %s",
- res->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ res->path, g_strerror(errno));
}
}
} else {
if (unlink(res->path) < 0 &&
errno != ENOENT) {
- char ebuf[1024];
VIR_WARN("Failed to unlink resource %s: %s",
- res->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ res->path, g_strerror(errno));
}
}
}
* one that now exists on the filesystem
*/
if (stat(res->path, &a) < 0) {
- char ebuf[1024] G_GNUC_UNUSED;
VIR_DEBUG("Resource '%s' disappeared: %s",
- res->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ res->path, g_strerror(errno));
VIR_FORCE_CLOSE(res->fd);
/* Someone else must be racing with us, so try again */
continue;
_("Failed to open config space file '%s'"),
dev->path);
} else {
- char ebuf[1024];
VIR_WARN("Failed to open config space file '%s': %s",
- dev->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ dev->path, g_strerror(errno));
}
return -1;
}
virPCIDeviceConfigClose(virPCIDevicePtr dev, int cfgfd)
{
if (VIR_CLOSE(cfgfd) < 0) {
- char ebuf[1024];
VIR_WARN("Failed to close config space file '%s': %s",
- dev->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ dev->path, g_strerror(errno));
}
}
if (lseek(cfgfd, pos, SEEK_SET) != pos ||
saferead(cfgfd, buf, buflen) != buflen) {
- char ebuf[1024];
VIR_WARN("Failed to read from '%s' : %s", dev->path,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return -1;
}
return 0;
{
if (lseek(cfgfd, pos, SEEK_SET) != pos ||
safewrite(cfgfd, buf, buflen) != buflen) {
- char ebuf[1024];
VIR_WARN("Failed to write to '%s' : %s", dev->path,
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return -1;
}
return 0;
* one that now exists on the filesystem
*/
if (stat(path, &a) < 0) {
- char ebuf[1024] G_GNUC_UNUSED;
VIR_DEBUG("Pid file '%s' disappeared: %s",
- path, virStrerror(errno, ebuf, sizeof(ebuf)));
+ path, g_strerror(errno));
VIR_FORCE_CLOSE(fd);
/* Someone else must be racing with us, so try again */
continue;
cpid = clone(virProcessDummyChild, childStack, flags, NULL);
if (cpid < 0) {
- char ebuf[1024] G_GNUC_UNUSED;
VIR_DEBUG("clone call returned %s, container support is not enabled",
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return -1;
} else if (virProcessWait(cpid, NULL, false) < 0) {
return -1;
if (!pw) {
if (rc != 0 && !missing_ok) {
- char buf[1024];
/* log the possible error from getpwnam_r. Unfortunately error
* reporting from this function is bad and we can't really
* rely on it, so we just report that the user wasn't found */
VIR_WARN("User record for user '%s' was not found: %s",
- name, virStrerror(rc, buf, sizeof(buf)));
+ name, g_strerror(rc));
}
ret = 1;
if (!gr) {
if (rc != 0 && !missing_ok) {
- char buf[1024];
/* log the possible error from getgrnam_r. Unfortunately error
* reporting from this function is bad and we can't really
* rely on it, so we just report that the user wasn't found */
VIR_WARN("Group record for user '%s' was not found: %s",
- name, virStrerror(rc, buf, sizeof(buf)));
+ name, g_strerror(rc));
}
ret = 1;
{
#ifndef WIN32
struct termios rawattr = ctl->termattr;
- char ebuf[1024];
+
if (!ctl->istty) {
if (report_errors) {
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &rawattr) < 0) {
if (report_errors)
vshError(ctl, _("unable to set tty attributes: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return -1;
}
#endif
assert(ctl->eventPipe[0] >= 0);
while ((rv = read(ctl->eventPipe[0], &buf, 1)) < 0 && errno == EINTR);
if (rv != 1) {
- char ebuf[1024];
-
if (!rv)
errno = EPIPE;
vshError(ctl, _("failed to determine loop exit status: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
return -1;
}
return buf;
void
vshCloseLogFile(vshControl *ctl)
{
- char ebuf[1024];
-
/* log file close */
if (VIR_CLOSE(ctl->log_fd) < 0) {
vshError(ctl, _("%s: failed to write log file: %s"),
ctl->logfile ? ctl->logfile : "?",
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
}
if (ctl->logfile) {
char *ret;
const char *tmpdir;
int fd;
- char ebuf[1024];
tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp";
fd = g_mkstemp_full(ret, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR);
if (fd == -1) {
vshError(ctl, _("g_mkstemp_full: failed to create temporary file: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
+ g_strerror(errno));
VIR_FREE(ret);
return NULL;
}
if (safewrite(fd, doc, strlen(doc)) == -1) {
vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
- ret, virStrerror(errno, ebuf, sizeof(ebuf)));
+ ret, g_strerror(errno));
VIR_FORCE_CLOSE(fd);
unlink(ret);
VIR_FREE(ret);
}
if (VIR_CLOSE(fd) < 0) {
vshError(ctl, _("close: %s: failed to write or close temporary file: %s"),
- ret, virStrerror(errno, ebuf, sizeof(ebuf)));
+ ret, g_strerror(errno));
unlink(ret);
VIR_FREE(ret);
return NULL;
vshEditReadBackFile(vshControl *ctl, const char *filename)
{
char *ret;
- char ebuf[1024];
if (virFileReadAll(filename, VSH_MAX_XML_FILE, &ret) == -1) {
vshError(ctl,
_("%s: failed to read temporary file: %s"),
- filename, virStrerror(errno, ebuf, sizeof(ebuf)));
+ filename, g_strerror(errno));
return NULL;
}
return ret;
if (ctl->historyfile != NULL) {
if (virFileMakePathWithMode(ctl->historydir, 0755) < 0 &&
errno != EEXIST) {
- char ebuf[1024];
vshError(ctl, _("Failed to create '%s': %s"),
- ctl->historydir, virStrerror(errno, ebuf, sizeof(ebuf)));
+ ctl->historydir, g_strerror(errno));
} else {
write_history(ctl->historyfile);
}
{
const char *dir = NULL;
g_autofree char *dir_malloced = NULL;
- char ebuf[1024];
if (!ctl->imode) {
vshError(ctl, "%s", _("cd: command valid only in interactive mode"));
if (chdir(dir) == -1) {
vshError(ctl, _("cd: %s: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)), dir);
+ g_strerror(errno), dir);
return false;
}