Ii was cross compiling agentx...

agentx involves two files...

one : fan.c

the other : exam.c


The compile error arise in exam.c


This is agent make file


============================================================================================

#
# Warning: you may need more libraries than are included here on the
# build line.  The agent frequently needs various libraries in order
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here.  Instead, look at the libraries that were
# used when linking the snmpd master agent and copy those to this
# file.
#
PROJDIR = /home/proj/msap/apps/sychoi
INSTDIR = $(PROJDIR)/rootfs/usr/sbin
SNMPINC = /home/proj/msap/apps/sychoi/install/usr
CC=ppc_82xx-gcc
STRIP=ppc_82xx-strip

OBJS += agentx.o
OBJS += fan.o
OBJS += exam.o

TARGETS = agentx

CFLAGS += -O2 -Dlinux -I. -I$(SNMPINC)/include
BUILDLIBS = -L$(SNMPINC)/lib -lnetsnmp -lcrypto -lm
BUILDAGENTLIBS = -L$(SNMPINC)/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lcrypto -lm


# shared library flags (assumes gcc)
DLFLAGS=-fPIC -shared -lpthread

all: $(TARGETS)

agentx: $(OBJS)
        $(CC) -o agentx $(OBJS) $(BUILDLIBS) $(BUILDAGENTLIBS)
        $(STRIP) agentx

install:
        cp -a agentx $(INSTDIR)

clean:
        rm -f $(OBJS) $(TARGETS)
===========================================================================================

when i "make agentx" this error arise...


===========================================================================================

[r...@localhost nextest]# make agentx
ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include   -c -o agentx.o agentx.c
ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include   -c -o fan.o fan.c
ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include   -c -o exam.o exam.c
ppc_82xx-gcc -o agentx agentx.o fan.o exam.o -L/home/proj/msap/apps/sychoi/install/usr/lib -lnetsnmp -lcrypto -lm  -L/home/proj/msap/apps/sychoi/install/usr/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lcrypto -lm
exam.o: In function `init_exam':
exam.c:(.text+0x27c): undefined reference to `sem_init'
exam.o: In function `examNEXTable_get_next_data_point':
exam.c:(.text+0x370): undefined reference to `sem_wait'
exam.c:(.text+0x3f8): undefined reference to `sem_post'
exam.c:(.text+0x4cc): undefined reference to `sem_post'

===========================================================================================

the problem is <semaphore.h>

I attatch exam.c


===========================================================================================

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "exam.h"
//#include "/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h"

#include <semaphore.h>


sem_t exam_sem;



....................................................................................

........


netsnmp_variable_list *
examNEXTable_get_next_data_point(void **my_loop_context,
                                 void **my_data_context,
                                 netsnmp_variable_list * put_index_data,
                                 netsnmp_iterator_info *mydata)
{
    struct examNEXTable_entry *entry = (struct examNEXTable_entry *) *my_loop_context;
    netsnmp_variable_list *idx = put_index_data;
    printf("entry :%d  put_index_data: %d\n", entry, put_index_data);

    struct examNEXTable_entry *ptr, *prev;
    int find =0;

    sem_wait(&exam_sem);
    printf("sema_wait end!!\n");

    for(prev =NULL, ptr=examNEXTable_head; ptr!=NULL; prev=ptr, ptr=ptr->next){

        if(entry==ptr)
         find =1;
         printf("find : %d  ptr : %d  entry: %d\n", find, ptr, entry);
      }


    if (entry && find) {
        snmp_set_var_value(idx, (u_char *)entry->name, strlen(entry->name));
        printf("entry->name : %s   len : %d  \n", (u_char *)entry->name, strlen(entry->name));

        idx = idx->next_variable;
        printf("idx : %d  idx->nex_variable : %d \n", idx, idx->next_variable);
        *my_data_context = (void *) entry;
        printf("my_data_context : %d \n", *my_data_context);
        *my_loop_context = (void *) entry->next;
        printf("my_loop_context: %d \n", *my_loop_context);
        sem_post(&exam_sem);
        printf("put_index_data : %d\n", put_index_data);
        return put_index_data;

    } else {

         sem_post(&exam_sem);
         printf("else!!\n");
         return NULL;
    }
}

=========================================================================================


I think <semaphore.h> is not ppc_82xx format

