[linux-cifs-client] Re: REAL fun ;-))
Jeremy Allison
jra at samba.org
Wed Jul 26 18:57:22 GMT 2006
On Sat, Jul 15, 2006 at 11:11:47PM -0700, Jeremy Allison wrote:
> On Sun, Jul 16, 2006 at 08:08:07AM +0200, Volker Lendecke wrote:
> >
> > Sure -- but it's still fun to watch that we still do not
> > properly check all malloc results.
>
> Don't we always check for failure - then fail
> the logic later ?
>
> Right now having fun with cifsfs. It doesn't
> understand the difference between fast and
> slow system calls - this is a killer for
> this particular test case (run on a local
> system to see what happens then run on
> a cifsfs mounted file :-).
After my latest checkin (rev 64)
the attached code now runs correctly on
a POSIX locking CIFS mounted share !!
w00t ! :-).
Jeremy.
-------------- next part --------------
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
int fd1;
void alarm_handler(int sig)
{
write(1,"in handler\n", 11);
alarm(2);
// close(fd1);
}
int main(int argc, const char **argv)
{
struct flock fl;
pid_t pid;
struct sigaction sa;
if ((fd1 = open(argv[1], O_RDWR, 0660)) == -1) {
fprintf(stderr, "open failed %s\n",
strerror(errno) );
return 1;
}
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 10;
if (fcntl(fd1, F_SETLK, &fl)==-1) {
fprintf(stderr, "setlk failed %s\n",
strerror(errno) );
return 1;
}
pid = fork();
if (pid == -1) {
fprintf(stderr, "fork failed %s\n",
strerror(errno) );
return 1;
}
if (pid != 0) {
/* Parent - wait for 10 seconds with the lock. */
sleep(10);
return 0;
}
printf("Child...\n");
/* Child. */
memset(&sa, '\0', sizeof(sa));
sa.sa_handler = alarm_handler;
sa.sa_flags = SA_RESTART;
sigaction(SIGALRM, &sa, NULL);
alarm(2);
if (fcntl(fd1, F_SETLKW, &fl)==-1) {
fprintf(stderr, "setlk failed %s\n",
strerror(errno) );
return 1;
}
printf("setlk succeeded ?\n");
}
More information about the linux-cifs-client
mailing list