diff --git a/ChangeLog b/ChangeLog index a71c9c5cec..853b46d52e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Jan 11 12:18:38 CET 2009 Guido Günther + + * src/qemu_driver.c (qemudLogFD): use snprintf instead of emulating it + Sun Jan 11 12:16:44 CET 2009 Guido Günther split out opening of the qemu logfile diff --git a/src/qemu_driver.c b/src/qemu_driver.c index d4c56d6780..f5168e1eaa 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -149,24 +149,16 @@ qemudLogFD(virConnectPtr conn, const char* logDir, const char* name) char logfile[PATH_MAX]; mode_t logmode; uid_t uid = geteuid(); - int fd = -1; + int ret, fd = -1; - if ((strlen(logDir) + /* path */ - 1 + /* Separator */ - strlen(name) + /* basename */ - 4 + /* suffix .log */ - 1 /* NULL */) > PATH_MAX) { + if ((ret = snprintf(logfile, sizeof(logfile), "%s/%s.log", logDir, name)) + < 0 || ret >= sizeof(logfile)) { qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, - _("config file path too long: %s/%s.log"), + _("failed to build logfile name %s/%s.log"), logDir, name); return -1; } - strcpy(logfile, logDir); - strcat(logfile, "/"); - strcat(logfile, name); - strcat(logfile, ".log"); - logmode = O_CREAT | O_WRONLY; if (uid != 0) logmode |= O_TRUNC;