Re: [vserver] Problem with locks

From: PV <pstm.spain_at_gmail.com>
Date: Fri 23 Mar 2012 - 17:17:19 GMT
Message-ID: <4F6CB01F.5020203@gmail.com>

El 23/03/12 15:30, Herbert Poetzl escribió:
>
> I'd wrap the other processes, e.g. the pickup with an
> strace shell wrapper, so that we get some information what
> is requested and denied from the kernel side ...
>
>
>
Really, I do not know how is possible that locks are not released after
all programs kill (except sshd). With sshd problem do not appear.

> [root@mail ~]# ps aux
> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
> root 1 0.0 0.1 10364 608 ? SNs 2011 8:39 init [2]
> root 24526 0.0 0.2 110212 1116 pts/12 R+ 2011 0:00 ps aux
> root 26049 0.0 0.2 64076 1104 ? Ss 2011 0:00
> /usr/sbin/sshd
> root 29638 0.0 0.7 95912 4120 ? S 2011 0:00 sshd:
> root@pts/12
> root 29662 0.0 0.3 110648 2020 pts/12 Ss 2011 0:00 -bash

> [root@mail ~]# cat locks2.c
> #include <stdlib.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <stdio.h>
>
>
>
>
> int
> lock (int fd)
> {
> struct flock fl;
> /* Make a non-blocking request to place a write lock
> on bytes 100-109 of testfile */
> fl.l_type = F_WRLCK;
> fl.l_whence = SEEK_SET;
> fl.l_start = 100;
> fl.l_len = 10;
>
> if (fcntl (fd, F_SETLK, &fl) == -1)
> {
> if (errno == EACCES || errno == EAGAIN)
> {
> printf ("Already locked by another process\n");
> /* We can't get the lock at the moment */
> }
> else
> {
> /* Handle unexpected error */ ;
> printf("Error not listed %u\n",errno);
> //perror();
> }
> }else{
> printf("locked\n");
> }
> }
>
>
>
> int
> unlock (int fd)
> {
> struct flock fl;
> /* Perform I/O on bytes 100 to 109 of file */
> /* Unlock the locked bytes */
> fl.l_type = F_UNLCK;
> fl.l_whence = SEEK_SET;
> fl.l_start = 100;
> fl.l_len = 10;
> if (fcntl (fd, F_SETLK, &fl) == -1)
> {
> printf ("Can not unlock file\n");
> }else{
> printf("unlocked\n");
> }
>
> }
>
>
>
>
>
>
>
>
>
>
> int
> main (int argc, char *argv[])
> {
> register unsigned counter = 0;
> int fd;
>
> fd = open ("testfile", O_RDWR);
> if (fd == -1)
> {
> printf ("Can not open file\n");
> }
>
>
> for (counter = 0; counter < 5; counter++)
> {
> printf("cycle %u\n",counter);
> lock (fd);
> unlock (fd);
> }
>
>
> /*malloc_test();
>
> char * buffer;
> printf ("How long do you want the string? ");
> scanf ("%d", &i);
> buffer = (char*) malloc (i+1);
> if (buffer==NULL) exit (1);
> free (buffer);
> */
>
>
> exit (EXIT_SUCCESS);
> }
> /* main */

[root@mail ~]# ./locks2
cycle 0
Error not listed 37
Can not unlock file
cycle 1
Error not listed 37
Can not unlock file
cycle 2
Error not listed 37
Can not unlock file
cycle 3
Error not listed 37
Can not unlock file
cycle 4
Error not listed 37
Can not unlock file
Received on Fri Mar 23 17:17:40 2012

[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Fri 23 Mar 2012 - 17:17:40 GMT by hypermail 2.1.8