Skip to main content

For MF COBOL to work across NFS-mounted file systems, NFS must be configured to handle locks correctly. This C program tests the NFS configuration.

Problem:

NFS-mounted file systems may cause file access errors when used with MF COBOL. Problems may occur, not only at runtime involving indexed files and data files, but also when compiling or using the Animator.

When opening a file, even a flat ASCII file such as a COBOL source file (.cbl), Micro Focus uses the UNIX system call fcntl() to establish a file lock.  This is to prevent other processes or programs from opening the file for "exclusive" access.

NFS-mounted file systems are sometimes configured such that the UNIX system call fcntl() does not work.  This is not the fault of COBOL, though it can result in a hang or an error reported by the COBOL system.

Resolution:

The following C program tests whether an NFS-mounted file system is configured to handle the UNIX system call fcntl() correctly. The program can demonstrate the problem outside of COBOL, to show that the fault lies with NFS and not with COBOL. If this program hangs or reports an error, you must fix the NFS configuration before you can expect COBOL to work.  If the program runs successfully to completion, then the "fnctl" lock was successful, and NFS has passed the test.

1) Change directories (cd) to a directory on the NFS-mounted file system where the problem occurs

2) Place this C program there in a file named 'nfs_lock2.c'.

3) Compile it with the command "make nfs_lock2".  If the C compiler reports some warnings, these can safely be ignored

4) Run the program:   ./nfs_lock2

#include <stdio.h>
#include <fcntl.h> main() { printf("nfs_lock2 program starting...\\n"); int fd , ret; struct flock strlock; printf("nfs_lock2 program attempting open...\\n"); fd = open("testfile", O_CREAT | O_RDWR , 0666 ); if (fd == -1) { printf("FATAL ERROR: Could not open file\\n"); exit(-1); } /* Set a write lock on the first 1024 butes of the file. It doesn't matter that they don't actually exist yet. */ printf("nfs_lock2 program attempting lock...\\n"); strlock.l_type = F_WRLCK; strlock.l_whence = 0; strlock.l_start = 0L; strlock.l_len = 1024L; ret = fcntl (fd, F_SETLK , &strlock); if (ret == -1) { printf("FATAL ERROR: Could not lock file\\n"); exit(-1); } printf("nfs_lock2 program attempting close...\\n"); ret = close( fd ); if (ret == -1) { printf("FATAL ERROR: Could not close file\\n"); exit(-1); } printf("nfs_lock2 program exiting.\\n"); }
Old KB# 14008

#ServerExpress
#netexpress
#AcuCobol
#COBOL
#RMCOBOL