Giter Club home page Giter Club logo

Comments (6)

bvanassche avatar bvanassche commented on July 28, 2024 1

Wouldn't what has been suggested above confuse all source code editors that support automatic indentation?

The patch has been applied on the v5.8 and master branches. The first release in which this patch will be included will have version number v5.8.1.

from net-snmp.

fenner avatar fenner commented on July 28, 2024

This is due to the code at https://github.com/net-snmp/net-snmp/blob/master/agent/netsnmp_close_fds.c#L35 and the fact that your system supports 1886130 file descriptors - net-snmp is trying to close all of the ones it doesn't need. Does FreeBSD support a way to enumerate the file descriptors a process has open, like Linux's /proc/self/fd?

from net-snmp.

liviozanol avatar liviozanol commented on July 28, 2024

Maybe you can use fstat -p <pid> or procstat -f <pid>.

fstat Example:
USER CMD PID FD MOUNT INUM MODE SZ|DV R/W
root snmpd 84096 text / 2491114 -rwxr-xr-x 28400 r
root snmpd 84096 wd / 2 drwxr-xr-x 1024 r
root snmpd 84096 root / 2 drwxr-xr-x 1024 r
root snmpd 84096 0 /dev 23 crw-rw-rw- null rw
root snmpd 84096 1 /dev 23 crw-rw-rw- null rw
root snmpd 84096 2 /dev 23 crw-rw-rw- null rw
root snmpd 84096 3 - 1364737 -rw------- 187 w
root snmpd 84096 4 /dev 19 crw-r----- mem r
root snmpd 84096 5 /dev 20 crw-r----- kmem r
root snmpd 84096 6* pipe fffff80010c055f0 <-> fffff80010c05758 0 rw
root snmpd 84096 7* pipe fffff80010c05758 <-> fffff80010c055f0 0 rw
root snmpd 84096 8* internet dgram udp fffff800a1d3f570
root snmpd 84096 11* pipe fffff8001099b2f8 <-> fffff8001099b460 0 rw

procstat Example:
PID COMM FD T V FLAGS REF OFFSET PRO NAME
84096 snmpd text v r r------- - - - /usr/local/sbin/snmpd
84096 snmpd cwd v d r------- - - - /
84096 snmpd root v d r------- - - - /
84096 snmpd 0 v c rw------ 3 0 - /dev/null
84096 snmpd 1 v c rw------ 3 0 - /dev/null
84096 snmpd 2 v c rw------ 3 0 - /dev/null
84096 snmpd 3 v r -w------ 1 105 - -
84096 snmpd 4 v c r------- 1 0 - /dev/mem
84096 snmpd 5 v c r------- 1 0 - /dev/kmem
84096 snmpd 6 p - rw------ 1 0 - -
84096 snmpd 7 p - rw------ 1 0 - -
84096 snmpd 8 s - rw------ 1 0 UDP 0.0.0.0:161 0.0.0.0:0

from net-snmp.

liviozanol avatar liviozanol commented on July 28, 2024

Well, I also found this:
https://www.freebsd.org/cgi/man.cgi?query=fdescfs&sektion=5&manpath=freebsd-release-ports

So, in the source code, you could change if ((dir = opendir("/proc/self/fd"))) { to if ((dir = opendir("/dev/fd"))) { if the system is freeBSD....

I really don't know how to get the OS using the sources from net-snmp, but found this piece of code the gives me hint: http://net-snmp.sourceforge.net/dev/agent/acconfig_8h_source.html

Or just make it more easy, like this:

(...)
dir = opendir("/proc/self/fd");
if (! dir)
    dir = opendir("/dev/fd");

if (dir) {
(...)

Can I make a pull request?

from net-snmp.

bvanassche avatar bvanassche commented on July 28, 2024

I'd like to keep the Linux and BSD code separate in case /dev/fd would ever be introduced on Linux or /proc/self/fd on BSD. Can you have a look at what I just checked in?

from net-snmp.

liviozanol avatar liviozanol commented on July 28, 2024

I think that will solve the issue. On which version will this be applied?

Just for suggestion, I would make the code a little cleaner, but off course, its up to you.

#ifdef __linux__
    dir = opendir("/proc/self/fd");
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
    dir = opendir("/dev/fd");
#endif

while ((ent = readdir(dir))) {
    if (sscanf(ent->d_name, "%d", &i) == 1) {
        if (i > largest_fd)
            largest_fd = i;
        }
    }
closedir(dir);

if (largest_fd < 0)
        largest_fd = getdtablesize() - 1;
for (i = largest_fd; i > fd && i >= 0; i--)
        close(i);

from net-snmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.