|
| 1 | +package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues |
| 2 | + |
| 3 | +import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator |
| 4 | +import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.* |
| 5 | +import java.util.Optional |
| 6 | + |
| 7 | +class RlimitOptionValue(grammar : Combinator) : GrammarOptionValue("config_parse_rlimit", grammar) { |
| 8 | + companion object { |
| 9 | + |
| 10 | + val GENERIC_SEQ = |
| 11 | + AlternativeCombinator( |
| 12 | + OptionalWhitespacePrefix(FlexibleLiteralChoiceTerminal("infinity")), |
| 13 | + OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE))) |
| 14 | + |
| 15 | + val BYTE_SEQ = AlternativeCombinator( |
| 16 | + FlexibleLiteralChoiceTerminal("infinity"), |
| 17 | + SequenceCombinator( |
| 18 | + OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)), |
| 19 | + OptionalWhitespacePrefix(LiteralChoiceTerminal("K", "M", "G", "T", "P", "E")) |
| 20 | + ), |
| 21 | + OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE))) |
| 22 | + |
| 23 | + val TIME_SEQ = AlternativeCombinator( |
| 24 | + FlexibleLiteralChoiceTerminal("infinity"), |
| 25 | + OneOrMore( |
| 26 | + SequenceCombinator( |
| 27 | + OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)), |
| 28 | + OptionalWhitespacePrefix(FlexibleLiteralChoiceTerminal("usec", "us", "μs", "msec", "ms", "seconds", "second", "sec", "s", "minutes", "minute", "min", "m", "hours", "hour", "hr", "h", "days", "day", "d", "weeks", "week", "w", "months", "month", "M", "years", "year", "y")) |
| 29 | + ) |
| 30 | + ), |
| 31 | + OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)) |
| 32 | + ) |
| 33 | + |
| 34 | + val NICE_SEQ = AlternativeCombinator( |
| 35 | + SequenceCombinator(LiteralChoiceTerminal("+", "-"), IntegerTerminal(0, 21)), |
| 36 | + OptionalWhitespacePrefix(SequenceCombinator(IntegerTerminal(0, 41))), |
| 37 | + ) |
| 38 | + |
| 39 | + val COLON = LiteralChoiceTerminal(":") |
| 40 | + |
| 41 | + val BYTE_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(BYTE_SEQ, COLON, BYTE_SEQ), BYTE_SEQ), EOF()) |
| 42 | + val TIME_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(TIME_SEQ, COLON, TIME_SEQ), TIME_SEQ), EOF()) |
| 43 | + val GENERIC_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(GENERIC_SEQ, COLON, GENERIC_SEQ), GENERIC_SEQ), EOF()) |
| 44 | + val NICE_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(NICE_SEQ, COLON, NICE_SEQ), NICE_SEQ), EOF()) |
| 45 | + |
| 46 | + |
| 47 | + val validators = mapOf( |
| 48 | + // Exec.LimitCPU, config_parse_rlimit, RLIMIT_CPU, offsetof(Settings, rlimit) |
| 49 | + Validator("config_parse_rlimit", "RLIMIT_CPU") to RlimitOptionValue(TIME_RLIMIT), |
| 50 | + // Exec.LimitFSIZE, config_parse_rlimit, RLIMIT_FSIZE, offsetof(Settings, rlimit) |
| 51 | + Validator("config_parse_rlimit", "RLIMIT_FSIZE") to RlimitOptionValue(BYTE_RLIMIT), |
| 52 | + // Exec.LimitDATA, config_parse_rlimit, RLIMIT_DATA, offsetof(Settings, rlimit) |
| 53 | + Validator("config_parse_rlimit", "RLIMIT_DATA") to RlimitOptionValue(BYTE_RLIMIT), |
| 54 | + // Exec.LimitSTACK, config_parse_rlimit, RLIMIT_STACK, offsetof(Settings, rlimit) |
| 55 | + Validator("config_parse_rlimit", "RLIMIT_STACK") to RlimitOptionValue(BYTE_RLIMIT), |
| 56 | + // Exec.LimitCORE, config_parse_rlimit, RLIMIT_CORE, offsetof(Settings, rlimit) |
| 57 | + Validator("config_parse_rlimit", "RLIMIT_CORE") to RlimitOptionValue(BYTE_RLIMIT), |
| 58 | + // Exec.LimitRSS, config_parse_rlimit, RLIMIT_RSS, offsetof(Settings, rlimit) |
| 59 | + Validator("config_parse_rlimit", "RLIMIT_RSS") to RlimitOptionValue(BYTE_RLIMIT), |
| 60 | + // Exec.LimitNOFILE, config_parse_rlimit, RLIMIT_NOFILE, offsetof(Settings, rlimit) |
| 61 | + Validator("config_parse_rlimit", "RLIMIT_NOFILE") to RlimitOptionValue(GENERIC_RLIMIT), |
| 62 | + // Exec.LimitAS, config_parse_rlimit, RLIMIT_AS, offsetof(Settings, rlimit) |
| 63 | + Validator("config_parse_rlimit", "RLIMIT_AS") to RlimitOptionValue(BYTE_RLIMIT), |
| 64 | + // Exec.LimitNPROC, config_parse_rlimit, RLIMIT_NPROC, offsetof(Settings, rlimit) |
| 65 | + Validator("config_parse_rlimit", "RLIMIT_NPROC") to RlimitOptionValue(GENERIC_RLIMIT), |
| 66 | + // Exec.LimitMEMLOCK, config_parse_rlimit, RLIMIT_MEMLOCK, offsetof(Settings, rlimit) |
| 67 | + Validator("config_parse_rlimit", "RLIMIT_MEMLOCK") to RlimitOptionValue(BYTE_RLIMIT), |
| 68 | + // Exec.LimitLOCKS, config_parse_rlimit, RLIMIT_LOCKS, offsetof(Settings, rlimit) |
| 69 | + Validator("config_parse_rlimit", "RLIMIT_LOCKS") to RlimitOptionValue(GENERIC_RLIMIT), |
| 70 | + // Exec.LimitSIGPENDING, config_parse_rlimit, RLIMIT_SIGPENDING, offsetof(Settings, rlimit) |
| 71 | + Validator("config_parse_rlimit", "RLIMIT_SIGPENDING") to RlimitOptionValue(GENERIC_RLIMIT), |
| 72 | + // Exec.LimitMSGQUEUE, config_parse_rlimit, RLIMIT_MSGQUEUE, offsetof(Settings, rlimit) |
| 73 | + Validator("config_parse_rlimit", "RLIMIT_MSGQUEUE") to RlimitOptionValue(BYTE_RLIMIT), |
| 74 | + // Exec.LimitNICE, config_parse_rlimit, RLIMIT_NICE, offsetof(Settings, rlimit) |
| 75 | + Validator("config_parse_rlimit", "RLIMIT_NICE") to RlimitOptionValue(NICE_RLIMIT), |
| 76 | + // Exec.LimitRTPRIO, config_parse_rlimit, RLIMIT_RTPRIO, offsetof(Settings, rlimit) |
| 77 | + Validator("config_parse_rlimit", "RLIMIT_RTPRIO") to RlimitOptionValue(GENERIC_RLIMIT), |
| 78 | + // Exec.LimitRTTIME, config_parse_rlimit, RLIMIT_RTTIME, offsetof(Settings, rlimit) |
| 79 | + Validator("config_parse_rlimit", "RLIMIT_RTTIME") to RlimitOptionValue(TIME_RLIMIT), |
| 80 | + ) |
| 81 | + } |
| 82 | +} |
0 commit comments