2907|0

3836

帖子

19

TA的资源

纯净的硅(中级)

楼主
 

X86学习之第一章开发板配置 [复制链接]

本帖最后由 paulhyde 于 2014-9-15 08:56 编辑

  1. 1.3 Advanced configuration
  2. Structure of the configuration files
  3. The config files are divided into sections and options/values.
  4. Every section has a type, but does not necessarily have a name. Every option has a name and a value and is assigned to the section it was written under.
  5. Syntax:
  6. config [""] # Section
  7. option "" # Option
  8. Every parameter needs to be a single string and is formatted exactly like a parameter for a shell function. The same rules for Quoting and special characters also apply, as it is parsed by the shell.
  9. Parsing configuration files in custom scripts
  10. To be able to load configuration files, you need to include the common functions with:
  11. . /etc/functions.sh
  12. Then you can use config_load to load config files. The function first checks for as absolute filename and falls back to loading it from /etc/config (which is the most common way of using it).
  13. If you want to use special callbacks for sections and/or options, you need to define the following shell functions before running config_load (after including /etc/functions.sh):
  14. config_cb() {
  15. local type="$1"
  16. local name="$2"
  17. # commands to be run for every section
  18. }
  19. option_cb() {
  20. # commands to be run for every option
  21. }
  22. You can also alter option_cb from config_cb based on the section type. This allows you to process every single config section based on its type individually.
  23. config_cb is run every time a new section starts (before options are being processed). You can access the last section through the CONFIG_SECTION variable. Also an extra call to config_cb (without a new section) is generated after config_load is done. That allows you to process sections both before and after all options were processed.
  24. Another way of iterating on config sections is using the config_foreach command.
  25. Syntax:
  26. config_foreach name> [] []
  27. This command will run the supplied function for every single config section in the currently loaded config. The section name will be passed to the function as argument 1. If the section type is added to the command line, the function will only be called for sections of the given type.
  28. You can access already processed options with the config_get command Syntax:
  29. # print the value of the option
  30. config_get
  31. # store the value inside the variable
  32. config_get
  33. In busybox ash the three-option config_get is faster, because it does not result in an extra fork, so it is the preferred way.
  34. Additionally you can also modify or add options to sections by using the config_set command.
  35. Syntax:
  36. config_set
  37. If a config section is unnamed, an automatically generated name will be assigned internally, e.g. cfg1, cfg2, ...
  38. While it is possible, using unnamed sections through these autogenerated names is strongly discouraged. Use callbacks or config_foreach instead.
  39. 1.3.1 Hotplug
  40. 1.3.2 Init scripts
  41. Because OpenWrt uses its own init script system, all init scripts must be installed as /etc/init.d/name use /etc/rc.common as a wrapper.
  42. Example: /etc/init.d/httpd
  43. #!/bin/sh /etc/rc.common
  44. # Copyright (C) 2006 OpenWrt.org
  45. START=50
  46. start() {
  47. [ -d /www ] && httpd -p 80 -h /www -r OpenWrt
  48. }
  49. stop() {
  50. killall httpd
  51. }
  52. as you can see, the script does not actually parse the command line arguments itself. This is done by the wrapper script /etc/rc.common.
  53. start() and stop() are the basic functions, which almost any init script should provide. start() is called when the user runs /etc/init.d/httpd start or (if the script is enabled and does not override this behavior) at system boot time.
  54. Enabling and disabling init scripts is done by running /etc/init.d/name enable or /etc/init.d/name disable. This creates or removes symbolic links to the init script in /etc/rc.d, which is processed by /etc/init.d/rcS at boot time.
  55. The order in which these scripts are run is defined in the variable START in the init script. Changing it requires running /etc/init.d/name enable again.
  56. You can also override these standard init script functions:
  57. * boot()
  58. Commands to be run at boot time. Defaults to start()
  59. * restart()
  60. Restart your service. Defaults to stop(); start()
  61. * reload()
  62. Reload the configuration files for your service. Defaults to restart()
  63. You can also add custom commands by creating the appropriate functions and referencing them in the EXTRA_COMMANDS variable. Helptext is added in EXTRA_HELP.
  64. Example:
  65. status() {
  66. # print the status info
  67. }
  68. EXTRA_COMMANDS="status"
  69. EXTRA_HELP=" status Print the status of the service"
复制代码
by 南京老练

 

此帖出自电子竞赛论坛
点赞 关注
 
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表