Пример #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
/**
 * 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
/**
 * 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;
}