INN commit: trunk (3 files)

INN Commit rra at isc.org
Thu Aug 18 13:56:07 UTC 2011


    Date: Thursday, August 18, 2011 @ 06:56:07
  Author: iulius
Revision: 9347

update the vector library from rra-c-util 3.7

* Add new vector_addn, vector_split_multi and cvector_split_multi functions.
(Still unused.)

* Update to the new test suite for vector.c.

Modified:
  trunk/include/inn/vector.h
  trunk/lib/vector.c
  trunk/tests/lib/vector-t.c

----------------------+
 include/inn/vector.h |   48 +++++---
 lib/vector.c         |  113 ++++++++++++++++++++
 tests/lib/vector-t.c |  275 +++++++++++++++++++++++++++++++------------------
 3 files changed, 324 insertions(+), 112 deletions(-)

Modified: include/inn/vector.h
===================================================================
--- include/inn/vector.h	2011-08-18 13:52:54 UTC (rev 9346)
+++ include/inn/vector.h	2011-08-18 13:56:07 UTC (rev 9347)
@@ -44,6 +44,10 @@
 void vector_add(struct vector *, const char *string);
 void cvector_add(struct cvector *, const char *string);
 
+/* Add a counted string to a vector.  Only available for vectors. */
+void vector_addn(struct vector *, const char *string, size_t length)
+    __attribute__((__nonnull__));
+
 /* Resize the array of strings to hold size entries.  Saves reallocation work
    in vector_add if it's known in advance how many entries there will be. */
 void vector_resize(struct vector *, size_t size);
@@ -59,23 +63,35 @@
 void vector_free(struct vector *);
 void cvector_free(struct cvector *);
 
-/* Split functions build a vector from a string.  vector_split splits on a
-   specified character, while vector_split_space splits on any sequence of
-   spaces or tabs (not any sequence of whitespace, as just spaces or tabs is
-   more useful for INN).  The cvector versions destructively modify the
-   provided string in-place to insert nul characters between the strings.  If
-   the vector argument is NULL, a new vector is allocated; otherwise, the
-   provided one is reused.
+/*
+ * Split functions build a vector from a string.  vector_split splits on a
+ * specified character, vector_split_multi splits on a set of characters, and
+ * vector_split_space splits on any sequence of spaces or tabs (not any
+ * sequence of whitespace, as just spaces or tabs is more useful).  The
+ * cvector versions destructively modify the provided string in-place to
+ * insert nul characters between the strings.  If the vector argument is NULL,
+ * a new vector is allocated; otherwise, the provided one is reused.
+ *
+ * Empty strings will yield zero-length vectors.  Adjacent delimiters are
+ * treated as a single delimiter by *_split_space and *_split_multi, but *not*
+ * by *_split, so callers of *_split should be prepared for zero-length
+ * strings in the vector.
+ */
+struct vector *vector_split(const char *string, char sep, struct vector *)
+    __attribute__((__nonnull__(1)));
+struct vector *vector_split_multi(const char *string, const char *seps,
+                                  struct vector *)
+    __attribute__((__nonnull__(1, 2)));
+struct vector *vector_split_space(const char *string, struct vector *)
+    __attribute__((__nonnull__(1)));
+struct cvector *cvector_split(char *string, char sep, struct cvector *)
+    __attribute__((__nonnull__(1)));
+struct cvector *cvector_split_multi(char *string, const char *seps,
+                                    struct cvector *)
+    __attribute__((__nonnull__(1, 2)));
+struct cvector *cvector_split_space(char *string, struct cvector *)
+    __attribute__((__nonnull__(1)));
 
-   Empty strings will yield zero-length vectors.  Adjacent delimiters are
-   treated as a single delimiter by *_split_space, but *not* by *_split, so
-   callers of *_split should be prepared for zero-length strings in the
-   vector. */
-struct vector *vector_split(const char *string, char sep, struct vector *);
-struct vector *vector_split_space(const char *string, struct vector *);
-struct cvector *cvector_split(char *string, char sep, struct cvector *);
-struct cvector *cvector_split_space(char *string, struct cvector *);
-
 /* Build a string from a vector by joining its components together with the
    specified string as separator.  Returns a newly allocated string; caller is
    responsible for freeing. */

