- /* separate the unit from the corpus */
- *end = 0;
-
- /* allocates a descriptor for the unit */
- d = realloc(descs, (n + 1) * sizeof *descs);
- if (d == NULL)
- rc2 = -ENOMEM;
- else {
- /* creates the unit description */
- memset(&d[n], 0, sizeof *d);
- descs = d;
- rc2 = process_one_unit(beg, &descs[n]);
- if (rc2 >= 0)
- n++;
+ befbeg = offset(beg, "%begin ", NULL);
+ if (befbeg && befbeg < end) {
+ /* sequence %begin ... %begin ... %end detected !! */
+ ERROR("unexpected %%begin after %%begin");
+ corpus = beg;
+ rc2 = -EINVAL;
+ } else {
+ *end = 0;
+ corpus = aftend;
+ if (matches("systemd-unit\n", beg, &beg)) {
+ if (!matches("systemd-unit\n", aftend, &corpus)) {
+ /* end doesnt match */
+ ERROR("unmatched %%begin systemd-unit (matching end mismatch)");
+ rc2 = -EINVAL;
+ } else {
+ /* allocates a descriptor for the unit */
+ u = realloc((void*)gdesc.units, ((unsigned)gdesc.nunits + 1) * sizeof *gdesc.units);
+ if (u == NULL)
+ rc2 = -ENOMEM;
+ else {
+ /* creates the unit description */
+ gdesc.units = u;
+ u = &u[gdesc.nunits];
+ memset(u, 0, sizeof *u);
+ rc2 = process_one_unit(beg, u);
+ if (rc2 >= 0)
+ gdesc.nunits++;
+ }
+ }
+ } else {
+ ERROR("unexpected %%begin name");
+ rc2 = -EINVAL;
+ }