/* * mgTaskDeleteForce is a dangerous function that should only be used in * the most extreme cases. You should call mgTaskDeleteForce only if you * know exactly what the target thread is doing, and you control all of * the code that the target thread could possibly be running at the time * of the termination. * */ int task_delete_force(OSI_LIB_HANDLE MgTaskHandle) { #ifdef WINDOWS_OS DWORD ExitCode; WIN_HANDLE WinThreadHandle; WinThreadHandle=(WIN_HANDLE)MgTaskHandle; if (GetExitCodeThread(WinThreadHandle,&ExitCode)==0) { return AII_ERROR; } if (TerminateThread(WinThreadHandle,ExitCode)==0) { return AII_ERROR; } return AII_OK; #endif #ifdef VXWORKS_OS int status; status=taskDeleteForce(MgTaskHandle); return status; #endif #ifdef LINUX_OS #endif }
bool TimeClean(Id*& id, milliseconds_t milliDuration) { // this would delete the task in any case bool ret = true; if (!Clean(id)) { Self::Sleep(milliDuration); taskDeleteForce(id->TaskId); id->TaskId = Id::INVALID_ID; ret = false; delete id; } return ret; }
static int __wind_task_deleteforce(struct pt_regs *regs) { xnhandle_t handle = __xn_reg_arg1(regs); WIND_TCB *pTcb; if (handle) pTcb = __wind_lookup_task(handle); else pTcb = __wind_task_current(current); if (!pTcb) return S_objLib_OBJ_ID_ERROR; if (taskDeleteForce((TASK_ID) pTcb) == ERROR) return wind_errnoget(); return 0; }
/* Start an Erlang node. return value 0 indicates that node was * started successfully, negative values indicate error. * * node - the name of the remote node to start (alivename@hostname). * flags - turn on or off certain options. See erl_start.h for a list. * erl - is the name of the erl script to call. If NULL, the default * name "erl" will be used. * args - a NULL-terminated list of strings containing * additional arguments to be sent to the remote Erlang node. These * strings are simply appended to the end of the command line, so any * quoting of special characters, etc must be done by the caller. * There may be some conflicts between some of these arguments and the * default arguments hard-coded into this function, so be careful. */ int erl_start_sys(ei_cnode *ec, char *alive, Erl_IpAddr adr, int flags, char *erl, char *args[]) { struct timeval timeout; struct sockaddr_in addr; SocklenType namelen; int port; int sockd = 0; int one = 1; #if defined(VXWORKS) || defined(__WIN32__) unsigned long pid = 0; #else int pid = 0; #endif int r = 0; if (((sockd = socket(AF_INET, SOCK_STREAM, 0)) < 0) || (setsockopt(sockd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)) < 0)) { r = ERL_SYS_ERROR; goto done; } memset(&addr,0,sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = 0; if (bind(sockd,(struct sockaddr *)&addr,sizeof(addr))<0) { return ERL_SYS_ERROR; } namelen = sizeof(addr); if (getsockname(sockd,(struct sockaddr *)&addr,&namelen)<0) { return ERL_SYS_ERROR; } port = ntohs(addr.sin_port); listen(sockd,5); #if defined(VXWORKS) || defined(__WIN32__) if((pid = spawn_erlang_epmd(ec,alive,adr,flags,erl,args,port,1)) == 0) return ERL_SYS_ERROR; timeout.tv_usec = 0; timeout.tv_sec = 10; /* ignoring ERL_START_TIME */ if((r = wait_for_erlang(sockd,unique_id(),&timeout)) == ERL_TIMEOUT) { #if defined(VXWORKS) taskDelete((int) pid); if(taskIdVerify((int) pid) != ERROR) taskDeleteForce((int) pid); #else /* Windows */ /* Well, this is not a nice way to do it, and it does not always kill the emulator, but the alternatives are few.*/ TerminateProcess((HANDLE) pid,1); #endif /* defined(VXWORKS) */ } #else /* Unix */ switch ((pid = fork())) { case -1: r = ERL_SYS_ERROR; break; case 0: /* child - start the erlang node */ exec_erlang(ec, alive, adr, flags, erl, args, port); /* error if reached - parent reports back to caller after timeout so we just exit here */ exit(1); break; default: /* parent - waits for response from Erlang node */ /* child pid used here as magic number */ timeout.tv_usec = 0; timeout.tv_sec = 10; /* ignoring ERL_START_TIME */ if ((r = wait_for_erlang(sockd,pid,&timeout)) == ERL_TIMEOUT) { /* kill child if no response */ kill(pid,SIGINT); sleep(1); if (waitpid(pid,NULL,WNOHANG) != pid) { /* no luck - try harder */ kill(pid,SIGKILL); sleep(1); waitpid(pid,NULL,WNOHANG); } } } #endif /* defined(VXWORKS) || defined(__WIN32__) */ done: #if defined(__WIN32__) if (sockd) closesocket(sockd); #else if (sockd) close(sockd); #endif return r; } /* erl_start_sys() */
static int __wind_task_init(struct pt_regs *regs) { xncompletion_t __user *u_completion; struct task_struct *p = current; char name[XNOBJECT_NAME_LEN]; struct wind_arg_bulk bulk; int err = 0, prio, flags; WIND_TCB_PLACEHOLDER ph; WIND_TCB *task; if (__xn_safe_copy_from_user(&bulk, (void __user *)__xn_reg_arg1(regs), sizeof(bulk))) return -EFAULT; if (bulk.a1) { if (__xn_safe_strncpy_from_user(name, (const char __user *)bulk.a1, sizeof(name) - 1) < 0) return -EFAULT; name[sizeof(name) - 1] = '\0'; strncpy(p->comm, name, sizeof(p->comm)); p->comm[sizeof(p->comm) - 1] = '\0'; } else *name = '\0'; /* Task priority. */ prio = bulk.a2; /* Task flags. */ flags = bulk.a3 | VX_SHADOW; /* Completion descriptor our parent thread is pending on. */ u_completion = (xncompletion_t __user *)__xn_reg_arg3(regs); task = (WIND_TCB *)xnmalloc(sizeof(*task)); if (!task) { err = -ENOMEM; goto fail; } xnthread_clear_state(&task->threadbase, XNZOMBIE); /* Force FPU support in user-space. This will lead to a no-op if the platform does not support it. */ if (taskInit(task, name, prio, flags, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == OK) { /* Let the skin discard the TCB memory upon exit. */ task->auto_delete = 1; task->ptid = bulk.a4; /* Copy back the registry handle to the ph struct. */ ph.handle = xnthread_handle(&task->threadbase); if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg2(regs), &ph, sizeof(ph))) err = -EFAULT; else { err = xnshadow_map(&task->threadbase, u_completion, (unsigned long __user *)bulk.a5); if (!err) goto out; } taskDeleteForce((TASK_ID) task); } else err = wind_errnoget(); /* Unblock and pass back error code. */ fail: if (u_completion) xnshadow_signal_completion(u_completion, err); if (task && !xnthread_test_state(&task->threadbase, XNZOMBIE)) xnfree(task); out: return err; }