Modified: lib/vector.c
===================================================================
--- lib/vector.c	2011-08-18 13:52:54 UTC (rev 9346)
+++ lib/vector.c	2011-08-18 13:56:07 UTC (rev 9347)
@@ -124,6 +124,24 @@
 
 
 /*
+ * Add a new counted string to the vector, resizing the vector as necessary
+ * the same as with vector_add.  This function is only available for vectors,
+ * not cvectors, since it requires the duplication of the input string to be
+ * sure it's nul-terminated.
+ */
+void
+vector_addn(struct vector *vector, const char *string, size_t length)
+{
+    size_t next = vector->count;
+
+    if (vector->count == vector->allocated)
+        vector_resize(vector, vector->allocated + 1);
+    vector->strings[next] = xstrndup(string, length);
+    vector->count++;
+}
+
+
+/*
 **  Empty a vector but keep the allocated memory for the pointer table.
 */
 void
@@ -271,6 +289,101 @@
 
 
 /*
+ * Given a string and a set of separators expressed as a string, count the
+ * number of strings that it will split into when splitting on those
+ * separators.
+ */
+static size_t
+split_multi_count(const char *string, const char *seps)
+{
+    const char *p;
+    size_t count;
+
+    if (*string == '\0')
+        return 0;
+    for (count = 1, p = string + 1; *p != '\0'; p++)
+        if (strchr(seps, *p) != NULL && strchr(seps, p[-1]) == NULL)
+            count++;
+
+    /*
+     * If the string ends in separators, we've overestimated the number of
+     * strings by one.
+     */
+    if (strchr(seps, p[-1]) != NULL)
+        count--;
+    return count;
+}
+
+
+/*
+ * Given a string, split it at any of the provided separators to form a
+ * vector, copying each string segment.  If the third argument isn't NULL,
+ * reuse that vector; otherwise, allocate a new one.  Any number of
+ * consecutive separators are considered a single separator.
+ */
+struct vector *
+vector_split_multi(const char *string, const char *seps,
+                   struct vector *vector)
+{
+    const char *p, *start;
+    size_t i, count;
+
+    vector = vector_reuse(vector);
+
+    count = split_multi_count(string, seps);
+    if (vector->allocated < count)
+        vector_resize(vector, count);
+
+    for (start = string, p = string, i = 0; *p; p++)
+        if (strchr(seps, *p) != NULL) {
+            if (start != p)
+                vector->strings[i++] = xstrndup(start, p - start);
+            start = p + 1;
+        }
+    if (start != p)
+        vector->strings[i++] = xstrndup(start, p - start);
+    vector->count = i;
+
+    return vector;
+}
+
+
+/*
+ * Given a string, split it at any of the provided separators to form a
+ * vector, destructively modifying the string to nul-terminate each segment.
+ * If the third argument isn't NULL, reuse that vector; otherwise, allocate a
+ * new one.  Any number of consecutive separators are considered a single
+ * separator.
+ */
+struct cvector *
+cvector_split_multi(char *string, const char *seps, struct cvector *vector)
+{
+    char *p, *start;
+    size_t i, count;
+
+    vector = cvector_reuse(vector);
+
+    count = split_multi_count(string, seps);
+    if (vector->allocated < count)
+        cvector_resize(vector, count);
+
+    for (start = string, p = string, i = 0; *p; p++)
+        if (strchr(seps, *p) != NULL) {
+            if (start != p) {
+                *p = '\0';
+                vector->strings[i++] = start;
+            }
+            start = p + 1;
+        }
+    if (start != p)
+        vector->strings[i++] = start;
+    vector->count = i;
+
+    return vector;
+}
+
+
+/*
 **  Given a string, count the number of strings that it will split into when
 **  splitting on whitespace.
 */

Modified: tests/lib/vector-t.c
===================================================================
--- tests/lib/vector-t.c	2011-08-18 13:52:54 UTC (rev 9346)
+++ tests/lib/vector-t.c	2011-08-18 13:56:07 UTC (rev 9347)
@@ -1,6 +1,24 @@
-/* $Id$ */
-/* vector test suite. */
+/*
+ * vector test suite.
+ *
+ * $Id$
+ *
+ * The canonical version of this file is maintained in the rra-c-util package,
+ * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Written by Russ Allbery <rra at stanford.edu>
+ *
+ * The authors hereby relinquish any claim to any copyright that they may have
+ * in this work, whether granted under contract or by operation of law or
+ * international treaty, and hereby commit to the public, at large, that they
+ * shall not, at any time in the future, seek to enforce any copyright in this
+ * work against any person or entity, or prevent any person or entity from
+ * copying, publishing, distributing or creating derivative works of this
+ * work.
+ */
 
