예제 #1
0
/**
 * check if all SER2Jab workers are still alive
 * - if not, try to launch new ones
 */
void xjab_check_workers(int mpid)
{
	int i, n, stat;
	//DBG("XJAB:%d:xjab_check_workers: time=%d\n", mpid, get_ticks());
	if(!jwl || jwl->len <= 0)
		return;
	for(i=0; i < jwl->len; i++)
	{
		if(jwl->workers[i].pid > 0)
		{
			stat = 0;
			n = waitpid(jwl->workers[i].pid, &stat, WNOHANG);
			if(n == 0 || n!=jwl->workers[i].pid)
				continue;
		
			LOG(L_ERR,"XJAB:xjab_check_workers: worker[%d][pid=%d] has exited"
				" - status=%d err=%d errno=%d\n", i, jwl->workers[i].pid, 
				stat, n, errno);
			xj_wlist_clean_jobs(jwl, i, 1);
			xj_wlist_set_pid(jwl, -1, i);
		}
		
#ifdef XJ_EXTRA_DEBUG
		DBG("XJAB:%d:xjab_check_workers: create a new worker[%d]\n", mpid, i);
#endif
		if ( (stat=fork())<0 )
		{
#ifdef XJ_EXTRA_DEBUG
			DBG("XJAB:xjab_check_workers: error - cannot launch new"
				" worker[%d]\n", i);
#endif
			LOG(L_ERR, "XJAB:xjab_check_workers: error - worker[%d] lost"
				" forever \n", i);
			return;
		}
		if (stat == 0)
		{
			if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
			{
				LOG(L_ERR, "XJAB:xjab_check_workers: error setting new"
					" worker's pid - w[%d]\n", i);
				return;
			}
			xj_worker_process(jwl,jaddress,jport,i,db_con[i]);
			exit(0);
		}
	}			
}
예제 #2
0
파일: jabber.c 프로젝트: mtulio/mtulio
/**
 * check if all SER2Jab workers are still alive
 * - if not, try to launch new ones
 */
void xjab_check_workers(int mpid)
{
	int i, n, stat;
	//LM_DBG("time=%d\n", get_ticks());
	if(!jwl || jwl->len <= 0)
		return;
	for(i=0; i < jwl->len; i++)
	{
		if(jwl->workers[i].pid > 0)
		{
			stat = 0;
			n = waitpid(jwl->workers[i].pid, &stat, WNOHANG);
			if(n == 0 || n!=jwl->workers[i].pid)
				continue;
		
			LM_ERR("worker[%d][pid=%d] has exited - status=%d err=%d"
					"errno=%d\n", i, jwl->workers[i].pid, stat, n, errno);
			xj_wlist_clean_jobs(jwl, i, 1);
			xj_wlist_set_pid(jwl, -1, i);
		}
		
#ifdef XJ_EXTRA_DEBUG
		LM_DBG("create a new worker[%d]\n", i);
#endif
		if ( (stat=fork())<0 )
		{
#ifdef XJ_EXTRA_DEBUG
			LM_DBG("cannot launch new worker[%d]\n", i);
#endif
			LM_ERR("worker[%d] lost forever \n", i);
			return;
		}
		if (stat == 0)
		{
			if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
			{
				LM_ERR("failed to set new worker's pid - w[%d]\n", i);
				return;
			}
			xj_worker_process(jwl,jaddress,jport,priority, i,
					db_con[i], &jabber_dbf);
			exit(0);
		}
	}			
}
예제 #3
0
파일: jabber.c 프로젝트: mtulio/mtulio
/*
 * Initialize children
 */
static int child_init(int rank)
{
	int i, j, mpid, cpid;
	
	LM_DBG("initializing child <%d>\n", rank);
	     /* Rank 0 is main process now - 1 is the first child (janakj) */
	if(rank == 1)
	{
#ifdef HAVE_IHTTP
		/** register iHTTP callbacks -- go forward in any case*/
		ihb.reg_f("xjab", "XMPP Gateway", IH_MENU_YES,
				xjab_mod_info, NULL);
		ihb.reg_f("xjabc", "XMPP connections", IH_MENU_YES,
				xjab_connections, NULL);
#endif
		if((mpid=fork())<0 )
		{
			LM_ERR("cannot launch worker's manager\n");
			return -1;
		}
		if(mpid == 0)
		{
			/** launching the workers */
			for(i=0;i<nrw;i++)
			{
				if ( (cpid=fork())<0 )
				{
					LM_ERR("cannot launch worker\n");
					return -1;
				}
				if (cpid == 0)
				{
					for(j=0;j<nrw;j++)
						if(j!=i) close(pipes[j][0]);
					close(pipes[i][1]);
					if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
					{
						LM_ERR("failed to set worker's pid\n");
						return -1;
					}
					xj_worker_process(jwl,jaddress,jport, priority, i, 
							db_con[i], &jabber_dbf);
					exit(0);
				}
			}

			mpid = getpid();
			while(1)
			{
				sleep(check_time);
				xjab_check_workers(mpid);
			}
		}
	}
	
	//if(pipes)
	//{
	//	for(i=0;i<nrw;i++)
	//		close(pipes[i][0]);
	//}
	return 0;
}
예제 #4
0
파일: jabber.c 프로젝트: 4N7HR4X/kamailio
/**
 * check if all SER2Jab workers are still alive
 * - if not, try to launch new ones
 */
void xjab_check_workers(int mpid)
{
	int i, n, stat;
	//DBG("XJAB:%d:xjab_check_workers: time=%d\n", mpid, get_ticks());
	if(!jwl || jwl->len <= 0)
		return;
	for(i=0; i < jwl->len; i++)
	{
		if(jwl->workers[i].pid > 0)
		{
			stat = 0;
			n = waitpid(jwl->workers[i].pid, &stat, WNOHANG);
			if(n == 0 || n!=jwl->workers[i].pid)
				continue;

			LOG(L_ERR,"XJAB:xjab_check_workers: worker[%d][pid=%d] has exited"
				" - status=%d err=%d errno=%d\n", i, jwl->workers[i].pid,
				stat, n, errno);
			xj_wlist_clean_jobs(jwl, i, 1);
			xj_wlist_set_pid(jwl, -1, i);
		}

#ifdef XJ_EXTRA_DEBUG
		DBG("XJAB:%d:xjab_check_workers: create a new worker[%d]\n", mpid, i);
#endif
		if ( (stat=fork())<0 )
		{
#ifdef XJ_EXTRA_DEBUG
			DBG("XJAB:xjab_check_workers: error - cannot launch new"
				" worker[%d]\n", i);
#endif
			LOG(L_ERR, "XJAB:xjab_check_workers: error - worker[%d] lost"
				" forever \n", i);
			return;
		}
		if (stat == 0)
		{
			if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
			{
				LOG(L_ERR, "XJAB:xjab_check_workers: error setting new"
					" worker's pid - w[%d]\n", i);
				return;
			}


			/* initialize the config framework
			 * The child process was not registered under
			 * the framework during mod_init, therefore the
			 * late version needs to be called. (Miklos) */
			if (cfg_late_child_init()) return;

			ctx = db_ctx("jabber");
			if (ctx == NULL) goto dberror;
			if (db_add_db(ctx, db_url) < 0) goto dberror;
			if (db_connect(ctx) < 0) goto dberror;

			cmd = db_cmd(DB_GET, ctx, db_table, db_cols, db_params, NULL);
			if (!cmd) goto dberror;
			
			xj_worker_process(jwl,jaddress,jport,i, cmd);

			db_cmd_free(cmd);
			db_ctx_free(ctx);
			ctx = NULL;

			/* destroy the local config */
			cfg_child_destroy();

			exit(0);
		}
	}
	
 dberror:
	if (cmd) db_cmd_free(cmd);
	cmd = NULL;
	if (ctx) db_ctx_free(ctx);
	ctx = NULL;
}
예제 #5
0
파일: jabber.c 프로젝트: 4N7HR4X/kamailio
/*
 * Initialize children
 */
static int child_init(int rank)
{
	int i, j, mpid, cpid;

	DBG("XJAB:child_init: initializing child <%d>\n", rank);
	     /* Rank 0 is main process now - 1 is the first child (janakj) */
	if(rank == 1)
	{
#ifdef HAVE_IHTTP
		/** register iHTTP callbacks -- go forward in any case*/
		ihb.reg_f("xjab", "XMPP Gateway", IH_MENU_YES,
				xjab_mod_info, NULL);
		ihb.reg_f("xjabc", "XMPP connections", IH_MENU_YES,
				xjab_connections, NULL);
#endif
		if((mpid=fork())<0 )
		{
			LOG(L_ERR, "XJAB:child_init:error - cannot launch worker's"
					" manager\n");
			return -1;
		}
		if(mpid == 0)
		{
			/** launching the workers */
			for(i=0;i<nrw;i++)
			{
				if ( (cpid=fork())<0 )
				{
					LOG(L_ERR,"XJAB:child_init:error - cannot launch worker\n");
					return -1;
				}
				if (cpid == 0)
				{
					for(j=0;j<nrw;j++)
						if(j!=i) close(pipes[j][0]);
					close(pipes[i][1]);
					if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
					{
						LOG(L_ERR, "XJAB:child_init:error setting worker's"
										" pid\n");
						return -1;
					}

					/* initialize the config framework */
					if (cfg_child_init()) return -1;

					ctx = db_ctx("jabber");
					if (ctx == NULL) goto dberror;
					if (db_add_db(ctx, db_url) < 0) goto dberror;
					if (db_connect(ctx) < 0) goto dberror;

					cmd = db_cmd(DB_GET, ctx, db_table, db_cols, db_params, NULL);
					if (!cmd) goto dberror;

					xj_worker_process(jwl,jaddress,jport,i, cmd);

					db_cmd_free(cmd);
					db_ctx_free(ctx);
					ctx = NULL;

					/* destroy the local config */
					cfg_child_destroy();

					exit(0);
				}
			}

			mpid = getpid();

			/* initialize the config framework */
			if (cfg_child_init()) return -1;

			while(1)
			{
				sleep(check_time);

				/* update the local config */
				cfg_update();

				xjab_check_workers(mpid);
			}
		}
	}

	//if(pipes)
	//{
	//	for(i=0;i<nrw;i++)
	//		close(pipes[i][0]);
	//}
	return 0;

 dberror:
	if (cmd) db_cmd_free(cmd);
	cmd = NULL;
	if (ctx) db_ctx_free(ctx);
	ctx = NULL;
	return -1;
}