summaryrefslogtreecommitdiff
path: root/src/libfaketime.c
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2021-02-25 10:38:48 -0500
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2021-02-25 10:50:57 -0500
commit7f4e5c378ae228b08ec4b10042d9de682281b3f9 (patch)
treee7257c8e630e69f74d715ddea5cb85916e4d123d /src/libfaketime.c
parent9337bccfcb7512ebf66bcbaf0f13f878cd53a6e8 (diff)
downloadlibfaketime-7f4e5c378ae228b08ec4b10042d9de682281b3f9.tar.gz
Use real_getpid instead of getpid in ft_shm_create() under FAKE_PID
This addresses part of the concerns raised in #297
Diffstat (limited to 'src/libfaketime.c')
-rw-r--r--src/libfaketime.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libfaketime.c b/src/libfaketime.c
index 66003e2..b2b0155 100644
--- a/src/libfaketime.c
+++ b/src/libfaketime.c
@@ -354,9 +354,15 @@ static void ft_shm_create(void) {
struct ft_shared_s *ft_sharedN;
char shared_objsN[513];
sem_t *shared_semT = NULL;
+ pid_t pid;
- snprintf(sem_name, 255, "/faketime_sem_%ld", (long)getpid());
- snprintf(shm_name, 255, "/faketime_shm_%ld", (long)getpid());
+#ifdef FAKE_PID
+ pid = real_getpid();
+#else
+ pid = getpid();
+#endif
+ snprintf(sem_name, 255, "/faketime_sem_%ld", (long)pid);
+ snprintf(shm_name, 255, "/faketime_shm_%ld", (long)pid);
if (SEM_FAILED == (semN = sem_open(sem_name, O_CREAT|O_EXCL, S_IWUSR|S_IRUSR, 1)))
{ /* silently fail on platforms that do not support sem_open() */
return;