static void *thread2(ThreadArgs *ta)
{	vFUNCP func;
	char **av;
	int si;

	thread_start(ta->a_name,ta);
	av = ta->a_argv;
	func = (vFUNCP)av[0];
	(*func)(av[1],av[2],av[3],av[4],av[5],av[6],av[7]);
	if( ta->a_saddr ){
		for( si = 0; si < ta->a_ssize; si++ ){
			if( ta->a_saddr[si] ){
				break;
			}
		}
		syslog_ERROR("--## used %X / %X ##-- %X %X + %X\n",
			ta->a_ssize-si,ta->a_ssize,
			p2i(&ta),p2i(ta->a_saddr),si
		);
		//free(ta->a_saddr);
	}
	/*
	free(ta);
	*/
	thread_done(0);
	pthread_exit(0);
	porting_dbg("#### pthread_exit() failed.");
	exit(-1);
}
Beispiel #2
0
void Jadro::run() { //only one instance thread can by run
	std::cout<<"RUN convert"<<std::endl;
	Glib::Mutex::Lock lock(mutex);
	Generator gen(gui, information);
	Glib::ustring command = gen.run();
	info->setStatus(-1);
	//info->setNazov(information->getName());
	status = 0;
	ex_duration = -1;
	ex_duration = information->getEnd() - information->getStart();
	int pc[2]; /* Parent to child pipe */
	int cp[2]; /* Child to parent pipe */
	int pid;
	chipid = -1;
	char ch;
	int assd = -1;
	int stat = 0;
	if (info->getConvert() == true) {
		if (pipe(pc) >= 0 && pipe(cp) >= 0) {
			switch (pid = fork()) {
			case -1:
				std::cout<<"ABORT"<<std::endl;
				abort(); //internal error
			case 0: /* Child. */
				close(2); /* Close current stderr. */
				if(dup(cp[1]) < 0 ){ /* Make stderr go to write end of pipe. */
					stat = -1;
				} 
				close(0); /* Close current stdin. */
				if(dup(pc[0]) < 0 ){ /* Make stdin come from read end of pipe. */
					stat = -1;
				} 
				close(pc[1]);
				close(cp[0]);
				if(stat != -1){
					assd = system(command.c_str());
					std::cerr<<"onibo_status="<<assd<<std::endl;
				}
				abort(); //exit proces
			default:
				chipid = pid;
				close(pc[1]);
				close(cp[1]);
				Glib::ustring riadok = "";
				while (read(cp[0], &ch, sizeof(char)) == 1) {
					if (ch == '\r' || ch == '\n') {
						analyza(riadok);
						riadok = "";
					} else {
						riadok = riadok + ch;
					}
				}
				wait(NULL); //wait for close child proces
				chipid = -1;
			}
		} else {
			status = 4; //system error
		}
	} else {
		status = 3;
	}
	info->setFragment(0);
	info->setStatus(status);
	message();
	thread_done();
}
static void thread_exit(void *code){
	thread_done(code);
	pthread_exit(code);
}