+#define LIBTEST_NEW_FORMAT 1
+
 #include "config.h"
 #include "clibrary.h"
 #include "portable/wait.h"
@@ -20,197 +38,262 @@
     static const char nulls1[] = "This\0is\0a\0test.";
     static const char nulls2[] = "This is a\t\0es\0.  ";
     char empty[] = "";
+    char buffer[256];
     char *string;
     char *p;
     pid_t child;
 
-    test_init(89);
+    plan(117);
 
     vector = vector_new();
-    ok(1, vector != NULL);
+    ok(vector != NULL, "vector_new returns non-NULL");
     vector_add(vector, cstring);
-    ok_int(2, 1, vector->count);
-    ok(3, vector->strings[0] != cstring);
+    is_int(1, vector->count, "vector_add increases count");
+    ok(vector->strings[0] != cstring, "...and allocated new memory");
     vector_resize(vector, 4);
-    ok_int(4, 4, vector->allocated);
+    is_int(4, vector->allocated, "vector_resize works");
     vector_add(vector, cstring);
     vector_add(vector, cstring);
     vector_add(vector, cstring);
-    ok_int(5, 4, vector->allocated);
-    ok_int(6, 4, vector->count);
-    ok(7, vector->strings[1] != vector->strings[2]);
-    ok(8, vector->strings[2] != vector->strings[3]);
-    ok(9, vector->strings[3] != vector->strings[0]);
-    ok(10, vector->strings[0] != cstring);
+    is_int(4, vector->allocated, "...and no reallocation when adding strings");
+    is_int(4, vector->count, "...and the count matches");
+    is_string(cstring, vector->strings[0], "added the right string");
+    is_string(cstring, vector->strings[1], "added the right string");
+    is_string(cstring, vector->strings[2], "added the right string");
+    is_string(cstring, vector->strings[3], "added the right string");
+    ok(vector->strings[1] != vector->strings[2], "each pointer is different");
+    ok(vector->strings[2] != vector->strings[3], "each pointer is different");
+    ok(vector->strings[3] != vector->strings[0], "each pointer is different");
+    ok(vector->strings[0] != cstring, "each pointer is different");
     vector_clear(vector);
-    ok_int(11, 0, vector->count);
-    ok_int(12, 4, vector->allocated);
+    is_int(0, vector->count, "vector_clear works");
+    is_int(4, vector->allocated, "...but doesn't free the allocation");
     string = xstrdup(cstring);
     vector_add(vector, cstring);
     vector_add(vector, string);
-    ok_int(13, 2, vector->count);
-    ok(14, vector->strings[1] != string);
+    is_int(2, vector->count, "added two strings to the vector");
+    ok(vector->strings[1] != string, "...and the pointers are different");
     vector_resize(vector, 1);
-    ok_int(15, 1, vector->count);
-    ok(16, vector->strings[0] != cstring);
+    is_int(1, vector->count, "vector_resize shrinks the vector");
+    ok(vector->strings[0] != cstring, "...and the pointer is different");
+    vector_addn(vector, cstring, 4);
+    is_int(2, vector->count, "vector_addn increments count");
+    is_string("This", vector->strings[1], "...and adds the right data");
     vector_free(vector);
     free(string);
 
     cvector = cvector_new();
-    ok(17, cvector != NULL);
+    ok(cvector != NULL, "cvector_new returns non-NULL");
     cvector_add(cvector, cstring);
-    ok_int(18, 1, cvector->count);
-    ok(19, cvector->strings[0] == cstring);
+    is_int(1, cvector->count, "cvector_add adds a string");
+    ok(cvector->strings[0] == cstring, "...and keeps the same pointer");
     cvector_resize(cvector, 4);
-    ok_int(20, 4, cvector->allocated);
+    is_int(4, cvector->allocated, "cvector_resize works");
     cvector_add(cvector, cstring);
     cvector_add(cvector, cstring);
     cvector_add(cvector, cstring);
-    ok_int(21, 4, cvector->allocated);
-    ok_int(22, 4, cvector->count);
-    ok(23, cvector->strings[1] == cvector->strings[2]);
-    ok(24, cvector->strings[2] == cvector->strings[3]);
-    ok(25, cvector->strings[3] == cvector->strings[0]);
-    ok(26, cvector->strings[0] == cstring);
+    is_int(4, cvector->allocated, "...and subsequent adds don't resize");
+    is_int(4, cvector->count, "...and the count is right");
+    ok(cvector->strings[1] == cvector->strings[2], "all pointers match");
+    ok(cvector->strings[2] == cvector->strings[3], "all pointers match");
+    ok(cvector->strings[3] == cvector->strings[0], "all pointers match");
+    ok(cvector->strings[0] == cstring, "all pointers match");
     cvector_clear(cvector);
-    ok_int(27, 0, cvector->count);
-    ok_int(28, 4, cvector->allocated);
+    is_int(0, cvector->count, "cvector_clear works");
+    is_int(4, cvector->allocated, "...but doesn't free the allocation");
     string = xstrdup(cstring);
     cvector_add(cvector, cstring);
     cvector_add(cvector, string);
-    ok_int(29, 2, cvector->count);
-    ok(30, cvector->strings[1] == string);
+    is_int(2, cvector->count, "added two strings to the vector");
+    ok(cvector->strings[1] == string, "...and the pointers match");
     cvector_resize(cvector, 1);
-    ok_int(31, 1, cvector->count);
-    ok(32, cvector->strings[0] == cstring);
+    is_int(1, cvector->count, "cvector_resize shrinks the vector");
+    ok(cvector->strings[0] == cstring, "...and the pointers match");
     cvector_free(cvector);
     free(string);
 
     vector = vector_split_space("This is a\ttest.  ", NULL);
-    ok_int(33, 4, vector->count);
-    ok_int(34, 4, vector->allocated);
-    ok_string(35, "This", vector->strings[0]);
-    ok_string(36, "is", vector->strings[1]);
-    ok_string(37, "a", vector->strings[2]);
-    ok_string(38, "test.", vector->strings[3]);
+    is_int(4, vector->count, "vector_split_space returns right count");
+    is_int(4, vector->allocated, "...and allocation");
+    is_string("This", vector->strings[0], "...first string");
+    is_string("is", vector->strings[1], "...second string");
+    is_string("a", vector->strings[2], "...third string");
+    is_string("test.", vector->strings[3], "...fourth string");
     vector_add(vector, cstring);
-    ok_string(39, cstring, vector->strings[4]);
-    ok(40, vector->strings[4] != cstring);
-    ok_int(41, 5, vector->allocated);
+    is_string(cstring, vector->strings[4], "...and can add another");
+    ok(vector->strings[4] != cstring, "allocates a new pointer");
+    is_int(5, vector->allocated, "allocation goes up by one");
     vector = vector_split(cstring, 't', vector);
-    ok_int(42, 3, vector->count);
-    ok_int(43, 5, vector->allocated);
-    ok_string(44, "This is a\t", vector->strings[0]);
-    ok_string(45, "es", vector->strings[1]);
-    ok_string(46, ".  ", vector->strings[2]);
-    ok(47, vector->strings[0] != cstring);
+    is_int(3, vector->count, "resplitting returns the right count");
+    is_int(5, vector->allocated, "...but doesn't change allocation");
+    is_string("This is a\t", vector->strings[0], "...first string");
+    is_string("es", vector->strings[1], "...second string");
+    is_string(".  ", vector->strings[2], "...third string");
+    ok(vector->strings[0] != cstring, "...and allocated new string");
     p = vector_join(vector, "fe");
-    ok_string(48, "This is a\tfeesfe.  ", p);
+    is_string("This is a\tfeesfe.  ", p, "vector_join works");
     free(p);
     vector_free(vector);
 
     string = xstrdup(cstring);
     cvector = cvector_split_space(string, NULL);
-    ok_int(49, 4, cvector->count);
-    ok_int(50, 4, cvector->allocated);
-    ok_string(51, "This", cvector->strings[0]);
-    ok_string(52, "is", cvector->strings[1]);
-    ok_string(53, "a", cvector->strings[2]);
-    ok_string(54, "test.", cvector->strings[3]);
-    ok(55, memcmp(string, nulls1, 16) == 0);
+    is_int(4, cvector->count, "cvector_split_space returns right count");
+    is_int(4, cvector->allocated, "...and allocation");
+    is_string("This", cvector->strings[0], "...first string");
+    is_string("is", cvector->strings[1], "...second string");
+    is_string("a", cvector->strings[2], "...third string");
+    is_string("test.", cvector->strings[3], "...fourth string");
+    ok(memcmp(string, nulls1, 16) == 0, "original string modified in place");
     cvector_add(cvector, cstring);
