Skip to content

Commit 692277f

Browse files
zippy2elmarco
authored andcommitted
chardev: Propagate error from logfile opening
If a chardev has a logfile the file is opened using qemu_open_old() which does the job, but since @errp is not propagated into qemu_open_internal() we lose much more accurate error and just report "Unable to open logfile $errno". When using plain files, it's probably okay as nothing complex is happening behind the curtains. But the problem becomes more prominent when passing an "/dev/fdset/XXX" path since much more needs to be done. The fix is to use qemu_create() which passes @errp further down. Signed-off-by: Michal Privoznik <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <f34ee80866e6f591bcb98401dee27682f5543fca.1629190206.git.mprivozn@redhat.com>
1 parent 2a2d51b commit 692277f

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

chardev/char.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,15 @@ static void qemu_char_open(Chardev *chr, ChardevBackend *backend,
241241
ChardevCommon *common = backend ? backend->u.null.data : NULL;
242242

243243
if (common && common->has_logfile) {
244-
int flags = O_WRONLY | O_CREAT;
244+
int flags = O_WRONLY;
245245
if (common->has_logappend &&
246246
common->logappend) {
247247
flags |= O_APPEND;
248248
} else {
249249
flags |= O_TRUNC;
250250
}
251-
chr->logfd = qemu_open_old(common->logfile, flags, 0666);
251+
chr->logfd = qemu_create(common->logfile, flags, 0666, errp);
252252
if (chr->logfd < 0) {
253-
error_setg_errno(errp, errno,
254-
"Unable to open logfile %s",
255-
common->logfile);
256253
return;
257254
}
258255
}

0 commit comments

Comments
 (0)