Bug 108149 - fcntl record lock failed to preserve across an execve
fcntl record lock failed to preserve across an execve
Status: CLOSED WONTFIX
Product: Red Hat Linux
Classification: Retired
Component: kernel (Show other bugs)
9
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Arjan van de Ven
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-10-27 20:09 EST by Reinhard Dunkel
Modified: 2007-04-18 12:58 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-09-30 11:41:39 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Reinhard Dunkel 2003-10-27 20:09:07 EST
Description of problem:

Accroding to the man page for fcntl, a record lock created through a fcntl call
should be preserved across an execve call. This is the case under Red Hat Linue
9 kernel-2.4.20-8smp release, but fails to work under kernel-2.4.20-20.9 release.

Here is a description of our test scenario: A process forks after starting up.
In the child process, it creates an exclusive file lock through fcntl() and then
calls execve(). In the parent process, it tests whether an exclusive lock is
placed on the file. Under kernel-2.4.20-20.9 release, the parent process finds
no lock, whereas under kernel-2.4.20-8smp, the parent process finds that an
exclusive lock is placed on the file.

The source code for our test case includes two files:
/*---First file is named "fcntl_test.cxx", here is the code:---*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>


int main(int argc, char *argv[])
{
   int pid, i;
   FILE *fp;
   struct flock lck;

   /* --- Open a file for writing. */
   printf("fcntl_test: About to open file '/tmp/test.txt' for writing... ");
   fp = fopen("/tmp/test.txt", "w");
   if (fp == NULL) {
      printf("Failed\n");
      exit(1);
   } else {
      printf("Succeeded\n");
   }

   /* --- Now fork. */
   printf("fcntl_test: About to fork...\n");
   pid = fork();

   if (pid == 0) {

      /* --- In child process: Try to place an exclusive lock. */
      printf("fcntl_test Child: Try to place an exclusive lock... ");
      lck.l_type = F_WRLCK;
      lck.l_start = 0;
      lck.l_whence = SEEK_END;
      lck.l_len = 0;
      if (fcntl(fileno(fp), F_SETLK, &lck) < 0) {
         printf("Failed\n");
         exit(2);
      } else {
         printf("Succeeded\n");
      }

      /* --- Try to exec */
      printf("fcntl_test Child: Try to exec fcntl_lock...\n");
      if (execve("fcntl_lock", argv, argv) == -1) {
         printf("fcntl_test Child: execvp Failed\n");
      }
   } else if (pid > 0) {

      /* --- Try to sleep for 5 seconds. */
      printf("fcntl_test Parent: Try to sleep for 5 seconds.\n");
      sleep(5);

      /* --- In parent process: Try to test whether an exclusive lock is */
      /* --- placed on file. Try this for 30 times. */
      printf("fcntl_test Parent: Try 30 times to test whether exclusive lock
exists...\n");
      for (i = 0; i < 30; i++) {
         lck.l_type = F_WRLCK;
         lck.l_start = 0;
         lck.l_whence = SEEK_SET;
         lck.l_len = 0;
         lck.l_pid = (pid_t)0;
         if (fcntl(fileno(fp), F_GETLK, &lck) < 0) {
            printf("   Failed\n");
            exit(3);
         } else {
            if (lck.l_type == F_UNLCK) {
               printf("   No lock placed on file\n");
            } else if (lck.l_type == F_WRLCK) {
               printf("   An exclusive lock placed on file by process %d\n",
                      lck.l_pid);
            } else if (lck.l_type == F_RDLCK) {
               printf("   A shared lock placed on file by process %d\n",
                      lck.l_pid);
            }
         }
      }

      printf("fcntl_test Parent: Now exit\n");
      exit(0);
   } else {
      printf("fcntl_test: fork() failed\n");
      exit(1);
   }
}


/*---Second file is named "fcntl_lock.cxx", here is the code:---*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>


int main(int argc, char *argv[])
{
   /* --- Sleep for 10 seconds. */
   printf("fcntl_lock: Now sleep for 10 seconds... \n");
   sleep(10);

   printf("fcntl_lock: Now exit\n");
   exit(0);
}



Version-Release number of selected component (if applicable):

kernel-2.4.20-20.9


How reproducible:

Everytime


Steps to Reproduce:

1.Compile the source code:
gcc fcntl_test.cxx -o fcntl_test
gcc fcntl_lock.cxx -o fcntl_lock

2. Make sure that you have write permission to the /tmp directory and the
directory does NOT contain a file named "test.txt".

3. Copy the executables fcntl_test and fcntl_lock into the same directory (such
as your home directory). cd into this directory and execute:
./fcntl_test


    
Actual results:

The results under kernel-2.4.20-20.9 release:

fcntl_test: About to open file '/tmp/test.txt' for writing... Succeeded
fcntl_test: About to fork...
fcntl_test Parent: Try to sleep for 5 seconds.
fcntl_test Parent: Try 30 times to test whether exclusive lock exists...
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
   No lock placed on file
fcntl_test Parent: Now exit
fcntl_lock: Now sleep for 10 seconds...
fcntl_lock: Now exit


Expected results:

The results under kernel-2.4.20-8smp release:

fcntl_test: About to open file '/tmp/test.txt' for writing... Succeeded
fcntl_test: About to fork...
fcntl_test Parent: Try to sleep for 5 seconds.
fcntl_test Parent: Try 30 times to test whether exclusive lock exists...
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
   An exclusive lock placed on file by process 8626
fcntl_test Parent: Now exit
fcntl_lock: Now sleep for 10 seconds...
fcntl_lock: Now exit

Additional info:
Comment 1 Bugzilla owner 2004-09-30 11:41:39 EDT
Thanks for the bug report. However, Red Hat no longer maintains this version of
the product. Please upgrade to the latest version and open a new bug if the problem
persists.

The Fedora Legacy project (http://fedoralegacy.org/) maintains some older releases, 
and if you believe this bug is interesting to them, please report the problem in
the bug tracker at: http://bugzilla.fedora.us/

Note You need to log in before you can comment on or make changes to this bug.