[libvirt] [PATCH 6/8] Pull code which finds a free MCS label out into its own method
Eric Blake
eblake at redhat.com
Fri Aug 10 21:02:24 UTC 2012
On 08/10/2012 07:48 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
>
> The code for picking a MCS label is about to get significantly
> more complicated, so it deserves to be in a standlone method,
> instead of a switch/case body.
>
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
> src/security/security_selinux.c | 75 ++++++++++++++++++++++++++---------------
> 1 file changed, 47 insertions(+), 28 deletions(-)
>
ACK.
> +
> +static char *
> +virSecuritySELinuxMCSFind(virSecurityManagerPtr mgr)
> +{
> + virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
> + int c1 = 0;
> + int c2 = 0;
> + char *mcs = NULL;
> +
> + for (;;) {
> + c1 = virRandomBits(10);
> + c2 = virRandomBits(10);
> +
> + if (c1 == c2) {
> + if (virAsprintf(&mcs, "s0:c%d", c1) < 0) {
> + virReportOOMError();
> + return NULL;
> + }
> + } else {
> + if (c1 > c2) {
> + c1 ^= c2;
> + c2 ^= c1;
> + c1 ^= c2;
I know this is just code motion, but is it really that hard to just
write the more straightforward:
int tmp = c1;
c1 = c2;
c2 = tmp;
which probably optimizes better in the compiler?
--
Eric Blake eblake at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120810/06aed2a1/attachment-0001.sig>
More information about the libvir-list
mailing list