diff options
author | Lukas Nykryn <lnykryn@redhat.com> | 2020-07-02 13:56:10 +0200 |
---|---|---|
committer | Jan Macku <jamacku@redhat.com> | 2022-01-14 14:01:34 +0100 |
commit | 43a42228eda6b0e05ca1d4c795d106a708d8749b (patch) | |
tree | 5c860523c535d662ba5fdfc791e4d788285d9dc4 /src/rename_device.c | |
parent | 33d3b47bdf31afafcb805a312cd498570d77f913 (diff) | |
download | initscripts-43a42228eda6b0e05ca1d4c795d106a708d8749b.tar initscripts-43a42228eda6b0e05ca1d4c795d106a708d8749b.tar.gz initscripts-43a42228eda6b0e05ca1d4c795d106a708d8749b.tar.bz2 initscripts-43a42228eda6b0e05ca1d4c795d106a708d8749b.tar.xz initscripts-43a42228eda6b0e05ca1d4c795d106a708d8749b.zip |
rename_device: also support dracut-style kernel cmdline configuration
There are 2 cases where this might be useful.
* On machines with initrd build without dracut-network, you can now
still use ifname option
* On older kernels where double renaming was allowed, normal system
replaced the name set by initrd.
(cherry picked from commit 55cdbccad3f6492b1e721154a45e5884044db76d)
Resolves: #1851503
Diffstat (limited to 'src/rename_device.c')
-rw-r--r-- | src/rename_device.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/rename_device.c b/src/rename_device.c index c39f447d..b67a536b 100644 --- a/src/rename_device.c +++ b/src/rename_device.c @@ -278,6 +278,46 @@ char *get_config_by_hwaddr(char *hwaddr, char *current) { return first; } +/* Let's check kernel cmdline and also process ifname= entries + * as they are documented in dracut.cmdline(7) + * Example: ifname=test:aa:bb:cc:dd:ee:ff + */ +char *get_cmdline_by_hwaddr(char *hwaddr) { + gchar *contents; + gchar **entries; + int i; + char *name = NULL; + g_file_get_contents("/proc/cmdline", &contents, NULL, NULL); + entries = g_strsplit(contents," ", 0); + for (i = 0; entries[i]; i++) { + char *c = (char *) entries[i]; + char *n; + + if (!g_str_has_prefix((gchar *)c,"ifname=")) + continue; + + c = strstr(c, "="); + if (c == NULL) + continue; + c++; + n=c; + + c = strstr(c, ":"); + if (c == NULL) + continue; + *c = '\0'; + c++; + + if (!strcasecmp(c, hwaddr)) { + name = strdup(n); + break; + } + } + g_free(contents); + g_strfreev(entries); + return name; +} + void take_lock() { int count = 0; int lockfd; @@ -343,7 +383,9 @@ int main(int argc, char **argv) { hw = get_hwaddr(src); if (!hw) goto out_unlock; - target = get_config_by_hwaddr(hw, src); + target = get_cmdline_by_hwaddr(hw); + if (!target) + target = get_config_by_hwaddr(hw, src); if (!target) goto out_unlock; |