PyMODINIT_FUNC initpypcap(void) { PyObject *m; #ifdef __DEBUG_V_ talloc_enable_leak_report_full(); #endif m = Py_InitModule("pypcap", pypcapMethods); PyPCAPType.tp_new = PyType_GenericNew; PyPCAPType.tp_iter = PyObject_SelfIter; if (PyType_Ready(&PyPCAPType) < 0) return; Py_INCREF(&PyPCAPType); PyModule_AddObject(m, "PyPCAP", (PyObject *)&PyPCAPType); // Init our network module network_structs_init(); // Do all the local import statements: FIXME: handle the case where // we cant import it. g_pypacket_module = PyImport_ImportModule("pypacket"); }
int main(void) { int number_failed; int memdebug; int error; // Check if memdebug enabled memdebug = getenv("MEMDEBUG") ? atoi(getenv("MEMDEBUG")) : 0; if( memdebug ) { talloc_enable_leak_report_full(); } // Set up test suite Suite * s = parser_suite(); SRunner * sr = srunner_create(s); if( IS_WIN || memdebug ) { srunner_set_fork_status(sr, CK_NOFORK); } srunner_run_all(sr, CK_ENV); number_failed = srunner_ntests_failed(sr); srunner_free(sr); error = (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; // Generate report for memdebug if( memdebug ) { talloc_report_full(NULL, stderr); } // Return return error; }
int main(void) { int number_failed; Suite * s; SRunner * sr; int memdebug = 0; int iswin = 0; int error = 0; #if defined(_WIN64) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN32__) iswin = 1; #endif memdebug = getenv("MEMDEBUG") ? atoi(getenv("MEMDEBUG")) : 0; if( memdebug ) { talloc_enable_leak_report_full(); } rootctx = talloc_new(NULL); // Load the spec spec_filename = getenv("handlebars_tokenizer_spec"); if( spec_filename == NULL ) { spec_filename = "./spec/handlebars/spec/tokenizer.json"; } error = loadSpec(spec_filename); if( error != 0 ) { goto error; } fprintf(stderr, "Loaded %lu test cases\n", tests_len); s = parser_suite(); sr = srunner_create(s); if( iswin || memdebug ) { srunner_set_fork_status(sr, CK_NOFORK); } srunner_run_all(sr, CK_ENV); number_failed = srunner_ntests_failed(sr); srunner_free(sr); error = (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; error: talloc_free(rootctx); if( memdebug ) { talloc_report_full(NULL, stderr); } return error; }
/* miscellaneous tests to try to get a higher test coverage percentage */ static bool test_misc(void) { void *root, *p1; char *p2; double *d; const char *name; printf("test: misc\n# MISCELLANEOUS\n"); root = talloc_new(NULL); p1 = talloc_size(root, 0x7fffffff); torture_assert("misc", !p1, "failed: large talloc allowed\n"); p1 = talloc_strdup(root, "foo"); talloc_increase_ref_count(p1); talloc_increase_ref_count(p1); talloc_increase_ref_count(p1); CHECK_BLOCKS("misc", p1, 1); CHECK_BLOCKS("misc", root, 2); talloc_unlink(NULL, p1); CHECK_BLOCKS("misc", p1, 1); CHECK_BLOCKS("misc", root, 2); talloc_unlink(NULL, p1); CHECK_BLOCKS("misc", p1, 1); CHECK_BLOCKS("misc", root, 2); p2 = talloc_strdup(p1, "foo"); torture_assert("misc", talloc_unlink(root, p2) == -1, "failed: talloc_unlink() of non-reference context should return -1\n"); torture_assert("misc", talloc_unlink(p1, p2) == 0, "failed: talloc_unlink() of parent should succeed\n"); talloc_unlink(NULL, p1); CHECK_BLOCKS("misc", p1, 1); CHECK_BLOCKS("misc", root, 2); name = talloc_set_name(p1, "my name is %s", "foo"); torture_assert_str_equal("misc", talloc_get_name(p1), "my name is foo", "failed: wrong name after talloc_set_name(my name is foo)"); torture_assert_str_equal("misc", talloc_get_name(p1), name, "failed: wrong name after talloc_set_name(my name is foo)"); CHECK_BLOCKS("misc", p1, 2); CHECK_BLOCKS("misc", root, 3); talloc_set_name_const(p1, NULL); torture_assert_str_equal ("misc", talloc_get_name(p1), "UNNAMED", "failed: wrong name after talloc_set_name(NULL)"); CHECK_BLOCKS("misc", p1, 2); CHECK_BLOCKS("misc", root, 3); torture_assert("misc", talloc_free(NULL) == -1, "talloc_free(NULL) should give -1\n"); talloc_set_destructor(p1, fail_destructor); torture_assert("misc", talloc_free(p1) == -1, "Failed destructor should cause talloc_free to fail\n"); talloc_set_destructor(p1, NULL); talloc_report(root, stderr); p2 = (char *)talloc_zero_size(p1, 20); torture_assert("misc", p2[19] == 0, "Failed to give zero memory\n"); talloc_free(p2); torture_assert("misc", talloc_strdup(root, NULL) == NULL, "failed: strdup on NULL should give NULL\n"); p2 = talloc_strndup(p1, "foo", 2); torture_assert("misc", strcmp("fo", p2) == 0, "strndup doesn't work\n"); p2 = talloc_asprintf_append_buffer(p2, "o%c", 'd'); torture_assert("misc", strcmp("food", p2) == 0, "talloc_asprintf_append_buffer doesn't work\n"); CHECK_BLOCKS("misc", p2, 1); CHECK_BLOCKS("misc", p1, 3); p2 = talloc_asprintf_append_buffer(NULL, "hello %s", "world"); torture_assert("misc", strcmp("hello world", p2) == 0, "talloc_asprintf_append_buffer doesn't work\n"); CHECK_BLOCKS("misc", p2, 1); CHECK_BLOCKS("misc", p1, 3); talloc_free(p2); d = talloc_array(p1, double, 0x20000000); torture_assert("misc", !d, "failed: integer overflow not detected\n"); d = talloc_realloc(p1, d, double, 0x20000000); torture_assert("misc", !d, "failed: integer overflow not detected\n"); talloc_free(p1); CHECK_BLOCKS("misc", root, 1); p1 = talloc_named(root, 100, "%d bytes", 100); CHECK_BLOCKS("misc", p1, 2); CHECK_BLOCKS("misc", root, 3); talloc_unlink(root, p1); p1 = talloc_init("%d bytes", 200); p2 = talloc_asprintf(p1, "my test '%s'", "string"); torture_assert_str_equal("misc", p2, "my test 'string'", "failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\""); CHECK_BLOCKS("misc", p1, 3); CHECK_SIZE("misc", p2, 17); CHECK_BLOCKS("misc", root, 1); talloc_unlink(NULL, p1); p1 = talloc_named_const(root, 10, "p1"); p2 = (char *)talloc_named_const(root, 20, "p2"); (void)talloc_reference(p1, p2); talloc_report_full(root, stderr); talloc_unlink(root, p2); talloc_report_full(root, stderr); CHECK_BLOCKS("misc", p2, 1); CHECK_BLOCKS("misc", p1, 2); CHECK_BLOCKS("misc", root, 3); talloc_unlink(p1, p2); talloc_unlink(root, p1); p1 = talloc_named_const(root, 10, "p1"); p2 = (char *)talloc_named_const(root, 20, "p2"); (void)talloc_reference(NULL, p2); talloc_report_full(root, stderr); talloc_unlink(root, p2); talloc_report_full(root, stderr); CHECK_BLOCKS("misc", p2, 1); CHECK_BLOCKS("misc", p1, 1); CHECK_BLOCKS("misc", root, 2); talloc_unlink(NULL, p2); talloc_unlink(root, p1); /* Test that talloc_unlink is a no-op */ torture_assert("misc", talloc_unlink(root, NULL) == -1, "failed: talloc_unlink(root, NULL) == -1\n"); talloc_report(root, stderr); talloc_report(NULL, stderr); CHECK_SIZE("misc", root, 0); talloc_free(root); CHECK_SIZE("misc", NULL, 0); talloc_enable_null_tracking_no_autofree(); talloc_enable_leak_report(); talloc_enable_leak_report_full(); printf("success: misc\n"); return true; }
static void popt_samba_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { const char *pname; if (reason == POPT_CALLBACK_REASON_POST) { if (lp_configfile(cmdline_lp_ctx) == NULL) { lp_load_default(cmdline_lp_ctx); } /* Hook any 'every Samba program must do this, after * the smb.conf is setup' functions here */ return; } /* Find out basename of current program */ pname = strrchr_m(poptGetInvocationName(con),'/'); if (!pname) pname = poptGetInvocationName(con); else pname++; if (reason == POPT_CALLBACK_REASON_PRE) { cmdline_lp_ctx = loadparm_init(talloc_autofree_context()); /* Hook for 'almost the first thing to do in a samba program' here */ /* setup for panics */ fault_setup(poptGetInvocationName(con)); /* and logging */ setup_logging(pname, DEBUG_STDOUT); return; } switch(opt->val) { case OPT_LEAK_REPORT: talloc_enable_leak_report(); break; case OPT_LEAK_REPORT_FULL: talloc_enable_leak_report_full(); break; case OPT_OPTION: if (!lp_set_option(cmdline_lp_ctx, arg)) { fprintf(stderr, "Error setting option '%s'\n", arg); exit(1); } break; case 'd': lp_set_cmdline(cmdline_lp_ctx, "log level", arg); break; case OPT_DEBUG_STDERR: setup_logging(pname, DEBUG_STDERR); break; case 's': if (arg) { lp_load(cmdline_lp_ctx, arg); } break; case 'l': if (arg) { char *new_logfile = talloc_asprintf(NULL, "%s/log.%s", arg, pname); lp_set_cmdline(cmdline_lp_ctx, "log file", new_logfile); talloc_free(new_logfile); } break; } }
/* sec_mod_server: * @config: server configuration * @socket_file: the name of the socket * @cmd_fd: socket to exchange commands with main * @cmd_fd_sync: socket to received sync commands from main * * This is the main part of the security module. * It creates the unix domain socket identified by @socket_file * and then accepts connections from the workers to it. Then * it serves commands requested on the server's private key. * * When the operation is decrypt the provided data are * decrypted and sent back to worker. The sign operation * signs the provided data. * * The security module's reply to the worker has the * following format: * byte[0-5]: length (uint32_t) * byte[5-total]: data (signature or decrypted data) * * The reason for having this as a separate process * is to avoid any bug on the workers to leak the key. * It is not part of main because workers are spawned * from main, and thus should be prevented from accessing * parts the key in stack or heap that was not zeroized. * Other than that it allows the main server to spawn * clients fast without becoming a bottleneck due to private * key operations. */ void sec_mod_server(void *main_pool, struct perm_cfg_st *perm_config, const char *socket_file, int cmd_fd, int cmd_fd_sync) { struct sockaddr_un sa; socklen_t sa_len; int cfd, ret, e, n; unsigned buffer_size; uid_t uid; uint8_t *buffer; int sd; sec_mod_st *sec; void *sec_mod_pool; fd_set rd_set; pid_t pid; #ifdef HAVE_PSELECT struct timespec ts; #else struct timeval ts; #endif sigset_t emptyset, blockset; #ifdef DEBUG_LEAKS talloc_enable_leak_report_full(); #endif sigemptyset(&blockset); sigemptyset(&emptyset); sigaddset(&blockset, SIGALRM); sigaddset(&blockset, SIGTERM); sigaddset(&blockset, SIGINT); sigaddset(&blockset, SIGHUP); sec_mod_pool = talloc_init("sec-mod"); if (sec_mod_pool == NULL) { seclog(sec, LOG_ERR, "error in memory allocation"); exit(1); } sec = talloc_zero(sec_mod_pool, sec_mod_st); if (sec == NULL) { seclog(sec, LOG_ERR, "error in memory allocation"); exit(1); } sec->perm_config = talloc_steal(sec, perm_config); sec->config = sec->perm_config->config; tls_cache_init(sec, &sec->tls_db); sup_config_init(sec); memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; strlcpy(sa.sun_path, socket_file, sizeof(sa.sun_path)); remove(socket_file); #define SOCKET_FILE sa.sun_path /* we no longer need the main pool after this point. */ talloc_free(main_pool); ocsignal(SIGHUP, handle_sighup); ocsignal(SIGINT, handle_sigterm); ocsignal(SIGTERM, handle_sigterm); ocsignal(SIGALRM, handle_alarm); sec_auth_init(sec, perm_config); sec->cmd_fd = cmd_fd; sec->cmd_fd_sync = cmd_fd_sync; #ifdef HAVE_PKCS11 ret = gnutls_pkcs11_reinit(); if (ret < 0) { seclog(sec, LOG_WARNING, "error in PKCS #11 reinitialization: %s", gnutls_strerror(ret)); } #endif if (sec_mod_client_db_init(sec) == NULL) { seclog(sec, LOG_ERR, "error in client db initialization"); exit(1); } sd = socket(AF_UNIX, SOCK_STREAM, 0); if (sd == -1) { e = errno; seclog(sec, LOG_ERR, "could not create socket '%s': %s", SOCKET_FILE, strerror(e)); exit(1); } set_cloexec_flag(sd, 1); umask(066); ret = bind(sd, (struct sockaddr *)&sa, SUN_LEN(&sa)); if (ret == -1) { e = errno; seclog(sec, LOG_ERR, "could not bind socket '%s': %s", SOCKET_FILE, strerror(e)); exit(1); } ret = chown(SOCKET_FILE, perm_config->uid, perm_config->gid); if (ret == -1) { e = errno; seclog(sec, LOG_INFO, "could not chown socket '%s': %s", SOCKET_FILE, strerror(e)); } ret = listen(sd, 1024); if (ret == -1) { e = errno; seclog(sec, LOG_ERR, "could not listen to socket '%s': %s", SOCKET_FILE, strerror(e)); exit(1); } ret = load_keys(sec, 1); if (ret < 0) { seclog(sec, LOG_ERR, "error loading private key files"); exit(1); } sigprocmask(SIG_BLOCK, &blockset, &sig_default_set); alarm(MAINTAINANCE_TIME); seclog(sec, LOG_INFO, "sec-mod initialized (socket: %s)", SOCKET_FILE); for (;;) { check_other_work(sec); FD_ZERO(&rd_set); n = 0; FD_SET(cmd_fd, &rd_set); n = MAX(n, cmd_fd); FD_SET(cmd_fd_sync, &rd_set); n = MAX(n, cmd_fd_sync); FD_SET(sd, &rd_set); n = MAX(n, sd); #ifdef HAVE_PSELECT ts.tv_nsec = 0; ts.tv_sec = 120; ret = pselect(n + 1, &rd_set, NULL, NULL, &ts, &emptyset); #else ts.tv_usec = 0; ts.tv_sec = 120; sigprocmask(SIG_UNBLOCK, &blockset, NULL); ret = select(n + 1, &rd_set, NULL, NULL, &ts); sigprocmask(SIG_BLOCK, &blockset, NULL); #endif if (ret == 0 || (ret == -1 && errno == EINTR)) continue; if (ret < 0) { e = errno; seclog(sec, LOG_ERR, "Error in pselect(): %s", strerror(e)); exit(1); } /* we do a new allocation, to also use it as pool for the * parsers to use */ buffer_size = MAX_MSG_SIZE; buffer = talloc_size(sec, buffer_size); if (buffer == NULL) { seclog(sec, LOG_ERR, "error in memory allocation"); exit(1); } /* we use two fds for communication with main. The synchronous is for * ping-pong communication which each request is answered immediated. The * async is for messages sent back and forth in no particular order */ if (FD_ISSET(cmd_fd_sync, &rd_set)) { ret = serve_request_main(sec, cmd_fd_sync, buffer, buffer_size); if (ret < 0 && ret == ERR_BAD_COMMAND) { seclog(sec, LOG_ERR, "error processing sync command from main"); exit(1); } } if (FD_ISSET(cmd_fd, &rd_set)) { ret = serve_request_main(sec, cmd_fd, buffer, buffer_size); if (ret < 0 && ret == ERR_BAD_COMMAND) { seclog(sec, LOG_ERR, "error processing async command from main"); exit(1); } } if (FD_ISSET(sd, &rd_set)) { sa_len = sizeof(sa); cfd = accept(sd, (struct sockaddr *)&sa, &sa_len); if (cfd == -1) { e = errno; if (e != EINTR) { seclog(sec, LOG_DEBUG, "sec-mod error accepting connection: %s", strerror(e)); goto cont; } } set_cloexec_flag (cfd, 1); /* do not allow unauthorized processes to issue commands */ ret = check_upeer_id("sec-mod", sec->perm_config->debug, cfd, perm_config->uid, perm_config->gid, &uid, &pid); if (ret < 0) { seclog(sec, LOG_INFO, "rejected unauthorized connection"); } else { memset(buffer, 0, buffer_size); serve_request_worker(sec, cfd, pid, buffer, buffer_size); } close(cfd); } cont: talloc_free(buffer); #ifdef DEBUG_LEAKS talloc_report_full(sec, stderr); #endif } }
/** * main program */ int main(int argc, const char *argv[]) { enum MAPISTATUS retval; int32_t num_tests_failed; TALLOC_CTX *mem_ctx; struct mapitest mt; poptContext pc; int opt; bool ret; bool opt_dumpdata = false; const char *opt_debug = NULL; const char *opt_profdb = NULL; char *opt_profname = NULL; const char *opt_password = NULL; const char *opt_outfile = NULL; char *prof_tmp = NULL; bool opt_leak_report = false; bool opt_leak_report_full = false; enum { OPT_PROFILE_DB=1000, OPT_PROFILE, OPT_PASSWORD, OPT_CONFIDENTIAL, OPT_OUTFILE, OPT_MAPI_CALLS, OPT_NO_SERVER, OPT_LIST_ALL, OPT_DUMP_DATA, OPT_DEBUG, OPT_COLOR, OPT_SUBUNIT, OPT_LEAK_REPORT, OPT_LEAK_REPORT_FULL }; struct poptOption long_options[] = { POPT_AUTOHELP { "database", 'f', POPT_ARG_STRING, NULL, OPT_PROFILE_DB, "set the profile database", NULL }, { "profile", 'p', POPT_ARG_STRING, NULL, OPT_PROFILE, "set the profile name", NULL }, { "password", 'p', POPT_ARG_STRING, NULL, OPT_PASSWORD, "set the profile or account password", NULL }, { "confidential", 0, POPT_ARG_NONE, NULL, OPT_CONFIDENTIAL, "remove any sensitive data from the report", NULL }, { "color", 0, POPT_ARG_NONE, NULL, OPT_COLOR, "color MAPI retval", NULL }, #if HAVE_SUBUNIT { "subunit", 0, POPT_ARG_NONE, NULL, OPT_SUBUNIT, "output in subunit protocol format", NULL }, #endif { "outfile", 'o', POPT_ARG_STRING, NULL, OPT_OUTFILE, "set the report output file", NULL }, { "mapi-calls", 0, POPT_ARG_STRING, NULL, OPT_MAPI_CALLS, "test custom ExchangeRPC tests", NULL }, { "list-all", 0, POPT_ARG_NONE, NULL, OPT_LIST_ALL, "list suite and tests - names and description", NULL }, { "no-server", 0, POPT_ARG_NONE, NULL, OPT_NO_SERVER, "only run tests that do not require server connection", NULL }, { "dump-data", 0, POPT_ARG_NONE, NULL, OPT_DUMP_DATA, "dump the hex data", NULL }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, OPT_DEBUG, "set debug level", NULL }, { "leak-report", 0, POPT_ARG_NONE, NULL, OPT_LEAK_REPORT, "enable talloc leak reporting on exit", NULL }, { "leak-report-full", 0, POPT_ARG_NONE, NULL, OPT_LEAK_REPORT_FULL, "enable full talloc leak reporting on exit", NULL }, POPT_OPENCHANGE_VERSION { NULL, 0, 0, NULL, 0, NULL, NULL } }; mem_ctx = talloc_named(NULL, 0, "mapitest"); mapitest_init(mem_ctx, &mt); mapitest_register_modules(&mt); pc = poptGetContext("mapitest", argc, argv, long_options, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_DUMP_DATA: opt_dumpdata = true; break; case OPT_DEBUG: opt_debug = poptGetOptArg(pc); break; case OPT_PROFILE_DB: opt_profdb = poptGetOptArg(pc); break; case OPT_PROFILE: prof_tmp = poptGetOptArg(pc); opt_profname = talloc_strdup(mem_ctx, prof_tmp); free(prof_tmp); prof_tmp = NULL; break; case OPT_PASSWORD: opt_password = poptGetOptArg(pc); break; case OPT_CONFIDENTIAL: mt.confidential = true; break; case OPT_OUTFILE: opt_outfile = poptGetOptArg(pc); break; case OPT_MAPI_CALLS: ret = mapitest_get_testnames(mem_ctx, &mt, poptGetOptArg(pc)); if (ret == false) exit (-1); mt.mapi_all = false; break; case OPT_NO_SERVER: mt.no_server = true; break; case OPT_COLOR: mt.color = true; break; case OPT_SUBUNIT: mt.subunit_output = true; break; case OPT_LIST_ALL: mapitest_list(&mt, NULL); talloc_free(mem_ctx); poptFreeContext(pc); return 0; break; case OPT_LEAK_REPORT: opt_leak_report = true; talloc_enable_leak_report(); break; case OPT_LEAK_REPORT_FULL: opt_leak_report_full = true; talloc_enable_leak_report_full(); break; } } poptFreeContext(pc); /* Sanity check */ if (mt.cmdline_calls && (mt.mapi_all == true)) { fprintf(stderr, "mapi-calls and mapi-all can't be set at the same time\n"); return -1; } /* Initialize MAPI subsystem */ if (!opt_profdb) { opt_profdb = talloc_asprintf(mem_ctx, DEFAULT_PROFDB, getenv("HOME")); } retval = MAPIInitialize(&(mt.mapi_ctx), opt_profdb); if (retval != MAPI_E_SUCCESS) { mapi_errstr("MAPIInitialize", retval); return -2; } mapitest_init_stream(&mt, opt_outfile); mt.online = mapitest_get_server_info(&mt, opt_profname, opt_password, opt_dumpdata, opt_debug); mapitest_print_headers(&mt); /* Do not run any tests if we couldn't find a profile or if * server is offline and connection to server was implicitly * specified */ if (!opt_profname && mt.online == false && mt.no_server == false) { fprintf(stderr, "No MAPI profile found for online tests\n"); return -2; } /* Run custom tests */ if (mt.cmdline_calls) { struct mapitest_unit *el; for (el = mt.cmdline_calls; el; el = el->next) { printf("[*] %s\n", el->name); mapitest_run_test(&mt, el->name); } } else { mapitest_run_all(&mt); } num_tests_failed = mapitest_stat_dump(&mt); mapitest_cleanup_stream(&mt); /* Uninitialize and free memory */ MAPIUninitialize(mt.mapi_ctx); talloc_free(mt.mem_ctx); if (opt_leak_report) { talloc_report(NULL, stdout); } if (opt_leak_report_full) { talloc_report_full(NULL, stdout); } return num_tests_failed; }
int main(int argc, char **argv) { int fd, fd_slow, fd_data, argch; int bps = 38400; int hwflow = 0; char *device = NULL; char *slowdevice = NULL; char *datadevice = NULL; char *vendor_name = NULL; char *machine_name = NULL; int wait = -1; signal(SIGTERM, sig_handler); signal(SIGINT, sig_handler); signal(SIGUSR1, sig_handler); signal(SIGALRM, sig_handler); gsmd_tallocs = talloc_named_const(NULL, 1, "GSMD"); print_header(); /*FIXME: parse commandline, set daemonize, device, ... */ while ((argch = getopt_long(argc, argv, "FVLdhp:P:D:s:l:v:m:w:", opts, NULL)) != -1) { switch (argch) { case 'V': print_version(); exit(0); break; case 'L': talloc_enable_leak_report_full(); break; case 'F': hwflow = 1; break; case 'd': daemonize = 1; break; case 'h': /* FIXME */ print_usage(); exit(0); break; case 'p': device = optarg; break; case 'P': slowdevice = optarg; break; case 'D': datadevice = optarg; break; case 's': bps = atoi(optarg); break; case 'l': if (gsmdlog_init(optarg)) { fprintf(stderr, "can't open logfile `%s'\n", optarg); exit(2); } break; case 'v': vendor_name = optarg; break; case 'm': machine_name = optarg; break; case 'w': wait = atoi(optarg); break; } } if (!device) { fprintf(stderr, "ERROR: you have to specify a port (-p port)\n"); print_usage(); exit(2); } fd = gsmd_open_serial(device, bps, hwflow); g_main = malloc (sizeof(struct gsmd)); if (gsmd_initialize(g_main) < 0) { fprintf(stderr, "internal error - main channel\n"); exit(1); } #ifdef GSMD_SLOW_MUX_DEVICE if (slowdevice) { fd_slow = gsmd_open_serial(slowdevice, bps, hwflow); g_slow = malloc (sizeof(struct gsmd)); if (gsmd_initialize(g_slow) < 0) { fprintf(stderr, "internal error - slow channel\n"); g_slow = g_main; } } else #endif g_slow = g_main; #ifdef GSMD_DATA_MUX_DEVICE if (datadevice) { fd_data = gsmd_open_serial(datadevice, bps, hwflow); /*FIXME*/ write(fd_data, "AT&F1\r", 6); } #endif gsmd_timer_init(); if (gsmd_machine_plugin_init(g_main, machine_name, vendor_name) < 0) { fprintf(stderr, "no machine plugins found\n"); exit(1); } /* initialize the machine plugin */ if (g_main->machinepl->init && (g_main->machinepl->init(g_main, fd) < 0)) { fprintf(stderr, "couldn't initialize machine plugin\n"); exit(1); } if (wait >= 0) g_main->interpreter_ready = !wait; if (atcmd_init(g_main, fd) < 0) { fprintf(stderr, "can't initialize main UART device\n"); exit(1); } #ifdef GSMD_SLOW_MUX_DEVICE if (atcmd_init(g_slow, fd_slow) < 0) { fprintf(stderr, "can't initialize slow UART device\n"); g_slow = g_main; } #endif write(fd, "\r", 1); atcmd_drain(fd); if (usock_init(g_main) < 0) { fprintf(stderr, "can't open T-BUS connection\n"); exit(1); } /* select a vendor plugin */ gsmd_vendor_plugin_find(g_main); unsolicited_init(g_main); if (g_main->interpreter_ready) { gsmd_initsettings(g_main); gsmd_initsettings_slow(g_slow); gsmd_alive_start(g_main); } gsmd_opname_init(g_main); while (1) { int ret = gsmd_select_main(); if (ret == 0) continue; if (ret < 0) { if (errno == EINTR) continue; else { DEBUGP("select returned error (%s)\n", strerror(errno)); break; } } } tbus_close(); ShmUnmap(g_main->shmem); free (g_main); free (g_slow); exit(0); }