On Sun, Apr 22, 2018 at 3:24 PM, Guus Sliepen <g...@debian.org> wrote: > On Fri, Apr 20, 2018 at 04:52:24PM -0400, Dan Streetman wrote: > >> Scripts in the if-pre-up.d and if-up.d dirs call ifquery directly, or call >> it indirectly >> through other scripts. However ifquery tries to lock each interface and >> exits with >> error if it's called from ifup or ifdown. Since ifquery doesn't change >> anything, >> there is no reason interface locks need to be taken; ifquery can be safely >> run >> recurseively from ifup/ifdown. > > You're right, it should be possible to run ifquery recursively. But it > should still ensure the interface is locked before querying it, to > ensure consistency. > >> In Ubuntu, the attached patch was applied to achieve the following: > > The patch avoids locking at all when no_act == true. Consider this: > > iface foo inet ... > pre-up ifquery --state bar > > iface bar inet ... > > Now if I call ifup foo and ifup bar at the same time, then the ifquery > might theoretically read a half-written /run/network/ifstate.bar.
Eh? ifquery --state doesn't use the ifstate.* files. It reads state from the global ifstate file. main() checks (state_query) and then calls do_state(argc, argv) to actually print out the current state of any/all specified interfaces (all if none specified). The do_state() function calls read_all_state() to actually get the state info of all interfaces. The read_all_state() function first locks the global .ifstate.lock file, then opens and reads the global /run/network/ifstate file (then closes both). It does not open or read any of the ifstate.* files. In fact ifquery --state returns do_state(), so it will never even reach the call to do_interface() that my patch adjusts. Am I misunderstanding your assertion? > Granted, the change of this is extremely small, and one could also > question whether it makes sense to run ifquery in this way at all, since > even if it did read a consistent /run/network/ifstate.bar, it could > either read the state as being up or down depending on whether ifup bar > finished before or after ifquery. But it's not hard to do it correctly, > so I'll make it so it only avoids locking if it detects recursion. > >> Thanks for considering the patch. > > Thanks for sending the patch :) > > -- > Met vriendelijke groet / with kind regards, > Guus Sliepen <g...@debian.org>