Bug 429

Summary: mdev passes incorrect $MDEV if rename is in effect
Product: Busybox Reporter: Michael Tokarev <mjt+busybox>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: 1.14.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Bug Depends on: 431    
Bug Blocks:    
Attachments: Fix

Description Michael Tokarev 2009-07-02 09:05:15 UTC
When *both* external script and node rename operations are specified in mdev.conf, mdev should set $MDEV to point to new name of the node when running a script, not an old, removed one.
Comment 1 Denys Vlasenko 2009-07-02 11:06:11 UTC
Fixing it like this:


const char *node_name;

node_name = device_name;
if (ENABLE_FEATURE_MDEV_RENAME && alias)
        node_name = alias = build_alias(alias, device_name);

if (!delete && major >= 0) {
        if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST)
                bb_perror_msg_and_die("mknod %s", node_name);
        if (major == root_major && minor == root_minor)
                symlink(node_name, "root");
        if (ENABLE_FEATURE_MDEV_CONF) {
                chmod(node_name, mode);
                chown(node_name, ugid.uid, ugid.gid);
        }
        if (ENABLE_FEATURE_MDEV_RENAME && alias) {
                if (aliaslink == '>')
                        symlink(node_name, device_name);
        }
}

if (ENABLE_FEATURE_MDEV_EXEC && command) {
        /* setenv will leak memory, use putenv/unsetenv/free */
        char *s = xasprintf("%s=%s", "MDEV", node_name);
-->        the main part of the fix is here  ^^^^^^^^^
        char *s1 = xasprintf("%s=%s", "SUBSYSTEM", subsystem);
        putenv(s);
        putenv(s1);
        if (system(command) == -1)
                bb_perror_msg_and_die("can't run '%s'", command);
        unsetenv("SUBSYSTEM");
        free(s1);
        unsetenv("MDEV");
        free(s);
        free(command);
}

if (delete) {
        if (ENABLE_FEATURE_MDEV_RENAME && alias) {
                if (aliaslink == '>')
                        unlink(device_name);
        }
        unlink(node_name);
}

if (ENABLE_FEATURE_MDEV_RENAME)
        free(alias);
Comment 2 Denys Vlasenko 2009-07-02 11:06:45 UTC
Created attachment 431 [details]
Fix
Comment 3 Michael Tokarev 2009-07-02 11:45:53 UTC
(In reply to comment #1)
> Fixing it like this:
...

The dreaded mdev ;)  It is receiving too many changes, each quite significant (shuffles lines/changing identation etc).

(A side note, it's the ONLY alternative to much-more-dreaded udev, and this alternative is more or less sane, unlike it's counterpart).

So with the latest post-1.14 changes this is much easier and yes the fix seems to be working.  Thanks!