This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=bbb52d7a9a8061920414634af22d76b7f02466eb commit bbb52d7a9a8061920414634af22d76b7f02466eb Author: Guillem Jover <[email protected]> AuthorDate: Fri Mar 15 03:08:50 2019 +0100 libdpkg: Create the logfile with correct permissions We switch from fopen(3) to open(2) so that we get more control when opening the log file and can explicitly give the corrent mode to use. Remove the code from the postinst, as it should now be unnecessary. --- debian/changelog | 3 +++ debian/dpkg.postinst | 14 -------------- lib/dpkg/log.c | 29 ++++++++++++++++++----------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1f33193d0..b7524055d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -43,6 +43,9 @@ dpkg (1.20.0) UNRELEASED; urgency=medium * dpkg-split: Create the parts/ database directory on demand. * libdpkg: Consider msdbrw_needsuperuser equivalent to msdbrw_write, so the same checks are performed on normal non --force-not-root operation. + * libdpkg: Add support for bootstrapping the installation of dpkg: + - Create the logfile with correct permissions, and remove the code + setting up the logfile from the dpkg postinst. * Perl modules: - Dpkg::Source::Package: Verify original tarball signatures at build time. - Dpkg::BuildFlags: Add new unset() method. diff --git a/debian/dpkg.postinst b/debian/dpkg.postinst index 7b2582dda..78b0e3362 100755 --- a/debian/dpkg.postinst +++ b/debian/dpkg.postinst @@ -14,23 +14,9 @@ create_database() { done } - -# Create log file and set default permissions if possible -create_logfile() { - logfile=$DPKG_ROOT/var/log/dpkg.log - - if [ ! -f "$logfile" ]; then - touch "$logfile" - chmod 644 "$logfile" - chown root:root "$logfile" 2>/dev/null || chown 0:0 "$logfile" - fi -} - - case "$1" in configure) create_database - create_logfile ;; abort-upgrade|abort-deconfigure|abort-remove) diff --git a/lib/dpkg/log.c b/lib/dpkg/log.c index c2221c819..b428e31d9 100644 --- a/lib/dpkg/log.c +++ b/lib/dpkg/log.c @@ -21,11 +21,14 @@ #include <config.h> #include <compat.h> +#include <sys/types.h> +#include <sys/stat.h> + #include <errno.h> #include <time.h> +#include <fcntl.h> #include <unistd.h> #include <stdarg.h> -#include <stdio.h> #include <dpkg/i18n.h> #include <dpkg/dpkg.h> @@ -38,7 +41,7 @@ void log_message(const char *fmt, ...) { static struct varbuf log; - static FILE *logfd = NULL; + static int logfd = -1; char time_str[20]; time_t now; va_list args; @@ -46,27 +49,31 @@ log_message(const char *fmt, ...) if (!log_file) return; - if (!logfd) { - logfd = fopen(log_file, "a"); - if (!logfd) { + if (logfd < 0) { + logfd = open(log_file, O_CREAT | O_APPEND, 0644); + if (logfd < 0) { notice(_("could not open log '%s': %s"), log_file, strerror(errno)); log_file = NULL; return; } - setlinebuf(logfd); - setcloexec(fileno(logfd), log_file); + setcloexec(logfd, log_file); } + time(&now); + strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", + localtime(&now)); + va_start(args, fmt); varbuf_reset(&log); + varbuf_add_str(&log, time_str); + varbuf_add_char(&log, ' '); varbuf_vprintf(&log, fmt, args); + varbuf_add_char(&log, '\n'); + varbuf_end_str(&log); va_end(args); - time(&now); - strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", - localtime(&now)); - fprintf(logfd, "%s %s\n", time_str, log.buf); + fd_write(logfd, log.buf, log.size); } struct pipef { -- Dpkg.Org's dpkg

