int main(int argc, char *argv[]) { START(argc, argv, "util_ctl"); common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, MAJOR_VERSION, MINOR_VERSION); if (argc != 2) UT_FATAL("usage: %s testconfig", argv[0]); testconfig_path = argv[1]; CTL_REGISTER_MODULE(NULL, global_debug); test_ctl_global_namespace(NULL); struct pool *pop = malloc(sizeof(pop)); pop->ctl = ctl_new(); test_ctl_global_namespace(NULL); CTL_REGISTER_MODULE(pop->ctl, debug); test_ctl_global_namespace(pop); test_fault_injection(pop); test_ctl_parser(pop); test_string_config(pop); test_file_config(pop); test_ctl_arg_parsers(); ctl_delete(pop->ctl); free(pop); common_fini(); DONE(NULL); }
int ctl_connect(const char *dir, const char *file) { DIR *dp = NULL; if (str_empty(dir)) { errno = EINVAL; return -1; } if (!file) { dp = opendir(dir); if (!dp) return -1; struct dirent *d = NULL; while (d = readdir(dp), d) { if (d->d_name[0] == '.') continue; if (file) { closedir(dp); return -3; } file = &d->d_name[0]; } if (!file) { closedir(dp); return -2; } } struct sockaddr_un sun; const int ret = ctl_setsun(&sun, dir, file); if (dp) { int err = errno; closedir(dp); errno = err; } if (ret) return -1; int fd = ctl_create(dir, NULL); if (fd == -1) return -1; if (connect(fd, (struct sockaddr *)&sun, sizeof(sun))) { int err = errno; ctl_delete(fd); errno = err; return -1; } return fd; }