void nk_set_chroot(const char *chroot_dir) { if (chroot(chroot_dir)) suicide("%s: chroot('%s') failed: %s", __func__, chroot_dir, strerror(errno)); if (chdir("/")) suicide("%s: chdir('/') failed: %s", __func__, strerror(errno)); }
/* Generate a move. */ static void generate_move(int *i, int *j, int color) { int moves[MAX_BOARD * MAX_BOARD]; int num_moves = 0; int move; int ai, aj; int k; memset(moves, 0, sizeof(moves)); for (ai = 0; ai < board_size; ai++) for (aj = 0; aj < board_size; aj++) { /* Consider moving at (ai, aj) if it is legal and not suicide. */ if (legal_move(ai, aj, color) && !suicide(ai, aj, color)) { /* Further require the move not to be suicide for the opponent... */ if (!suicide(ai, aj, OTHER_COLOR(color))) moves[num_moves++] = POS(ai, aj); else { /* ...however, if the move captures at least one stone, * consider it anyway. */ for (k = 0; k < 4; k++) { int bi = ai + deltai[k]; int bj = aj + deltaj[k]; if (on_board(bi, bj) && get_board(bi, bj) == OTHER_COLOR(color)) { moves[num_moves++] = POS(ai, aj); break; } } } } } /* Choose one of the considered moves randomly with uniform * distribution. (Strictly speaking the moves with smaller 1D * coordinates tend to have a very slightly higher probability to be * chosen, but for all practical purposes we get a uniform * distribution.) */ if (num_moves > 0) { move = moves[xor_randn(num_moves)]; *i = I(move); *j = J(move); } else { /* But pass if no move was considered. */ *i = -1; *j = -1; } }
int setup_signals_subprocess(void) { sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) suicide("sigprocmask failed"); int sfd = signalfd(-1, &mask, SFD_NONBLOCK); if (sfd < 0) suicide("signalfd failed"); return sfd; }
void coEditorTextValueWidget::save() { if (valueLineEdit->isModified()) { QString value = valueLineEdit->text(); // if (this->property("infoWidget").toBool() ) hide(); //this->setProperty("infoWidget", false); fType should be enough, except i do systemwide colorize by property if (fType == coEditorValueWidget::InfoName) // this was a infoWidget that now for first time got a name { emit nameAdded(value); // saveValue is called in coEditorEntryWidget::nameAddedSlot } else // standard behaviour - call save { emit saveValue(fvariable, value); } // change behaviour for "delete this value" context menu if (fType == coEditorValueWidget::InfoName || fType == coEditorValueWidget::Info) { fType = coEditorValueWidget::Text; disconnect(deleteValueAction, SIGNAL(triggered()), this, SLOT(explainShowInfoButton())); connect(deleteValueAction, SIGNAL(triggered()), this, SLOT(suicide())); } valueLineEdit->setModified(false); } }
void print_lav_match (FILE* f, seq* seq1, unspos pos1, seq* seq2, unspos pos2, unspos length, score s) { seqpartition* sp1 = &seq1->partition; seqpartition* sp2 = &seq2->partition; unspos end1 = pos1 + length; unspos end2 = pos2 + length; int pctId; if ((sp1->p != NULL) || (sp2->p != NULL)) suicide ("lav format can't handle multi-sequences"); // compute percent identity pctId = percent_identical (seq1, pos1, seq2, pos2, length); // print it fprintf (f, "a {\n"); fprintf (f, " s " scoreFmtSimple "\n", s); fprintf (f, " b " unsposFmt " " unsposFmt "\n", pos1+1, pos2+1); fprintf (f, " e " unsposFmt " " unsposFmt "\n", end1, end2); fprintf (f, " l " unsposFmt " " unsposFmt " " unsposFmt " " unsposFmt " %d\n", pos1+1, pos2+1, end1, end2, pctId); fprintf (f, "}\n"); }
void print_lavscore_match // same as regular lav except we output the score (FILE* f, // .. wherever the pctid would normally go; this seq* seq1, // .. is to allow compatibility with some very old unspos pos1, // .. programs (Dblast, chain) seq* seq2, unspos pos2, unspos length, score s) { seqpartition* sp1 = &seq1->partition; seqpartition* sp2 = &seq2->partition; unspos end1 = pos1 + length; unspos end2 = pos2 + length; if ((sp1->p != NULL) || (sp2->p != NULL)) suicide ("lav format can't handle multi-sequences"); // print it fprintf (f, "a {\n"); fprintf (f, " s " scoreFmtSimple "\n", s); fprintf (f, " b " unsposFmt " " unsposFmt "\n", pos1+1, pos2+1); fprintf (f, " e " unsposFmt " " unsposFmt "\n", end1, end2); fprintf (f, " l " unsposFmt " " unsposFmt " " unsposFmt " " unsposFmt " " scoreFmtSimple "\n", pos1+1, pos2+1, end1, end2, s); fprintf (f, "}\n"); }
static int mask_interval (u8* fwd, u8* rev, unspos beg, unspos end, census* cen, void (*func)(unspos beg, unspos end, void* info), void* info) { unspos revLen, pos; unspos basesMasked = 0; u32 count; if ((cen == NULL) || (cen->maskThresh == 0)) return 0; if ((beg < 1) || (end > cen->len)) suicide ("mask_interval, internal error"); revLen = cen->len - 1; for (pos=beg-1 ; pos<end ; pos++) { count = (cen->kind == 'B')? cen->count8 [pos] : (cen->kind == 'W')? cen->count16[pos] : cen->count32[pos]; if (count >= cen->maskThresh) { if (dna_isupper(fwd[pos])) { fwd[pos] = 'x'; basesMasked++; } if (rev != NULL) rev[revLen-pos] = 'x'; } } return basesMasked; }
time_t clock_time(void) { struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts)) suicide("%s: clock_gettime failed: %s", __func__, strerror(errno)); return ts.tv_sec; }
/*----------------------------------------------------------------------*/ void test_init_TF() { /* TF卡 */ TCHAR *path = "0:"; LCD_P8x16Str(0,0, (BYTE*)"TF.."); if (!SD_init()) { /* 挂载TF卡文件系统 */ if (FR_OK == f_mount(&fatfs1, path, 1)) { /* 文件读写测试 */ if (!test_file_system()) { g_devices_init_status.TFCard_is_OK = 1; } } } if (g_devices_init_status.TFCard_is_OK) { LCD_P8x16Str(0,0, (BYTE*)"TF..OK"); } else { LCD_P8x16Str(0,0, (BYTE*)"TF..NOK"); suicide(); } }
/** * M81: Turn off Power, including Power Supply, if there is one. * * This code should ALWAYS be available for EMERGENCY SHUTDOWN! */ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); print_job_timer.stop(); planner.finish_and_disable(); #if FAN_COUNT > 0 thermalManager.zero_fan_speeds(); #if ENABLED(PROBING_FANS_OFF) thermalManager.fans_paused = false; ZERO(thermalManager.paused_fan_speed); #endif #endif safe_delay(1000); // Wait 1 second before switching off #if HAS_SUICIDE suicide(); #elif HAS_POWER_SWITCH PSU_OFF(); #endif #if HAS_LCD_MENU LCD_MESSAGEPGM(MACHINE_NAME " " MSG_OFF "."); #endif }
void CBomb::explode() { suicide(); std::list<CHitableInterface *> lObjects(m_ObjectManager.getMap().getHitableInterfacesInSphere(Ogre::Sphere(m_pSceneNode->getPosition(), BOMB_EXPLOSION_RADIUS))); for (CHitableInterface *pHI : lObjects) { pHI->receiveDamage(CDamage(CDamage::DMG_BOMB, (pHI->getPosition() - getPosition()).normalisedCopy())); } }
unspos census_mask_aligns (alignel* alignList, u8* fwd, u8* rev, census* cen, void (*func)(unspos beg, unspos end, void* info), void* info) { alignel* a; unspos beg, end, pos; unspos count = 0; if (cen == NULL) return 0; for (a=alignList ; a!=NULL ; a=a->next) { if (a->beg1 < 1) suicide ("census_mask_aligns, internal error"); if (a->end1 > cen->len) suicide ("census_mask_aligns, internal error"); beg = a->beg1 - 1; end = a->end1; switch (cen->kind) { case 'B': for (pos=beg ; pos<end ; pos++) { if (cen->count8[pos] < u8max) cen->count8 [pos]++; } break; case 'W': for (pos=beg ; pos<end ; pos++) { if (cen->count16[pos] < u16max) cen->count16[pos]++; } break; case 'L': for (pos=beg ; pos<end ; pos++) { if (cen->count32[pos] < u32max) cen->count32[pos]++; } break; } if (cen->maskThresh > 0) count += mask_interval (fwd, rev, beg+1, end, cen, func, info); } masking_add_stat (maskedBases, count); return count; }
static unspos mask_interval (u8* fwd, u8* rev, unspos beg, unspos end, census* cen, void (*func)(unspos beg, unspos end, void* info), void* info) { static const u32 noRun = (u32) -1; unspos revLen, runBeg, pos, j; unspos basesMasked = 0; u32 count; if (cen == NULL) return 0; if ((beg < 1) || (end > cen->len)) suicide ("mask_interval, internal error"); revLen = cen->len - 1; runBeg = noRun; for (pos=beg-1 ; pos<end ; pos++) { count = (cen->kind == 'B')? cen->count8 [pos] : (cen->kind == 'W')? cen->count16[pos] : cen->count32[pos]; if ((cen->maskThresh > 0) && (count >= cen->maskThresh) && (dna_isupper(fwd[pos]))) { if (runBeg == noRun) runBeg = pos; } else if (runBeg != noRun) { func (runBeg+1, pos, info); for (j=runBeg ; j<pos ; j++) { fwd[j] = 'x'; basesMasked++; if (rev != NULL) rev[revLen-j] = 'x'; } runBeg = noRun; } } if (runBeg != noRun) { func (runBeg+1, end, info); for (j=runBeg ; j<end ; j++) { fwd[j] = 'x'; basesMasked++; if (rev != NULL) rev[revLen-j] = 'x'; } } return basesMasked; }
void detected(int code, const char *msg) { char tmp[512] = ""; struct flag_record fr = { FR_GLOBAL, 0, 0, 0 }; int act = DET_WARN, do_fatal = 0, killbots = 0; if (code == DETECT_LOGIN) act = login; if (code == DETECT_TRACE) act = trace; if (code == DETECT_PROMISC) act = promisc; #ifdef NOT_USED if (code == DETECT_PROCESS) act = badprocess; #endif if (code == DETECT_HIJACK) act = hijack; switch (act) { case DET_IGNORE: break; case DET_WARN: putlog(LOG_WARN, "*", msg); break; case DET_REJECT: do_fork(); putlog(LOG_WARN, "*", STR("Setting myself +d: %s"), msg); simple_snprintf(tmp, sizeof(tmp), "+d: %s", msg); set_user(&USERENTRY_COMMENT, conf.bot->u, tmp); fr.global = USER_DEOP; fr.bot = 1; set_user_flagrec(conf.bot->u, &fr, 0); sleep(1); break; case DET_DIE: putlog(LOG_WARN, "*", STR("Dying: %s"), msg); simple_snprintf(tmp, sizeof(tmp), STR("Dying: %s"), msg); set_user(&USERENTRY_COMMENT, conf.bot->u, tmp); if (!conf.bot->hub) nuke_server(STR("BBL")); sleep(1); killbots++; do_fatal++; break; case DET_SUICIDE: suicide(msg); break; } if (killbots && conf.bot->localhub) { conf_checkpids(conf.bots); conf_killbot(conf.bots, NULL, NULL, SIGKILL); } if (do_fatal) fatal(msg, 0); }
void epoll_del(int epfd, int fd) { struct epoll_event ev; int r; ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP; ev.data.fd = fd; r = epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ev); if (r < 0) suicide("epoll_del failed %s", strerror(errno)); }
/*----------------------------------------------------------------------*/ void read_device_no() { LCD_P8x16Str(0, 4, (BYTE*)"DeviceNo="); if (!read_device_no_from_TF()) { if (g_device_NO!=0) { LCD_PrintoutInt(72, 4, g_device_NO); } else { suicide(); } } else { suicide(); } }
void getmove(char move[], int *i, int *j) /* interpret response of human move to board position */ { FILE *fp; int m, n; if (strcmp(move, "stop") == 0) /* stop game */ play = 0; else { if (strcmp(move, "save") == 0) /* save data and stop game */ { fp = fopen("gnugo.dat", "w"); /* save board configuration */ for (m = 0; m < 19; m++) for (n = 0; n < 19; n++) fprintf(fp, "%c", p[m][n]); /* my color, pieces captured */ fprintf(fp, "%d %d %d ", mymove, mk, uk); /* opening pattern flags */ for (m = 0; m < 9; m++) fprintf(fp, "%d ", opn[m]); fclose(fp); play = -1; } else { if (strcmp(move, "pass") == 0) /* human pass */ { pass++; *i = -1; /* signal pass */ } else { pass = 0; /* move[0] from A to T, move[1] move[2] from 1 to 19 */ /* convert move to coordinate */ if (!getij(move, i, j) || (p[*i][*j] != EMPTY) || suicide(*i, *j)) { if (feof(stdin)) exit(1); printf("illegal move !\n"); printf("your move? "); scanf("%s", move); getmove(move, i, j); } } } } } /* end getmove */
void TurrentBullet::update() { posX_ += vX_; posY_ += vY_; posRect_.x = posX_; posRect_.y = posY_; if (SDL_HasIntersection(&posRect_, Window::rect()) == SDL_FALSE) suicide(); }
void kill() { cli(); // Stop interrupts #if defined(PS_ON_PIN) && PS_ON_PIN > -1 Digital psoPin = new Digital(PS_ON_PIN); psoPin.pinMode(INPUT); #endif motorControl->commandEmergencyStop(); //SERIAL_ERROR_START; //SERIAL_ERRORLNPGM(MSG_ERR_KILLED); suicide(); while(1) { /* Intentionally left empty */ } // Wait for reset }
/* * This function frees the given block */ void freemem(void *x) { #ifdef AUDIT void *y = (void *)(((char *)x) - 8); if ((*((unsigned long *)y)) != 0xdeadbeefUL) suicide(*((unsigned long *)y)); *((unsigned long *)y) = 0xfeedbabeUL; free(y); #else free(x); #endif }
/* * Do stuff with the shell input here. */ int sh_handle_input(char *line, int fd_toserver) { /* Check for \seg command and create segfault */ if (starts_with(line,CMD_SEG) && is_server == 0) { suicide(); exit(-1); } /* Write message to server for processing */ else { write(fd_toserver,line,MSG_SIZE); } return 0; }
void cfg_set_group(char *groupname) { int t; char *p; struct group *grp; t = (unsigned int) strtol(groupname, &p, 10); if (*p != '\0') { grp = getgrnam(groupname); if (grp) cfg_gid = (int)grp->gr_gid; else suicide("%s: invalid gid specified.", __func__); } else cfg_gid = t; }
/*===========================================================================* * panic * *===========================================================================*/ void panic(const char *fmt, ...) { /* Something awful has happened. Panics are caused when an internal * inconsistency is detected, e.g., a programming error or illegal * value of a defined constant. */ endpoint_t me = NONE; char name[20]; int priv_flags; int init_flags; void (*suicide)(void); va_list args; if(sys_whoami(&me, name, sizeof(name), &priv_flags, &init_flags) == OK && me != NONE) printf("%s(%d): panic: ", name, me); else printf("(sys_whoami failed): panic: "); if(fmt) { va_start(args, fmt); vprintf(fmt, args); va_end(args); } else { printf("no message\n"); } printf("\n"); printf("syslib:panic.c: stacktrace: "); util_stacktrace(); panic_hook(); /* Try exit */ _exit(1); /* Try to signal ourself */ abort(); /* If exiting nicely through PM fails for some reason, try to * commit suicide. E.g., message to PM might fail due to deadlock. */ suicide = (void (*)(void)) -1; suicide(); /* If committing suicide fails for some reason, hang. */ for(;;) { } }
static void do_sleep(void) { struct timespec req = { update_interval, 0 }, rem; retry: if (pending_exit) exit(EXIT_SUCCESS); if (nanosleep(&req, &rem)) { switch (errno) { case EINTR: req = rem; goto retry; default: suicide("nanosleep failed"); } } }
bool turn(Labyrinth &map) { take_objects_from_cell(map, map.player[map.current_player]); if (DEBUG) print_debug(map); user_message(map.player[map.current_player].name + ", it's your turn"); string message = map.player[map.current_player].name + ", enter what you want (go, bomb, shoot, knife, suicide, stay, leave"; if (SERVER) message += ")"; else message += ", save)"; user_message(message); if (SERVER) server.clear_user_messages(map.current_player); string s = read_user_command(map.current_player); if (s == "leave") return leave_game(map, map.player[map.current_player]); if (s == "suicide") return suicide(map, map.player[map.current_player]); if (s == "knife") return use_knife(map, map.player[map.current_player]); if (s == "bomb") return bomb(map, map.player[map.current_player]); if (s == "go") return go(map, map.player[map.current_player]); if (s == "shoot") return shoot(map, map.player[map.current_player]); if (s == "stay") return stay(map.player[map.current_player]); if (s == "save" && !SERVER) { save_game(map); return false; } if (s == "winthemall") { if (is_developer(map.player[map.current_player])) { user_message("Okay, master"); finish_game(map); return true; } } user_message(map.player[map.current_player].name + ", you entered incorrect command! Try again, if you can!"); return false; }
void cfg_set_user(char *username) { int t; char *p; struct passwd *pws; t = (unsigned int) strtol(username, &p, 10); if (*p != '\0') { pws = getpwnam(username); if (pws) { cfg_uid = (int)pws->pw_uid; if (!cfg_gid) cfg_gid = (int)pws->pw_gid; } else suicide("%s: invalid uid specified.", __func__); } else cfg_uid = t; }
unspos census_mask_segments (segtable* st, u8* fwd, u8* rev, census* cen, void (*func)(unspos beg, unspos end, void* info), void* info) { segment* seg; u32 ix; unspos beg, end, pos; unspos count = 0; if (cen == NULL) return 0; for (ix=0,seg=st->seg ; ix<st->len ; ix++,seg++) { if ((seg->length > cen->len) || (seg->pos1 > cen->len - seg->length)) suicide ("census_mask_segments, internal error"); beg = seg->pos1; end = beg + seg->length; switch (cen->kind) { case 'B': for (pos=beg ; pos<end ; pos++) { if (cen->count8[pos] < u8max) cen->count8 [pos]++; } break; case 'W': for (pos=beg ; pos<end ; pos++) { if (cen->count16[pos] < u16max) cen->count16[pos]++; } break; case 'L': for (pos=beg ; pos<end ; pos++) { if (cen->count32[pos] < u32max) cen->count32[pos]++; } break; } if (cen->maskThresh > 0) count += mask_interval (fwd, rev, beg+1, end, cen, func, info); } masking_add_stat (maskedBases, count); return count; }
void print_lav_align_list (FILE* f, alignel* alignList, seq* seq1, seq* seq2) { seqpartition* sp1 = &seq1->partition; seqpartition* sp2 = &seq2->partition; alignel* a; if ((sp1->p != NULL) || (sp2->p != NULL)) suicide ("lav format can't handle multi-sequences"); // the issue is that we'd have to check if the partition changed // since the previous alignment, and generate an s/h-stanza pair for (a=alignList ; a!=NULL ; a=a->next) print_lav_align (f, a->seq1, a->beg1-1, a->end1, a->seq2, a->beg2-1, a->end2, a->script, a->s); }
void KviSplashScreen::fadeTimerShot() { if(m_bIncreasing) { m_rTransparency += 0.05; setWindowOpacity(m_rTransparency); if(m_rTransparency>=1) { m_pFadeTimer->stop(); m_bIncreasing = false; } } else { m_rTransparency -= 0.02; setWindowOpacity(m_rTransparency); if(m_rTransparency<=0) { m_pFadeTimer->stop(); m_bIncreasing = true; suicide(); } } }
/* * This function is equivalent to a realloc(); if the realloc() call * fails, it will try a malloc() and a memcpy(). If not enough memory is * available, the program exits with an error message */ void *(incmem)(void *m, size_t x, size_t nx) { void *nm; #ifdef AUDIT m = (void *)(((char *)m) - ALIGNSHIFT); if (*((unsigned long *)m) != 0xdeadbeefUL) suicide(*((unsigned long *)m)); x += ALIGNSHIFT; nx += ALIGNSHIFT; #endif if (!(nm = realloc(m, nx))) { if (x > nx) x = nx; nm = (getmem)(nx); memcpy(nm, m, x); /* free() and not freemem(), because of the Schrodinger beef */ free(m); } #ifdef AUDIT return (void *)(((char *)nm) + ALIGNSHIFT); #else return nm; #endif }