Arch2Arch Tab BEA.com
Syndicate this blog (XML)

Parsing arguments passed to tpsvrinit()

Bookmark Blog Post

del.icio.us del.icio.us
Digg Digg
DZone DZone
Furl Furl
Reddit Reddit

Gary Jones's Blog | March 17, 2008   5:27 PM | Comments (0)


The servopts(5) entry in the Tuxedo reference documentation describes the arguments passed to a server during startup.  Application-specific options can be passed in to a server and processed in tpsvrinit(). Internally Tuxedo uses getopt() to process the arguments. Associated with getopt() are optarg and optind. optarg is used to access the current argument parameter, whilst optind is the current index.

Because Tuxedo has already parsed its arguments prior to calling tpsvrinit(), optind and optarg can be used to correctly access the user defined arguments during successive calls to getopt().

For example, suppose we have a Tuxedo server that has user defined arguments A, T and W and T has a string parameter whilst W has a long parameter. The correct way to process these in tpsvrinit() is as follows:

 

#if defined(__STDC__) || defined(__cplusplus)
tpsvrinit(int argc, char *argv[])
#else
tpsvrinit(argc, argv)
int argc;
char **argv;
#endif
{
    int c;

    int a_flag;

    int t_flag;

    int w_flag;

    char sval[32];

    long lval;

 

    a_flag = t_flag = w_flag = 0;

    while ((c = getopt(argc, argv, "AT:W:")) != EOF) {
            switch ((char)c) {

            case 'A':
                a_flag++;

                userlog("A argument: optind = %d", optind);

                break;
            case 'T':
                t_flag++;

                userlog("T argument: optind = %d, optarg = %s", optind, optarg);

                strcpy(sval, optarg);

                break;

            case 'W':
                w_flag++;

                userlog("W argument: optind = %d, optarg = %s", optind, optarg);

                lval = atol(optarg);

                break;            
            default:
                    return(-1);
            }
        }

 

    /*

    * Do some processing based on arguments and parameters...

    */

 

    return(0);
}

 

The purpose of the userlog() statements in the sample code is to show how optind and optarg change as the arguments are processed by getopt().

Also note how we can successfully use an argument letter that is also used by Tuxedo (for example 'A').

Often the reason stated for processing arguments in some other way is that the user wants to also access the Tuxedo arguments, for example to find what the group is. Because there is no guarantee that Tuxedo arguments wont change between releases, this type of information should be retrieved by accessing the MIB. This will be the topic of a future entry.


Comments

Comments are listed in date ascending order (oldest first) | Post Comment



Only logged in users may post comments. Login Here.

Powered by
Movable Type 3.31