Debian Codegraph @

debian/patches/no-shmdt-before-fork-428105

raw
1 --- a/buffer.c
2 +++ b/buffer.c
3 @@ -507,14 +507,14 @@
4 get_buffer();
5
6 if( debug )
7 - fprintf( stderr, "%s pbuffer is 0x%08x, buffer_size is %d [%d x %d]\n",
8 + fprintf( stderr, "%s pbuffer is 0x%08lx, buffer_size is %d [%d x %d]\n",
9 proc_string,
10 - (char *)pbuffer, buffer_size, blocks, blocksize );
11 + (unsigned long)pbuffer, buffer_size, blocks, blocksize );
12
13 #ifdef SYS5
14 - memset( (char *)pbuffer, '\0', buffer_size );
15 + memset( pbuffer->data_space, '\0', blocks * blocksize );
16 #else
17 - bzero( (char *)pbuffer, buffer_size );
18 + bzero( pbuffer->data_space, blocks * blocksize );
19 #endif
20 pbuffer->semid = -1;
21 pbuffer->blocks_used_lock = -1;
22 @@ -539,9 +539,20 @@
23 #else
24 sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks );
25 #endif
26 +
27 + /* Do not detach the shared memory, but leave it mapped. It will be inherited
28 + * over fork just fine and this ensures that it's mapped at the same address
29 + * both in the reader and writer. The original code did a shmdt() here followed
30 + * by shmat() both in the reader and writer and relied on it getting mapped at
31 + * the same address in both processes, which of course isn't guaranteed and
32 + * actually did fail under some unknown circumstances on amd64.
33 + * <[email protected]> 2008-05-09
34 + */
35 +#if 0
36 /* Detattach the shared memory so the fork doesnt do anything odd */
37 shmdt( (char *)pbuffer );
38 pbuffer = NO_BUFFER;
39 +#endif
40 }
41
42 void
43 @@ -629,8 +640,6 @@
44 if( debug )
45 fprintf( stderr, "R: Entering reader\n" );
46
47 - get_buffer();
48 -
49 while( 1 ){
50 get_next_free_block();
51 if( ! fill_block() )
52 @@ -723,8 +732,6 @@
53 blocks,
54 maxfilled );
55
56 - get_buffer();
57 -
58 while( 1 ){
59 if( !filled )
60 first_block = pbuffer->next_block_out;