-    ok(56, cvector->strings[4] == cstring);
-    ok_int(57, 5, cvector->allocated);
+    ok(cvector->strings[4] == cstring, "cvector_add then works");
+    is_int(5, cvector->allocated, "...and allocation increases by one");
     free(string);
     string = xstrdup(cstring);
     cvector = cvector_split(string, 't', cvector);
-    ok_int(58, 3, cvector->count);
-    ok_int(59, 5, cvector->allocated);
-    ok_string(60, "This is a\t", cvector->strings[0]);
-    ok_string(61, "es", cvector->strings[1]);
-    ok_string(62, ".  ", cvector->strings[2]);
-    ok(63, cvector->strings[0] == string);
-    ok(64, memcmp(string, nulls2, 18) == 0);
+    is_int(3, cvector->count, "cvector_split into same cvector works");
+    is_int(5, cvector->allocated, "...and doesn't lower allocation");
+    is_string("This is a\t", cvector->strings[0], "...first string");
+    is_string("es", cvector->strings[1], "...second string");
+    is_string(".  ", cvector->strings[2], "...third string");
+    ok(cvector->strings[0] == string, "no new memory is allocated");
+    ok(memcmp(string, nulls2, 18) == 0, "...and string is modified in place");
     p = cvector_join(cvector, "oo");
-    ok_string(65, "This is a\tooesoo.  ", p);
+    is_string("This is a\tooesoo.  ", p, "cvector_join works");
     free(p);
     cvector_free(cvector);
     free(string);
 
     vector = vector_split("", ' ', NULL);
-    ok_int(66, 1, vector->count);
-    ok_string(67, "", vector->strings[0]);
+    is_int(1, vector->count, "vector_split on empty string");
+    is_string("", vector->strings[0], "...returns only empty string");
     vector_free(vector);
     cvector = cvector_split(empty, ' ', NULL);
-    ok_int(68, 1, cvector->count);
-    ok_string(69, "", cvector->strings[0]);
+    is_int(1, cvector->count, "cvector_split on empty string");
+    is_string("", cvector->strings[0], "...returns only empty string");
     cvector_free(cvector);
 
     vector = vector_split_space("", NULL);
-    ok_int(70, 0, vector->count);
+    is_int(0, vector->count, "vector_split_space on empty string");
     vector_free(vector);
     cvector = cvector_split_space(empty, NULL);
-    ok_int(71, 0, cvector->count);
+    is_int(0, cvector->count, "cvector_split_space on empty string");
     cvector_free(cvector);
 
     vector = vector_split(tabs, '\t', NULL);
-    ok_int(72, 4, vector->count);
-    ok_string(73, "test", vector->strings[0]);
-    ok_string(74, "", vector->strings[1]);
-    ok_string(75, "ing", vector->strings[2]);
-    ok_string(76, "", vector->strings[3]);
+    is_int(4, vector->count, "vector_split on tab string");
+    is_string("test", vector->strings[0], "...first string");
+    is_string("", vector->strings[1], "...second string");
+    is_string("ing", vector->strings[2], "...third string");
+    is_string("", vector->strings[3], "...fourth string");
     p = vector_join(vector, "");
-    ok_string(77, "testing", p);
+    is_string("testing", p, "vector_join with an empty string works");
     free(p);
     vector_free(vector);
 
     string = xstrdup(tabs);
     cvector = cvector_split(string, '\t', NULL);
-    ok_int(78, 4, cvector->count);
-    ok_string(79, "test", cvector->strings[0]);
-    ok_string(80, "", cvector->strings[1]);
-    ok_string(81, "ing", cvector->strings[2]);
-    ok_string(82, "", cvector->strings[3]);
+    is_int(4, cvector->count, "cvector_split on tab string");
+    is_string("test", cvector->strings[0], "...first string");
+    is_string("", cvector->strings[1], "...second string");
+    is_string("ing", cvector->strings[2], "...third string");
+    is_string("", cvector->strings[3], "...fourth string");
     p = cvector_join(cvector, "");
-    ok_string(83, "testing", p);
+    is_string("testing", p, "cvector_join with an empty string works");
     free(p);
     cvector_free(cvector);
     free(string);
 
     vector = vector_split_space("foo\nbar", NULL);
-    ok_int(84, 1, vector->count);
-    ok_string(85, "foo\nbar", vector->strings[0]);
+    is_int(1, vector->count, "newline is not space for vector_split_space");
+    is_string("foo\nbar", vector->strings[0], "...first string");
     vector_free(vector);
 
     string = xstrdup("foo\nbar");
     cvector = cvector_split_space(string, NULL);
