]> err.no Git - systemd/commitdiff
unset variable with ENV{VAR}=""
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 24 Apr 2007 23:52:00 +0000 (01:52 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 24 Apr 2007 23:52:00 +0000 (01:52 +0200)
udev.h
udev_rules.c
udev_utils.c

diff --git a/udev.h b/udev.h
index 5bd0e301c6d2681782d158b8901cbf87f7145fae..6ef95133d57e7f33f8f1845ca2c19388d0a23d2b 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -137,6 +137,7 @@ struct name_entry {
 extern int log_priority(const char *priority);
 extern char *name_list_add(struct list_head *name_list, const char *name, int sort);
 extern char *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
+extern int name_list_key_remove(struct list_head *name_list, const char *key);
 extern void name_list_cleanup(struct list_head *name_list);
 extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
 extern uid_t lookup_user(const char *user);
index 6bd28ad4b7981a5ee136d38c6a80cd666b416fa6..61b39b45c80514b338b8113024d6c76f2af1b8dd 100644 (file)
@@ -831,18 +831,23 @@ try_parent:
                        char temp_value[NAME_SIZE];
                        const char *key_name = key_pair_name(rule, pair);
                        const char *value = key_val(rule, &pair->key);
-                       char *key_value;
 
                        /* make sure we don't write to the same string we possibly read from */
                        strlcpy(temp_value, value, sizeof(temp_value));
                        udev_rules_apply_format(udev, temp_value, NAME_SIZE);
 
-                       key_value = name_list_key_add(&udev->env_list, key_name, temp_value);
-                       if (key_value == NULL)
-                               break;
+                       if (temp_value[0] == '\0') {
+                               name_list_key_remove(&udev->env_list, key_name);
+                               unsetenv(key_name);
+                               info("unset ENV '%s'", key_name);
+                       } else {
+                               char *key_value = name_list_key_add(&udev->env_list, key_name, temp_value);
 
-                       putenv(key_value);
-                       dbg("export ENV '%s'", key_value);
+                               if (key_value == NULL)
+                                       break;
+                               putenv(key_value);
+                               info("set ENV '%s'", key_value);
+                       }
                }
        }
 
index e892012132eff8678c5a7fdd139a5a6356fc28ab..6d646b0ee6f1f51f4c0f0969d6da2f2b4b6dc5e5 100644 (file)
@@ -110,6 +110,26 @@ char *name_list_key_add(struct list_head *name_list, const char *key, const char
        return new_name->name;
 }
 
+int name_list_key_remove(struct list_head *name_list, const char *key)
+{
+       struct name_entry *name_loop;
+       struct name_entry *temp_loop;
+       size_t keylen = strlen(key);
+       int retval = 0;
+
+       list_for_each_entry_safe(name_loop, temp_loop, name_list, node) {
+               if (strncmp(name_loop->name, key, keylen) != 0)
+                       continue;
+               if (name_loop->name[keylen] != '=')
+                       continue;
+               list_del(&name_loop->node);
+               free(name_loop);
+               retval = 1;
+               break;
+       }
+       return retval;
+}
+
 void name_list_cleanup(struct list_head *name_list)
 {
        struct name_entry *name_loop;