Commit ee3905f6 authored by houkime's avatar houkime

make locks honor TMPDIR

parent ad0faecb
...@@ -42,13 +42,26 @@ ...@@ -42,13 +42,26 @@
#include "rt_lck.h" #include "rt_lck.h"
static char lck_cName[lck_eLock__][40] static char lck_cName[lck_eLock__][40]
= { "/tmp/pwr_nmps_lock", "/tmp/pwr_time_lock", "/tmp/pwr_str_lock" }; = { "pwr_nmps_lock", "pwr_time_lock", "pwr_str_lock" };
sect_sHead* lck_locksect[lck_eLock__] = {0, 0, 0}; sect_sHead* lck_locksect[lck_eLock__] = {0, 0, 0};
static void appendTmpdirPrefix(pwr_tFileName segname, char* name)
{
char *tmpdir = getenv("TMPDIR");
if (!tmpdir) {
tmpdir = lck_cDefaultTmpDir;
}
sprintf(segname, "%s/%s", tmpdir, name);
}
void lck_Create(pwr_tStatus* sts, lck_eLock lock) void lck_Create(pwr_tStatus* sts, lck_eLock lock)
{ {
pwr_tBoolean created; pwr_tBoolean created;
pwr_tFileName segname;
if (lock >= lck_eLock__) { if (lock >= lck_eLock__) {
*sts = 0; *sts = 0;
...@@ -60,8 +73,10 @@ void lck_Create(pwr_tStatus* sts, lck_eLock lock) ...@@ -60,8 +73,10 @@ void lck_Create(pwr_tStatus* sts, lck_eLock lock)
return; return;
} }
appendTmpdirPrefix(segname, lck_cName[lock]);
lck_locksect[lock] = sect_Alloc(sts, &created, 0, sizeof(sect_sMutex), lck_locksect[lock] = sect_Alloc(sts, &created, 0, sizeof(sect_sMutex),
lck_cName[lock], sect_mFlags_Create); segname, sect_mFlags_Create);
if (ODD(*sts) && created) if (ODD(*sts) && created)
sect_InitLock( sect_InitLock(
sts, lck_locksect[lock], (sect_sMutex*)lck_locksect[lock]->base); sts, lck_locksect[lock], (sect_sMutex*)lck_locksect[lock]->base);
...@@ -87,7 +102,8 @@ void lck_Delete(pwr_tStatus* sts, lck_eLock lock) ...@@ -87,7 +102,8 @@ void lck_Delete(pwr_tStatus* sts, lck_eLock lock)
return; return;
} }
char segname[128]; pwr_tFileName proto_segname;
pwr_tFileName segname;
char busid[8]; char busid[8];
char* str = getenv(pwr_dEnvBusId); char* str = getenv(pwr_dEnvBusId);
key_t key; key_t key;
...@@ -97,7 +113,8 @@ void lck_Delete(pwr_tStatus* sts, lck_eLock lock) ...@@ -97,7 +113,8 @@ void lck_Delete(pwr_tStatus* sts, lck_eLock lock)
strncpy(busid, (str ? str : "XXX"), 3); strncpy(busid, (str ? str : "XXX"), 3);
busid[3] = '\0'; busid[3] = '\0';
sprintf(segname, "%s_%.3s", lck_cName[lock], busid); appendTmpdirPrefix(proto_segname, lck_cName[lock]);
sprintf(segname, "%s_%.3s", proto_segname, busid);
key = ftok(segname, 'P'); key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660); shm_id = shmget(key, 0, 0660);
......
...@@ -50,6 +50,8 @@ typedef enum { ...@@ -50,6 +50,8 @@ typedef enum {
lck_eLock__ lck_eLock__
} lck_eLock; } lck_eLock;
#define lck_cDefaultTmpDir "/tmp/"
#define lck_Lock(lock) \ #define lck_Lock(lock) \
sect_Lock(NULL, lck_locksect[lock], (sect_sMutex*)lck_locksect[lock]->base); sect_Lock(NULL, lck_locksect[lock], (sect_sMutex*)lck_locksect[lock]->base);
#define lck_Unlock(lock) \ #define lck_Unlock(lock) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment