Solaris System Management Agent Developer's Guide

Reading Persistent Data in demo_module_5

Data is read from the configuration files into a module by registering a callback function to be called whenever an relevant token is encountered. For example, you can call the function as follows:

register_config_handler(DEMO5_CONF_FILE, "demo5_file1",
demo5_load_tokens, NULL, NULL);

Whenever the demo5_file1 token in the demo_module_5.conf file is read by the agent, the function demo5_load_tokens() is called with token name and value as arguments. The demo5_load_tokens() function stores the token value in appropriate variables:

void
demo5_load_tokens(const char *token, char *cptr)
{

    if (strcmp(token, "demo5_file1") == 0) {
        strcpy(file1, cptr);
    } else if (strcmp(token, "demo5_file2") == 0) {
        strcpy(file2, cptr);
    } else if (strcmp(token, "demo5_file3") == 0) {
        strcpy(file3, cptr);
    } else if (strcmp(token, "demo5_file4") == 0) {
        strcpy(file4, cptr);
    } else {
        /* Do Nothing */
    }

    return;

}