Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net-snmp-5.8 build error: ./.libs/libnetsnmpagent.so: undefined reference to `getdtablesize' #155

Closed
rybasd opened this issue Aug 5, 2020 · 7 comments

Comments

@rybasd
Copy link

rybasd commented Aug 5, 2020

Trying to build net-snmp-5.8 in termux enviroment on android 10
Differences of termux envinronment from typical Linux: https://wiki.termux.com/wiki/Differences_from_Linux

I invoke configure with
./configure --prefix=@PREFIX

First, config.guess did not proceed

UNAME_MACHINE = aarch64
UNAME_RELEASE = 4.14.117-18571899
UNAME_SYSTEM  = Linux
UNAME_VERSION = #2 SMP PREEMPT Thu Jun 4 16:59:11 KST 2020
configure: error: cannot guess build type; you must specify one

I have replaced config.guess and config.sub with what was in my system in /data/data/com.termux/files/usr/share/automake-1.16 and that fixed the issue.

Second, make all throwed errors on undeclared identifier ushort and undeclared type ulong, so I replaced with unsigned short and unsigned long (for details see #154 ) and that fixed the issue

And now, the problem is that make all throws an error: error: ./.libs/libnetsnmpagent.so: undefined reference to getdtablesize'`

The error chunk of output:

libtool: link: gcc -g -O2 -DNETSNMP_ENABLE_IPV6 -fno-strict-aliasing -DNETSNMP_REMOVE_U64 -g -O2 -Ulinux -Dlinux=linux -o .libs/snmpd .libs/snmpd.o ./.libs/libnetsnmpagent.so ./.libs/libnetsnmpmibs.so /data/data/com.termux/files/home/snmp/net-snmp-5.8/agent/.libs/libnetsnmpagent.so /data/data/com.termux/files/home/snmp/net-snmp-5.8/snmplib/.libs/libnetsnmp.so -lnl -lpcre ../snmplib/.libs/libnetsnmp.so -lcrypto -lm -Wl,-rpath -Wl,/data/data/com.termux/files/usr/lib 
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: ./.libs/libnetsnmpagent.so: undefined reference to `getdtablesize' 
clang-10: error: linker command failed with exit code 1 (use -v to see invocation) 
make[1]: *** [Makefile:1002: snmpd] Error 1 
make[1]: Leaving directory '/data/data/com.termux/files/home/snmp/net-snmp-5.8/agent' 
make: *** [Makefile:663: subdirs] Error 1
$

Please help to fix.

@csmall
Copy link
Contributor

csmall commented Aug 24, 2020

gdtablesize is checked in the configure step and HAVE_GETSTABLESIZE is defined (or not, as the case may be).
However, agent/netsnmp_close_fds.c doesn't check for this.

If your library has it, then you could use sysconf(_SC_OPEN_MAX) and in fact, the getdtablesize man page suggest this for portable applications. As a last resort, just wrapping the relevant line with #ifdef HAVE_GETDTABLESIZE/#ENDIF will do the job, but other file descriptors won't get closed.

If your version of Linux has /proc/self/fd/ (I'm not sure of how good termux's procfs is) then it will use this value anyway.

@rybasd
Copy link
Author

rybasd commented Aug 24, 2020

Yes, after googling I have put into include/net-snmp/net-snmp-config.h a line with
#define getdtablesize() sysconf(_SC_OPEN_MAX)
And it worked

@rybasd rybasd closed this as completed Aug 24, 2020
@rybasd
Copy link
Author

rybasd commented Aug 24, 2020

I have put into include/net-snmp/net-snmp-config.h a line with
#define getdtablesize() sysconf(_SC_OPEN_MAX)
And it worked

@rybasd rybasd reopened this Aug 24, 2020
@rybasd
Copy link
Author

rybasd commented Aug 24, 2020

I'm not sure if I should close this as I'm novice. I've got a workaround, so that's not an issue for me anymore. Please advise.

@bvanassche
Copy link
Contributor

Please revert the net-snmp-config.h changes and try the following patch instead:

Subject: [PATCH] snmpd, snmptrapd: Let configure check whether getdtablesize()
 is available

This patch fixes the Net-SNMP build for termux.

See also https://github.com/net-snmp/net-snmp/issues/155.
---
 agent/netsnmp_close_fds.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/agent/netsnmp_close_fds.c b/agent/netsnmp_close_fds.c
index 556c3dcfba89..8b75e97cd14d 100644
--- a/agent/netsnmp_close_fds.c
+++ b/agent/netsnmp_close_fds.c
@@ -44,8 +44,13 @@ void netsnmp_close_fds(int fd)
         closedir(dir);
     }
 #endif
-    if (largest_fd < 0)
+    if (largest_fd < 0) {
+#ifdef HAVE_GETDTABLESIZE
         largest_fd = getdtablesize() - 1;
+#else
+        largest_fd = sysconf(_SC_OPEN_MAX);
+#endif
+    }
 
     for (i = largest_fd; i > fd && i >= 0; i--)
         close(i);

@rybasd
Copy link
Author

rybasd commented Aug 24, 2020

@bvanassche I'm sorry but that says nothing to me. If you give step by step instructions, I would try.

bvanassche added a commit that referenced this issue Aug 24, 2020
…lable

This patch fixes the Net-SNMP build for termux.

See also #155.
@bvanassche
Copy link
Contributor

The fix has been applied on the V5-9-patches branch and also on the master branch. Please download the latest version of the Net-SNMP source code from either branch and retest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants