_Noreturn void serv_error(const char *fmt, ...) { va_list fmt_args; fprintf(stderr, "Server error: "); va_start(fmt_args, fmt); vfprintf(stderr, fmt, fmt_args); va_end(fmt_args); fprintf(stderr, " (%d; %s)\n", errno, strerror(errno)); if(interrupted) { fprintf(stderr, "An error has occured during error handling. Exiting"); quick_exit(EXIT_FAILURE); } interrupted = true; // If an error has occurred in the main thread, call the signal handler if(pthread_equal(main_thread, pthread_self())) exit_server(interrupted); else { // Otherwise, report the error to the main thread if(-1 == kill(getpid(), SIGINT)) { fprintf(stderr, "Fatal error. Unable to kill\n"); quick_exit(EXIT_FAILURE);; } else exit_thread(); } }
// Show Main Menu int main_menu(int argc, char *argv[]) { char main_menu_char; printf("\n----------------------------------------------------\n"); printf(" What do you want to do?"); printf("\n----------------------------------------------------\n"); printf("\na) interact with the Fortune Cookie Server\nb) interact with the encryption/decryption server\nc) quit\n"); printf("\n----------------------------------------------------\n\n"); scanf("%s", &main_menu_char); getchar(); switch (tolower(main_menu_char)) { case 'a': fortune_cookie(); break; case 'b': encryption_decryption(); break; case 'c': quick_exit(); break; default : printf("\nPlease enter either a or b or c.\n"); break; } return 1; }
int main(int argumentCount, char **argumentVector) { // setup logging boost::log::add_file_log("sample.log"); //start signal handler KDetTestArea::signalBlockingHandler daHandler; // daHandler.wait();// I guess this is a degenerate test of the handler construction //spawn my threads static KDetTestArea::RedShirt gonnaDieAtWeirdTimes; KDetTestArea::RedShirt mightLive; //detach from console pid_t processId = fork(); if(0 != processId) { quick_exit(EXIT_SUCCESS); } daHandler.wait();// I guess this is a degenerate test of the handler construction //never reached with call to exit() BOOST_LOG_TRIVIAL(trace) << "WTF"; return EXIT_FAILURE; }
void keyPress(unsigned char key, int x, int y){ if (key == 'w'){ btVector3 velocity(0,0,0); velocity = box2->getLinearVelocity(); box2->applyCentralImpulse(btVector3(0,0,-3)); } if (key == 's'){ btVector3 velocity(0,0,0); velocity = box2->getLinearVelocity(); box2->applyCentralImpulse(btVector3(0,0,3)); } if (key == 'a'){ btVector3 velocity(0,0,0); velocity = box2->getLinearVelocity(); box2->applyCentralImpulse(btVector3(-3,0,0)); } if (key == 'd'){ btVector3 velocity(0,0,0); velocity = box2->getLinearVelocity(); box2->applyCentralImpulse(btVector3(3,0,0)); } else if (key == 27){ quick_exit(0); } tim(); }
// Test procedure for quick_exit() int main() { // Attempt to exit using quick_exit quick_exit(EXIT_SUCCESS); // Return failure return EXIT_FAILURE; }
// Show fortune cookie menu int fortune_cookie() { int sock; struct sockaddr_in server; char message[1000] , server_reply[2000]; //Create socket sock = socket(AF_INET , SOCK_STREAM , 0); if (sock == -1) { printf("Could not create socket"); } //puts("Socket created"); server.sin_addr.s_addr = inet_addr("127.0.0.1"); server.sin_family = AF_INET; server.sin_port = htons(5000); //Connect to remote server if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0) { perror("connect failed. Error"); return 1; } //keep communicating with server while(1) { printf("\n----------------------------------------------------\n"); printf(" How many fortune cookies do you need?"); printf("\n----------------------------------------------------\n\n"); scanf("%s" , message); //Send some data if( send(sock , message , strlen(message) , 0) < 0) { puts("Send failed"); return 1; } //Receive a reply from the server if( recv(sock , server_reply , 2000 , 0) < 0) { puts("recv failed"); quick_exit(); } printf("Server reply :"); char *pch = strstr(server_reply, "#"); pch++; //Remove the first char int server_reply_len = atoi(pch); printf(" %.*s\n", server_reply_len, server_reply); } return 0; }
TEST(stdlib, quick_exit) { pid_t pid = fork(); ASSERT_NE(-1, pid) << strerror(errno); if (pid == 0) { quick_exit(99); } AssertChildExited(pid, 99); }
int main(void) { int a = -1; atexit( nexit); at_quick_exit( qexit); if( a < 0) quick_exit(EXIT_FAILURE); return 0; }
int main(int argc, const char *argv[]) { int status; if (argc != 2) abort(); status = atoi(argv[1]); quick_exit(status); abort(); }
TEST(stdlib, at_quick_exit) { pid_t pid = fork(); ASSERT_NE(-1, pid) << strerror(errno); if (pid == 0) { ASSERT_EQ(at_quick_exit(quick_exit_2), 0); ASSERT_EQ(at_quick_exit(quick_exit_1), 0); atexit(not_run); quick_exit(99); } AssertChildExited(pid, 99); }
TEST(stdlib, quick_exit) { pid_t pid = fork(); ASSERT_NE(-1, pid) << strerror(errno); if (pid == 0) { quick_exit(99); } int status; ASSERT_EQ(pid, waitpid(pid, &status, 0)); ASSERT_TRUE(WIFEXITED(status)); ASSERT_EQ(99, WEXITSTATUS(status)); }
TEST(stdlib, at_quick_exit) { pid_t pid = fork(); ASSERT_NE(-1, pid) << strerror(errno); if (pid == 0) { ASSERT_EQ(at_quick_exit(quick_exit_2), 0); ASSERT_EQ(at_quick_exit(quick_exit_1), 0); atexit(not_run); quick_exit(99); } int status; ASSERT_EQ(pid, waitpid(pid, &status, 0)); ASSERT_TRUE(WIFEXITED(status)); ASSERT_EQ(99, WEXITSTATUS(status)); }
// Disconnect players, free the sockets, and exit quickly // Does NOT run the atexits Widget::~Widget() { logInfos=false; // logMessage while we're trying to destroy would crash. //logMessage(QString("UDP: Disconnecting all players")); for (;udpPlayers.size();) { Player* player = udpPlayers[0]; sendMessage(player, MsgDisconnect, "Connection closed by the server admin"); // Save the pony QList<Pony> ponies = Player::loadPonies(player); for (int i=0; i<ponies.size(); i++) if (ponies[i].ponyData == player->pony.ponyData) ponies[i] = player->pony; Player::savePonies(player, ponies); player->pony.saveInventory(); player->pony.saveQuests(); // Free delete player; udpPlayers.removeFirst(); } for (int i=0; i<quests.size(); i++) { delete quests[i].commands; delete quests[i].name; delete quests[i].descr; } stopServer(false); delete tcpServer; delete tcpReceivedDatas; delete udpSocket; delete pingTimer; delete cmdPeer; delete[] usedids; delete ui; // We freed everything that was important, so don't waste time in atexits #if defined WIN32 || defined _WIN32 || defined __APPLE__ _exit(EXIT_SUCCESS); #else quick_exit(EXIT_SUCCESS); #endif }
void server_node::start() { if (is_started()) throw std::runtime_error("Server node \"" + m_path + "\" is already started"); if (m_fork) { m_kill_sent = false; m_pid = fork(); if (m_pid == -1) { m_pid = 0; int err = -errno; throw_error(err, "Failed to fork process"); } else if (m_pid == 0) { char buffer[3][1024] = { " ", "-c" }; std::string ios_path = ioserv_path(); char * const args[] = { const_cast<char*>(ios_path.c_str()), buffer[1], const_cast<char*>(m_path.c_str()), NULL }; auto ld_path = std::string("LD_LIBRARY_PATH=") + getenv("LD_LIBRARY_PATH"); char * const env[] = { const_cast<char*>(ld_path.c_str()), NULL }; if (execve(ios_path.data(), args, env) == -1) { int err = -errno; std::cerr << create_error(err, "Failed to start process \"%s\"", ios_path.c_str()).message() << std::endl; quick_exit(1); } } } else { m_node = dnet_parse_config(m_path.c_str(), 0); } if (!is_started()) throw std::runtime_error("Can not start server with config file: \"" + m_path + "\""); }
// Disconnect players, free the sockets, and exit quickly // Does NOT run the atexits Widget::~Widget() { logMessage(QString("UDP: Disconnecting all players")); for (;udpPlayers.size();) { Player* player = udpPlayers[0]; sendMessage(player, MsgDisconnect, "Connection closed by the server admin"); // Save the pony QList<Pony> ponies = Player::loadPonies(player); for (int i=0; i<ponies.size(); i++) if (ponies[i].ponyData == player->pony.ponyData) ponies[i] = player->pony; Player::savePonies(player, ponies); // Free delete player; udpPlayers.removeFirst(); } stopServer(); delete tcpServer; delete tcpReceivedDatas; delete udpSocket; delete pingTimer; delete cmdPeer; delete ui; // We freed everything that was important, so don't waste time in atexits #ifdef WIN32 _exit(EXIT_SUCCESS); #else quick_exit(EXIT_SUCCESS); #endif }
int main() { at_quick_exit(bar); quick_exit(0); }
void exit_error(const std::string &s) { perror(s); quick_exit(EXIT_FAILURE); }
void timeout(int x) { quick_exit(19); }
void exit_error(const std::string &s, const std::string &fileName) { perror(s, fileName); quick_exit(EXIT_FAILURE); }
static void handler (int unused) { quick_exit (EXPECTED_STATUS); }