]>
Commit | Line | Data |
---|---|---|
32938903 AM |
1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
2 | ## 004_separate_file_and_sem_perms.dpatch by <divanov@creditreform.bg> | |
3 | ## | |
4 | ## All lines beginning with `## DP:' are a description of the patch. | |
5 | ## DP: Separate definitions for file and semaphore permissions | |
6 | ||
7 | @DPATCH@ | |
8 | ||
9 | --- firebird2-1.5.2.orig/src/jrd/isc_sync.cpp | |
10 | +++ firebird2-1.5.2/src/jrd/isc_sync.cpp | |
11 | @@ -136,8 +136,20 @@ | |
12 | #endif | |
13 | ||
14 | #define FTOK_KEY 15 | |
15 | -#define PRIV 0666 | |
16 | #define LOCAL_SEMAPHORES 4 | |
17 | +#define FILE_PERM 0666 | |
18 | +#if defined(SEM_R) && defined(SEM_A) | |
19 | +#define SEM_PERM SEM_R | SEM_A | (SEM_R>>3) | (SEM_A>>3) \ | |
20 | + | (SEM_R>>6) | (SEM_A>>6) | |
21 | +#else | |
22 | +#define SEM_PERM FILE_PERM | |
23 | +#endif | |
24 | +#if defined(SHM_R) && defined(SHM_W) | |
25 | +#define SHM_PERM SHM_R | SHM_W | (SHM_R>>3) | (SHM_W>>3) \ | |
26 | + | (SHM_R>>6) | (SHM_W>>6) | |
27 | +#else | |
28 | +#define SHM_PERM FILE_PERM | |
29 | +#endif | |
30 | ||
31 | #ifndef GDS_RELAY | |
32 | #define GDS_RELAY "/bin/gds_relay" | |
33 | @@ -2381,7 +2393,7 @@ | |
34 | ||
35 | /* Create the shared memory region if it doesn't already exist. */ | |
36 | ||
37 | - if ((shmid = shmget(key, length, IPC_CREAT | PRIV)) == -1) | |
38 | + if ((shmid = shmget(key, length, IPC_CREAT | SHM_PERM)) == -1) | |
39 | #ifdef SUPERSERVER | |
40 | if (errno == EINVAL) { | |
41 | /* There are two cases when shmget() returns EINVAL error: | |
42 | @@ -2428,7 +2440,7 @@ | |
43 | way to get shmid is to attach to the segment with zero | |
44 | length | |
45 | */ | |
46 | - if ((shmid = shmget(key, 0, PRIV)) == -1) { | |
47 | + if ((shmid = shmget(key, 0, SHM_PERM)) == -1) { | |
48 | error(status_vector, "shmget", errno); | |
49 | ib_fclose(fp); | |
50 | return NULL; | |
51 | @@ -2446,7 +2458,7 @@ | |
52 | we use IPC_EXCL flag to get an error if by some miracle | |
53 | the sagment with the same key is already exists | |
54 | */ | |
55 | - if ((shmid = shmget(key, length, IPC_CREAT | IPC_EXCL | PRIV)) == | |
56 | + if ((shmid = shmget(key, length, IPC_CREAT | IPC_EXCL | SHM_PERM)) == | |
57 | -1) { | |
58 | error(status_vector, "shmget", errno); | |
59 | ib_fclose(fp); | |
60 | @@ -2491,7 +2503,7 @@ | |
61 | return NULL; | |
62 | } | |
63 | ||
64 | - if ((shmid = shmget(key, length, IPC_CREAT | IPC_EXCL | PRIV)) == | |
65 | + if ((shmid = shmget(key, length, IPC_CREAT | IPC_EXCL | SHM_PERM)) == | |
66 | -1) { | |
67 | error(status_vector, "shmget", errno); | |
68 | ib_fclose(fp); | |
69 | @@ -2500,7 +2512,7 @@ | |
70 | } | |
71 | else { | |
72 | length = buf.shm_segsz; | |
73 | - if ((shmid = shmget(key, length, PRIV)) == -1) { | |
74 | + if ((shmid = shmget(key, length, SHM_PERM)) == -1) { | |
75 | error(status_vector, "shmget", errno); | |
76 | ib_fclose(fp); | |
77 | return NULL; | |
78 | @@ -2521,7 +2533,7 @@ | |
79 | ||
80 | /* Now remap with the new-found length */ | |
81 | ||
82 | - if ((shmid = shmget(key, length, PRIV)) == -1) { | |
83 | + if ((shmid = shmget(key, length, SHM_PERM)) == -1) { | |
84 | error(status_vector, "shmget", errno); | |
85 | ib_fclose(fp); | |
86 | return NULL; | |
87 | @@ -4176,7 +4188,7 @@ | |
88 | /* Produce shared memory key for file */ | |
89 | ||
90 | if ((key = ftok(filename, FTOK_KEY)) == -1) { | |
91 | - if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, PRIV)) == -1) { | |
92 | + if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, FILE_PERM)) == -1) { | |
93 | error(status_vector, "open", errno); | |
94 | return 0L; | |
95 | } | |
96 | @@ -4208,7 +4220,7 @@ | |
97 | * | |
98 | **************************************/ | |
99 | // Open semaphore set | |
100 | - SLONG semid = semget(key, 0, PRIV); | |
101 | + SLONG semid = semget(key, 0, SEM_PERM); | |
102 | if (semid == -1) { | |
103 | error(status_vector, "semget", errno); | |
104 | return -1; | |
105 | @@ -4251,7 +4263,7 @@ | |
106 | SLONG semid; | |
107 | do { | |
108 | // Try to open existing semaphore set | |
109 | - semid = semget(key, 0, PRIV); | |
110 | + semid = semget(key, 0, SEM_PERM); | |
111 | if (semid == -1) { | |
112 | if (errno != ENOENT) { | |
113 | error(status_vector, "semget", errno); | |
114 | @@ -4278,8 +4290,8 @@ | |
115 | } | |
116 | ||
117 | // Try to create new semaphore set | |
118 | - semid = semget(key, semaphores, IPC_CREAT | IPC_EXCL | PRIV); | |
119 | - if (semid != -1) | |
120 | + semid = semget(key, semaphores, IPC_CREAT | IPC_EXCL | SEM_PERM); | |
121 | + if (semid != -1) | |
122 | return semid; | |
123 | else | |
124 | if (errno != EEXIST) { |