|
| 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 | + |
| 6 | +class RlimitOptionValue(grammar : Combinator) : GrammarOptionValue("config_parse_rlimit", grammar) { |
| 7 | + companion object { |
| 8 | + |
| 9 | + val GENERIC_SEQ = AlternativeCombinator(LiteralChoiceTerminal("infinity"), IntegerTerminal(0, Int.MAX_VALUE)) |
| 10 | + val BYTE_SEQ = AlternativeCombinator(LiteralChoiceTerminal("infinity"), SequenceCombinator(IntegerTerminal(0, Int.MAX_VALUE), OptionalWhitespacePrefix(LiteralChoiceTerminal("K", "M", "G", "T", "P", "E"))), IntegerTerminal(0, Int.MAX_VALUE)) |
| 11 | + val TIME_SEQ = AlternativeCombinator( |
| 12 | + LiteralChoiceTerminal("infinity"), |
| 13 | + SequenceCombinator( |
| 14 | + IntegerTerminal(0, Int.MAX_VALUE), |
| 15 | + OptionalWhitespacePrefix(LiteralChoiceTerminal("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")) |
| 16 | + ) |
| 17 | + , |
| 18 | + IntegerTerminal(0, Int.MAX_VALUE) |
| 19 | + ) |
| 20 | + |
| 21 | + val NICE_SEQ = AlternativeCombinator( |
| 22 | + SequenceCombinator(LiteralChoiceTerminal("+", "-"), IntegerTerminal(0, 21)), |
| 23 | + SequenceCombinator(IntegerTerminal(0, 41)), |
| 24 | + ) |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + val COLON = LiteralChoiceTerminal(":") |
| 29 | + val BYTE_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(BYTE_SEQ, COLON, BYTE_SEQ), BYTE_SEQ), EOF()) |
| 30 | + val TIME_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(TIME_SEQ, COLON, TIME_SEQ), TIME_SEQ), EOF()) |
| 31 | + val GENERIC_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(GENERIC_SEQ, COLON, GENERIC_SEQ), GENERIC_SEQ), EOF()) |
| 32 | + val NICE_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(NICE_SEQ, COLON, NICE_SEQ), NICE_SEQ), EOF()) |
| 33 | + |
| 34 | + |
| 35 | + val validators = mapOf( |
| 36 | + // Exec.LimitCPU, config_parse_rlimit, RLIMIT_CPU, offsetof(Settings, rlimit) |
| 37 | + Validator("config_parse_rlimit", "RLIMIT_CPU") to RlimitOptionValue(TIME_RLIMIT), |
| 38 | + // Exec.LimitFSIZE, config_parse_rlimit, RLIMIT_FSIZE, offsetof(Settings, rlimit) |
| 39 | + Validator("config_parse_rlimit", "RLIMIT_FSIZE") to RlimitOptionValue(BYTE_RLIMIT), |
| 40 | + // Exec.LimitDATA, config_parse_rlimit, RLIMIT_DATA, offsetof(Settings, rlimit) |
| 41 | + Validator("config_parse_rlimit", "RLIMIT_DATA") to RlimitOptionValue(BYTE_RLIMIT), |
| 42 | + // Exec.LimitSTACK, config_parse_rlimit, RLIMIT_STACK, offsetof(Settings, rlimit) |
| 43 | + Validator("config_parse_rlimit", "RLIMIT_STACK") to RlimitOptionValue(BYTE_RLIMIT), |
| 44 | + // Exec.LimitCORE, config_parse_rlimit, RLIMIT_CORE, offsetof(Settings, rlimit) |
| 45 | + Validator("config_parse_rlimit", "RLIMIT_CORE") to RlimitOptionValue(BYTE_RLIMIT), |
| 46 | + // Exec.LimitRSS, config_parse_rlimit, RLIMIT_RSS, offsetof(Settings, rlimit) |
| 47 | + Validator("config_parse_rlimit", "RLIMIT_RSS") to RlimitOptionValue(BYTE_RLIMIT), |
| 48 | + // Exec.LimitNOFILE, config_parse_rlimit, RLIMIT_NOFILE, offsetof(Settings, rlimit) |
| 49 | + Validator("config_parse_rlimit", "RLIMIT_NOFILE") to RlimitOptionValue(GENERIC_RLIMIT), |
| 50 | + // Exec.LimitAS, config_parse_rlimit, RLIMIT_AS, offsetof(Settings, rlimit) |
| 51 | + Validator("config_parse_rlimit", "RLIMIT_AS") to RlimitOptionValue(BYTE_RLIMIT), |
| 52 | + // Exec.LimitNPROC, config_parse_rlimit, RLIMIT_NPROC, offsetof(Settings, rlimit) |
| 53 | + Validator("config_parse_rlimit", "RLIMIT_NPROC") to RlimitOptionValue(GENERIC_RLIMIT), |
| 54 | + // Exec.LimitMEMLOCK, config_parse_rlimit, RLIMIT_MEMLOCK, offsetof(Settings, rlimit) |
| 55 | + Validator("config_parse_rlimit", "RLIMIT_MEMLOCK") to RlimitOptionValue(BYTE_RLIMIT), |
| 56 | + // Exec.LimitLOCKS, config_parse_rlimit, RLIMIT_LOCKS, offsetof(Settings, rlimit) |
| 57 | + Validator("config_parse_rlimit", "RLIMIT_LOCKS") to RlimitOptionValue(GENERIC_RLIMIT), |
| 58 | + // Exec.LimitSIGPENDING, config_parse_rlimit, RLIMIT_SIGPENDING, offsetof(Settings, rlimit) |
| 59 | + Validator("config_parse_rlimit", "RLIMIT_SIGPENDING") to RlimitOptionValue(GENERIC_RLIMIT), |
| 60 | + // Exec.LimitMSGQUEUE, config_parse_rlimit, RLIMIT_MSGQUEUE, offsetof(Settings, rlimit) |
| 61 | + Validator("config_parse_rlimit", "RLIMIT_MSGQUEUE") to RlimitOptionValue(BYTE_RLIMIT), |
| 62 | + // Exec.LimitNICE, config_parse_rlimit, RLIMIT_NICE, offsetof(Settings, rlimit) |
| 63 | + Validator("config_parse_rlimit", "RLIMIT_NICE") to RlimitOptionValue(NICE_RLIMIT), |
| 64 | + // Exec.LimitRTPRIO, config_parse_rlimit, RLIMIT_RTPRIO, offsetof(Settings, rlimit) |
| 65 | + Validator("config_parse_rlimit", "RLIMIT_RTPRIO") to RlimitOptionValue(GENERIC_RLIMIT), |
| 66 | + // Exec.LimitRTTIME, config_parse_rlimit, RLIMIT_RTTIME, offsetof(Settings, rlimit) |
| 67 | + Validator("config_parse_rlimit", "RLIMIT_RTTIME") to RlimitOptionValue(TIME_RLIMIT), |
| 68 | + ) |
| 69 | + } |
| 70 | +} |
0 commit comments