so i include ppc_82xx format semaphore.h

but the result is below

=========================================================================================

[r...@localhost nextest]# make agentx
ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include   -c -o agentx.o agentx.c
ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include   -c -o fan.o fan.c
ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include   -c -o exam.o exam.c
In file included from exam.c:10:
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:30:28: error: bits/semaphore.h: No such file or directory
In file included from exam.c:10:
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:37: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:40: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:43: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:43: warning: data definition has no type or storage class
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:46: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:55: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:67: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:70: error: parse error before '*' token
/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:73: error: parse error before '*' token
exam.c:14: error: parse error before 'exam_sem'
exam.c:14: warning: data definition has no type or storage class
make: *** [exam.o] 오류 1

=========================================================================================


I don't what's the problem...

anyone do you know about it...

please help me...

thank you....












/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.iterate.conf 16004 2007-03-27 09:20:28Z dts12 $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "exam.h"

#include <semaphore.h>

sem_t exam_sem;

char *fname[] ={"choi", "kim", "lee", "kang", "han"};

char *getname(int index);
void firstval(void);

struct examNEXTable_entry {
    
    char            *name;
    char            *old_name;
    long            num1;
    long            old_num1;
    long            num2;
    long            old_num2;

    int             valid;
    struct examNEXTable_entry *next;
};


struct examNEXTable_entry *examNEXTable_head;
struct examNEXTable_entry *examNEXTable_createEntry(char *name);
void examNEXTable_removeEntry(struct examNEXTable_entry *entry);


struct examNEXTable_entry *examNEXTable_createEntry(char *name)
{
    struct examNEXTable_entry *entry;

    entry = SNMP_MALLOC_TYPEDEF(struct examNEXTable_entry);
    if (!entry)
        return NULL;

     printf("examNEXTable_createEntry memory define done!!\n");

    entry->name = name;
   printf("name: %s\n", name);
   printf("entry->name : %s\n", entry->name);
   entry->next = examNEXTable_head;
   printf("entry->next: %d\n", entry->next);
   examNEXTable_head = entry;
   printf("examNEXTable_createEntry!!\n");
    return entry;
}


char *getname(int index){
  return fname[index];
}

void firstval(){

struct examNEXTable_entry *tmpentry;
char *fname ;
int i;

for(i=0; i <5; i++) {
     fname=getname(i);
     printf("fanme : %s\n", fname);
     tmpentry = examNEXTable_createEntry(fname);
     printf("firstval: createEntry done!\n");
     printf("tmpentry : %d\n", tmpentry);
     tmpentry->valid=1;
}
}



/** Initializes the exam module */
void
init_exam(void)
{
    /*
     * here we initialize all the tables we're planning on supporting 
     */
     sem_init(&exam_sem, 0, 1);
     initialize_table_examNEXTable();
      printf("initialize function init!!\n");

}

//# Determine the first/last column names

/** Initialize the examNEXTable table by defining its contents and how it's structured */
void
initialize_table_examNEXTable(void)
{
    static oid      examNEXTable_oid[] = { 1, 3, 6, 1, 4, 1, 50000, 3 };
    size_t          examNEXTable_oid_len = OID_LENGTH(examNEXTable_oid);
    netsnmp_handler_registration *reg;
    netsnmp_iterator_info *iinfo;
    netsnmp_table_registration_info *table_info;
    printf(" initalize_table start!!\n");

    reg =
        netsnmp_create_handler_registration("examNEXTable",
                                            examNEXTable_handler,
                                            examNEXTable_oid,
                                            examNEXTable_oid_len,
                                            HANDLER_CAN_RWRITE);

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, /* index: name */
                                     0);
    table_info->min_column = COLUMN_NAME;
    table_info->max_column = COLUMN_NUM2;

    iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
    iinfo->get_first_data_point = examNEXTable_get_first_data_point;
    iinfo->get_next_data_point = examNEXTable_get_next_data_point;
    iinfo->table_reginfo = table_info;
    printf("iinfo->get_first_data_point : %d   iinfo->get_next_data_point : %d \n", iinfo->get_first_data_point, iinfo->get_next_data_point);


    netsnmp_register_table_iterator(reg, iinfo);

    /*
     * Initialise the contents of the table here 
     */
     firstval();
}


#if 0
    /*
     * Typical data structure for a row entry 
     */
struct examNEXTable_entry {
    /*
     * Index values 
     */
    char            name;

    /*
     * Column values 
     */
    char            name;
    long            num1;
    long            old_num1;
    long            num2;
    long            old_num2;

    /*
     * Illustrate using a simple linked list 
     */
    int             valid;
    struct examNEXTable_entry *next;
};

struct examNEXTable_entry *examNEXTable_head;

/*
 * create a new row in the (unsorted) table 
 */
struct examNEXTable_entry *
examNEXTable_createEntry(char name,)
{
    struct examNEXTable_entry *entry;

    entry = SNMP_MALLOC_TYPEDEF(struct examNEXTable_entry);
    if (!entry)
        return NULL;

    entry->name = name;
    entry->next = examNEXTable_head;
    examNEXTable_head = entry;
    return entry;
}
#endif

/*
 * remove a row from the table 
 */
void
examNEXTable_removeEntry(struct examNEXTable_entry *entry)
{
    struct examNEXTable_entry *ptr, *prev;

    if (!entry)
        return;                 /* Nothing to remove */

    for (ptr = examNEXTable_head, prev = NULL;
         ptr != NULL; prev = ptr, ptr = ptr->next) {
        if (ptr == entry)
            break;
    }
    if (!ptr)
        return;                 /* Can't find it */

    if (prev == NULL)
        examNEXTable_head = ptr->next;
    else
        prev->next = ptr->next;

    SNMP_FREE(entry);           /* XXX - release any other internal resources */
}


/*
 * Example iterator hook routines - using 'get_next' to do most of the work 
 */
netsnmp_variable_list *
examNEXTable_get_first_data_point(void **my_loop_context,
                                  void **my_data_context,
                                  netsnmp_variable_list * put_index_data,
                                  netsnmp_iterator_info *mydata)
{
    *my_loop_context = examNEXTable_head;
     printf("get_first_data_point=>my_loop_context : %d\n", *my_loop_context);

    return examNEXTable_get_next_data_point(my_loop_context,
                                            my_data_context,
                                            put_index_data, mydata);
}

netsnmp_variable_list *
examNEXTable_get_next_data_point(void **my_loop_context,
                                 void **my_data_context,
                                 netsnmp_variable_list * put_index_data,
                                 netsnmp_iterator_info *mydata)
{
    struct examNEXTable_entry *entry = (struct examNEXTable_entry *) *my_loop_context;
    netsnmp_variable_list *idx = put_index_data;
    printf("entry :%d  put_index_data: %d\n", entry, put_index_data);

    struct examNEXTable_entry *ptr, *prev;
    int find =0;

    sem_wait(&exam_sem);
    printf("sema_wait end!!\n");

    for(prev =NULL, ptr=examNEXTable_head; ptr!=NULL; prev=ptr, ptr=ptr->next){

        if(entry==ptr)
         find =1;
         printf("find : %d  ptr : %d  entry: %d\n", find, ptr, entry);
      }


    if (entry && find) {
        snmp_set_var_value(idx, (u_char *)entry->name, strlen(entry->name));
        printf("entry->name : %s   len : %d  \n", (u_char *)entry->name, strlen(entry->name));

        idx = idx->next_variable;
        printf("idx : %d  idx->nex_variable : %d \n", idx, idx->next_variable);
        *my_data_context = (void *) entry;
        printf("my_data_context : %d \n", *my_data_context);
        *my_loop_context = (void *) entry->next;
        printf("my_loop_context: %d \n", *my_loop_context);
        sem_post(&exam_sem);
        printf("put_index_data : %d\n", put_index_data);
        return put_index_data;

    } else {

         sem_post(&exam_sem);
         printf("else!!\n");
         return NULL;
    }
}


