~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to src/libsystemd-bus/bus-bloom.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Michael Biebl, Michael Stapelberg, Daniel Schaal, Ondrej Balaz
  • Date: 2013-09-12 00:13:11 UTC
  • mfrom: (1.1.11) (9.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: package-import@ubuntu.com-20130912001311-dz35it34wr2lbday
Tags: 204-3
[ Michael Biebl ]
* Upload to unstable.
* Use /bin/bash in debug-shell.service as Debian doesn't have /sbin/sushell.
* Only import net.ifaces cmdline property for network devices.
* Generate strict dependencies between the binary packages using a
  shlibs.local file and add an explicit versioned dependency on
  libsystemd-login0 to systemd to ensure packages are upgraded in sync.
  Closes: #719444
* Drop obsolete Replaces: libudev0 from udev package.
* Use correct paths for various binaries, like /sbin/quotaon, which are
  installed in / and not /usr in Debian.  Closes: #721347
* Don't install kernel-install(8) man page since we don't install the
  corresponding binary either.  Closes: #722180
* Cherry-pick upstream fixes to make switching runlevels and starting
  reboot via ctrl-alt-del more robust.
* Cherry-pick upstream fix to properly apply ACLs to Journal files.

[ Michael Stapelberg ]
* Make systemctl enable|disable call update-rc.d for SysV init scripts.
  Closes: #709780
* Don't mount /tmp as tmpfs by default and make it possible to enable this
  feature via "systemctl enable tmp.mount".

[ Daniel Schaal ]
* Add bug-script to systemd and udev.  Closes: #711245

[ Ondrej Balaz ]
* Recognize discard option in /etc/crypttab.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
 
2
 
 
3
/***
 
4
  This file is part of systemd.
 
5
 
 
6
  Copyright 2013 Lennart Poettering
 
7
 
 
8
  systemd is free software; you can redistribute it and/or modify it
 
9
  under the terms of the GNU Lesser General Public License as published by
 
10
  the Free Software Foundation; either version 2.1 of the License, or
 
11
  (at your option) any later version.
 
12
 
 
13
  systemd is distributed in the hope that it will be useful, but
 
14
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
16
  Lesser General Public License for more details.
 
17
 
 
18
  You should have received a copy of the GNU Lesser General Public License
 
19
  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
20
***/
 
21
 
 
22
#include "util.h"
 
23
#include "MurmurHash3.h"
 
24
 
 
25
#include "bus-bloom.h"
 
26
 
 
27
static inline void set_bit(uint64_t filter[], unsigned b) {
 
28
        filter[b >> 6] |= 1ULL << (b & 63);
 
29
}
 
30
 
 
31
void bloom_add_data(uint64_t filter[BLOOM_SIZE/8], const void *data, size_t n) {
 
32
        uint16_t hash[8];
 
33
        unsigned k = 0;
 
34
 
 
35
        /*
 
36
         * Our bloom filter has the following parameters:
 
37
         *
 
38
         * m=512   (bits in the filter)
 
39
         * k=8     (hash functions)
 
40
         *
 
41
         * We calculate a single 128bit MurmurHash value of which we
 
42
         * use 8 parts of 9 bits as individual hash functions.
 
43
         *
 
44
         */
 
45
 
 
46
        MurmurHash3_x64_128(data, n, 0, hash);
 
47
 
 
48
        assert_cc(BLOOM_SIZE*8 == 512);
 
49
 
 
50
        for (k = 0; k < ELEMENTSOF(hash); k++)
 
51
                set_bit(filter, hash[k] & 511);
 
52
}
 
53
 
 
54
void bloom_add_pair(uint64_t filter[BLOOM_SIZE/8], const char *a, const char *b) {
 
55
        size_t n;
 
56
        char *c;
 
57
 
 
58
        assert(filter);
 
59
        assert(a);
 
60
        assert(b);
 
61
 
 
62
        n = strlen(a) + 1 + strlen(b);
 
63
        c = alloca(n + 1);
 
64
        strcpy(stpcpy(stpcpy(c, a), ":"), b);
 
65
 
 
66
        bloom_add_data(filter, c, n);
 
67
}
 
68
 
 
69
void bloom_add_prefixes(uint64_t filter[BLOOM_SIZE/8], const char *a, const char *b, char sep) {
 
70
        size_t n;
 
71
        char *c, *p;
 
72
 
 
73
        assert(filter);
 
74
        assert(a);
 
75
        assert(b);
 
76
 
 
77
        n = strlen(a) + 1 + strlen(b);
 
78
        c = alloca(n + 1);
 
79
 
 
80
        p = stpcpy(stpcpy(c, a), ":");
 
81
        strcpy(p, b);
 
82
 
 
83
        for (;;) {
 
84
                char *e;
 
85
 
 
86
                e = strrchr(p, sep);
 
87
                if (!e || e == p)
 
88
                        break;
 
89
 
 
90
                *e = 0;
 
91
                bloom_add_data(filter, c, e - c);
 
92
        }
 
93
}