logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

systemd.lua (7804B)


  1. -- Copyright 2016-2024 Christian Hesse. See LICENSE.
  2. -- systemd unit file LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('systemd', {lex_by_line = true})
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  11. -- Boolean values.
  12. 'true', 'false', 'on', 'off', 'yes', 'no',
  13. -- Service types.
  14. 'forking', 'simple', 'oneshot', 'dbus', 'notify', 'idle',
  15. -- Special system units.
  16. 'basic.target', 'ctrl-alt-del.target', 'cryptsetup.target', 'dbus.service', 'dbus.socket',
  17. 'default.target', 'display-manager.service', 'emergency.target', 'exit.target', 'final.target',
  18. 'getty.target', 'graphical.target', 'hibernate.target', 'hybrid-sleep.target', 'halt.target',
  19. 'initrd-fs.target', 'kbrequest.target', 'kexec.target', 'local-fs.target', 'multi-user.target',
  20. 'network-online.target', 'paths.target', 'poweroff.target', 'reboot.target', 'remote-fs.target',
  21. 'rescue.target', 'initrd-root-fs.target', 'runlevel2.target', 'runlevel3.target',
  22. 'runlevel4.target', 'runlevel5.target', 'shutdown.target', 'sigpwr.target', 'sleep.target',
  23. 'slices.target', 'sockets.target', 'suspend.target', 'swap.target', 'sysinit.target',
  24. 'syslog.socket', 'system-update.target', 'timers.target', 'umount.target',
  25. -- Special system units for devices.
  26. 'bluetooth.target', 'printer.target', 'smartcard.target', 'sound.target',
  27. -- Special passive system units.
  28. 'cryptsetup-pre.target', 'local-fs-pre.target', 'network.target', 'network-pre.target',
  29. 'nss-lookup.target', 'nss-user-lookup.target', 'remote-fs-pre.target', 'rpcbind.target',
  30. 'time-sync.target',
  31. -- Specail slice units.
  32. '-.slice', 'system.slice', 'user.slice', 'machine.slice',
  33. -- Environment variables.
  34. 'PATH', 'LANG', 'USER', 'LOGNAME', 'HOME', 'SHELL', 'XDG_RUNTIME_DIR', 'XDG_SESSION_ID',
  35. 'XDG_SEAT', 'XDG_VTNR', 'MAINPID', 'MANAGERPID', 'LISTEN_FDS', 'LISTEN_PID', 'LISTEN_FDNAMES',
  36. 'NOTIFY_SOCKET', 'WATCHDOG_PID', 'WATCHDOG_USEC', 'TERM'
  37. }))
  38. -- Options.
  39. lex:add_rule('option', token(lexer.PREPROCESSOR, word_match{
  40. -- Unit section.
  41. 'Description', 'Documentation', 'Requires', 'Requisite', 'Wants', 'BindsTo', 'PartOf',
  42. 'Conflicts', 'Before', 'After', 'OnFailure', 'PropagatesReloadTo', 'ReloadPropagatedFrom',
  43. 'JoinsNamespaceOf', 'RequiresMountsFor', 'OnFailureJobMode', 'IgnoreOnIsolate',
  44. 'StopWhenUnneeded', 'RefuseManualStart', 'RefuseManualStop', 'AllowIsolate',
  45. 'DefaultDependencies', 'JobTimeoutSec', 'JobTimeoutAction', 'JobTimeoutRebootArgument',
  46. 'StartLimitInterval', 'StartLimitBurst', 'StartLimitAction', 'RebootArgument',
  47. 'ConditionArchitecture', 'ConditionVirtualization', 'ConditionHost', 'ConditionKernelCommandLine',
  48. 'ConditionSecurity', 'ConditionCapability', 'ConditionACPower', 'ConditionNeedsUpdate',
  49. 'ConditionFirstBoot', 'ConditionPathExists', 'ConditionPathExistsGlob',
  50. 'ConditionPathIsDirectory', 'ConditionPathIsSymbolicLink', 'ConditionPathIsMountPoint',
  51. 'ConditionPathIsReadWrite', 'ConditionDirectoryNotEmpty', 'ConditionFileNotEmpty',
  52. 'ConditionFileIsExecutable', 'AssertArchitecture', 'AssertVirtualization', 'AssertHost',
  53. 'AssertKernelCommandLine', 'AssertSecurity', 'AssertCapability', 'AssertACPower',
  54. 'AssertNeedsUpdate', 'AssertFirstBoot', 'AssertPathExists', 'AssertPathExistsGlob',
  55. 'AssertPathIsDirectory', 'AssertPathIsSymbolicLink', 'AssertPathIsMountPoint',
  56. 'AssertPathIsReadWrite', 'AssertDirectoryNotEmpty', 'AssertFileNotEmpty',
  57. 'AssertFileIsExecutable', 'SourcePath',
  58. -- Install section.
  59. 'Alias', 'WantedBy', 'RequiredBy', 'Also', 'DefaultInstance',
  60. -- Service section.
  61. 'Type', 'RemainAfterExit', 'GuessMainPID', 'PIDFile', 'BusName', 'BusPolicy', 'ExecStart',
  62. 'ExecStartPre', 'ExecStartPost', 'ExecReload', 'ExecStop', 'ExecStopPost', 'RestartSec',
  63. 'TimeoutStartSec', 'TimeoutStopSec', 'TimeoutSec', 'RuntimeMaxSec', 'WatchdogSec', 'Restart',
  64. 'SuccessExitStatus', 'RestartPreventExitStatus', 'RestartForceExitStatus', 'PermissionsStartOnly',
  65. 'RootDirectoryStartOnly', 'NonBlocking', 'NotifyAccess', 'Sockets', 'FailureAction',
  66. 'FileDescriptorStoreMax', 'USBFunctionDescriptors', 'USBFunctionStrings',
  67. -- Socket section.
  68. 'ListenStream', 'ListenDatagram', 'ListenSequentialPacket', 'ListenFIFO', 'ListenSpecial',
  69. 'ListenNetlink', 'ListenMessageQueue', 'ListenUSBFunction', 'SocketProtocol', 'BindIPv6Only',
  70. 'Backlog', 'BindToDevice', 'SocketUser', 'SocketGroup', 'SocketMode', 'DirectoryMode', 'Accept',
  71. 'Writable', 'MaxConnections', 'KeepAlive', 'KeepAliveTimeSec', 'KeepAliveIntervalSec',
  72. 'KeepAliveProbes', 'NoDelay', 'Priority', 'DeferAcceptSec', 'ReceiveBuffer', 'SendBuffer',
  73. 'IPTOS', 'IPTTL', 'Mark', 'ReusePort', 'SmackLabel', 'SmackLabelIPIn', 'SmackLabelIPOut',
  74. 'SELinuxContextFromNet', 'PipeSize', 'MessageQueueMaxMessages', 'MessageQueueMessageSize',
  75. 'FreeBind', 'Transparent', 'Broadcast', 'PassCredentials', 'PassSecurity', 'TCPCongestion',
  76. 'ExecStartPre', 'ExecStartPost', 'ExecStopPre', 'ExecStopPost', 'TimeoutSec', 'Service',
  77. 'RemoveOnStop', 'Symlinks', 'FileDescriptorName',
  78. -- Mount section.
  79. 'What', 'Where', 'Type', 'Options', 'SloppyOptions', 'DirectoryMode', 'TimeoutSec',
  80. -- Path section.
  81. 'PathExists', 'PathExistsGlob', 'PathChanged', 'PathModified', 'DirectoryNotEmpty', 'Unit',
  82. 'MakeDirectory', 'DirectoryMode',
  83. -- Timer section.
  84. 'OnActiveSec', 'OnBootSec', 'OnStartupSec', 'OnUnitActiveSec', 'OnUnitInactiveSec', 'OnCalendar',
  85. 'AccuracySec', 'RandomizedDelaySec', 'Unit', 'Persistent', 'WakeSystem', 'RemainAfterElapse',
  86. -- Exec section.
  87. 'WorkingDirectory', 'RootDirectory', 'User', 'Group', 'SupplementaryGroups', 'Nice',
  88. 'OOMScoreAdjust', 'IOSchedulingClass', 'IOSchedulingPriority', 'CPUSchedulingPolicy',
  89. 'CPUSchedulingPriority', 'CPUSchedulingResetOnFork', 'CPUAffinity', 'UMask', 'Environment',
  90. 'EnvironmentFile', 'PassEnvironment', 'StandardInput', 'StandardOutput', 'StandardError',
  91. 'TTYPath', 'TTYReset', 'TTYVHangup', 'TTYVTDisallocate', 'SyslogIdentifier', 'SyslogFacility',
  92. 'SyslogLevel', 'SyslogLevelPrefix', 'TimerSlackNSec', 'LimitCPU', 'LimitFSIZE', 'LimitDATA',
  93. 'LimitSTACK', 'LimitCORE', 'LimitRSS', 'LimitNOFILE', 'LimitAS', 'LimitNPROC', 'LimitMEMLOCK',
  94. 'LimitLOCKS', 'LimitSIGPENDING', 'LimitMSGQUEUE', 'LimitNICE', 'LimitRTPRIO', 'LimitRTTIME',
  95. 'PAMName', 'CapabilityBoundingSet', 'AmbientCapabilities', 'SecureBits', 'Capabilities',
  96. 'ReadWriteDirectories', 'ReadOnlyDirectories', 'InaccessibleDirectories', 'PrivateTmp',
  97. 'PrivateDevices', 'PrivateNetwork', 'ProtectSystem', 'ProtectHome', 'MountFlags',
  98. 'UtmpIdentifier', 'UtmpMode', 'SELinuxContext', 'AppArmorProfile', 'SmackProcessLabel',
  99. 'IgnoreSIGPIPE', 'NoNewPrivileges', 'SystemCallFilter', 'SystemCallErrorNumber',
  100. 'SystemCallArchitectures', 'RestrictAddressFamilies', 'Personality', 'RuntimeDirectory',
  101. 'RuntimeDirectoryMode'
  102. }))
  103. -- Identifiers.
  104. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0))
  105. -- Strings.
  106. local sq_str = lexer.range("'")
  107. local dq_str = lexer.range('"')
  108. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  109. -- Sections.
  110. lex:add_rule('section', token(lexer.LABEL, '[' *
  111. word_match('Automount BusName Install Mount Path Service Service Socket Timer Unit') * ']'))
  112. -- Comments.
  113. lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S(';#')))))
  114. -- Numbers.
  115. local integer = S('+-')^-1 * (lexer.hex_num + lexer.oct_num_('_') + lexer.dec_num_('_'))
  116. lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer))
  117. -- Operators.
  118. lex:add_rule('operator', token(lexer.OPERATOR, '='))
  119. lexer.property['scintillua.comment'] = '#'
  120. return lex