From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RrATH-0001C8-Pa for garchives@archives.gentoo.org; Sat, 28 Jan 2012 15:45:44 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0CAECE0BBD; Sat, 28 Jan 2012 15:45:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id CE0E2E0BBD for ; Sat, 28 Jan 2012 15:45:35 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 26BC41B4022 for ; Sat, 28 Jan 2012 15:45:35 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 4EA3580044 for ; Sat, 28 Jan 2012 15:45:34 +0000 (UTC) From: "Christian Ruppert" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Christian Ruppert" Message-ID: <6be8a0679b8d64ea5b99ea98839eab2ce129988b.idl0r@gentoo> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/runscript.c X-VCS-Directories: src/rc/ X-VCS-Committer: idl0r X-VCS-Committer-Name: Christian Ruppert X-VCS-Revision: 6be8a0679b8d64ea5b99ea98839eab2ce129988b Date: Sat, 28 Jan 2012 15:45:34 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 6b4fca48-1c39-408b-8574-c9eab488b239 X-Archives-Hash: 1c70ee133b015e1cd142faa26c870028 commit: 6be8a0679b8d64ea5b99ea98839eab2ce129988b Author: Christian Ruppert gentoo org> AuthorDate: Sat Jan 28 15:40:49 2012 +0000 Commit: Christian Ruppert gentoo org> CommitDate: Sat Jan 28 15:43:54 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/openrc.git;a=3D= commit;h=3D6be8a067 Do not loop flock() There's no need to loop until flock was successfully as flock() would sim= ply block till a previous lock has been released. There's more to do to fix it properly, see my comments in the patch. Reported-by: James Le Cuirot aura-online.co.uk> X-Gentoo-Bug: 360013 X-Gentoo-Bug-URL: https://bugs.gentoo.org/360013 --- src/rc/runscript.c | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/rc/runscript.c b/src/rc/runscript.c index 8e0ced9..b0d8084 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -288,6 +288,13 @@ cleanup(void) #endif } =20 +/* Buffer and lock all output messages so that we get readable content *= / +/* FIXME: Use a dynamic lock file that contains the tty/pts as well. + * For example openrc-pts8.lock or openrc-tty1.lock. + * Using a static lock file makes no sense, esp. in multi-user environme= nts. + * Why don't we use (f)printf, as it is thread-safe through POSIX alread= y? + * Bug: 360013 + */ static int write_prefix(const char *buffer, size_t bytes, bool *prefixed) { @@ -297,14 +304,20 @@ write_prefix(const char *buffer, size_t bytes, bool= *prefixed) ssize_t ret =3D 0; int fd =3D fileno(stdout), lock_fd =3D -1; =20 - /* Spin until we lock the prefix */ - for (;;) { - lock_fd =3D open(PREFIX_LOCK, O_WRONLY | O_CREAT, 0664); - if (lock_fd !=3D -1) - if (flock(lock_fd, LOCK_EX) =3D=3D 0) - break; - close(lock_fd); + /* + * Lock the prefix. + * open() may fail here when running as user, as RC_SVCDIR may not be w= ritable. + */ + lock_fd =3D open(PREFIX_LOCK, O_WRONLY | O_CREAT, 0664); + + if (lock_fd !=3D -1) { + if (flock(lock_fd, LOCK_EX) !=3D 0) + eerror("flock() failed: %s", strerror(errno)); } +#ifdef RC_DEBUG + else + ewarn("Couldn't open the prefix lock, please make sure you have enough= permissions"); +#endif =20 for (i =3D 0; i < bytes; i++) { /* We don't prefix eend calls (cursor up) */ @@ -332,6 +345,7 @@ write_prefix(const char *buffer, size_t bytes, bool *= prefixed) =20 /* Release the lock */ close(lock_fd); + return ret; } =20