RFD: Rework/extending functionality of mdev

Michael Conrad mconrad at intellitree.com
Thu Mar 12 23:05:01 UTC 2015


On 03/12/2015 04:32 PM, Harald Becker wrote:
> On 12.03.2015 19:38, Michael Conrad wrote:
>> On 3/12/2015 12:04 PM, Harald Becker wrote:
>>> but that one will only work when you either use the kernel hotplug
>>> helper mechanism, or the netlink approach. You drop out those who
>>> can't / doesn't want to use either.
>>
>> ...which I really do think could be answered in one paragraph :-) If the
>> netlink socket is the "right way" to solve the forkbomb problem that
>> happens with hotplug helpers, then why would anyone want to solve it the
>> wrong way?  I don't understand the need.

To clarify,
   1 - kernel-spawned hotplug helpers is the traditional way,
   2 - netlink socket daemon is the "right way to solve the forkbomb 
problem"
   3 - kernel-spawned fifo-writer, with fifo read by hotplug daemon is 
"solve it the wrong way".

> ohh, good question! ... ask Isaac! (answer in one paragraph?)

What I hear Isaac say is "leave #1 (traditional way) alone.  I want to 
keep using it".

I agree with him that it should stay.  But I would choose to use #2 if 
it were available.  I am asking the purpose of #3.

> Conclusion: As I accept different preferences, and I do not want to 
> force others more than possible, I tried to find a solution which 
> allows every required mechanism (with maximum code sharing), and let 
> the user chose which one to use. In addition BB has a config system 
> which allows to disable unwanted stuff, so you can opt out the hotplug 
> stuff when you like.

So I think your answer to my original question is "the fifo design is a 
way to have #1 and #2 without duplicating code".

In that case, I would offer this idea:

1.  Refactor mdev to look like this:  (pseudocode)

    mdev_main() {
      read_options();
      load_config();
      process_request(); // from environment variables
    }

2.  Add the following:

   mdev_main() {
     read_options();
     load_config();
     #ifdef FEATURE_MDEV_NETLINK
     if (option_netlink) {
       open_netlink_socket();
       while (recv(message)) {
         apply_env_from_message(message);
         process_request();
       }
     }
     else
     #endif
       process_request();
   }

3.  Then to support the ability to launch mdev connected to a netlink 
socket that already exists, and time out when not used,

   mdev_main() {
     read_options();
     load_config();
     #ifdef FEATURE_MDEV_NETLINK
     if (option_netlink) {
       if (!option_netlink_on_stdin) {
         close(0);
         open_netlink_socket();
       }
       while (select([0], timeout)) {
         if (recv(0, message)) {
           apply_env_from_message(message);
           process_request();
         }
       }
     }
     else
     #endif
       process_request();
   }


I think this will be even smaller than what you propose with the fifo.  
It will do netlink, it will do the traditional hotplug helper, and even 
allow the trick where a tiny daemon monitors netlink and can start mdev 
in daemon mode on demand.

-Mike


More information about the busybox mailing list