|
17 | 17 | * |
18 | 18 | *------------------------------------------------------------------------- |
19 | 19 | */ |
| 20 | +#include "catalog/pg_collation_d.h" |
20 | 21 | #include "postgres.h" |
21 | 22 |
|
22 | 23 | #include "miscadmin.h" |
| 24 | +#include "regex/regex.h" |
23 | 25 | #include "utils/guc.h" |
24 | 26 | #include "cdb/cdbvars.h" |
25 | 27 | #include "libpq-fe.h" |
@@ -567,6 +569,44 @@ gpvars_show_gp_resource_manager_policy(void) |
567 | 569 | } |
568 | 570 | } |
569 | 571 |
|
| 572 | +bool gpvars_check_gp_resource_group_cgroup_parent(char **newval, void **extra, GucSource source) |
| 573 | +{ |
| 574 | + int regres; |
| 575 | + char err[128]; |
| 576 | + regex_t re; |
| 577 | + char *pattern = "^[0-9a-zA-Z][-._0-9a-zA-Z]*$"; |
| 578 | + pg_wchar *wpattern = palloc((strlen(pattern) + 1) * sizeof(pg_wchar)); |
| 579 | + int wlen = pg_mb2wchar_with_len(pattern, wpattern, strlen(pattern)); |
| 580 | + pg_wchar *data = palloc((strlen(*newval) + 1) * sizeof(pg_wchar)); |
| 581 | + int data_len = pg_mb2wchar_with_len(*newval, data, sizeof(*newval)); |
| 582 | + bool match = true; |
| 583 | + |
| 584 | + regres = pg_regcomp(&re, wpattern, wlen, REG_ADVANCED, DEFAULT_COLLATION_OID); |
| 585 | + if (regres != REG_OKAY) |
| 586 | + { |
| 587 | + pg_regerror(regres, &re, err, sizeof(err)); |
| 588 | + GUC_check_errmsg("compile regex failed: %s", err); |
| 589 | + |
| 590 | + pfree(wpattern); |
| 591 | + pfree(data); |
| 592 | + |
| 593 | + return false; |
| 594 | + } |
| 595 | + |
| 596 | + regres = pg_regexec(&re, data, data_len, 0, NULL, 0, NULL, 0); |
| 597 | + if (regres != REG_OKAY) |
| 598 | + { |
| 599 | + match = false; |
| 600 | + GUC_check_errmsg("gp_resource_group_cgroup_parent can only contains alphabet, number and non-leading . _ -"); |
| 601 | + } |
| 602 | + |
| 603 | + pg_regfree(&re); |
| 604 | + pfree(wpattern); |
| 605 | + pfree(data); |
| 606 | + |
| 607 | + return match; |
| 608 | +} |
| 609 | + |
570 | 610 | /* |
571 | 611 | * gpvars_assign_statement_mem |
572 | 612 | */ |
|
0 commit comments