[luci] How does LuCI hook into the back-end?

Jo-Philipp Wich xm at subsignal.org
Thu Jul 9 18:20:14 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Kunal.

> We are trying to port OpenWRT to our platform and need to modify some of
> the default LuCI functionality. Please forgive me if this post appears
> to sound "beginner"-ish, but I don't understand LuCi yet in its
> entirety, hence I need some help from the community.

No problem :)

> Question 1
> 
> Adding an entry to the "Mount Points" section of this page (as shown
> below in the screenshot) and then pressing "Save and Apply" causes the
> USB device to get mounted.
> 
> There is a "hook" that ties the press of "Save and apply" to the "mount"
> command in the back-end. Where is this hook exactly? Something is
> transferring control over to the "mount" command.

In the current implementation there is "mapping" defined in
/etc/config/ucitrack that links various configurations (in this case
/etc/config/fstab) to the appropriate init script (/etc/init.d/fstab).

Once LuCI detects that changes to a config are made, it uses this
mapping to determine which services (or init scripts) might be affected
and restarts them one-by-one.

So basicly the control is transferred from the Controller to the init
script which triggers the actual mount commands.

> The reason I ask is because we need to do the opposite (i.e. unmount)
> when the 'x' button next to a mount point entry is clicked on the UI.
> The entry gets removed from the UI, but our console shows that the
> device is still mounted. I want to add code to unmount the device when
> the entry is deleted, so I need to know the appropriate place to insert
> that "hook".

You need to do this in the init script then, by comparing the current
/proc/mtab against the state saved in uci (e.g. if it is mounted and
config says enabled = 0, then call umount, else call mount - if states
match, do nothing).

> Question 2
> 
> There seems to be a bug here: a) Unchecking the "enable" box under
> "Mount Points" (see screenshot of the Mount Points page, attached) and
> pressing "Save and Apply" does NOT pass validation and I see
> 
> Required option "fstab. at mount[1].enabled" has no value

Yes. This bug was addressed in changeset 4602, see here for a proper
solution: http://luci.subsignal.org/trac/changeset/4602 .

> However what this does is remove the checkbox, but the "back end"
> (validation code) still expects this value to be set? I want to disable
> this validation.

The message you see is caused by the implicit uci validation. The cbi
(config to form mapper) will validate an updated configuration against a
uci schema file if such a schema exists. You'll find the schemas in
/lib/uci/schema/default/ on the target.

You can, however, disable this implicit validation by assigning the
following attribute to the appropriate cbi section:

s = map:section(...)
s.override_scheme = true  -- Disable implicit uci validation

> The documentation states that the validation comes in the form:

Indeed, imho this needs clarification. This kind of validation descriped
there is for manual validation of fields, e.g. not using the implicit
uci schemas but check values through custom regular expressions or similar.



I hope this clarifies your questions, if you need further information,
feel free to ask here again.


Regards,
JoW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpWGLoACgkQdputYINPTPOZVwCfciY50egNYAbE4fHGblxdyvsT
UhAAn0/XzGVfEIdc2GlPC72YtbgupYuQ
=0zhe
-----END PGP SIGNATURE-----


More information about the luci mailing list