/* * Catch an unexpected signal. */ static void disaster(int sig) { emergency("fatal signal: %s", (unsigned)sig < NSIG ? sys_siglist[sig] : "unknown signal"); sleep(STALL_TIMEOUT); _exit(sig); /* reboot */ }
void ch_att::play() { long r; double rate=(double)hp/(double)maxhp; char flag=!MOVED; srand(time(NULL)); getInfo(); assignPoints(); //Try to attack if (rate<0.4) { if (emergency()) flag=MOVED; else goto RUN; } else// if (rate<0.9 || lev<15) { if (normalAtt()) flag=MOVED; } /*else { if (healthyAtt()) flag=MOVED; }*/ if (flag==MOVED) goto ASSIGN_POINTS; r=rand()%10+1; if (r<=7 && multiHit(2)) flag=MOVED; else if (r<=3 && multiHit(3)) flag=MOVED; else if (r<=1 && multiHit(4)) flag=MOVED; //Run if (flag!=MOVED) { RUN: if (rate<0.4) run(0.7); else run(0.3); } ASSIGN_POINTS: getInfo(); assignPoints(); }
int main(int argc, char **argv) { void *lib = 0; void (*func) (int argc, char **argv); time_t mod = 0; mod = lastmod(THELIB); if (mod > 0) { _log("Last modified: %s", ctime(&mod)); } _log("Opening " THELIB); /* initial dl opening */ lib = dlopen(THELIB, RTLD_LAZY); if (lib == NULL) { char *err; err=dlerror(); if(err) { _log("Error opening %s, reason unknown.", THELIB); } else { _log("Error opening %s: %s", THELIB, err); } } for (;;) { /* If it's been modified since we last recorded mod date... */ if (lastmod(THELIB) > mod) { _log("Last modified: %s", ctime(&mod)); /* record a new mod date */ mod = lastmod(THELIB); /* close the library */ if(lib) dlclose(lib); /* open a new one. we don't care if it succeeds after start */ lib = dlopen(THELIB, RTLD_LAZY); } func = getfunc(lib); if (func != NULL) { func(argc, argv); } else { /* Emergency function, just read and report an error */ emergency(); } } /* close it, we're leaving now, not that any of this will ever happen */ /* NOTREACHED */ if(lib) dlclose(lib); return(0); }
// -------------------------------------------------------------------------- // ARDrone::landing() // Description : Land the AR.Drone. // Return value : NONE // -------------------------------------------------------------------------- void ARDrone::landing(void) { // Get the state if (mutexCommand) pthread_mutex_lock(mutexNavdata); int state = navdata.ardrone_state; if (mutexCommand) pthread_mutex_unlock(mutexNavdata); // If AR.Drone is in emergency, reset it if (state & ARDRONE_EMERGENCY_MASK) emergency(); else { // Send langding if (mutexCommand) pthread_mutex_lock(mutexCommand); sockCommand.sendf("AT*REF=%d,290717696\r", ++seq); if (mutexCommand) pthread_mutex_unlock(mutexCommand); } }
/* * Get the security level of the kernel. */ static int getsecuritylevel(void) { #ifdef KERN_SECURELVL int name[2], curlevel; size_t len; name[0] = CTL_KERN; name[1] = KERN_SECURELVL; len = sizeof curlevel; if (sysctl(name, 2, &curlevel, &len, NULL, 0) == -1) { emergency("cannot get kernel security level: %s", strerror(errno)); return (-1); } return (curlevel); #else return (-1); #endif }
// This function is initiated in a separate thread, since nothing after // OSStart() void monitorThread(void *pdata) { while (1) { printf("Beginning of monitor thread.\n"); curISRState = ISRState; switch (ISRState) { case MANUAL_MODE: *(red_LED_ptr) = LED_MANUAL; ISRState = NORMAL_MODE; // Clear flag manual(); break; case EMERGENCY_MODE: *(red_LED_ptr) = LED_EMERGENCY; ISRState = NORMAL_MODE; // Clear flag emergency(); break; case BROKEN_MODE: *(red_LED_ptr) = LED_BROKEN; ISRState = NORMAL_MODE; // Clear flag broken(); break; case TURN_MODE: *(red_LED_ptr) = LED_TURN; ISRState = NORMAL_MODE; // Clear flag turnLane(); break; case PEDESTRIAN_MODE: *(red_LED_ptr) = LED_PEDESTRIAN; ISRState = NORMAL_MODE; // Clear flag pedestrian(); break; default: *(red_LED_ptr) = LED_NORMAL; ISRState = NORMAL_MODE; // Clear flag normal(); break; } } }
SUMOReal MSCFModel_Wiedemann::_v(const MSVehicle* veh, SUMOReal predSpeed, SUMOReal gap) const { const VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables(); const SUMOReal dx = gap + myType->getLength(); // wiedemann uses brutto gap const SUMOReal v = veh->getSpeed(); const SUMOReal vpref = veh->getMaxSpeed(); const SUMOReal dv = v - predSpeed; const SUMOReal bx = myAX + (1 + 7 * mySecurity) * sqrt(v); // Harding propose a factor of *.8 here const SUMOReal ex = 2 - myEstimation; // + RandHelper::randNorm(0.5, 0.15) const SUMOReal sdx = myAX + ex * (bx - myAX); /// the distance at which we drift out of following const SUMOReal sdv_root = (dx - myAX) / myCX; const SUMOReal sdv = sdv_root * sdv_root; const SUMOReal cldv = sdv * ex * ex; const SUMOReal opdv = cldv * (-1 - 2 * RandHelper::randNorm(0.5, 0.15)); // select the regime, get new acceleration, compute new speed based SUMOReal accel; if (dx <= bx) { accel = emergency(dv, dx); } else if (dx < sdx) { if (dv > cldv) { accel = approaching(dv, dx, bx); } else if (dv > opdv) { accel = following(vars->accelSign); } else { accel = fullspeed(v, vpref, dx, bx); } } else { if (dv > sdv && dx < D_MAX) { //@note other versions have an disjunction instead of conjunction accel = approaching(dv, dx, bx); } else { accel = fullspeed(v, vpref, dx, bx); } } // since we have hard constrainst on accel we may as well use them here accel = MAX2(MIN2(accel, myAccel), -myDecel); const SUMOReal vNew = MAX2(SUMOReal(0), v + ACCEL2SPEED(accel)); // don't allow negative speeds return vNew; }
/* * Set the security level of the kernel. */ static void setsecuritylevel(int newlevel) { #ifdef KERN_SECURELVL int name[2], curlevel; curlevel = getsecuritylevel(); if (newlevel == curlevel) return; name[0] = CTL_KERN; name[1] = KERN_SECURELVL; if (sysctl(name, 2, NULL, NULL, &newlevel, sizeof newlevel) == -1) { emergency( "cannot change kernel security level from %d to %d: %s", curlevel, newlevel, strerror(errno)); return; } #ifdef SECURE warning("kernel security level changed from %d to %d", curlevel, newlevel); #endif #endif }
/* * Bring the system up single user. */ static state_func_t single_user(void) { pid_t pid, wpid; int status; sigset_t mask; const char *shell; char *argv[2]; #ifdef SECURE struct ttyent *typ; struct passwd *pp; static const char banner[] = "Enter root password, or ^D to go multi-user\n"; char *clear, *password; #endif #ifdef DEBUGSHELL char altshell[128]; #endif if (Reboot) { /* Instead of going single user, let's reboot the machine */ sync(); reboot(howto); _exit(0); } shell = get_shell(); if ((pid = fork()) == 0) { /* * Start the single user session. */ open_console(); #ifdef SECURE /* * Check the root password. * We don't care if the console is 'on' by default; * it's the only tty that can be 'off' and 'secure'. */ typ = getttynam("console"); pp = getpwnam("root"); if (typ && (typ->ty_status & TTY_SECURE) == 0 && pp && *pp->pw_passwd) { write_stderr(banner); for (;;) { clear = getpass("Password:"******"single-user login failed\n"); } } endttyent(); endpwent(); #endif /* SECURE */ #ifdef DEBUGSHELL { char *cp = altshell; int num; #define SHREQUEST "Enter full pathname of shell or RETURN for " write_stderr(SHREQUEST); write_stderr(shell); write_stderr(": "); while ((num = read(STDIN_FILENO, cp, 1)) != -1 && num != 0 && *cp != '\n' && cp < &altshell[127]) cp++; *cp = '\0'; if (altshell[0] != '\0') shell = altshell; } #endif /* DEBUGSHELL */ /* * Unblock signals. * We catch all the interesting ones, * and those are reset to SIG_DFL on exec. */ sigemptyset(&mask); sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); /* * Fire off a shell. * If the default one doesn't work, try the Bourne shell. */ char name[] = "-sh"; argv[0] = name; argv[1] = 0; execv(shell, argv); emergency("can't exec %s for single user: %m", shell); execv(_PATH_BSHELL, argv); emergency("can't exec %s for single user: %m", _PATH_BSHELL); sleep(STALL_TIMEOUT); _exit(1); } if (pid == -1) { /* * We are seriously hosed. Do our best. */ emergency("can't fork single-user shell, trying again"); while (waitpid(-1, (int *) 0, WNOHANG) > 0) continue; return (state_func_t) single_user; } requested_transition = 0; do { if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1) collect_child(wpid); if (wpid == -1) { if (errno == EINTR) continue; warning("wait for single-user shell failed: %m; restarting"); return (state_func_t) single_user; } if (wpid == pid && WIFSTOPPED(status)) { warning("init: shell stopped, restarting\n"); kill(pid, SIGCONT); wpid = -1; } } while (wpid != pid && !requested_transition); if (requested_transition) return (state_func_t) requested_transition; if (!WIFEXITED(status)) { if (WTERMSIG(status) == SIGKILL) { /* * reboot(8) killed shell? */ warning("single user shell terminated."); sleep(STALL_TIMEOUT); _exit(0); } else { warning("single user shell terminated, restarting"); return (state_func_t) single_user; } } runcom_mode = FASTBOOT; return (state_func_t) runcom; }
int main (int argc, char *argv[]) { COpts options; MBK::CFig *fig; string name_lofig, name_placed, name_routed; int layers, global; set<string>* netSet = NULL; try { options.add ("v", "verbose"); options.add ("V", "very-verbose"); options.add ("h", "help"); options.add ("c", "coredump"); options.add ("H", "half-pitch"); options.add ("R", "rotate"); options.add ("2", "layers-2"); options.add ("3", "layers-3"); options.add ("4", "layers-4"); options.add ("5", "layers-5"); options.add ("6", "layers-6"); options.add ("G", "global"); options.add ("L", "local"); options.add ("p", "place", true); options.add ("N", "netset", true); options.getopts (argc, argv); if (options["c"]->parsed) interrupt.coredump = true; cmess0.setVL (0); if (options["v"]->parsed) cmess0.setVL (1); if (options["V"]->parsed) cmess0.setVL (2); MBK::alliancebanner ( "NeRo" , VERSION , "Negotiating Router" , "2002" , ALLIANCE_VERSION ); if ((cmess0.getVL () > 0) || options["h"]->parsed ) { serial (); cmess1 << "\n"; } if (options["h"]->parsed) { help (); exit (0); } if (options.tVals.size() < 2) { cerr << herr ("nero:\n"); cerr << " Missing mandatory argument <netlist> or <routed> (or both)\n"; cerr << "\n"; help (); throw except_done (); } name_lofig = options.tVals[0]; name_routed = options.tVals[1]; if (options["p"]->parsed) { name_placed = options["p"]->value; } else { name_placed = name_lofig; } if (options["N"]->parsed) { string fileNetSet = options["N"]->value; cout << "File: " << fileNetSet << endl; FILE* file = fopen ( fileNetSet.c_str(), "r" ); if ( file ) { cout << "File Sucessfully opened." << endl; netSet = new set<string>(); char buffer[2048]; while ( !feof(file) ) { fgets ( buffer, 2048, file ); size_t length = strlen(buffer); if ( buffer[length-1] == '\n' ) buffer[length-1] = '\0'; netSet->insert ( buffer ); } fclose ( file ); } } layers = 3; if (options["2"]->parsed) layers = 3; if (options["3"]->parsed) layers = 4; if (options["4"]->parsed) layers = 5; if (options["5"]->parsed) layers = 6; if (options["6"]->parsed) layers = 7; global = D::ROUTING_CHOOSE; if (options["L"]->parsed) { global = D::ROUTING_LOCAL; } if (options["G"]->parsed) { global = D::ROUTING_GLOBAL; if (layers < 5) layers = 5; } cmess1 << MBK::env; fig = new MBK::CFig (name_lofig, name_placed); crbox = new CRBox (); //crbox = new CRBox (global, true); //cdebug.on (); crbox->mbkload ( fig , layers , 4 , global , options["H"]->parsed , options["R"]->parsed , netSet ); //cdebug.off (); crbox->route (); crbox->mbksave (name_routed); if ( netSet ) delete netSet; } catch (e_zupper &e) { cerr << "\n\n" << " First \"double pitch\" layer must be at least equal to ALU5 " << "(here : " << MBK::env.z2alu (e.zupper) << ").\n\n" << endl; exit (1); } catch (bad_grab &e) { cerr << herr ("\n"); cerr << " Net \"" << e.netName << "\" attempt to grab node (" << e.x << "," << e.y << "," << e.z << "),\n" << " which belongs to net \"" << e.ownerName << "\".\n" << endl; cerr << " (nodepri := " << e.nodepri << " , pri := " << e.pri << ", terminal := " << e.terminal << ", ident := " << e.ident << ")\n" << endl; emergency (); exit (1); } //catch (coord_outbound &e) { // cerr << herr ("\n"); // cerr << " Atempt to use outbound coordinates := (" // << e.x << "," << e.y << "," << e.z << ") real := (" // << MBK::UNSCALE (crbox->fig->XAB1() + e.x * D::X_GRID) << "," // << MBK::UNSCALE (crbox->fig->YAB1() + e.y * D::Y_GRID) << "," // << MBK::layer2a (MBK::env.z2alu (e.z)) << ")\n" // << endl; // // emergency (); // exit (1); //} // Case of exceptions that have already been processed. catch (dup_term &e) { cerr << " Duplicated terminal node for " << e.name << " at " << e.node << endl; exit (1); } catch (reach_max_pri &e) { cerr << "\n\n" << " Negotiation algorithm failed, NeRo was unable to route this" << " design.\n Maximum priority reached for net " << "\"" << e.net->name << "\".\n\n"; emergency (); exit (1); } catch (except_done &e) { cerr << e.what () << endl; emergency (); exit (1); } // Case of unexpected (undefined) exceptions. catch (...) { cerr << herr ("\n"); cerr << " An unexpected exception have occurs.\n\n"; cerr << " This is a bug. Please e-mail to \"[email protected]\".\n\n"; exit (1); } // This is the End. cmess1 << "\n\n"; exit (0); }
/* * Bring the system up single user. */ state_func_t single_user(void) { pid_t pid, wpid; int status; sigset_t mask; const char *shell; char *argv[2]; #ifdef SECURE struct ttyent *typ; struct passwd *pp; static const char banner[] = "Enter root password, or ^D to go multi-user\n"; char *clear, *password; #endif #ifdef DEBUGSHELL char altshell[128]; #endif if (Reboot) { /* Instead of going single user, let's reboot the machine */ sync(); alarm(2); pause(); reboot(howto); _exit(0); } shell = get_shell(); if ((pid = fork()) == 0) { /* * Start the single user session. */ setctty(_PATH_CONSOLE); #ifdef TESTBED #define TERMCMD "/bootcmd" if (access(TERMCMD, F_OK) == 0) { FILE *fp; char cmd[256], *bp; char *myargv[3]; /* * Very simple; the file contains the path of a * command to run. No arguments supported, sorry. */ if ((fp = fopen(TERMCMD, "r")) == NULL) { /* Lets avoid loops! */ unlink(TERMCMD); goto skip; } if (fgets(cmd, sizeof(cmd), fp) == NULL) { fclose(fp); /* Lets avoid loops! */ unlink(TERMCMD); goto skip; } fclose(fp); /* Lets avoid loops! */ unlink(TERMCMD); if ((bp = rindex(cmd, '\n'))) *bp = '\0'; if (access(cmd, X_OK) != 0) { emergency("%s does not exist!", cmd); goto skip; } /* See comment below */ sigemptyset(&mask); sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); char name[] = "-sh"; myargv[0] = name; myargv[1] = cmd; myargv[2] = 0; execv(_PATH_BSHELL, myargv); stall("can't exec %s for %s: %m", _PATH_BSHELL, cmd); } /* * If something goes wrong, we want to sit in single user mode * so that we might catch the error. Not sure, might have to * do something fancier, like perhaps add a state transition * for this */ skip: #endif #ifdef SECURE /* * Check the root password. * We don't care if the console is 'on' by default; * it's the only tty that can be 'off' and 'secure'. */ typ = getttynam("console"); pp = getpwnam("root"); if (typ && (typ->ty_status & TTY_SECURE) == 0 && pp && *pp->pw_passwd) { write_stderr(banner); for (;;) { clear = getpass("Password:"******"single-user login failed\n"); } } endttyent(); endpwent(); #endif /* SECURE */ #ifdef DEBUGSHELL { char *cp = altshell; int num; #define SHREQUEST "Enter full pathname of shell or RETURN for " write_stderr(SHREQUEST); write_stderr(shell); write_stderr(": "); while ((num = read(STDIN_FILENO, cp, 1)) != -1 && num != 0 && *cp != '\n' && cp < &altshell[127]) cp++; *cp = '\0'; if (altshell[0] != '\0') shell = altshell; } #endif /* DEBUGSHELL */ /* * Unblock signals. * We catch all the interesting ones, * and those are reset to SIG_DFL on exec. */ sigemptyset(&mask); sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); /* * Fire off a shell. * If the default one doesn't work, try the Bourne shell. */ char name[] = "-sh"; argv[0] = name; argv[1] = 0; execv(shell, argv); emergency("can't exec %s for single user: %m", shell); execv(_PATH_BSHELL, argv); emergency("can't exec %s for single user: %m", _PATH_BSHELL); sleep(STALL_TIMEOUT); _exit(1); } if (pid == -1) { /* * We are seriously hosed. Do our best. */ emergency("can't fork single-user shell, trying again"); while (waitpid(-1, (int *) 0, WNOHANG) > 0) continue; return (state_func_t) single_user; } requested_transition = 0; do { if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1) collect_child(wpid); if (wpid == -1) { if (errno == EINTR) continue; warning("wait for single-user shell failed: %m; restarting"); return (state_func_t) single_user; } if (wpid == pid && WIFSTOPPED(status)) { warning("init: shell stopped, restarting\n"); kill(pid, SIGCONT); wpid = -1; } } while (wpid != pid && !requested_transition); if (requested_transition) return (state_func_t) requested_transition; if (!WIFEXITED(status)) { if (WTERMSIG(status) == SIGKILL) { /* * reboot(8) killed shell? */ warning("single user shell terminated."); sleep(STALL_TIMEOUT); _exit(0); } else { warning("single user shell terminated, restarting"); return (state_func_t) single_user; } } runcom_mode = FASTBOOT; return (state_func_t) runcom; }