Exemplo n.º 1
0
/*{
** Name: CXget_context - Parse command arguments for NUMA args.
**
** Description:
**
**	One particularly ugly requirement of NUMA clusters, is the need
**	to specify the target context of certain commands that
**	normally could easily determine a default context by themselves.
**
**	E.g. 'lockstat' run on any node of a non-NUMA cluster "knows"
**	implicitly that the current node corresponds to the current host.
**
**	However, in a NUMA cluster, this happy state, no longer applies.
**	If our sysadm logs onto a node which is configured into two or
**	more virtual NUMA nodes, there is no way for 'lockstat', etc.,
**	to guess which of the virtual nodes is the target for the Ingres
**	tool.
**
**	We try to make a virtue of this neccesity by centralizing the
**	parsing needed for these commands and in passing pick up a
**	generalized way of setting processor affinity for Ingres tools.
**	
**	Two types of arguments are checked here:
**	 '-rad' is a RAD spec, in which the host machine is implicitly
**	the local machine.
**
**	 '-node' may refer to either a local RAD by its node name or 
**	node alias, or to a node anywhere in thr cluster if CX_NSC_NODE_GLOBAL
**	is set.
**
**	Both arguments can be in the form -arg=value, or -arg value.
**
**	The users input	is checked against the following rules:
**
**	R1: If NOT running clusters, '-node' parameter will always
**	    cause an error.
**
**	R2: Only one of either "-node" or "-rad" is allowed.
**
**	R3: If "-rad" is present, value must correspond to a valid RAD.
**
**	R4: If "-node" is present, it must be a valid node, or node alias.
**
**	    R4a: If CX_NSC_NODE_GLOBAL is not set, node must match local host
**	         name or be hosted (virtual nodes only) by local host.
**
**	R5: If not otherwise specified, and running NUMA clusters,
**	    RAD value is taken from environment variable II_DEFAULT_RAD.
**
**	R6: If running NUMA clusters, and CX_NSC_RAD_OPTIONAL is not
**	    set, an error will be reported if context is not set by a
**	    valid -rad, or -node, or II_DEFAULT_RAD value.
**
**	R7: If rules R2-R6 are not violated, and CX_NSC_CONSUME is set,
**	    and an matching parameter or parameter pair was provided,
**	    the parameters are removed from the argument vector, and
**	    the argument count is adjusted.
**
**	R8: If CX_NSC_SET_CONTEXT is set, and not running NUMA clusters,
**	    and a valid RAD value was provided with an explicit '-rad'
**	    argument, CXnuma_bind_to_rad is called to set process affinity
**	    to the specified RAD.
**
**	R9: If CX_NSC_SET_CONTEXT is set, running NUMA clusters, or
**	    if a valid '-node' parameter was supplied, CXset_cluster
**	    is called for the specified node.
**
**	R10: If CX_NSC_REPORT_ERRS is set, and an error occurred,
**	    message is sent to stdout.
**	
**	If all appropriate rules are met, then OK is returned.
**	Caller should be set up to catch and complain about any
**	extra invalid parameters.
**	
**	If outbuf is not NULL, node name if copied out if status =
**	OK, else error message text is copies out.  In both cases
**	only a max of outlen chars are returned, including an EOS.
**
** Inputs:
**	
**	pargc	- Address of integer holding # of arg strings.
**
**	argv	- Array of string pointers to argument values.
**
**	flags	- Flag bits OR'ed together.  Valid flags are:
**
**		CX_NSC_REPORT_ERRS - Emit any error message to stdout.
**
**		CX_NSC_NODE_GLOBAL - Allow node argument to refer to
**				     Nodes outside the current host.
**
**		CX_NSC_CONSUME	   - Eat any -rad/-node args & values if OK.
**
**		CX_NSC_IGNORE_NODE - Ignore '-node' params in scan.
**
**		CX_NSC_SET_CONTEXT - Set CX context based on good params.
**
**		CX_NSC_RAD_OPTIONAL - Don't fail if NUMA & RAD not set.
**				     If running NUMA clusters, only
**				     set this in combination with
**				     CX_NSC_SET_CONTEXT if you are sure
**				     that shared memory won't be accessed,
**				     and all you need is to retreive the
**				     context later (e.g. iirun).
**
**	outbuf  - buffer to receive nodename, or error message text.
**
**	outlen  - limit to # bytes copied to outbuf.
**
** Outputs:
**	
**	*pargc	- decremented by if argument(s) are consumed.
**
**	argv	- Adjused to remove consumed argument(s).
**
**	outbuf  - Holds '\0' terminated string with either nodename
**		  or error message depending on status.
**
**	Returns:
**		OK				- All is well.
**		E_CL2C40_CX_E_BAD_PARAMETER	- Bad params values, 
**						  or bad combination
**						  of parameters.
**		E_CL2C43_CX_E_REMOTE_NODE	- Node specified was not on
**						  current host machine.
**		E_CL2C2F_CX_E_BADRAD		- Rad value out of range.
**		E_CL2C42_CX_E_NOT_CONFIGURED	- Node or RAD not configured
**						  as part of a cluster.
**		E_CL2C41_CX_E_MUST_SET_RAD	- Running NUMA clusters,
**						  and no argument, or
**						  environment variable, set
**					          the RAD context.
**	
**	Exceptions:
**	    none
**
** Side Effects:
**	    See CXnuma_bind_to_rad(), if called with a '-rad'
**	    argument outside a NUMA cluster, else see
**	    CXset_context().
**
** Notes:
**	Typically in a NUMA cluster configuration, the target RAD
**	information is needed very early in the applications logic,
**      since it cannot implicitly determine the virtual node it
**	is intended to be running on.
**
** History:
**	18-sep-2002 (devjo01)
**	    Created.
*/
STATUS
CXget_context( i4 *pargc, char *argv[], i4 flags, char *outbuf, i4 outlen )
{
    STATUS		 status = OK;
    CX_NODE_INFO        *pni = NULL;
    bool		 numa;
    i4			 arg, radarg = 0, nodearg = 0, badarg = 0;
    i4			 target_rad;
    i4			 argstokill = 1;
    char		*pvalue = NULL, *argp, *host;
    char		 lclbuf[256];
    i4			 erargc;
    ER_ARGUMENT	 	 erargs[2];

    host = CXhost_name();

    do
    {
	/* Scan passed arguments for "-rad" & "-node" */
	for ( arg = 1; arg < *pargc; arg++ )
	{
	    argp = argv[arg];
	    if ( '-' != *argp ) continue;

	    if ( 0 == STxcompare(argp, 4, ERx( "-rad" ), 4, FALSE, FALSE) )
	    {
		if ( radarg || nodearg )
		{
		    /* R2 */
		    badarg = arg;
		    break;
		}

		radarg = arg;
		if ( *(argp + 4) == '=' )
		{
		    pvalue = argp + 5;
		}
		else if ( '\0' != *(argp + 4) || 
			  (arg >= (*pargc - 1)) )
		{
		    /* R3 */
		    badarg = arg;
		    break;
		}
		else
		{
		    /* Next argument must be a valid RAD ID */
		    pvalue = argv[++arg];
		    argstokill = 2;
		}
		if ( '\0' == *pvalue )
		{
		    /* R3 */
		    badarg = radarg;
		    break;
		}
		if ( OK != CVan( pvalue, &target_rad ) ||
				  target_rad <= 0 )
		{
		    /* R3 */
		    badarg = arg;
		    break;
		}
	    }
	    else if ( !(CX_NSC_IGNORE_NODE & flags) &&
		      0 == STxcompare(argp, 5, ERx( "-node" ), 5,
				      FALSE, FALSE ) ) 
	    {
		if ( radarg || nodearg )
		{
		    /* R2 */
		    badarg = arg;
		    break;
		}
		nodearg = arg;
		if ( *(argp + 5) == '=' )
		{
		    pvalue = argp + 6;
		}
		else if ( ('\0' != *(argp + 5)) || 
			  (arg >= (*pargc - 1)) )
		{
		    /* R4 */
		    badarg = arg;
		    break;
		}
		else
		{
		    /* Next argument must be a node ID */
		    pvalue = argv[++arg];
		    argstokill = 2;
		}
		if ( '\0' == *pvalue )
		{
		    /* R4 */
		    badarg = nodearg;
		    break;
		}
	    }
	} /* end for */

	/* If bad syntax seen, scram & fail */
	if ( badarg )
	{
	    status = E_CL2C40_CX_E_BAD_PARAMETER;
	    erargc = 1;
	    erargs[0].er_size = 0; erargs[0].er_value = (PTR)argv[badarg];
	    break;
	}

	numa = CXnuma_cluster_configured();

	/* If no explicit parameters seen, try default */
	if ( numa && !pvalue && !(flags & CX_NSC_RAD_OPTIONAL) )
	{
	    /* R5 */
	    argp = ERx( "II_DEFAULT_RAD" );
	    pvalue = getenv( argp );
	    if ( pvalue &&
		 ( ( '\0' == *pvalue ) || OK != CVan(pvalue, &target_rad) ) )
		pvalue = NULL;
	}

	/* Got a value either from command line or environment */
	if ( pvalue )
	{
	    if ( nodearg )
	    {
		if ( CXcluster_configured() )
		{
		    pni = CXnode_info(pvalue, 0);
		    if ( pni )
		    {
			/* If can't be global, make sure its local */
			if ( !(flags & CX_NSC_NODE_GLOBAL) &&
			     !( ( 0 == STxcompare( host, 0,
				 pni->cx_node_name, pni->cx_node_name_l,
				 TRUE, FALSE ) ) ||
				( ( 0 != pni->cx_host_name_l ) &&
				  ( 0 == STxcompare( host, 0,
				    pni->cx_host_name,
				    pni->cx_host_name_l, TRUE, FALSE ) ) )
			      )
			   )
			{
			    /* Node must be local and was not.  (R4a) */
			    status = E_CL2C43_CX_E_REMOTE_NODE;
			    erargc = 2;
			    erargs[0].er_size = 0;
			    erargs[0].er_value = (PTR)argv[0];
			    erargs[1].er_size = pni->cx_host_name_l;
			    erargs[1].er_value = (PTR)(pni->cx_host_name);
			    break;
			}
		    }
		}
	    }
	    else if ( numa )
	    {
		pni = CXnode_info(host, target_rad);
	    }
	    else if ( target_rad > CXnuma_rad_count() )
	    {
		if ( !(flags & CX_NSC_RAD_OPTIONAL) )
		{
		    /* R3 */
		    status = E_CL2C2F_CX_E_BADRAD;
		    erargc = 0;
		    break;
		}
		target_rad = 0;
	    }

	    if ( ( numa || nodearg ) && ( NULL == pni ) )
	    {
		/* Requested node/rad not configured */
		/* R3, R4 */
		if ( !argp ) argp = argv[radarg+nodearg];
		status = E_CL2C42_CX_E_NOT_CONFIGURED;
		erargc = 1;
		erargs[0].er_size = 0; erargs[0].er_value = (PTR)argp;
		break;
	    }
	}
	else
	{
	    if ( numa && !(flags & CX_NSC_RAD_OPTIONAL) )
	    {
		/* If required argument missing, scram & fail */
		status = E_CL2C41_CX_E_MUST_SET_RAD;
		erargc = 1;
		erargs[0].er_size = 0; erargs[0].er_value = (PTR)argv[0];
		break;
	    }
	}

	if ( (flags & CX_NSC_CONSUME) && (radarg || nodearg) )
	{
	    for ( arg = radarg + nodearg + argstokill; arg < *pargc; arg++ )
	    {
		argv[arg-argstokill] = argv[arg];
	    }
	    *pargc = *pargc - argstokill;
	    argv[*pargc] = NULL;
	}

    } while (0);	

    if ( OK == status )
    {
	lclbuf[CX_MAX_NODE_NAME_LEN] = '\0';
	if ( NULL == pni )
	{
	    (void)STlcopy(host, lclbuf, CX_MAX_NODE_NAME_LEN);
	}
	else
	{
	    (void)STlcopy(pni->cx_node_name, lclbuf, CX_MAX_NODE_NAME_LEN);
	}
	CVlower( lclbuf );
	if ( flags & CX_NSC_SET_CONTEXT )
	{
	    if ( !numa && 0 != target_rad )
	    {
		(void)CXnuma_bind_to_rad( target_rad );
	    }
	    (void)CXset_context(lclbuf, 0);
	}
    }

    if ( OK != status )
    {
	cx_fmt_msg( status, lclbuf, sizeof(lclbuf), erargc, erargs );
        if ( flags & CX_NSC_REPORT_ERRS )
	    (void)SIprintf( "\n%s\n", lclbuf );
    }

    if ( outbuf )
    {
	STlcopy( lclbuf, outbuf, outlen - 1 );
	*(outbuf + outlen - 1) = '\0';
    }
    return status;
} /*CXget_context*/
Exemplo n.º 2
0
/*{
** Name: CXcluster_nodes	- Retrun information about configured nodes.
**
** Description:
**
**	Function will return information about the nodes configured
**	in this installation.
**
** Inputs:
**	
**	pnodecnt	- Pointer to u_i4 to hold node count, or NULL.
**
**	hconfig		- Address of pointer to be filled with pointer
**			  to an initialized CX_CONFIGURATION, or NULL.
**			  DO NOT alter the contents of the cached
**			  CX_CONFIGURATION through the returned address!
**
** Outputs:
**
**	*pnodecnt	- Filled in with # nodes.
**
**	*hconfig	- Holds pointer to cached CX_CONFIGURATION.
**
**	Returns:
**		OK		- Normal successful completion.
**		FAIL		- Problem with configuration found.
**		
**	Exceptions:
**	    none
**
** Side Effects:
**	    none.
**
** History:
**	18-apr-2001 (devjo01)
**	    Created. (Much of code lifted from DMFCSP)
**	15-Apr-2005 (fanch01)
**	    Modified cx_nodes array references to be valid from element zero.
*/
STATUS
CXcluster_nodes( u_i4 *pnodecnt, CX_CONFIGURATION **hconfig )
{
    static		 i4			 config_valid = 0;
    static		 CX_CONFIGURATION	 config = { 0 };

    STATUS		 status = OK;
    u_i4		 nodecnt;
    PM_SCAN_REC 	 scanrec;
    char		*resname;
    char		*resvalue;
    char		*nodename;
    i4			 nodename_l;
    i4			 clusterid;
    CX_NODE_INFO	*pni;
    i4			 i, rad;
    char		 param[80];

    if ( !config_valid )
    {
	status = PMinit();
	if ( OK == status )
	{
	    status = PMload( (LOCATION *)NULL, (PM_ERR_FUNC *)0);
	}
	else if ( PM_DUP_INIT == status )
	{
	    status = OK;
	}
	if ( status == OK )
	{
	    nodecnt = 0;

	    /*
	    ** Start the scan
	    */
	    status = PMscan( "^II\\.[^.]*\\.CONFIG\\.CLUSTER\\.ID$",
			     &scanrec, (char *) NULL,
			     &resname, &resvalue );

	    while ( status == OK )
	    {
		/*
		** Extract out node name and convert value to integer
		*/
		nodename = PMgetElem( 1, resname );
		nodename_l = STlength(nodename);

		CVal( resvalue, &clusterid );

		/* Ignore entries with zero cluster id. */
		if ( 0 != clusterid )
		{
		    /*
		    ** Check id is withing range
		    */
		    if ( (clusterid > CX_MAX_NODES) ||
			 (clusterid < 0) )
		    {
			TRdisplay( ERx( \
"%@ CSP node config: Node %s has an invalid id: %d, valid range (0 - %d)\n"),
			     nodename, clusterid, CX_MAX_NODES );
			status = FAIL;
			break;
		    }

		    /*
		    ** Adjust clusterid so array references are zero based.
		    */
		    clusterid--;

		    /*
		    ** Check that specified id is not already used.
		    */
		    if ( config.cx_nodes[clusterid].cx_node_name_l != 0 )
		    {
			/*
			** Location is already being used issue a message 
			** accordingly
			*/
			if (STxcompare( nodename, nodename_l, 
			    config.cx_nodes[clusterid].cx_node_name,
			    config.cx_nodes[clusterid].cx_node_name_l,
			    TRUE, FALSE) == 0)
			{
			    TRdisplay(
ERx("%@ Cluster configuration: Node %~t already exists in correct location.\n"),
			     nodename_l, nodename );
			}
			else
			{
			    TRdisplay(
ERx("%@ Cluster configuration: Node %~t has same id as Node %~t.\n"),
			     nodename_l, nodename,
			     config.cx_nodes[clusterid].cx_node_name_l,
			     config.cx_nodes[clusterid].cx_node_name );
			}
			status = FAIL;
			break;
		    }

		    /*
		    ** Make sure nodename is unique
		    */
		    for (i = 1; i <= nodecnt; i++)
		    {
			if (STxcompare(
			     config.cx_nodes[config.cx_xref[i]].cx_node_name,
			     config.cx_nodes[config.cx_xref[i]].cx_node_name_l,
			     nodename, nodename_l, TRUE, FALSE) == 0)
			{
			    TRdisplay( 
		 ERx("%@ Cluster configuration: Node %s already exists.\n"),
			     nodename );
			    status = FAIL;
			    break;
			}
		    }

		    /*
		    ** Add to configuration
		    */
		    nodecnt++;
		    config.cx_xref[nodecnt] = clusterid;
		    pni = &config.cx_nodes[clusterid];
		    STmove( nodename, '\0', CX_MAX_NODE_NAME_LEN,
		     pni->cx_node_name );
		    pni->cx_node_name_l = 
		     STnlength(CX_MAX_NODE_NAME_LEN,
		     pni->cx_node_name );
		    pni->cx_node_number = clusterid + 1;
		    pni->cx_host_name_l = pni->cx_rad_id = 0;

		    STprintf(param,"ii.%s.gcn.local_vnode", nodename);
		    if ( OK == PMget(param, &resvalue) )
		    {
			STmove( resvalue, '\0', CX_MAX_HOST_NAME_LEN,
				 pni->cx_host_name );
			pni->cx_host_name_l = STnlength( CX_MAX_HOST_NAME_LEN,
			 pni->cx_host_name );
		    }

		    STprintf(param,"ii.%s.config.numa.rad", nodename);
		    if ( OK == PMget(param, &resvalue) &&
			 OK == CVan(resvalue, &rad) && rad > 0 )
		    {
			pni->cx_rad_id = rad;
		    }

		    /*
		    ** Find next element
		    */
		    status = PMscan( (char *) NULL, &scanrec, (char *) NULL,
			     &resname, &resvalue );
		}
	    }

	    /*
	    ** End condition 
	    */
	    if ( status == PM_NOT_FOUND )
		status = OK;
	}

	if (status != OK )    
	{
	    TRdisplay( ERx("%@ Cluster configuration Error\n") );
	    return (FAIL);
	}
	config.cx_node_cnt = nodecnt;
	config_valid = 1;

    }
    if ( pnodecnt )
	*pnodecnt = config.cx_node_cnt;
    if ( hconfig )
	*hconfig = &config;
    
    return OK;
} /*CXcluster_nodes*/
Exemplo n.º 3
0
/*
** Name: WMODocument() - insert, update, delete, select and retrieve documents
**
** Description:
**
** Inputs:
**	ACT_PSESSION	: active session
**	char*[]			: list of parameters
**
** Outputs:
**	bool*			: TRUE is there is something to print
**	PTR*			: cursor pointer (if NULL means no more information)
**
** Returns:
**	GSTATUS	:	GSTAT_OK
**
** Exceptions:
**	None
**
** Side Effects:
**	None
**
** History:
**      28-Apr-2000 (fanra01)
**          Add additional scheme parameter to WPSrequest.
**      30-Oct-2001 (fanra01)
**          Replace ambiguous profile error message with authorization
**          and permission messages.
*/
GSTATUS
WMODocument (
    ACT_PSESSION act_session,
    char* params[],
    bool* print,
    PTR*  user_info)
{
    GSTATUS        err = GSTAT_OK;
    u_i4            action;
    u_i4            unit_id = 0;
    u_i4            ext_loc = 0;
    i4        flag = 0;
    u_i4            owner = 0;
    u_i4            *pid = NULL;
    u_i4            *punit_id = NULL;
    i4        *pflag = NULL;
    u_i4            *powner = NULL;
    u_i4            *pext_loc = NULL;
    char            *ext_file;
    char            *ext_suffix;
    bool            accessible = TRUE;
    WPS_FILE    *cache = NULL;
    bool        status;

    *print = TRUE;
    if (*user_info == NULL)
    {
    G_ASSERT (params[0] == NULL || params[0][0] == EOS, E_WS0059_WSF_BAD_PARAM);

    if (act_session->user_session == NULL)
    {
        *print = FALSE;
        err = DDFStatusAlloc( E_WS0101_WSS_UNAUTHORIZED_USE );
        return(err);
    }

    if (err == GSTAT_OK)
        err = WMOTypeAction(params[0], &action);
    }
    else
    action = WSS_ACTION_TYPE_SEL;

    if (err == GSTAT_OK)
    if (action == WSS_ACTION_TYPE_SEL)
    {
        if (*user_info == NULL)
        {
        err = WCSOpenDocument(user_info);
        if (err == GSTAT_OK)
            err = GAlloc((PTR*)&params[1], NUM_MAX_INT_STR, FALSE);
        }

        if (err == GSTAT_OK)
        {
        err = WCSGetDocument(
                     user_info,
                     &pid,
                     &punit_id,
                     &params[4],
                     &params[5],
                     (u_i4**)&pflag,
                     &powner,
                     &pext_loc,
                     &params[12],
                     &params[13]);

        if (err != GSTAT_OK || *user_info == NULL)
        {
            CLEAR_STATUS (WCSCloseDocument(user_info));
            *print = FALSE;
        }
        else
        {
            err = WSSDocAccessibility(act_session->user_session, *pid, WSF_READ_RIGHT, &accessible);
            if (err == GSTAT_OK && accessible == TRUE)
            {
            WSF_CVNA(err, *pid, params[1]);
            unit_id = *punit_id;
            flag = *pflag;
            ext_loc= *pext_loc;
            }
            else
            *print = FALSE;
        }
        }
    }
    else
    {
        u_i4        id;

        switch(action)
        {
        case WSS_ACTION_TYPE_DEL:
        case WSS_ACTION_TYPE_RET:
        G_ASSERT (params[1] == NULL || CVan(params[1], (i4*)&id) != OK, E_WS0059_WSF_BAD_PARAM);
        if (action == WSS_ACTION_TYPE_DEL)
        {
            err = WSSDocAccessibility(act_session->user_session, id, WSF_DEL_RIGHT, &accessible);

            if (err == GSTAT_OK)
            if (accessible == TRUE)
                err = WCSDeleteDocument (id);
            else
                err = DDFStatusAlloc( E_WS0065_WSF_UNAUTH_ACCESS );
        }
        else
        {
            err = WSSDocAccessibility(act_session->user_session, id, WSF_READ_RIGHT, &accessible);
            if (err == GSTAT_OK && accessible == TRUE)
            {
            err = WCSRetrieveDocument (
                           id,
                           &punit_id,
                           &params[4],
                           &params[5],
                           (u_i4**)&pflag,
                           &powner,
                           &pext_loc,
                           &params[12],
                           &params[13]);

            if (err == GSTAT_OK && punit_id != NULL)
            {
                unit_id = *punit_id;
                flag = *pflag;
                ext_loc= *pext_loc;
                owner = *powner;

                if (err == GSTAT_OK)
                {
                err = WPSRequest(
                         act_session->user_session->name,
                         act_session->scheme,
                         act_session->host,
                         act_session->port,
                         NULL,
                         unit_id,
                         params[4],
                         params[5],
                         &cache,
                         &status);

                if (err == GSTAT_OK)
                {
                    if (status == WCS_ACT_LOAD)
                    {
                    if ((flag & WCS_EXTERNAL) == FALSE)
                        err = WCSExtractDocument (cache->file);

                    if (err == GSTAT_OK)
                        CLEAR_STATUS(WCSLoaded(cache->file, TRUE))
                        else
                            CLEAR_STATUS(WCSLoaded(cache->file, FALSE))
                        }

                    if (err == GSTAT_OK)
                    {
                    char *tmp = (cache->url == NULL) ? WSF_UNDEFINED : cache->url;
                    u_i4 length = STlength(tmp) + 1;
                    err = GAlloc((PTR*)&params[10], length, FALSE);
                    if (err == GSTAT_OK)
                        MECOPY_VAR_MACRO(tmp, length, params[10]);
                    }
                    CLEAR_STATUS(WPSRelease(&cache));
                }
                }
            }
            }
            else
Exemplo n.º 4
0
VOID
r_rep_load ()
{
	char    *outname;
	char    *tempname;


	/* start of routine */

	r_open_db();		/* open database. If not there, abort */

	STtrmwhite(En_report);

	/* start object-oriented facility for retrieving reports */
	IIOOinit((OO_OBJECT **)NULL);

	En_rid = -1;

	/* set up report environment. */
	if (St_style==RS_NULL && (St_ispec || r_env_set()))
	{	/* report found.  Read in report specifications */
		if (!St_silent)
		{
			SIprintf(ERget(F_RW0005_Reading_report_spec));
			SIflush(stdout);
		}

		r_rco_set();	/* read in the RCOMMANDS table into core */
	}
	else
	{	/* no report found.  Use report name */
		if (St_repspec)
		{	/* error because report does not exist */
			r_error(0x3F7, FATAL, En_report, NULL);
		}
		En_rtype = RT_DEFAULT;
		En_ferslv.name = En_report;
		if  ((En_ferslv.name_dest = (char *)FEreqmem((u_i4)Rst4_tag,
		     (u_i4)(FE_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL)
		{
			IIUGbmaBadMemoryAllocation(
					ERx("r_rep_loadld - name_dest"));
		}

		if  ((En_ferslv.owner_dest = (char *)FEreqmem((u_i4)Rst4_tag,
		     (u_i4)(FE_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL)
		{
			IIUGbmaBadMemoryAllocation(
					ERx("r_rep_loadld - owner_dest"));
		}
		/*
		** If the server supports delimited identifiers, then
		** ensure that .DELIMID is enabled since we're doing a report
		** based upon a table, and it may require such services.
		*/
		if  (IIUIdlmcase() != UI_UNDEFCASE)
		{
			St_xns_given = TRUE;
		}
	}

	/*
	** set up (and maybe prompt for) declared variables
	*/
	r_dcl_set(TRUE);

        if ((En_qlang == FEDMLSQL) && (IIUIdbdata()->firstAutoCom == FALSE))
	{
		IIUIautocommit(UI_AC_OFF);
	}

	if( r_sc_qry(Ptr_set_top) == FAIL )
	{
		return;
	}
    
	IIUIdlmcase();          /* Hack for bug 96801 ingcbt198 */

	if(!r_chk_dat())		/* check for a valid data relation */
	{
		return;
	}


	if( !r_sendqry())/* send the query to the backend */
	{
		return;
	}
	

	if (!r_att_dflt())	/* set up ATT structures for each */
	{			/* attribute in the data relation */
		return;
	}


	if (En_rtype == RT_DEFAULT)
	{	/* set up the default report */
		if (!St_silent)
		{
			SIprintf(ERget(F_RW0006_Setting_up_default));
			SIflush(stdout);
		}

		/* Set up first column as a sort column */

		if  (!r_m_dsort())
		{
			r_error(0x416,NONFATAL,NULL);
			return;
		}
	}

	if (!r_srt_set())		/* set up the SORT data structures */
	{	/* bad RSORT */
		r_error(0x0C, FATAL, NULL);
	}
	/* set up the BRK data structures
	** for each sort attribute with a
	** RACTION tuple defined for it
	*/
	if( !r_brk_set())	
	{
		return;
	}


	/* 
	** If there is a .PAGEWIDTH command and no -l flag has been specified 
	** on the commandline, then reset En_lmax. (The -l flag overrides the 
	** .PAGEWIDTH command). (#129, #588)
	*/
        if( STlength(En_pg_width) > 0 && !St_lspec)
	{
		/* If the pagewidth value is preceded by
		* a dollar, evaluate it as a parameter
		*/
		r_g_set(En_pg_width);
		if( r_g_skip() == TK_DOLLAR )
		{
			CMnext(Tokchar);
			outname = r_g_name();
			if( (tempname = r_par_get(outname)) == NULL )
			{
				r_error(0x3F0, FATAL, outname, NULL);
			}
			STcopy(tempname, En_pg_width);
		}
		/* need to convert to a number and set it to En_lmax */
		if (CVan(En_pg_width, &En_lmax) != OK)
		{
			/* Unable to convert so ignore input */
			r_error(0x403, NONFATAL, outname, NULL);
		}
	}
		
	if (En_rtype == RT_DEFAULT)
	{	/* set up default report */
		r_m_rprt();
	}
	else
	{
		Tcmd_tag = FEbegintag();
		r_tcmd_set();		/* set up the tcmd data structures */
		FEendtag();
	}


	r_lnk_agg();		/* set up the CLR and OP structures for
				** fast processing of aggregates.
				*/

	return;
}
Exemplo n.º 5
0
FUNC_EXTERN AITCB *
AITinit( int argc, char** argv, void (*msg)() )
{
    STATUS	status;
    char	*inputFileName; 
    char	*outputFileName = default_output;
    char	*tracefile = NULL;
    i4		i = 1;

    ait_cb.state = AIT_DONE;
    ait_cb.msg = msg;

    if ( argc < 2)
    {
	(*ait_cb.msg)( "Usage:\napitest [-db dbname] [-trace level] [-log traceFile] [-user username] [-passwd password] [-verbose] inputfilename outputfilename\n" );
	return( &ait_cb );
    }

    while ( i < argc -1  && argv[i][0] == '-' )
    {
	if ( STequal( argv[i], db_flag ) )
	{
	    i++;
	    dbname = (char *)ait_malloc( STlength( argv[i] ) + 1 );
	    STcopy( argv[i], dbname );
	    i++;
	}
        else  if ( STequal( argv[i], log_flag ) )
	{
	    i++;
	    tracefile = argv[ i++ ];
       	}	      
	else  if ( STequal( argv[i], tr_flag ) )
	{
	    i++;
	    status = CVan( argv[i], &traceLevel );
	    if ( status != OK )
	    {
		(*ait_cb.msg)( "Command line error: trace-level is not an integer.\n" );
		return( &ait_cb );
	    }
	    i++;
	}	    
	else  if ( STequal( argv[i], user_flag ) )
	{
	    i++;
	    username = ( char * )
		       ait_malloc( STlength( argv[i] ) + 1 );
	    STcopy( argv[i], username );
	    i++;
	}
	else  if ( STequal( argv[i], passwd_flag ) )
	{
	    i++;
	    password = ( char * )
		       ait_malloc( STlength( argv[i] ) + 1 );
	    STcopy( argv[i], password );
	    i++;
	}
	else  if ( STequal( argv[i], verbose_flag ) )
	{
	    i++;
	    verboseLevel = 1;
	}
	else
	{
	    STprintf( str, "%s: unknown option.\n", argv[i] );
	    (*ait_cb.msg)( str );
	    (*ait_cb.msg)( "Usage:\napitest [-db dbname] [-trace level] [-log traceFile] inputfilename outputfilename\n" );
	    i++;
	    break;
	}
    }

    if ( i == argc )
    {
	(*ait_cb.msg)( "Command line error: inputfilename unknown.\n" );
	return( &ait_cb );
    }

    inputFileName = argv[ i++ ];

    if ( i < argc )
    {
	outputFileName = argv[ i++ ];

	if ( STequal( inputFileName, outputFileName ) )
	{
	    (*ait_cb.msg)( "input and output file name must not be the same.\n" );
	    return( &ait_cb );
	}
    }

    if ( i < argc )
    {
	for ( ; i < argc; i++ )
	{
	    STprintf( str, "%s ignored\n", argv[i] );
	    (*ait_cb.msg)( str );
	}
    }
   
    if ( tracefile  &&  *tracefile )  ait_initTrace( tracefile );
    AIT_TRACE( AIT_TR_TRACE )( "initialize the api tester...\n" );
    AIT_TRACE( AIT_TR_TRACE )( "inputfile = %s, outputfile = %s\n",
			     inputFileName, outputFileName );
    
    /*
    ** Open input/output files.  Only
    ** enter parsing state if successful.
    */
    if ( ait_openfile( inputFileName, "r", &inputf ) )
        if ( STequal( outputFileName, default_output ) )
	{
	    outputf = stdout;
	    ait_cb.state = AIT_PARSE;
        }
	else  if ( ait_openfile ( outputFileName, "w", &outputf ) )
	    ait_cb.state = AIT_PARSE;

    return( &ait_cb );
}
Exemplo n.º 6
0
STATUS
gcn_bedcheck( VOID )
{
    GCA_FS_PARMS	fast;
    STATUS		status;
    CL_ERR_DESC		sys_err;
    char		gcn_addr[ GCA_SERVER_ID_LNG + 1 ];
    static char		msg_buff[ GCA_FS_MAX_DATA ];
    char		obj_buffer [ 32 ]; 
    char		*p, *var;
    i4			len, server_flags;
    char		gca_partner_name[] = "/IINMSVR";
 
    /*
    ** We can bail out early if Name Server
    ** ID has not been globally registered.
    */
    status = GCnsid( GC_FIND_NSID, gcn_addr, sizeof( gcn_addr ), &sys_err );
    if ( status == GC_NM_SRVR_ID_ERR )  return( E_GC0126_GCN_NO_GCN );

    /* 
    ** Roll up GCM_GET message.
    */
    p = msg_buff;		/* point to start of message data */
    p += sizeof( i4 );          /* bump past error_status */
    p += sizeof( i4 );          /* bump past error_index */
    p += sizeof( i4 );          /* bump past future[0] */
    p += sizeof( i4 );          /* bump past future[1] */
    p += gcm_put_int( p, -1 );  /* set client_perms */
    p += gcm_put_int( p, 1 );   /* set row_count */
    p += gcm_put_int( p, 1 );   /* set element_count */
    p += gcm_put_str( p, GCA_MIB_CLIENT_FLAGS );	/* classid */
    p += gcm_put_str( p, "" );		/* instance */
    p += gcm_put_str( p, "" );		/* value */
    p += gcm_put_int( p, 0 );		/* perms */

    /* 
    ** Issue GCA_FASTSELECT.
    */
    MEfill( sizeof( fast ), '\0', (PTR)&fast );
    fast.gca_partner_name = gca_partner_name;
    fast.gca_modifiers = GCA_RQ_GCM;
    fast.gca_peer_protocol = GCA_PROTOCOL_LEVEL_62;
    fast.gca_buffer = msg_buff;
    fast.gca_b_length = sizeof( msg_buff );
    fast.gca_message_type = GCM_GETNEXT;
    fast.gca_msg_length = p - msg_buff;

    gca_call( &gcn_gca_cb, GCA_FASTSELECT, (GCA_PARMLIST *)&fast, 
	      GCA_SYNC_FLAG, NULL, -1, &status );

    if ( status == OK  &&  fast.gca_status != OK )  status = fast.gca_status;

    /* 
    ** If we can't probe it, we'll just 
    ** have to assume it is a GCN. 
    */
    if ( status == E_GC003F_PM_NOPERM )  
	status = OK;
    else  if ( status == OK )
    {
	/* 
	** Unroll GCM msg.
	*/
        p = msg_buff;
        p += gcm_get_int( p, &status );

        /* 
        ** if GCM GET succeeded, test server flags.
        */
        if ( status == OK )
        {
	    p += sizeof( i4 );		/* bump past element_count */
	    p += sizeof( i4 );		/* bump past error_index */
	    p += sizeof( i4 );		/* bump past future[0] */
	    p += sizeof( i4 );		/* bump past future[1] */
	    p += sizeof( i4 );		/* bump past client_perms */
	    p += sizeof( i4 );		/* bump past row_count */
            p += gcm_get_str( p, &var, &len );  /* skip classid */
            p += gcm_get_str( p, &var, &len );  /* skip instance */
            p += gcm_get_str( p, &var, &len );  /* get value */
            MEcopy( var, len, obj_buffer );
            obj_buffer[ len ] = '\0';
            CVan( obj_buffer,  &server_flags );

	    if ( ! (server_flags & GCA_RG_IINMSVR) )
    	        status = E_GC0126_GCN_NO_GCN;
        }
    }
 
    return( status );
}