net-snmp로 subagent를 만드는데 semaphore.h를 include 안했을 때 에러가 나네요.

bakdorazi의 이미지

net-snmp-5.3.2를 깔고 agent/mibgroup/nextest 폴더에 소스 파일을 넣었습니다.

소스명 : module.c module.h

소스 파일을 간단히 소개하자면 아래와 같습니다.

/*
 * 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 <semaphore.h>
#include "common.h"
#include "nex_common.h"
#include "module.h"
#include "nex_module.h"
#include "nex_module.c"
 
static sem_t module_sem;
 
/*
 * Typical data structure for a row entry
 */
struct moduleTable_entry {
    /*
     * Index values
     */
    long            modulenum;
 
    /*
     * Column values
     */
    long            devicetype;
    long            old_devicetype;
    long            devicemode;
    long            old_devicemode;
    char            description;
    char            old_description;
    char            type;
    char            firmware;
    char            uptime;
    char            restart;
    char            old_restart;
 
    /*
     * Illustrate using a simple linked list
     */
 
................................................
 
netsnmp_variable_list *moduleTable_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 = moduleTable_head;
    return moduleTable_get_next_data_point(my_loop_context,my_data_context, put_index_data,mydata);
}
 
netsnmp_variable_list * moduleTable_get_next_data_point(void **my_loop_context,
                                void **my_data_context,
                                netsnmp_variable_list * put_index_data,
                                netsnmp_iterator_info *mydata)
{
    struct moduleTable_entry *entry =  (struct moduleTable_entry *) *my_loop_context;
    netsnmp_variable_list *idx = put_index_data;
 
        struct moduleTable_entry *ptr;
        struct moduleTalbe_entry *prev;
        int     find=0;
        sem_wait(&module_sem);
        for (ptr = moduleTable_head, prev = NULL; ptr != NULL; prev = ptr, ptr = ptr->next) {
                if (entry == ptr){
                        find = 1;
                        printf("entry : %d  ptr: %d  find : %d \n", entry, ptr, find);
                }
        }
 
    if (entry && find) {
        snmp_set_var_value(idx, (u_char *)&entry->modulenum, sizeof(entry->modulenum));
        printf("modulenum : %d  idx : %d  (u_char *)&entry->modulenum : %d  sizeof(entry->modulenum) : %d \n", idx, entry->modulenum, (u_char *)&entry->modulenum, sizeof(entry->modulenum));
        idx = idx->next_variable;
        *my_data_context = (void *) entry;
        *my_loop_context = (void *) entry->next;
                printf("put_index_data : %d \n", put_index_data);
                sem_post(&module_sem);
                return put_index_data;
    } else {
                sem_post(&module_sem);
        return NULL;
    }
}

위의 소스를 가지고 아래와 같은 작업을 진행했었는데...
net-snmp에서 서브 에이젼트 만드는 명령은 아래와 같습니다.

net-snmp-config --compile-subagent "서브에이젼트명" "소스명"

위의 명령어를 가지고 아래와 같이 컴파일 했는데요...
semaphore.h를 include 안했을때 에러가 나왔습니다.
다른 소스들도 세마포어 함수를 쓴 것들은 다른 에러들은 안나오는데 아래와 같은 에러가 동일하게 나옵니다.

