@@ -29,7 +29,7 @@ defmodule Systemd.UnitFile.Validator do
2929 ) ,
3030 "Service" =>
3131 MapSet . new (
32- ~w( Type ExecStart ExecStartPre ExecStartPost ExecCondition ExecReload ExecStop ExecStopPost Restart RestartSec User Group WorkingDirectory RootDirectory Environment EnvironmentFile PassEnvironment UnsetEnvironment TimeoutStartSec TimeoutStopSec TimeoutAbortSec KillSignal KillMode RemainAfterExit GuessMainPID PIDFile RuntimeDirectory RuntimeDirectoryPreserve StateDirectory CacheDirectory LogsDirectory ConfigurationDirectory StandardOutput StandardError SyslogIdentifier LimitNOFILE LimitNPROC LimitMEMLOCK LimitCORE LimitCPU LimitAS LimitFSIZE NoNewPrivileges PrivateTmp PrivateDevices ProtectSystem ProtectHome AmbientCapabilities CapabilityBoundingSet ReadWritePaths ReadOnlyPaths InaccessiblePaths OOMPolicy)
32+ ~w( Type ExecStart ExecStartPre ExecStartPost ExecCondition ExecReload ExecStop ExecStopPost Restart RestartSec User Group WorkingDirectory RootDirectory Environment EnvironmentFile PassEnvironment UnsetEnvironment TimeoutStartSec TimeoutStopSec TimeoutAbortSec KillSignal KillMode RemainAfterExit GuessMainPID PIDFile RuntimeDirectory RuntimeDirectoryPreserve StateDirectory CacheDirectory LogsDirectory ConfigurationDirectory StandardOutput StandardError SyslogIdentifier Slice Delegate CPUAccounting CPUWeight CPUQuota MemoryAccounting MemoryMin MemoryLow MemoryHigh MemoryMax MemorySwapMax TasksAccounting TasksMax IOAccounting IOWeight IPAccounting LimitNOFILE LimitNPROC LimitMEMLOCK LimitCORE LimitCPU LimitAS LimitFSIZE NoNewPrivileges PrivateTmp PrivateDevices ProtectSystem ProtectHome AmbientCapabilities CapabilityBoundingSet ReadWritePaths ReadOnlyPaths InaccessiblePaths OOMPolicy)
3333 ) ,
3434 "Install" => MapSet . new ( ~w( WantedBy RequiredBy Also Alias DefaultInstance) ) ,
3535 "Socket" =>
@@ -223,13 +223,39 @@ defmodule Systemd.UnitFile.Validator do
223223 when directive in [
224224 "RemainAfterExit" ,
225225 "GuessMainPID" ,
226+ "Delegate" ,
227+ "CPUAccounting" ,
228+ "MemoryAccounting" ,
229+ "TasksAccounting" ,
230+ "IOAccounting" ,
231+ "IPAccounting" ,
226232 "NoNewPrivileges" ,
227233 "PrivateTmp" ,
228234 "PrivateDevices"
229235 ] do
230236 boolean ( "Service" , directive , value , span )
231237 end
232238
239+ defp value_errors ( "Service" , directive , value , span )
240+ when directive in [
241+ "MemoryMin" ,
242+ "MemoryLow" ,
243+ "MemoryHigh" ,
244+ "MemoryMax" ,
245+ "MemorySwapMax" ,
246+ "TasksMax"
247+ ] do
248+ resource_limit ( "Service" , directive , value , span )
249+ end
250+
251+ defp value_errors ( "Service" , directive , value , span )
252+ when directive in [ "CPUWeight" , "IOWeight" ] do
253+ positive_integer ( "Service" , directive , value , span )
254+ end
255+
256+ defp value_errors ( "Service" , "CPUQuota" , value , span ) ,
257+ do: percentage ( "Service" , "CPUQuota" , value , span )
258+
233259 defp value_errors ( "Service" , "KillMode" , value , span ) do
234260 one_of ( "Service" , "KillMode" , value , ~w( control-group mixed process none) , span )
235261 end
@@ -367,6 +393,40 @@ defmodule Systemd.UnitFile.Validator do
367393 end
368394 end
369395
396+ defp resource_limit ( _section , _directive , "infinity" , _span ) , do: [ ]
397+
398+ defp resource_limit ( section , directive , value , span ) do
399+ if ValueParser . resource_quantity? ( value ) do
400+ [ ]
401+ else
402+ [
403+ value_error (
404+ section ,
405+ directive ,
406+ value ,
407+ "expected bytes, K/M/G/T/P/E suffix, or infinity" ,
408+ span
409+ )
410+ ]
411+ end
412+ end
413+
414+ defp positive_integer ( section , directive , value , span ) do
415+ if ValueParser . positive_integer? ( value ) do
416+ [ ]
417+ else
418+ [ value_error ( section , directive , value , "expected a positive integer" , span ) ]
419+ end
420+ end
421+
422+ defp percentage ( section , directive , value , span ) do
423+ if ValueParser . percentage? ( value ) do
424+ [ ]
425+ else
426+ [ value_error ( section , directive , value , "expected a percentage such as 50%" , span ) ]
427+ end
428+ end
429+
370430 defp octal_mode ( section , directive , value , span ) do
371431 if ValueParser . octal_mode? ( value ) do
372432 [ ]
0 commit comments