]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a path
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Feb 2018 17:58:35 +0000 (18:58 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 12 Feb 2018 10:07:55 +0000 (11:07 +0100)
Let's make use of our new hash_ops!

13 files changed:
src/basic/mount-util.c
src/cgtop/cgtop.c
src/core/device.c
src/core/manager.c
src/core/mount.c
src/core/swap.c
src/core/unit.c
src/journal/sd-journal.c
src/login/logind-acl.c
src/shared/bus-unit-util.c
src/shared/install.c
src/sysctl/sysctl.c
src/tmpfiles/tmpfiles.c

index a8947cefc2ed07cc2fdb531491b0fff25b0a46ae..b1243456597fb8efaeb26341c84f462e80a70232 100644 (file)
@@ -426,7 +426,7 @@ int bind_remount_recursive_with_mountinfo(const char *prefix, bool ro, char **bl
 
         path_kill_slashes(cleaned);
 
-        done = set_new(&string_hash_ops);
+        done = set_new(&path_hash_ops);
         if (!done)
                 return -ENOMEM;
 
@@ -436,7 +436,7 @@ int bind_remount_recursive_with_mountinfo(const char *prefix, bool ro, char **bl
                 char *x;
                 unsigned long orig_flags;
 
-                todo = set_new(&string_hash_ops);
+                todo = set_new(&path_hash_ops);
                 if (!todo)
                         return -ENOMEM;
 
index 1a73fb099df875375a5bc972eee915acfd9214ce..413946182c7dca980dba177caf50022dbbde7620 100644 (file)
@@ -928,8 +928,8 @@ int main(int argc, char *argv[]) {
         } else
                 log_debug("Cgroup path: %s", root);
 
-        a = hashmap_new(&string_hash_ops);
-        b = hashmap_new(&string_hash_ops);
+        a = hashmap_new(&path_hash_ops);
+        b = hashmap_new(&path_hash_ops);
         if (!a || !b) {
                 r = log_oom();
                 goto finish;
index a43664d3bd7ec2ae0055157855a07dce5b574351..b0dd469fd14b8eb9abc5165f7874897a95672cc5 100644 (file)
@@ -77,7 +77,7 @@ static int device_set_sysfs(Device *d, const char *sysfs) {
         if (streq_ptr(d->sysfs, sysfs))
                 return 0;
 
-        r = hashmap_ensure_allocated(&UNIT(d)->manager->devices_by_sysfs, &string_hash_ops);
+        r = hashmap_ensure_allocated(&UNIT(d)->manager->devices_by_sysfs, &path_hash_ops);
         if (r < 0)
                 return r;
 
index 5021e00b870e4ababc3f569bc1bebec91452facd..f57a08cd067ac9ad0532068e526ffbbd59874259 100644 (file)
@@ -731,7 +731,7 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) {
         if (r < 0)
                 goto fail;
 
-        r = hashmap_ensure_allocated(&m->cgroup_unit, &string_hash_ops);
+        r = hashmap_ensure_allocated(&m->cgroup_unit, &path_hash_ops);
         if (r < 0)
                 goto fail;
 
@@ -1314,7 +1314,7 @@ static void manager_build_unit_path_cache(Manager *m) {
 
         set_free_free(m->unit_path_cache);
 
-        m->unit_path_cache = set_new(&string_hash_ops);
+        m->unit_path_cache = set_new(&path_hash_ops);
         if (!m->unit_path_cache) {
                 r = -ENOMEM;
                 goto fail;
index 914458f8e6d99e253967cdd7897a614b37583b4c..7be4e89a61486031a6a077c42be3dad03ae70d2b 100644 (file)
@@ -1837,7 +1837,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
                             mount->parameters_proc_self_mountinfo.what) {
 
                                 /* Remember that this device might just have disappeared */
-                                if (set_ensure_allocated(&gone, &string_hash_ops) < 0 ||
+                                if (set_ensure_allocated(&gone, &path_hash_ops) < 0 ||
                                     set_put(gone, mount->parameters_proc_self_mountinfo.what) < 0)
                                         log_oom(); /* we don't care too much about OOM here... */
                         }
@@ -1892,7 +1892,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
                     mount->from_proc_self_mountinfo &&
                     mount->parameters_proc_self_mountinfo.what) {
 
-                        if (set_ensure_allocated(&around, &string_hash_ops) < 0 ||
+                        if (set_ensure_allocated(&around, &path_hash_ops) < 0 ||
                             set_put(around, mount->parameters_proc_self_mountinfo.what) < 0)
                                 log_oom();
                 }
index fffd8d4627b1bb372c18bf184c0f1f6fc1f96d08..37c97bc14e119a34b79f0b6021bba654e266e89d 100644 (file)
@@ -85,7 +85,7 @@ static int swap_set_devnode(Swap *s, const char *devnode) {
 
         assert(s);
 
-        r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, &string_hash_ops);
+        r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, &path_hash_ops);
         if (r < 0)
                 return r;
 
index 9a57bcfb4b36d3521e2cdf0be4c704ffc7a04b71..32119171feab802ddcd988730fe32e2e379f243d 100644 (file)
@@ -4594,7 +4594,7 @@ int unit_require_mounts_for(Unit *u, const char *path, UnitDependencyMask mask)
         if (!path_is_absolute(path))
                 return -EINVAL;
 
-        r = hashmap_ensure_allocated(&u->requires_mounts_for, &string_hash_ops);
+        r = hashmap_ensure_allocated(&u->requires_mounts_for, &path_hash_ops);
         if (r < 0)
                 return r;
 
@@ -4631,7 +4631,7 @@ int unit_require_mounts_for(Unit *u, const char *path, UnitDependencyMask mask)
                 if (!x) {
                         char *q;
 
-                        r = hashmap_ensure_allocated(&u->manager->units_requiring_mounts_for, &string_hash_ops);
+                        r = hashmap_ensure_allocated(&u->manager->units_requiring_mounts_for, &path_hash_ops);
                         if (r < 0)
                                 return r;
 
index 46e2b47344b2eceaafe04cdeeaa073a6a40490ba..4df0abe32922baccee1ea360b5b8a6d947b12dd3 100644 (file)
@@ -1733,12 +1733,12 @@ static sd_journal *journal_new(int flags, const char *path) {
                         j->path = t;
         }
 
-        j->files = ordered_hashmap_new(&string_hash_ops);
+        j->files = ordered_hashmap_new(&path_hash_ops);
         if (!j->files)
                 goto fail;
 
         j->files_cache = ordered_hashmap_iterated_cache_new(j->files);
-        j->directories_by_path = hashmap_new(&string_hash_ops);
+        j->directories_by_path = hashmap_new(&path_hash_ops);
         j->mmap = mmap_cache_new();
         if (!j->files_cache || !j->directories_by_path || !j->mmap)
                 goto fail;
index d785f67ca31021e0aaf12088b5ec710a938d45e9..3f355e7ea80213df53894da97c1ff3589e119f7b 100644 (file)
@@ -192,7 +192,7 @@ int devnode_acl_all(struct udev *udev,
 
         assert(udev);
 
-        nodes = set_new(&string_hash_ops);
+        nodes = set_new(&path_hash_ops);
         if (!nodes)
                 return -ENOMEM;
 
index bc77c3abdb9a3c2b170f5626aeb520cbd1751389..78b9b69557764d1894c17c9d1772d1b67c35a54c 100644 (file)
@@ -2369,7 +2369,7 @@ int unit_show_processes(
         if (r < 0)
                 return r;
 
-        cgroups = hashmap_new(&string_hash_ops);
+        cgroups = hashmap_new(&path_hash_ops);
         if (!cgroups)
                 return -ENOMEM;
 
index 026aa323028db3231992b152a68af74ba4888d18..fdce447c89e37a13a2ff47d2bb62bd7b787f74c1 100644 (file)
@@ -522,7 +522,7 @@ static int mark_symlink_for_removal(
 
         assert(p);
 
-        r = set_ensure_allocated(remove_symlinks_to, &string_hash_ops);
+        r = set_ensure_allocated(remove_symlinks_to, &path_hash_ops);
         if (r < 0)
                 return r;
 
index a1dc95b2bb2dec021ea98a7772fb6274a1987058..d97656d6fecece0b6d66d819acca6b81bfd0c9ed 100644 (file)
@@ -110,19 +110,19 @@ static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ign
                 _cleanup_free_ char *l = NULL;
                 void *v;
                 int k;
+
                 k = read_line(f, LONG_LINE_MAX, &l);
                 if (k == 0)
                         break;
-
                 if (k < 0)
                         return log_error_errno(k, "Failed to read file '%s', ignoring: %m", path);
 
                 c++;
 
                 p = strstrip(l);
-                if (!*p)
-                        continue;
 
+                if (isempty(p))
+                        continue;
                 if (strchr(COMMENTS "\n", *p))
                         continue;
 
@@ -261,7 +261,7 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        sysctl_options = ordered_hashmap_new(&string_hash_ops);
+        sysctl_options = ordered_hashmap_new(&path_hash_ops);
         if (!sysctl_options) {
                 r = log_oom();
                 goto finish;
index 29e66b0a87fdccdaefb0008ad16060f3c522e233..d887e9d148f54ced06425166b5ff2cc647548600 100644 (file)
@@ -383,9 +383,11 @@ static void load_unix_sockets(void) {
 
         /* We maintain a cache of the sockets we found in /proc/net/unix to speed things up a little. */
 
-        unix_sockets = set_new(&string_hash_ops);
-        if (!unix_sockets)
+        unix_sockets = set_new(&path_hash_ops);
+        if (!unix_sockets) {
+                log_oom();
                 return;
+        }
 
         f = fopen("/proc/net/unix", "re");
         if (!f) {