/* * 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; }
/* * 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; }