From 8a7fb0cf6844ed09173fd58224f7753a1b504cf4 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Fri, 8 Jul 2016 14:44:23 -0400 Subject: fd-io-styleify for svm Change-Id: I816de8b1f255dc3bc6d2904566ea0b0f68fac5d8 Signed-off-by: Dave Barach --- svm/svmdbtool.c | 464 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 260 insertions(+), 204 deletions(-) (limited to 'svm/svmdbtool.c') diff --git a/svm/svmdbtool.c b/svm/svmdbtool.c index c2efbc52a34..cf475c4d1ba 100644 --- a/svm/svmdbtool.c +++ b/svm/svmdbtool.c @@ -38,289 +38,345 @@ #include #include "svmdb.h" -static void get_string (char *chroot_path, u8 *vbl) +static void +get_string (char *chroot_path, u8 * vbl) { - svmdb_client_t *c; - char *rv; + svmdb_client_t *c; + char *rv; - c = svmdb_map_chroot(chroot_path); + c = svmdb_map_chroot (chroot_path); - rv = svmdb_local_get_string_variable (c, (char *)vbl); - - fformat(stdout, "%s\n", rv ? rv : "UNSET"); - vec_free(rv); - svmdb_unmap (c); + rv = svmdb_local_get_string_variable (c, (char *) vbl); + + fformat (stdout, "%s\n", rv ? rv : "UNSET"); + vec_free (rv); + svmdb_unmap (c); } -static void set_string (char *chroot_path, u8 *vbl, u8 *value) +static void +set_string (char *chroot_path, u8 * vbl, u8 * value) { - svmdb_client_t *c; + svmdb_client_t *c; - c = svmdb_map_chroot(chroot_path); - svmdb_local_set_string_variable (c, (char *)vbl, (char *)value); - svmdb_unmap (c); + c = svmdb_map_chroot (chroot_path); + svmdb_local_set_string_variable (c, (char *) vbl, (char *) value); + svmdb_unmap (c); } -static void unset_string (char *chroot_path, u8 *vbl) +static void +unset_string (char *chroot_path, u8 * vbl) { - svmdb_client_t *c; + svmdb_client_t *c; - c = svmdb_map_chroot(chroot_path); - svmdb_local_unset_string_variable (c, (char *)vbl); - svmdb_unmap (c); + c = svmdb_map_chroot (chroot_path); + svmdb_local_unset_string_variable (c, (char *) vbl); + svmdb_unmap (c); } -static void dump_strings(char *chroot_path) +static void +dump_strings (char *chroot_path) { - svmdb_client_t *c; + svmdb_client_t *c; - c = svmdb_map_chroot(chroot_path); - svmdb_local_dump_strings (c); - svmdb_unmap (c); + c = svmdb_map_chroot (chroot_path); + svmdb_local_dump_strings (c); + svmdb_unmap (c); } -static void test_vlib_vec_rate (char *chroot_path, f64 vr) +static void +test_vlib_vec_rate (char *chroot_path, f64 vr) { - svmdb_client_t *c; - f64 *tv = 0; + svmdb_client_t *c; + f64 *tv = 0; - vec_add1 (tv, vr); + vec_add1 (tv, vr); - c = svmdb_map_chroot(chroot_path); + c = svmdb_map_chroot (chroot_path); - svmdb_local_set_vec_variable (c, "vlib_vector_rate", (char *)tv, sizeof (*tv)); - svmdb_unmap (c); + svmdb_local_set_vec_variable (c, "vlib_vector_rate", (char *) tv, + sizeof (*tv)); + svmdb_unmap (c); - vec_free(tv); + vec_free (tv); } -static void test_vec (char *chroot_path, u8 *vbl) +static void +test_vec (char *chroot_path, u8 * vbl) { - svmdb_client_t *c; - u64 *tv = 0; - int i; - - /* my amp goes to 11 */ - for (i = 0; i < 11; i++) { - vec_add1(tv, i); + svmdb_client_t *c; + u64 *tv = 0; + int i; + + /* my amp goes to 11 */ + for (i = 0; i < 11; i++) + { + vec_add1 (tv, i); } - c = svmdb_map_chroot(chroot_path); - svmdb_local_set_vec_variable (c, (char *)vbl, (char *)tv, sizeof (tv[0])); - svmdb_unmap (c); + c = svmdb_map_chroot (chroot_path); + svmdb_local_set_vec_variable (c, (char *) vbl, (char *) tv, sizeof (tv[0])); + svmdb_unmap (c); - vec_free(tv); + vec_free (tv); } -static void fake_install (char *chroot_path, u8 *add_value) +static void +fake_install (char *chroot_path, u8 * add_value) { - svmdb_client_t *c; - u8 *v = 0; - u8 **values = 0; - u8 *oldvalue; - u8 *value; - int nitems = 0, i; - serialize_main_t m; - - c = svmdb_map_chroot(chroot_path); - - oldvalue = svmdb_local_get_vec_variable (c, "installed_sw", 1); - if (oldvalue) { - unserialize_open_data (&m, oldvalue, vec_len (oldvalue)); - nitems = unserialize_likely_small_unsigned_integer (&m); - for (i = 0; i < nitems; i++) { - unserialize_cstring (&m, (char **)&value); - vec_add1 (values, value); - } - vec_free (v); + svmdb_client_t *c; + u8 *v = 0; + u8 **values = 0; + u8 *oldvalue; + u8 *value; + int nitems = 0, i; + serialize_main_t m; + + c = svmdb_map_chroot (chroot_path); + + oldvalue = svmdb_local_get_vec_variable (c, "installed_sw", 1); + if (oldvalue) + { + unserialize_open_data (&m, oldvalue, vec_len (oldvalue)); + nitems = unserialize_likely_small_unsigned_integer (&m); + for (i = 0; i < nitems; i++) + { + unserialize_cstring (&m, (char **) &value); + vec_add1 (values, value); + } + vec_free (v); } - nitems++; - value = format (0, "%s%c", add_value, 0); + nitems++; + value = format (0, "%s%c", add_value, 0); - vec_add1 (values, value); + vec_add1 (values, value); - fformat (stdout, "Resulting installed_sw vector:\n"); + fformat (stdout, "Resulting installed_sw vector:\n"); - serialize_open_vector (&m, v); - serialize_likely_small_unsigned_integer (&m, vec_len (values)); - for (i = 0; i < vec_len (values); i++) { - fformat (stdout, "%s\n", values[i]); - serialize_cstring (&m, (char *)values[i]); + serialize_open_vector (&m, v); + serialize_likely_small_unsigned_integer (&m, vec_len (values)); + for (i = 0; i < vec_len (values); i++) + { + fformat (stdout, "%s\n", values[i]); + serialize_cstring (&m, (char *) values[i]); } - v = serialize_close_vector (&m); + v = serialize_close_vector (&m); - svmdb_local_set_vec_variable (c, "installed_sw", v, sizeof (v[0])); - svmdb_unmap (c); + svmdb_local_set_vec_variable (c, "installed_sw", v, sizeof (v[0])); + svmdb_unmap (c); - for (i = 0; i < vec_len (values); i++) - vec_free (values[i]); - vec_free (values); + for (i = 0; i < vec_len (values); i++) + vec_free (values[i]); + vec_free (values); } -static void sigaction_handler (int signum, siginfo_t *i, void *notused) +static void +sigaction_handler (int signum, siginfo_t * i, void *notused) { - u32 action, opaque; + u32 action, opaque; - action = (u32)(uword) i->si_ptr; - action >>= 28; - opaque = (u32)(uword) i->si_ptr; - opaque &= ~(0xF0000000); + action = (u32) (uword) i->si_ptr; + action >>= 28; + opaque = (u32) (uword) i->si_ptr; + opaque &= ~(0xF0000000); - clib_warning ("signal %d, action %d, opaque %x", - signum, action, opaque); + clib_warning ("signal %d, action %d, opaque %x", signum, action, opaque); } -static void test_reg (char *chroot_path, u8 *vbl) +static void +test_reg (char *chroot_path, u8 * vbl) { - svmdb_client_t *c; - svmdb_notification_args_t args; - svmdb_notification_args_t *a = &args; - struct sigaction sa; - - memset (&sa, 0, sizeof (sa)); - sa.sa_sigaction = sigaction_handler; - sa.sa_flags = SA_SIGINFO; - if (sigaction (SIGUSR2, &sa, 0) < 0) { - clib_unix_warning ("sigaction"); - return; + svmdb_client_t *c; + svmdb_notification_args_t args; + svmdb_notification_args_t *a = &args; + struct sigaction sa; + + memset (&sa, 0, sizeof (sa)); + sa.sa_sigaction = sigaction_handler; + sa.sa_flags = SA_SIGINFO; + if (sigaction (SIGUSR2, &sa, 0) < 0) + { + clib_unix_warning ("sigaction"); + return; } - memset (a, 0, sizeof (*a)); + memset (a, 0, sizeof (*a)); + + c = svmdb_map_chroot (chroot_path); - c = svmdb_map_chroot(chroot_path); + a->add_del = 1 /* add */ ; + a->nspace = SVMDB_NAMESPACE_STRING; + a->var = (char *) vbl; + a->elsize = 1; + a->signum = SIGUSR2; + a->action = SVMDB_ACTION_GET; + a->opaque = 0x0eadbeef; - a->add_del = 1 /* add */; - a->nspace = SVMDB_NAMESPACE_STRING; - a->var = (char *) vbl; - a->elsize = 1; - a->signum = SIGUSR2; - a->action = SVMDB_ACTION_GET; - a->opaque = 0x0eadbeef; + svmdb_local_add_del_notification (c, a); - svmdb_local_add_del_notification (c, a); + (void) svmdb_local_get_string_variable (c, (char *) vbl); - (void) svmdb_local_get_string_variable (c, (char *)vbl); + a->add_del = 0; /* del */ + svmdb_local_add_del_notification (c, a); - a->add_del = 0; /* del */ - svmdb_local_add_del_notification (c, a); - - - svmdb_unmap (c); + + svmdb_unmap (c); } -static void unset_vec (char *chroot_path, u8 *vbl) +static void +unset_vec (char *chroot_path, u8 * vbl) { - svmdb_client_t *c; + svmdb_client_t *c; - c = svmdb_map_chroot(chroot_path); - svmdb_local_unset_vec_variable (c, (char *)vbl); - svmdb_unmap (c); + c = svmdb_map_chroot (chroot_path); + svmdb_local_unset_vec_variable (c, (char *) vbl); + svmdb_unmap (c); } -static void dump_vecs(char *chroot_path) +static void +dump_vecs (char *chroot_path) { - svmdb_client_t *c; + svmdb_client_t *c; - c = svmdb_map_chroot(chroot_path); - svmdb_local_dump_vecs (c); - svmdb_unmap (c); + c = svmdb_map_chroot (chroot_path); + svmdb_local_dump_vecs (c); + svmdb_unmap (c); } -static void crash_test(char *chroot_path) +static void +crash_test (char *chroot_path) { - svmdb_client_t *c; + svmdb_client_t *c; - c = svmdb_map_chroot(chroot_path); + c = svmdb_map_chroot (chroot_path); - clib_warning ("Grab region mutex and crash deliberately!"); - c->db_rp->mutex_owner_pid = getpid(); - c->db_rp->mutex_owner_tag = -13; - pthread_mutex_lock(&c->db_rp->mutex); + clib_warning ("Grab region mutex and crash deliberately!"); + c->db_rp->mutex_owner_pid = getpid (); + c->db_rp->mutex_owner_tag = -13; + pthread_mutex_lock (&c->db_rp->mutex); - abort(); + abort (); } -static void map_with_size (char *chroot_path, uword size) +static void +map_with_size (char *chroot_path, uword size) { - svmdb_client_t *c; - c = svmdb_map_chroot_size (chroot_path, size); - svmdb_unmap (c); + svmdb_client_t *c; + c = svmdb_map_chroot_size (chroot_path, size); + svmdb_unmap (c); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { - unformat_input_t input; - int parsed =0; - u8 *vbl=0, *value=0; - char *chroot_path = 0; - u8 *chroot_path_u8; - uword size; - f64 vr; - - unformat_init_command_line (&input, argv); - - while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) { - if (unformat (&input, "get-string %s", &vbl)) { - get_string (chroot_path, vbl); - vec_free(vbl); - parsed++; - } else if (unformat (&input, "set-string %s %s", &vbl, &value)) { - set_string (chroot_path, vbl, value); - vec_free(vbl); - vec_free(value); - parsed++; - } else if (unformat(&input, "unset-string %s", &vbl)) { - unset_string (chroot_path, vbl); - vec_free(vbl); - parsed++; - } else if (unformat(&input, "dump-strings")) { - dump_strings(chroot_path); - parsed++; - } else if (unformat(&input, "unset-vec %s", &vbl)) { - unset_vec (chroot_path, vbl); - vec_free(vbl); - parsed++; - } else if (unformat(&input, "dump-vecs")) { - dump_vecs(chroot_path); - parsed++; - } else if (unformat (&input, "test-vec %s", &vbl)) { - test_vec(chroot_path, vbl); - // vec_free(vbl); - parsed++; - } else if (unformat (&input, "vlib-vec-rate %f", &vr)) { - test_vlib_vec_rate(chroot_path, vr); - parsed++; - } else if (unformat (&input, "test-reg %s", &vbl)) { - test_reg(chroot_path, vbl); - parsed++; - } else if (unformat (&input, "crash-test")) { - crash_test (chroot_path); - } else if (unformat (&input, "chroot %s", &chroot_path_u8)) { - chroot_path = (char *) chroot_path_u8; - } else if (unformat (&input, "fake-install %s", &value)) { - fake_install (chroot_path, value); - parsed++; - } else if (unformat (&input, "size %d", &size)) { - map_with_size (chroot_path, size); - parsed++; - } else { - break; - } + unformat_input_t input; + int parsed = 0; + u8 *vbl = 0, *value = 0; + char *chroot_path = 0; + u8 *chroot_path_u8; + uword size; + f64 vr; + + unformat_init_command_line (&input, argv); + + while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (&input, "get-string %s", &vbl)) + { + get_string (chroot_path, vbl); + vec_free (vbl); + parsed++; + } + else if (unformat (&input, "set-string %s %s", &vbl, &value)) + { + set_string (chroot_path, vbl, value); + vec_free (vbl); + vec_free (value); + parsed++; + } + else if (unformat (&input, "unset-string %s", &vbl)) + { + unset_string (chroot_path, vbl); + vec_free (vbl); + parsed++; + } + else if (unformat (&input, "dump-strings")) + { + dump_strings (chroot_path); + parsed++; + } + else if (unformat (&input, "unset-vec %s", &vbl)) + { + unset_vec (chroot_path, vbl); + vec_free (vbl); + parsed++; + } + else if (unformat (&input, "dump-vecs")) + { + dump_vecs (chroot_path); + parsed++; + } + else if (unformat (&input, "test-vec %s", &vbl)) + { + test_vec (chroot_path, vbl); + // vec_free(vbl); + parsed++; + } + else if (unformat (&input, "vlib-vec-rate %f", &vr)) + { + test_vlib_vec_rate (chroot_path, vr); + parsed++; + } + else if (unformat (&input, "test-reg %s", &vbl)) + { + test_reg (chroot_path, vbl); + parsed++; + } + else if (unformat (&input, "crash-test")) + { + crash_test (chroot_path); + } + else if (unformat (&input, "chroot %s", &chroot_path_u8)) + { + chroot_path = (char *) chroot_path_u8; + } + else if (unformat (&input, "fake-install %s", &value)) + { + fake_install (chroot_path, value); + parsed++; + } + else if (unformat (&input, "size %d", &size)) + { + map_with_size (chroot_path, size); + parsed++; + } + else + { + break; + } } - unformat_free (&input); + unformat_free (&input); - if (!parsed) { - fformat(stdout, "%s: get-string | set-string \n", - argv[0]); - fformat(stdout, " unset-string | dump-strings\n"); - fformat(stdout, " test-vec |\n"); - fformat(stdout, " unset-vec | dump-vecs\n"); + if (!parsed) + { + fformat (stdout, "%s: get-string | set-string \n", + argv[0]); + fformat (stdout, " unset-string | dump-strings\n"); + fformat (stdout, " test-vec |\n"); + fformat (stdout, " unset-vec | dump-vecs\n"); } - - exit (0); + + exit (0); } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg