skarnet / s6

The s6 supervision suite.
https://skarnet.org/software/s6/
ISC License
777 stars 35 forks source link

readiness notification not working #20

Closed tdeva14 closed 4 years ago

tdeva14 commented 4 years ago

I have been trying to make readiness notification work for snmpd daemon but somehow I always end up in errno 9 EBADF 9 Bad file descriptor

Below is the readiness snippet in snmpd

#ifdef S6_NOTIFY
#define NOTIFY_FD 9
    if (write(NOTIFY_FD, "\n", 1) > 0) {
        close(NOTIFY_FD);
        printf("notifying s6 success\n");
    } else {
        printf("notifying s6 failed with errno=%d\n", errno);
    }
#endif

And below are the contents in snmpd-srv directory

root@(none):/etc/s6/source/snmpd-srv# cat notification-fd
9
root@(none):/etc/s6/source/snmpd-srv#
root@(none):/etc/s6/source/snmpd-srv# cat run
#!/bin/execlineb -P
foreground { echo "snmp service started" }
/usr/local/sbin/snmpd -f
root@(none):/etc/s6/source/snmpd-srv#
root@(none):/etc/s6/source/snmpd-srv# cat type
longrun
root@(none):/etc/s6/source/snmpd-srv#

Am I missing something? Please let me know if any further information is required. Any help is really appreciated.

tdeva14 commented 4 years ago

Just an additional info. s6-supervise for snmpd-srv has this pipe opened for reading the notification message (I assume) but not sure if this gets destroyed right before the write call s6-superv 2784 root 8r FIFO 0,10 0t0 160433 pipe

tdeva14 commented 4 years ago

Sorry my bad. There was a piece of code in snmpd which closed all non-standard fds (fds >2) that destroyed the notification pipe. Notification worked after commenting out below code.

     * close all non-standard file descriptors we may have
     * inherited from the shell.
     */
    if (!prepared_sockets)
        netsnmp_close_fds(2);