-    ok_int(86, 1, cvector->count);
-    ok_string(87, "foo\nbar", cvector->strings[0]);
+    is_int(1, cvector->count, "newline is not space for cvector_split_space");
+    is_string("foo\nbar", cvector->strings[0], "...first string");
     cvector_free(cvector);
+    free(string);
 
+    vector = vector_split_space(" \t foo\t", NULL);
+    is_int(1, vector->count, "extra whitespace in vector_split_space");
+    is_string("foo", vector->strings[0], "...first string");
+    vector_free(vector);
+
+    string = xstrdup(" \t foo\t");
+    cvector = cvector_split_space(string, NULL);
+    is_int(1, cvector->count, "extra whitespace in cvector_split_space");
+    is_string("foo", cvector->strings[0], "...first string");
+    cvector_free(cvector);
+    free(string);
+
+    vector = vector_split_space(" \t ", NULL);
+    is_int(0, vector->count, "vector_split_space on all whitespace string");
+    vector_free(vector);
+    string = xstrdup(" \t ");
+    cvector = cvector_split_space(string, NULL);
+    is_int(0, cvector->count, "cvector_split_space on all whitespace string");
+    cvector_free(cvector);
+
+    vector = vector_split_multi("foo, bar, baz", ", ", NULL);
+    is_int(3, vector->count, "vector_split_multi returns right count");
+    is_string("foo", vector->strings[0], "...first string");
+    is_string("bar", vector->strings[1], "...second string");
+    is_string("baz", vector->strings[2], "...third string");
+    vector = vector_split_multi("", ", ", NULL);
+    is_int(0, vector->count, "vector_split_multi reuse with empty string");
+    vector = vector_split_multi(",,,  foo,   ", ", ", vector);
+    is_int(1, vector->count, "vector_split_multi with extra separators");
+    is_string("foo", vector->strings[0], "...first string");
+    vector = vector_split_multi(", ,  ", ", ", vector);
+    is_int(0, vector->count, "vector_split_multi with only separators");
+    vector_free(vector);
+
+    string = xstrdup("foo, bar, baz");
+    cvector = cvector_split_multi(string, ", ", NULL);
+    is_int(3, cvector->count, "cvector_split_multi returns right count");
+    is_string("foo", cvector->strings[0], "...first string");
+    is_string("bar", cvector->strings[1], "...second string");
+    is_string("baz", cvector->strings[2], "...third string");
+    free(string);
+    cvector = cvector_split_multi(empty, ", ", NULL);
+    is_int(0, cvector->count, "cvector_split_multi reuse with empty string");
+    string = xstrdup(",,,  foo,   ");
+    cvector = cvector_split_multi(string, ", ", cvector);
+    is_int(1, cvector->count, "cvector_split_multi with extra separators");
+    is_string("foo", cvector->strings[0], "...first string");
+    free(string);
+    string = xstrdup(", ,  ");
+    cvector = cvector_split_multi(string, ", ", cvector);
+    is_int(0, cvector->count, "cvector_split_multi with only separators");
+    cvector_free(cvector);
+    free(string);
+
     vector = vector_new();
     vector_add(vector, "/bin/sh");
     vector_add(vector, "-c");
-    vector_add(vector, "echo ok 88");
+    snprintf(buffer, sizeof(buffer), "echo ok %lu - vector_exec", testnum++);
+    vector_add(vector, buffer);
     child = fork();
     if (child < 0)
-        sysdie("unable to fork");
+        sysbail("unable to fork");
     else if (child == 0)
         if (vector_exec("/bin/sh", vector) < 0)
-            syswarn("unable to exec /bin/sh");
+            sysdiag("unable to exec /bin/sh");
     waitpid(child, NULL, 0);
     vector_free(vector);
 
     cvector = cvector_new();
     cvector_add(cvector, "/bin/sh");
     cvector_add(cvector, "-c");
-    cvector_add(cvector, "echo ok 89");
+    snprintf(buffer, sizeof(buffer), "echo ok %lu - cvector_exec", testnum++);
+    cvector_add(cvector, buffer);
     child = fork();
     if (child < 0)
-        sysdie("unable to fork");
+        sysbail("unable to fork");
     else if (child == 0)
         if (cvector_exec("/bin/sh", cvector) < 0)
-            syswarn("unable to exec /bin/sh");
+            sysdiag("unable to exec /bin/sh");
     waitpid(child, NULL, 0);
     cvector_free(cvector);
 




More information about the inn-committers mailing list