[root@localhost nextest]# net-snmp-config --compile-subagent module module.c
generating the tmporary code file: netsnmptmp.29599.c
void            init_module(void);
checking for init_module in module.c
void init_module(void)
running: ppc_82xx-gcc  -g -O2 -Dlinux  -I. -I/home/test/install/usr/include -o module netsnmptmp.29599.c  module.c  -L/home/test/install/usr/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lcrypto -lm    
module.c: In function 'moduleTable_get_next_data_point':
module.c:285: warning: assignment from incompatible pointer type
/tmp/cc5rU0Qx.o: In function `moduleTable_remove':
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:238: undefined reference to `sem_wait'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:256: undefined reference to `sem_post'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:246: undefined reference to `sem_post'
/tmp/cc5rU0Qx.o: In function `moduleTable_createEntry':
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:195: undefined reference to `sem_wait'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:198: undefined reference to `sem_post'
/tmp/cc5rU0Qx.o: In function `init_module':
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:139: undefined reference to `sem_init'
/tmp/cc5rU0Qx.o: In function `moduleTable_removeEntry':
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:213: undefined reference to `sem_wait'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:229: undefined reference to `sem_post'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:219: undefined reference to `sem_post'
/tmp/cc5rU0Qx.o: In function `moduleTable_get_next_data_point':
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:284: undefined reference to `sem_wait'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:302: undefined reference to `sem_post'
/home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:299: undefined reference to `sem_post'
collect2: ld returned 1 exit status
removing the tmporary code file: netsnmptmp.29599.c

웹에서 찾아보니 -lpthread를 쓰라고 되어 있던데...

서브 에이젼트 말고 전체 snmp 깔때 mib-modle 에 소스추가해서 하는 방식으로 할 때 LIBFLAGS에 추가시켜서 해봤는데
아무 소용이 없더라구요...

도대체 세마포어 관련 에러는 왜 나오는 것이며 이걸 클리어 할 방법은 없습니까?
아무리 질문 올려도 답이 없어서요..

제발 좀 도와주세요.

hys545의 이미지

한번 semaphore.h여기에 sem_wait가 어떻게 정의되어있나 보세여

즐린

즐린

bakdorazi의 이미지

semaphore.h 파일을 살펴보았는데요..
아래 파일 입니다.

#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H    1
 
#include <features.h>
#include <sys/types.h>
#ifdef __USE_XOPEN2K
# define __need_timespec
# include <time.h>
#endif
 
/* Get the definition for sem_t.  */
#include <bits/semaphore.h>
 
 
__BEGIN_DECLS
 
/* Initialize semaphore object SEM to VALUE.  If PSHARED then share it
   with other processes.  */
extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
     __THROW;
/* Free resources associated with semaphore object SEM.  */
extern int sem_destroy (sem_t *__sem) __THROW;
 
/* Open a named semaphore NAME with open flags OFLAG.  */
extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
 
/* Close descriptor for named semaphore SEM.  */
extern int sem_close (sem_t *__sem) __THROW;
 
/* Remove named semaphore NAME.  */
extern int sem_unlink (__const char *__name) __THROW;
 
/* Wait for SEM being posted.
 
   This function is a cancellation point and therefore not marked with
   __THROW.  */
extern int sem_wait (sem_t *__sem);
 
#ifdef __USE_XOPEN2K
/* Similar to `sem_wait' but wait only until ABSTIME.
 
   This function is a cancellation point and therefore not marked with
   __THROW.  */
extern int sem_timedwait (sem_t *__restrict __sem,
                          __const struct timespec *__restrict __abstime);
#endif
/* Test whether SEM is posted.  */
extern int sem_trywait (sem_t *__sem) __THROW;
 
/* Post SEM.  */
extern int sem_post (sem_t *__sem) __THROW;
 
/* Get current value of SEM and store it in *SVAL.  */
extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
     __THROW;
 
 
__END_DECLS
 
#endif  /* semaphore.h */

보시면 아시겠지만 extern int 형으로 선언되어 있습니다.

혹은 위와 같은 경우 제가 어떻게 하면 좋을까요?

hys545의 이미지

[hys545@localhost lib]$ nm libpthread-2.11.1.so | grep sem_wait
00ba0f40 t __new_sem_wait
00ba0fe0 t __old_sem_wait
00ba0f40 T sem_wait@@GLIBC_2.1
00ba0fe0 T sem_wait@GLIBC_2.0
00ba0fcc t sem_wait_cleanup
00ba1177 t sem_wait_cleanup

이런경우 -lpthread로 하면 될거 같은데
이 옵션 주고도 안되면
한번
pthread 라이브러리에 함수가 있나 확인해보세여
즐린

즐린

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.