1 message in net.sourceforge.lists.courier-maildrop[maildropl] NFS check function
FromSent OnAttachments
Chris MastersOct 21, 2003 2:57 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[maildropl] NFS check functionActions...
From:Chris Masters (roti@yahoo.com)
Date:Oct 21, 2003 2:57:40 pm
List:net.sourceforge.lists.courier-maildrop

Hi all,

I've just written an NFS check function that verifies and gives a timeout to 'hard' linked NFS mounts.

It seems that most accept that broken 'hard linked' NFS mounts will hang, but this will cause postfix to timeout it's call to maildrop and bounce the mail.

I've attached the function (not in a diff format) and it can be used in any C program to check and give a timeout for an nfs mount. It needs to be called before a system io call on an NFS mount.

NFS mount need to be mounted with the -intr option.

Hope this helps someone!

Bring up any errors,

Chris

__________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com

I use this in main.C (and possibly other places) just before the chdir check:

int nfs_res = check_nfs(5,h); if(nfs_res == 0) { if (VerboseLevel() > 1) merr << "maildrop: Possible NFS timeout" << h << "\n";

errexit=EX_TEMPFAIL; throw "Possible NFS error."; } else if(nfs_res == -1) { if (VerboseLevel() > 1) merr << "maildrop: Error testing NFS mount" << h << "\n";

errexit=EX_TEMPFAIL; throw "NFS Test Error."; }

if (chdir(h) < 0) {

//checks if an nfs mount is broken without hanging int check_nfs(int timeout,const char *nfs_dir) { int fds[2],rc; fd_set fdset; struct timeval t; pid_t child;

if(pipe(fds) != 0) { return -1; } child = fork(); if(child == -1) { return -1; }

if( child == 0 ) { char *buf = "ok"; chdir(nfs_dir); write(fds[1],buf,3); close(fds[0]); close(fds[1]); exit(0); } else { t.tv_sec = timeout; t.tv_usec = 0; FD_ZERO(&fdset); FD_SET(fds[0], &fdset);

rc = select(fds[0] + 1,&fdset,NULL,NULL,&t);

if(rc == -1) { close(fds[0]); close(fds[1]); return -1; } else if(rc == 0) { kill(child,SIGINT); close(fds[0]); close(fds[1]); return 0; } else if(FD_ISSET(fds[0],&fdset)) { //close all stuff close(fds[0]); close(fds[1]); } } return 1; }