Read lsf.conf parameters

You can refer to the contents of the lsf.conf file or even define your own site specific variables in the lsf.conf file.

The lsf.conf file follows the Bourne shell syntax. It can be sourced by a shell script and set into your environment before starting your C program. Use these variables as environment variables in your program.

ls_readconfenv()

ls_readconfenv() reads the lsf.conf variables in your C program:

int ls_readconfenv(paramList, confPath)

where confPath is the directory in which the lsf.conf file is stored. paramList is an array of the following data structure:

struct config_param {
    char *paramName;       Name of the parameter, input
    char *paramValue;      Value of the parameter, output
}

ls_readconfenv() reads the values of the parameters defined in lsf.conf and matches the names described in the paramList array. Each resulting value is saved into the paramValue variable of the array element matching paramName. If a particular parameter mentioned in the paramList is not defined in lsf.conf, then on return its value is left NULL.

Example

The following example program reads the variables LSF_CONFDIR, MY_PARAM1, and MY_PARAM2 in lsf.conf file and displays them on screen. Note that LSF_CONFDIR is a standard LSF parameter, while the other two parameters are user site specific. The example program below assumes lsf.conf is in /etc directory.

#include <stdio.h>
#include <lsf/lsf.h>
struct config_param myParams[] =
{
#define LSF_CONFDIR                  0
     {"LSF_CONFDIR", NULL},
#define MY_PARAM1                    1
     {"MY_PARAM1", NULL},
#define MY_PARAM2                    2
     {"MY_PARAM2", NULL},
     {NULL, NULL}
};
main()
{
    if (ls_readconfenv(myParams, "/etc") < 0) {
        ls_perror("ls_readconfenv");
        exit(-1);
    }
    if (myParams[LSF_CONFDIR].paramValue == NULL) 
        printf("LSF_CONFDIR is not defined in
        /etc/lsf.conf\n");
    else
        printf("LSF_CONFDIR=%s\n",myParams[LSF_CONFDIR].paramValue);
    if (myParams[MY_PARAM1].paramValue == NULL)
        printf("MY_PARAM1 is not defined in /etc/lsf.conf\n");
    else
        printf("MY_PARAM1=%s\n", myParams[MY_PARAM1].paramValue);
    if (myParams[MY_PARAM2].paramValue == NULL)
        printf("MY_PARAM2 is not defined\n");
    else
        printf("MY_PARAM2=%s\n", myParams[MY_PARAM2].paramValue);
    exit(0);
}

Initialize the paramValue parameter in the config_param data structure must be initialized to NULL. Next, modify the paramValue to point to a result string if a matching paramName is found in the lsf.conf file. End the array with a NULL paramName.