Example to monitor fs-nfs3

QNX SDP8.0High Availability Framework Developer's GuideDeveloper

The following code snippet shows how to begin monitoring the fs-nfs3 process:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/netmgr.h>
#include <fcntl.h>
#include <ha/ham.h>

int main(int argc, char *argv[])
{
    int status;
    ham_entity_t *ehdl;
    ham_condition_t *chdl;
    ham_action_t *ahdl;
    char *fsnfspath;
    int fsnfs3pid;

    fsnfspath = strdup("/usr/sbin/fs-nfs3");
    fsnfs3pid = -1;

    ham_connect(0);
    ehdl = ham_attach("Fs-nfs3", fsnfs3pid, fsnfspath, 0);
    if (ehdl != NULL)
    {
        chdl = ham_condition(ehdl,CONDDEATH, "Death", HREARMAFTERRESTART);
        if (chdl != NULL) {
            ahdl = ham_action_restart(chdl, "Restart", fsnfspath,
                    HREARMAFTERRESTART);
            if (ahdl == NULL)
                printf("add action failed\n");
            else {
                ahdl = ham_action_waitfor(chdl, "Delay1", NULL, 2000,
                        HREARMAFTERRESTART);
                if (ahdl == NULL)
                    printf("add action failed\n");
                ahdl = ham_action_execute(chdl, "MountDir1",
                        "/bin/mount -t nfs a.b.c.d:/dir1 /dir1",
                        HREARMAFTERRESTART|HACTIONDONOW));
                if (ahdl == NULL)
                    printf("add action failed\n");
                ahdl = ham_action_waitfor(chdl, "Delay2", NULL, 2000,
                        HREARMAFTERRESTART);
                if (ahdl == NULL)
                    printf("add action failed\n");
                ahdl = ham_action_execute(chdl, "Mountdir2",
                        "/bin/mount -t nfs a.b.c.d:/dir2 /dir2",
                        HREARMAFTERRESTART|HACTIONDONOW);
                if (ahdl == NULL)
                    printf("add action failed\n");
            }
        }
        else
            printf("add condition failed\n");
    }
    else
        printf("add entity failed\n");
    ham_disconnect(0);
    exit(0);
}
Page updated: