Skip to content

Commit d9f4bef

Browse files
committed
Move MSHash to lsof_ctx_dialect for thread safety
1 parent a70e6fe commit d9f4bef

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

lib/dialects/linux/dlsof.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,17 @@ void lsof_dialect_destroy(struct lsof_context *ctx) {
115115
CLEAN(Path);
116116
Pathl = 0;
117117
}
118+
#if defined(HASMNTSUP)
119+
if (MSHash) {
120+
for (int h = 0; h < HASHMNT; h++) {
121+
mntsup_t *mp, *mpn;
122+
for (mp = MSHash[h]; mp; mp = mpn) {
123+
mpn = mp->next;
124+
CLEAN(mp->dir_name);
125+
CLEAN(mp);
126+
}
127+
}
128+
CLEAN(MSHash);
129+
}
130+
#endif
118131
}

lib/dialects/linux/dlsof.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ struct llock {
209209
struct llock *next;
210210
};
211211

212+
# if defined(HASMNTSUP)
213+
typedef struct mntsup {
214+
char *dir_name; /* mounted directory name */
215+
size_t dir_name_len; /* strlen(dir_name) */
216+
dev_t dev; /* device number */
217+
int ln; /* line on which defined */
218+
struct mntsup *next; /* next entry */
219+
} mntsup_t;
220+
221+
# define HASHMNT \
222+
128 /* mount supplement hash bucket count \
223+
* !!!MUST BE A POWER OF 2!!! */
224+
225+
# endif /* defined(HASMNTSUP) */
226+
212227
struct lsof_context_dialect {
213228
/* dnode.c - lock hash table */
214229
struct llock **lock_hash;
@@ -238,6 +253,10 @@ struct lsof_context_dialect {
238253
/* dproc.c - /proc/FD temp buffer */
239254
char *temp_path_buf;
240255
int temp_path_buf_sz;
256+
# if defined(HASMNTSUP)
257+
mntsup_t **mntsup_hash; /* mount supplement
258+
* hash buckets */
259+
# endif /* defined(HASMNTSUP) */
241260
};
242261

243262
/* Dialect-specific cleanup function */
@@ -278,4 +297,7 @@ void lsof_dialect_destroy(struct lsof_context *ctx);
278297
# define Path (ctx->dialect.temp_path_buf)
279298
# define Pathl (ctx->dialect.temp_path_buf_sz)
280299

300+
/* mount supplement hash buckets */
301+
# define MSHash (ctx->dialect.mntsup_hash)
302+
281303
#endif /* LINUX_LSOF_H */

lib/dialects/linux/dmnt.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
* Local definitions
3535
*/
3636

37-
#if defined(HASMNTSUP)
38-
# define HASHMNT \
39-
128 /* mount supplement hash bucket count \
40-
* !!!MUST BE A POWER OF 2!!! */
41-
#endif /* defined(HASMNTSUP) */
42-
4337
/*
4438
* Local function prototypes
4539
*/
@@ -56,23 +50,10 @@ static int hash_mnt(char *dir_name);
5650
* Local structure definitions.
5751
*/
5852

59-
#if defined(HASMNTSUP)
60-
typedef struct mntsup {
61-
char *dir_name; /* mounted directory name */
62-
size_t dir_name_len; /* strlen(dir_name) */
63-
dev_t dev; /* device number */
64-
int ln; /* line on which defined */
65-
struct mntsup *next; /* next entry */
66-
} mntsup_t;
67-
#endif /* defined(HASMNTSUP) */
68-
6953
/*
7054
* Local static definitions
7155
*/
7256

73-
static mntsup_t **MSHash = (mntsup_t **)NULL; /* mount supplement
74-
* hash buckets */
75-
7657
/*
7758
* convert_octal_escaped() -- convert octal-escaped characters in string
7859
*/

0 commit comments

Comments
 (0)