condition: extend ConditionKernelVersion= with relative version checks
Now that we have str_verscmp() in our source tree anyway, let's make it generic and reuse it for ConditionKernelVersion=.
This commit is contained in:
@@ -553,3 +553,65 @@ int version(void) {
|
||||
SYSTEMD_FEATURES);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is a direct translation of str_verscmp from boot.c */
|
||||
static bool is_digit(int c) {
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
static int c_order(int c) {
|
||||
if (c == 0 || is_digit(c))
|
||||
return 0;
|
||||
|
||||
if ((c >= 'a') && (c <= 'z'))
|
||||
return c;
|
||||
|
||||
return c + 0x10000;
|
||||
}
|
||||
|
||||
int str_verscmp(const char *s1, const char *s2) {
|
||||
const char *os1, *os2;
|
||||
|
||||
assert(s1);
|
||||
assert(s2);
|
||||
|
||||
os1 = s1;
|
||||
os2 = s2;
|
||||
|
||||
while (*s1 || *s2) {
|
||||
int first;
|
||||
|
||||
while ((*s1 && !is_digit(*s1)) || (*s2 && !is_digit(*s2))) {
|
||||
int order;
|
||||
|
||||
order = c_order(*s1) - c_order(*s2);
|
||||
if (order != 0)
|
||||
return order;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
while (*s1 == '0')
|
||||
s1++;
|
||||
while (*s2 == '0')
|
||||
s2++;
|
||||
|
||||
first = 0;
|
||||
while (is_digit(*s1) && is_digit(*s2)) {
|
||||
if (first == 0)
|
||||
first = *s1 - *s2;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
if (is_digit(*s1))
|
||||
return 1;
|
||||
if (is_digit(*s2))
|
||||
return -1;
|
||||
|
||||
if (first != 0)
|
||||
return first;
|
||||
}
|
||||
|
||||
return strcmp(os1, os2);
|
||||
}
|
||||
|
||||
@@ -189,3 +189,5 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max);
|
||||
int update_reboot_parameter_and_warn(const char *param);
|
||||
|
||||
int version(void);
|
||||
|
||||
int str_verscmp(const char *s1, const char *s2);
|
||||
|
||||
Reference in New Issue
Block a user