/** handles requests for the examNEXTable table */
int
examNEXTable_handler(netsnmp_mib_handler *handler,
                     netsnmp_handler_registration *reginfo,
                     netsnmp_agent_request_info *reqinfo,
                     netsnmp_request_info *requests)
{
    printf("examNEXTable handler enter!!\n");
    netsnmp_request_info *request;
    netsnmp_table_request_info *table_info;
    struct examNEXTable_entry *table_entry, *table_row;



    printf("reqinfo->mode : %d\n", reqinfo->mode);

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *)netsnmp_extract_iterator_context(request);
           printf("MODE_GET :table_entry : %d\n", table_entry);
            table_info = netsnmp_extract_table_info(request);
            printf("table_info : %d\n", table_info);


            switch (table_info->colnum) {
            case COLUMN_NAME:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *)table_entry->name,
                                         strlen(table_entry->name));
		 printf("mode_get:snmp_set_var_typed_value : table_entry->name : %s  lens : %d\n", (u_char *)table_entry->name, strlen(table_entry->name));

                break;

            case COLUMN_NUM1:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                        (u_char *)&table_entry->num1,
                                         sizeof(table_entry->num1));
                printf("mode_get:snmp_set_var_typed_value : table_entry->numl : %d  sizeof(table_entry->num1) : %d\n", table_entry->num1, sizeof(table_entry->num1));
               break;

            case COLUMN_NUM2:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                        (u_char *)&table_entry->num2,
                                         sizeof(table_entry->num2));
                  printf("mode_get:snmp_set_var_typed_value : table_entry->num2 : %d  sizeof(table_entry->num2) : %d\n", table_entry->num2, sizeof(table_entry->num2));


                break;

            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *) netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_NUM1:
                if (request->requestvb->type != ASN_INTEGER) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * Also may need to check size/value 
                 */
				
                break;
            case COLUMN_NUM2:
                if (request->requestvb->type != ASN_INTEGER) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * Also may need to check size/value 
                 */
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *)netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);
		

            switch (table_info->colnum) {
            case COLUMN_NUM1:
            case COLUMN_NUM2:
                if (!table_entry) {
                    table_entry = examNEXTable_createEntry((char*)table_info->indexes->val.integer);
                    if (table_entry) {
                        netsnmp_insert_iterator_context(request, &table_entry->num1);
                    } else {
                        netsnmp_set_request_error(reqinfo, request,SNMP_ERR_RESOURCEUNAVAILABLE);
                        return SNMP_ERR_NOERROR;
                    }
                }
                break;
            }
        }
        break;

    case MODE_SET_FREE:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *)netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_NUM1:
            case COLUMN_NUM2:
                if (table_entry && !table_entry->valid) {
                    examNEXTable_removeEntry(table_entry);
                }
                break;
            }
        }
        break;

    case MODE_SET_ACTION:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *)netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);
             printf("this is set action!!\n");
            printf("netsnmp_extract_iterator_context : %d \n", netsnmp_extract_iterator_context(request));
            printf("MODE_SET : table_entry : %d, request : %d \n", table_entry, request);
            printf("table_info : %d \n", table_info);

            switch (table_info->colnum) {
            case COLUMN_NUM1:
                /*
                 * Need to save old 'table_entry->num1' value.
                 * May need to use 'memcpy' 
                 */
                table_entry->old_num1 = table_entry->num1;
                table_entry->num1 = *request->requestvb->val.integer;
                break;
            case COLUMN_NUM2:
                /*
                 * Need to save old 'table_entry->num2' value.
                 * May need to use 'memcpy' 
                 */
                table_entry->old_num2 = table_entry->num2;
                table_entry->num2 = *request->requestvb->val.integer;
                break;
            }
        }
        break;

    case MODE_SET_UNDO:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *)
                netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_NUM1:
                if (table_entry && !table_entry->valid) {
                    examNEXTable_removeEntry(table_entry);
                } else {
                    /*
                     * Need to restore old 'table_entry->num1' value.
                     * May need to use 'memcpy' 
                     */
                    table_entry->num1 = table_entry->old_num1;
                }
                break;
            case COLUMN_NUM2:
                if (table_entry && !table_entry->valid) {
                    examNEXTable_removeEntry(table_entry);
                } else {
                    /*
                     * Need to restore old 'table_entry->num2' value.
                     * May need to use 'memcpy' 
                     */
                    table_entry->num2 = table_entry->old_num2;
                }
                break;
            }
        }
        break;

    case MODE_SET_COMMIT:
        for (request = requests; request; request = request->next) {
            table_entry = (struct examNEXTable_entry *)
                netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_NUM1:
            case COLUMN_NUM2:
                if (table_entry && !table_entry->valid) {
                    table_entry->valid = 1;
                }
            }
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to