summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrrelyea <rrelyea@fba4d07e-fe0f-4d7f-8147-e0026e666dc0>2006-09-07 20:57:20 +0000
committerrrelyea <rrelyea@fba4d07e-fe0f-4d7f-8147-e0026e666dc0>2006-09-07 20:57:20 +0000
commitab3ee25a58eb8e5b4e0a9c29fc43c7df54befca3 (patch)
tree9010b00d1809cfe8640c92204b4d158b009f0b4d /src
parente2eb6f3d07d7cb507db41235737400d725deeea5 (diff)
create separate cache files for each user.
Set permissions so all users can share the directory. git-svn-id: http://svn.fedorahosted.org/svn/coolkey/trunk@27 fba4d07e-fe0f-4d7f-8147-e0026e666dc0
Diffstat (limited to 'src')
-rw-r--r--src/coolkey/machdep.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/coolkey/machdep.cpp b/src/coolkey/machdep.cpp
index 68f566f..773b2c3 100644
--- a/src/coolkey/machdep.cpp
+++ b/src/coolkey/machdep.cpp
@@ -177,6 +177,7 @@ void OSSleep(int time)
#define FULL_CLEANUP
#else
/* if we can't lock on open, don't use locking for now */
+#undef FULL_CLEANUP
#define O_EXLOCK 0
#endif
@@ -207,9 +208,11 @@ SHMemData::~SHMemData() {
#ifdef FULL_CLEANUP
flock(fd,LOCK_EX);
unsigned long ref = --(*(unsigned long *)addr);
+#ifdef notdef
if (ref == 0) {
unlink(path);
}
+#endif
flock(fd, LOCK_UN);
#endif
munmap(addr,size+RESERVED_OFFSET);
@@ -228,6 +231,14 @@ SHMem *
SHMem::initSegment(const char *name, int size, bool &init)
{
bool needInit = true;
+ /* big enough to hold a uid_t value in decimal */
+ /* decimal digits = ceiling(log10(uid_t_max)); */
+ /* log10(uid_t_max) = log256(uid_t_max)/log256(10); */
+ /* log256(uid_t_max) = sizeof(uid_t); */
+ /* log10(256) just greater than .41 */
+ /* so decimal_digits = (sizeof(uid_t)*100 +40)/41 */
+#define UID_DIGITS (((sizeof(uid_t)*100)+40)/41)
+ char uid_str[UID_DIGITS+2]; /* 1 for '-', 1 for null */
init = 0;
SHMemData *shmemData = new SHMemData;
@@ -236,12 +247,13 @@ SHMem::initSegment(const char *name, int size, bool &init)
// from getSHMemAddr.
return NULL;
}
- int ret = mkdir (MEMSEGPATH, 0755);
+ int ret = mkdir (MEMSEGPATH, 0777);
if ((ret == -1) && (errno != EEXIST)) {
delete shmemData;
return NULL;
}
- shmemData->path = new char [sizeof(MEMSEGPATH)+strlen(name)+2];
+ /* 1 for the '/', one for the '-' and one for the null */
+ shmemData->path = new char [sizeof(MEMSEGPATH)+strlen(name)+UID_DIGITS+3];
if (shmemData->path == NULL) {
delete shmemData;
return NULL;
@@ -249,11 +261,19 @@ SHMem::initSegment(const char *name, int size, bool &init)
memcpy(shmemData->path,MEMSEGPATH, sizeof(MEMSEGPATH));
shmemData->path[sizeof(MEMSEGPATH)-1] = '/';
strcpy(&shmemData->path[sizeof(MEMSEGPATH)],name);
+
+ int mode = 0777;
+ if (strcmp(name,"token_names") != 0) {
+ /* each user gets his own uid array */
+ sprintf(uid_str, "-%u",getuid());
+ strcat(shmemData->path,uid_str);
+ mode = 0700;
+ }
shmemData->fd = open(shmemData->path,
- O_CREAT|O_RDWR|O_EXCL|O_APPEND|O_EXLOCK, 0700);
+ O_CREAT|O_RDWR|O_EXCL|O_APPEND|O_EXLOCK, mode);
if (shmemData->fd < 0) {
needInit = false;
- shmemData->fd = open(shmemData->path,O_RDWR|O_EXLOCK, 0700);
+ shmemData->fd = open(shmemData->path,O_RDWR|O_EXLOCK, mode);
} else {
char *buf;
int len = size+RESERVED_OFFSET;