static void *thread_wrapper ( void* value) { LOGE("thread wrapper"); int pts; char** thread_arg = (char**)value; global_vm->AttachCurrentThread(&global_env, NULL); setsid(); pts = open(thread_arg[0], O_RDWR); if(pts < 0){ LOGE("PTY open failed"); pth_exit(-1); } dup2(pts, 0); dup2(pts, 1); dup2(pts, 2); char* argv[3]; argv[0] = (char*)"vim"; argv[1] = (char*)thread_arg[1]; argv[2] = NULL; int val = setjmp(longjmp_env); if (val == 0) AndroidMain(argv[1]?2:1, (char**)argv); global_vm->DetachCurrentThread(); LOGE("thread leave"); pthread_mutex_destroy(&global_mutex); pth_exit(0); }
void * Thread::ThreadWrapper (void *arg) { ((Thread *) arg)->Run (&((Thread *) arg)->should_stop); if (((Thread *) arg)->autodel) delete ((Thread *) arg); pth_exit (0); return 0; }
/* enter a cancellation point */ void pth_cancel_point(void) { if ( pth_gctx_get()->pth_current->cancelreq == TRUE && pth_gctx_get()->pth_current->cancelstate & PTH_CANCEL_ENABLE) { /* avoid looping if cleanup handlers contain cancellation points */ pth_gctx_get()->pth_current->cancelreq = FALSE; pth_debug2("pth_cancel_point: terminating cancelled thread \"%s\"", pth_gctx_get()->pth_current->name); pth_exit(PTH_CANCELED); } return; }
void * Thread::ThreadWrapper (void *arg) { Thread *t = (Thread *) arg; t->Run (&t->should_stop); if (!t->joinable) t->tid = 0; if (t->autodel) delete t; pth_exit (0); return 0; }
int main (int ac, char *ag[]) { int addr; int len; int index; CArray result; LowLevelDriverInterface *iface = 0; memset (&arg, 0, sizeof (arg)); argp_parse (&argp, ac, ag, 0, &index, &arg); if (index > ac - 3) die ("more parameter expected"); if (index < ac - 3) die ("unexpected parameter"); signal (SIGPIPE, SIG_IGN); pth_init (); Logs t; t.setTraceLevel (arg.tracelevel); iface = Create (ag[index], &t); if (!iface) die ("initialisation failed"); if (!iface->init ()) die ("initialisation failed"); addr = readHex (ag[index + 1]); len = atoi (ag[index + 2]); int res = readEMIMem (iface, addr, len, result); if (!res) { printf ("Read failed"); } else { for (int i = 0; i < result (); i++) printf ("%02x ", result[i]); printf ("\n"); } delete iface; if (Cleanup) Cleanup (); pth_exit (0); return 0; }
__noreturn__ void task_exit (void) { int i; #ifdef PTHDEBUG printf ("task_exit: pid=%p\n", task_getpid ()); #endif for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == task_getpid ()) { task_data_table[i].pid = 0; #ifdef CONFIG_UI ui_write_task (i, 0); #endif for (;;) pth_exit (0); } fatal (ERR_TASK_KILL_FAILED); }
static void *RunThread(void *data) { SDL_RunThread(data); pth_exit((void*)0); return((void *)0); /* Prevent compiler warning */ }
void ldap_pvt_thread_exit( void *retval ) { pth_exit( retval ); }
int main (int ac, char *ag[]) { int index; pth_init (); argp_parse (&argp, ac, ag, ARGP_IN_ORDER, &index, &arg); // if you ever want this to be fatal, doing it here would be too late if (getuid () == 0) ERRORPRINTF (arg.tracer(), E_WARNING | 20, 0, "EIBD should not run as root"); signal (SIGPIPE, SIG_IGN); if (arg.daemon) { int fd = open (arg.daemon, O_WRONLY | O_APPEND | O_CREAT, FILE_MODE); if (fd == -1) die ("Can not open file %s", arg.daemon); int i = fork (); if (i < 0) die ("fork failed"); if (i > 0) exit (0); close (1); close (2); close (0); dup2 (fd, 1); dup2 (fd, 2); close (fd); setsid (); } FILE *pidf; if (arg.pidfile) if ((pidf = fopen (arg.pidfile, "w")) != NULL) { fprintf (pidf, "%d", getpid ()); fclose (pidf); } signal (SIGINT, SIG_IGN); signal (SIGTERM, SIG_IGN); // main loop #ifdef HAVE_SYSTEMD sd_notify(0,"READY=1"); #endif int sig; if (! arg.stop_now) do { sigset_t t1; sigemptyset (&t1); sigaddset (&t1, SIGINT); sigaddset (&t1, SIGHUP); sigaddset (&t1, SIGTERM); pth_sigwait (&t1, &sig); if (sig == SIGHUP && arg.daemon) { int fd = open (arg.daemon, O_WRONLY | O_APPEND | O_CREAT, FILE_MODE); if (fd == -1) { ERRORPRINTF (arg.tracer(), E_ERROR | 21, 0, "can't open log file %s", arg.daemon); continue; } close (1); close (2); dup2 (fd, 1); dup2 (fd, 2); close (fd); } } while (sig == SIGHUP); #ifdef HAVE_SYSTEMD sd_notify(0,"STOPPING=1"); #endif signal (SIGINT, SIG_DFL); signal (SIGTERM, SIG_DFL); #ifdef HAVE_GROUPCACHE DeleteGroupCache (); #endif arg.free_l3(); if (arg.pidfile) unlink (arg.pidfile); pth_yield (0); pth_yield (0); pth_yield (0); pth_yield (0); pth_exit (0); return 0; }
int main (int ac, char *ag[]) { int index; Queue < Server * >server; Server *s; Layer2Interface *l2; Layer3 *l3; #ifdef HAVE_EIBNETIPSERVER EIBnetServer *serv = 0; #endif memset (&arg, 0, sizeof (arg)); arg.addr = 0x0001; arg.errorlevel = LEVEL_WARNING; argp_parse (&argp, ac, ag, 0, &index, &arg); if (index > ac - 1) die ("url expected"); if (index < ac - 1) die ("unexpected parameter"); if (arg.port == 0 && arg.name == 0 && arg.serverip == 0) die ("No listen-address given"); signal (SIGPIPE, SIG_IGN); pth_init (); Trace t; t.SetTraceLevel (arg.tracelevel); t.SetErrorLevel (arg.errorlevel); /* if (getuid () == 0) ERRORPRINTF (&t, 0x37000001, 0, "EIBD should not run as root"); */ if(arg.eibnetname) { if(arg.eibnetname[0] == '=') arg.eibnetname++; if(strlen(arg.eibnetname) >= 30) die("EIBnetServer/IP name can't be longer then 30 char"); } if (arg.daemon) { int fd = open (arg.daemon, O_WRONLY | O_APPEND | O_CREAT, FILE_MODE); if (fd == -1) die ("Can not open file %s", arg.daemon); int i = fork (); if (i < 0) die ("fork failed"); if (i > 0) exit (0); close (1); close (2); close (0); dup2 (fd, 1); dup2 (fd, 2); close (fd); setsid (); } FILE *pidf; if (arg.pidfile) if ((pidf = fopen (arg.pidfile, "w")) != NULL) { fprintf (pidf, "%d", getpid ()); fclose (pidf); } l2 = Create (ag[index], arg.backendflags, &t); if (!l2 || !l2->init ()) die ("initialisation of the backend failed"); l3 = new Layer3 (l2, &t); if (arg.port) { s = new InetServer (l3, &t, arg.port); if (!s->init ()) die ("initialisation of the knxd inet protocol failed"); server.put (s); } if (arg.name) { s = new LocalServer (l3, &t, arg.name); if (!s->init ()) die ("initialisation of the knxd unix protocol failed"); server.put (s); } #ifdef HAVE_EIBNETIPSERVER serv = startServer (l3, &t, arg.eibnetname); #endif #ifdef HAVE_GROUPCACHE if (!CreateGroupCache (l3, &t, arg.groupcache)) die ("initialisation of the group cache failed"); #endif signal (SIGINT, SIG_IGN); signal (SIGTERM, SIG_IGN); int sig; do { sigset_t t1; sigemptyset (&t1); sigaddset (&t1, SIGINT); sigaddset (&t1, SIGHUP); sigaddset (&t1, SIGTERM); pth_sigwait (&t1, &sig); if (sig == SIGHUP && arg.daemon) { int fd = open (arg.daemon, O_WRONLY | O_APPEND | O_CREAT, FILE_MODE); if (fd == -1) { ERRORPRINTF (&t, 0x27000002, 0, "can't open log file %s", arg.daemon); continue; } close (1); close (2); dup2 (fd, 1); dup2 (fd, 2); close (fd); } } while (sig == SIGHUP); signal (SIGINT, SIG_DFL); signal (SIGTERM, SIG_DFL); while (!server.isempty ()) delete server.get (); #ifdef HAVE_EIBNETIPSERVER if (serv) delete serv; #endif #ifdef HAVE_GROUPCACHE DeleteGroupCache (); #endif delete l3; if (Cleanup) Cleanup (); if (arg.pidfile) unlink (arg.pidfile); pth_exit (0); return 0; }
static void pth_ex_terminate(ex_t *ex) { pth_exit(ex->ex_value); }
int main(int argc, char **argv) { struct sigaction action; struct sigaction o_action; #ifdef MPISRC int myid; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&myid); #endif #ifdef PTH // For debugging put interrupt here // On interrupt type this into gdb console: handle SIGUSR1 nostop print pass // Then continue int rc = pth_init(); if (!rc) { std::cerr << "couldn't start pth environment\n"; } #endif /* INTERRUPT HANDLER FOR GRACEFUL EXIT ON CTRL-C */ action.sa_handler = ctrlc; sigemptyset(&action.sa_mask); action.sa_flags = 0; if (sigaction(SIGTERM,&action,&o_action)) printf("interrupt handler failed\n"); /* NORMAL SIMULATION */ if (argc < 2) { std::cerr << "# Need to specify input file" << std::endl; exit(1); } // sleep(20); sim::blks.go(argv[1]); #ifdef PTH pth_exit(NULL); #endif #ifdef MPISRC MPI_Finalize(); #endif // //#ifdef DEBUG // extern FLT f1(int n, FLT x, FLT y); // // myblock.init(argv[1]); // myblock.minvrt_test(10,f1); // myblock.output(-2,text); // myblock.go(); //#endif // // //#ifdef FINDMAX // tri_basis b; // hp_mgrid hp; // b.initialize(4,5); // hp.in_mesh(argv[1],grid,1.0); // hp.tri_hp::allocate(&b); // hp.input(argv[1],tecplot); // hp.findintercept(CURV_MASK,&ydist); // //hp.findmaxy(CURV_MASK); // // hp.findmaxx(CURV_MASK); // //FLT avg[5]; // //hp.integrated_averages(avg); // //printf("%e %e %e %e %e\n",avg[0],avg[1],avg[2],avg[3],avg[4]); //#endif }
int main(int argc, char **argv) { struct sigaction action; struct sigaction o_action; #ifdef MPISRC int myid; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&myid); std::cout << "Running processes " << getpid() << std::endl; // system("sleep 20"); #endif #ifdef PTH // For debugging put interrupt here // Then on interrupt in console window type: // for gdb console: handle SIGUSR1 nostop print pass // for lldb: pro hand -p true -s false SIGUSR1 // Then hit continue int rc = pth_init(); if (!rc) { std::cerr << "couldn't start pth environment" << std::endl; } #endif #ifdef petsc PetscErrorCode err = PetscInitialize(&argc,&argv,(char *)0,help); CHKERRABORT(MPI_COMM_WORLD,err); #endif /* INTERRUPT HANDLER FOR GRACEFUL EXIT ON CTRL-C */ action.sa_handler = ctrlc; sigemptyset(&action.sa_mask); action.sa_flags = 0; if (sigaction(SIGTERM,&action,&o_action)) std::cerr << "interrupt handler failed" << std::endl; /* NORMAL SIMULATION */ if (argc < 2) { std::cerr << "# Need to specify input file" << std::endl; sim::abort(__LINE__,__FILE__,&std::cerr); } sim::blks.go(argv[1]); #ifdef petsc PetscFinalize(); #endif #ifdef PTH pth_exit(NULL); #endif #ifdef MPISRC MPI_Finalize(); #endif // //#ifdef DEBUG // extern FLT f1(int n, FLT x, FLT y); // // myblock.init(argv[1]); // myblock.minvrt_test(10,f1); // myblock.output(-2,text); // myblock.go(); //#endif // // //#ifdef FINDMAX // tri_basis b; // hp_mgrid hp; // b.initialize(4,5); // hp.in_mesh(argv[1],grid,1.0); // hp.tri_hp::allocate(&b); // hp.input(argv[1],tecplot); // hp.findintercept(CURV_MASK,&ydist); // //hp.findmaxy(CURV_MASK); // // hp.findmaxx(CURV_MASK); // //FLT avg[5]; // //hp.integrated_averages(avg); //#endif return 0; }