int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(stdio_auto); MBED_HOSTTEST_DESCRIPTION(stdio); MBED_HOSTTEST_START("MBED_2"); DigitalOut led1(LED1); DigitalOut led2(LED2); int value_int; notify_start(); // Just to sync with host test supervisor const char* PRINT_PATTERN = "MBED: Your value was: %d\r\n"; while (true) { // SCANF PRINTF family value_int = 0; led1 = 1; scanf("%d", &value_int); printf(PRINT_PATTERN, value_int); led1 = 0; // FSCANF, FPRINTF family value_int = 0; led2 = 1; fscanf(stdin, "%d", &value_int); fprintf(stdout, PRINT_PATTERN, value_int); led2 = 0; } }
int main() { notify_start(); for (i=0; i<=65535; i++) { bus1 = i; bus2 = i; wait(0.0001); } notify_completion(true); }
int main() { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(detect_auto); MBED_HOSTTEST_DESCRIPTION(Simple detect test); MBED_HOSTTEST_START("DTCT_1"); notify_start(); printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME); printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID); printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID); MBED_HOSTTEST_RESULT(true); }
int main ( int argc, char **argv ) { pthread_mutex_t spinLockMutex; pid_t childPid; struct sigaction sa; sigset_t sigmsk; size_t len; ThreadCallback_t callbacks; GlobalAbort = false; /* Parse the command line options */ MainParseArgs( argc, argv ); #ifndef __CYGWIN__ len = confstr( _CS_GNU_LIBPTHREAD_VERSION, NULL, 0 ); if( len ) { pthreadsVersion = (char *)malloc(len); confstr( _CS_GNU_LIBPTHREAD_VERSION, pthreadsVersion, len ); } if( !pthreadsVersion || strstr( pthreadsVersion, "linuxthreads" ) ) { fprintf( stderr, "beirdobot requires NPTL to operate correctly.\n\n" "The signal handling in linuxthreads is just too " "broken to use.\n\n" ); exit( 1 ); } #else len = 0; #endif /* Do we need to detach? */ if( Daemon ) { childPid = fork(); if( childPid < 0 ) { perror( "Couldn't detach in daemon mode" ); _exit( 1 ); } if( childPid != 0 ) { /* This is still the parent, report the child's pid and exit */ printf( "[Detached as PID %d]\n", childPid ); /* And exit the parent */ _exit( 0 ); } /* After this is in the detached child */ /* Close stdin, stdout, stderr to release the tty */ close(0); close(1); close(2); } mainThreadId = pthread_self(); /* * Setup the sigmasks for this thread (which is the parent to all others). * This will propogate to all children. */ sigfillset( &sigmsk ); sigdelset( &sigmsk, SIGUSR1 ); sigdelset( &sigmsk, SIGUSR2 ); sigdelset( &sigmsk, SIGHUP ); sigdelset( &sigmsk, SIGWINCH ); sigdelset( &sigmsk, SIGINT ); sigdelset( &sigmsk, SIGSEGV ); sigdelset( &sigmsk, SIGILL ); sigdelset( &sigmsk, SIGFPE ); pthread_sigmask( SIG_SETMASK, &sigmsk, NULL ); /* Initialize the non-threadsafe CURL library functionality */ curl_global_init( CURL_GLOBAL_ALL ); /* Start up the Logging thread */ logging_initialize(TRUE); memset( &callbacks, 0, sizeof(ThreadCallback_t) ); callbacks.sighupFunc = mainSighup; thread_register( &mainThreadId, "thread_main", &callbacks ); /* Setup signal handler for SIGUSR1 (toggles Debug) */ sa.sa_sigaction = (sigAction_t)logging_toggle_debug; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGUSR1, &sa, NULL ); /* Setup the exit handler */ atexit( MainDelayExit ); /* Setup signal handler for SIGINT (shut down cleanly) */ sa.sa_sigaction = signal_interrupt; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGINT, &sa, NULL ); /* Setup signal handlers that are to be propogated to all threads */ sa.sa_sigaction = signal_everyone; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGUSR2, &sa, NULL ); sigaction( SIGHUP, &sa, NULL ); sigaction( SIGWINCH, &sa, NULL ); /* Setup signal handlers for SEGV, ILL, FPE */ sa.sa_sigaction = signal_death; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGSEGV, &sa, NULL ); sigaction( SIGILL, &sa, NULL ); sigaction( SIGFPE, &sa, NULL ); versionTree = BalancedBTreeCreate( BTREE_KEY_STRING ); #ifndef __CYGWIN__ versionAdd( "pthreads", pthreadsVersion ); #endif curses_start(); cursesMenuItemAdd( 2, MENU_SYSTEM, "About", mainAbout, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Licensing", mainLicensing, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Versions", mainVersions, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Reload All", mainReloadAll, NULL ); /* Add the terminal setting as a version */ versionAdd( "TERM", getenv("TERM") ); /* Print the startup log messages */ LogBanner(); LogPrint( LOG_INFO, "CFLAGS: %s", CFLAGS ); LogPrint( LOG_INFO, "LDFLAGS: %s", LDFLAGS ); /* Setup the CLucene indexer */ clucene_init(0); /* Setup the MySQL connection */ db_setup(); db_check_schema_main(); /* Setup the bot commands */ botCmd_initialize(); /* Setup the regexp support */ regexp_initialize(); /* Setup the plugins */ plugins_initialize(); /* Start the notifier thread */ notify_start(); /* Start the authenticate thread */ authenticate_start(); /* Start the bot */ bot_start(); /* Sit on this and rotate - this causes an intentional deadlock, this * thread should stop dead in its tracks */ pthread_mutex_init( &spinLockMutex, NULL ); pthread_mutex_lock( &spinLockMutex ); pthread_mutex_lock( &spinLockMutex ); return(0); }
int main(int argc, char *argv[]) { ni_status status; ni_name myname = argv[0]; int create = 0; int log_pri = LOG_NOTICE; ni_name dbsource_name = NULL; ni_name dbsource_addr = NULL; ni_name dbsource_tag = NULL; struct rlimit rlim; char *str; unsigned db_checksum; FILE *logf; int nctoken; logf = NULL; forcedIsRoot = 0; Argv = argv; /* Save program and argument information for setproctitle */ Argc = argc; argc--; argv++; while (argc > 0 && **argv == '-') { if (strcmp(*argv, "-d") == 0) { debug = 1; log_pri = LOG_DEBUG; if (argc < 2) logf = stderr; else { debug = atoi(argv[1]); argc -= 1; argv += 1; } } else if (strcmp(*argv, "-l") == 0) { if (argc < 2) usage(myname); else { log_pri = atoi(argv[1]); argc -= 1; argv += 1; } } else if (strcmp(*argv, "-n") == 0) forcedIsRoot = 1; else if (strcmp(*argv, "-s") == 0) standalone = 1; else if (strcmp(*argv, "-m") == 0) create++; else if (strcmp(*argv, "-c") == 0) { if (argc < 4) usage(myname); create++; dbsource_name = argv[1]; dbsource_addr = argv[2]; dbsource_tag = argv[3]; argc -= 3; argv += 3; } else usage(myname); argc--; argv++; } if (argc != 1) usage(myname); if (debug == 0) { closeall(); if (standalone == 1) daemon(1, 1); } db_tag = malloc(strlen(argv[0]) + 1); strcpy(db_tag, argv[0]); str = malloc(strlen("netinfod ") + strlen(db_tag) + 1); sprintf(str, "netinfod %s", db_tag); system_log_open(str, (LOG_NDELAY | LOG_PID), LOG_NETINFO, logf); free(str); system_log_set_max_priority(log_pri); system_log(LOG_DEBUG, "version %s (pid %d) - starting", _PROJECT_VERSION_, getpid()); rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = FD_SETSIZE; setrlimit(RLIMIT_NOFILE, &rlim); umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); srandom(gethostid() ^ time(NULL)); readall_syslock = syslock_new(0); lockup_syslock= syslock_new(0); cleanupwait = CLEANUPWAIT; auth_count[GOOD] = 0; auth_count[BAD] = 0; auth_count[WGOOD] = 0; auth_count[WBAD] = 0; if (create) { if (dbsource_addr == NULL) { system_log(LOG_DEBUG, "creating master"); status = dir_mastercreate(db_tag); } else { system_log(LOG_DEBUG, "creating clone"); status = dir_clonecreate(db_tag, dbsource_name, dbsource_addr, dbsource_tag); } if (status != NI_OK) { system_log_close(); exit(status); } } nctoken = -1; notify_register_signal(NETWORK_CHANGE_NOTIFICATION, SIGHUP, &nctoken); if (standalone == 0) signal(SIGTERM, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, (void *)catch_sighup); signal(SIGCHLD, (void *)readall_catcher); if (debug == 0) { signal(SIGINT, (void *)dblock_catcher); if (standalone == 0) { if (setsid() < 0) syslog(LOG_WARNING, "setsid failed: %m"); } } writepid(db_tag); status = start_service(db_tag); if (status != NI_OK) { system_log(LOG_ERR, "start_service failed: %s - exiting", ni_error(status)); system_log_close(); exit(status); } setproctitle("netinfod %s (%s)", db_tag, i_am_clone ? "clone" : "master"); if (i_am_clone) { system_log(LOG_DEBUG, "checking clone"); cloneReadallResponseOK = get_clone_readall(db_ni); dir_clonecheck(); if (get_sanitycheck(db_ni)) sanitycheck(db_tag); system_log(LOG_DEBUG, "finished clone check"); } else { system_log(LOG_DEBUG, "setting up master server"); promote_admins = get_promote_admins(db_ni); get_readall_info(db_ni, &max_readall_proxies, &strict_proxies); max_subthreads = get_max_subthreads(db_ni); update_latency_secs = get_update_latency(db_ni); /* Tracking readall proxy pids uses ObjC, so isolate it */ initialize_readall_proxies(-1 == max_readall_proxies ? MAX_READALL_PROXIES : max_readall_proxies); system_log(LOG_DEBUG, "starting notify thread"); (void) notify_start(); } /* Shutdown gracefully after this point */ if (standalone == 1) signal(SIGTERM, (void *)sig_shutdown); signal(SIGUSR1, (void *)sig_shutdown); system_log(LOG_DEBUG, "starting RPC service"); ni_svc_run(_rpc_dtablesize() - (FD_SLOPSIZE + max_subthreads)); system_log(LOG_DEBUG, "shutting down"); /* * Tell the readall proxies to shut down */ if (readall_proxies > 0) { system_log(LOG_INFO, "killing %d readall prox%s", readall_proxies, 1 == readall_proxies ? "y" : "ies"); if (!kill_proxies()) system_log(LOG_WARNING, "some readall proxies still running"); } db_checksum = ni_getchecksum(db_ni); ni_shutdown(db_ni, db_checksum); system_log(LOG_INFO, "exiting; checksum %u", db_checksum); system_log_close(); exit(0); }
int main() { notify_start(); bool result = false; for (;;) { const int mask = bus_out.mask(); int led_mask = 0x00; if (LED1 != NC) led_mask |= 0x01; if (LED2 != NC) led_mask |= 0x02; if (LED3 != NC) led_mask |= 0x04; if (LED4 != NC) led_mask |= 0x08; printf("MBED: BusIn mask: 0x%X\r\n", mask); printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask); // Let's check bus's connected pins mask if (mask != led_mask) { break; } // Checking if DigitalOut is correctly set as connected for (int i=0; i < 4; i++) { printf("MBED: BusOut.bit[%d] is %s\r\n", i, (led_pins[i] != NC && bus_out[i].is_connected()) ? "connected" : "not connected"); } for (int i=0; i < 4; i++) { if (led_pins[i] != NC && bus_out[0].is_connected() == 0) { break; } } // Write mask all LEDs bus_out.write(mask); // Set all LED's pins in high state if (bus_out.read() != mask) { break; } // Zero all LEDs and see if mask is correctly cleared on all bits bus_out.write(~mask); if (bus_out.read() != 0x00) { break; } result = true; break; } printf("MBED: Blinking LEDs: \r\n"); // Just a quick LED blinking... for (int i=0; i<4; i++) { if (led_pins[i] != NC && bus_out[i].is_connected()) { bus_out[i] = 1; printf("%c", 'A' + i); } else { printf("."); } wait(0.2); if (led_pins[i] != NC && bus_out[i].is_connected()) { bus_out[i] = 0; printf("%c", 'a' + i); } else { printf("."); } } printf("\r\n"); notify_completion(result); }