[stsf-commit] stsf/STFontServer/src fontenumerator.c, 1.3,
1.4 fontserver.c, 1.4, 1.5 handler.c, 1.6, 1.7 handler.h, 1.2,
1.3 saverestore.c, 1.4, 1.5 stfs-door.c, 1.7, 1.8 stpfc.c, 1.2, 1.3
Alexander Gelfenbain
stsf-commit at pdx.freedesktop.org
Sun May 30 16:07:20 PDT 2004
- Previous message: [stsf-commit] stsf/STClientLibrary/src STSysCtl.c, 1.1.1.1,
1.2 libtest.c, 1.3, 1.4 serverconnection.c, 1.8,
1.9 sysctlvars.h, 1.1.1.1, 1.2
- Next message: [stsf-commit]
stsf/interface stprivate.h, 1.1, 1.2 sttypes.tmpl, 1.7, 1.8
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: adg
Index: fontenumerator.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/fontenumerator.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/fontenumerator.c 22 Apr 2004 20:56:32 -0000 1.3
+++ b/fontenumerator.c 30 May 2004 23:07:17 -0000 1.4
@@ -897,7 +897,7 @@
f->vfont = f->vfont == NULL ? (FSVirtualFontRecord *) NULL : (FSVirtualFontRecord *) ofe->fontarray[(intptr_t) f->vfont-1];
}
- if ((ofe->fontIDArray = calloc(ofe->fontcount, sizeof(uint32_t))) == NULL) {
+ if ((ofe->fontIDArray = calloc(ofe->fontslots, sizeof(uint32_t))) == NULL) {
FontEnumeratorDispose((FontEnumerator) ofe);
return ST_MEMORY;
}
Index: fontserver.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/fontserver.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/fontserver.c 25 May 2004 21:08:21 -0000 1.4
+++ b/fontserver.c 30 May 2004 23:07:17 -0000 1.5
@@ -79,10 +79,6 @@
#include "path.h"
#include "dict.h"
-#ifndef TEMP_FONT_DIR
-#define TEMP_FONT_DIR "/var/tmp/stsf/fonts"
-#endif
-
#ifndef TEMP_PATTERN
#define TEMP_PATTERN "XXXXXX"
#endif
@@ -860,8 +856,8 @@
if (cid == 0 || cid == 0xFFFFFFFF) return ST_PROTECTION;
if (iURLCount <= 0) return ST_COUNT;
- if ((stat(TEMP_FONT_DIR, &st) == -1) && CreateDir(TEMP_FONT_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
- ErrorStr("Error creating STSF temporary font directory: %s.", TEMP_FONT_DIR);
+ if ((stat(STSF_TEMPFONTDIR, &st) == -1) && CreateDir(STSF_TEMPFONTDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+ ErrorStr("Error creating STSF temporary font directory: %s.", STSF_TEMPFONTDIR);
return ST_FILEIO;
}
@@ -874,7 +870,7 @@
for (i=0; i<iURLCount; i++) {
char *q;
- strlcpy(tempfile, TEMP_FONT_DIR, MAXPATHLEN);
+ strlcpy(tempfile, STSF_TEMPFONTDIR, MAXPATHLEN);
strlcat(tempfile, "/", MAXPATHLEN);
strlcat(tempfile, TEMP_PATTERN, MAXPATHLEN);
/* Handle "file: URLs */
@@ -949,8 +945,8 @@
if (cid == 0 || cid == 0xFFFFFFFF) return ST_PROTECTION;
if (iDataCount <= 0) return ST_COUNT;
- if ((stat(TEMP_FONT_DIR, &st) == -1) && CreateDir(TEMP_FONT_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
- ErrorStr("Error creating STSF temporary font directory: %s.", TEMP_FONT_DIR);
+ if ((stat(STSF_TEMPFONTDIR, &st) == -1) && CreateDir(STSF_TEMPFONTDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+ ErrorStr("Error creating STSF temporary font directory: %s.", STSF_TEMPFONTDIR);
return ST_FILEIO;
}
@@ -960,7 +956,7 @@
/* Store data in temporary files */
for (i=0; i<iDataCount; i++) {
- strlcpy(tempfile, TEMP_FONT_DIR, MAXPATHLEN);
+ strlcpy(tempfile, STSF_TEMPFONTDIR, MAXPATHLEN);
strlcat(tempfile, "/", MAXPATHLEN);
strlcat(tempfile, TEMP_PATTERN, MAXPATHLEN);
@@ -1853,14 +1849,13 @@
*url = 0;
gethostname(hname, MAXHOSTNAMELEN);
- *url = malloc(strlen(file) + strlen(hname) + strlen(font->filename) + 1 /* slash */ + 1 /* null */);
+ *url = malloc(strlen(file) + strlen(hname) + strlen(font->filename) + 1 /* null */);
if (*url == NULL) {
return ST_MEMORY;
}
strcpy((char *) *url, file);
strcat((char *) *url, hname);
- strcat((char *) *url, "/");
strcat((char *) *url, font->filename);
return ST_OK;
Index: handler.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/handler.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/handler.c 25 May 2004 21:34:49 -0000 1.6
+++ b/handler.c 30 May 2004 23:07:17 -0000 1.7
@@ -102,11 +102,16 @@
intptr_t cdata,
STFSProtoOpcode *opcode, /* on exit contains reply */
byte *p, /* protocol shared memory */
- uint32_t s) /* size of the protocol shared memory */
+ uint32_t s, /* size of the protocol shared memory */
+ int *fd, /* file descriptors passed from or to a client */
+ int *nfd) /* number of file descriptor */
{
int n;
STStatus ret;
STFSProtoOpcode op = *opcode;
+ int fdcount = *nfd;
+
+ *nfd = 0; /* typically no file descriptors are returned */
if (fsc_copyout(op, p, s) != 0 || ((*opcode = ProtoOutForIn(op)) == FS_PROTO_ERROR)) {
ErrorStr("%s: error analyzing the incoming request.", __func__);
@@ -618,7 +623,33 @@
ret = FSGetFontData(fs, q->font, q->table, &nbytes, &rawdata);
- if ((n = ci_getfontdata_out(p, s, nbytes, rawdata)) != 0) ret = ST_PROTO_BUFF;
+ if ((n = ci_getfontdata_out(p, s, nbytes)) != 0) ret = ST_PROTO_BUFF;
+
+ if (nbytes != 0) {
+ char *shmfname = "/tmp/XXXXXX";
+ int shmfd;
+
+ if ((shmfd = mkstemp(shmfname)) == -1) {
+ ret = ST_FILEIO;
+ } else {
+ unlink(shmfname);
+ if (ftruncate(shmfd, nbytes) == -1) {
+ close(shmfd);
+ ret = ST_FILEIO;
+ } else {
+ char *dptr = mmap(NULL, nbytes, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
+ if (dptr == MAP_FAILED) {
+ close(shmfd);
+ ret = ST_FILEIO;
+ } else {
+ memcpy(dptr, rawdata, nbytes);
+ munmap(dptr, nbytes);
+ *nfd = 1;
+ *fd = shmfd;
+ }
+ }
+ }
+ }
if (rawdata) free(rawdata);
}
return ret;
@@ -659,14 +690,44 @@
case FS_CREATEFONTS_IN:
{
fsc_createfonts_in *q = (fsc_createfonts_in *) p;
- STCount fontcount;
- STFont *fonts = 0;
+ STCount fontcount = 0;
+ STFont *fonts = NULL;
+ byte **data = NULL;
- ret = FSCreateFonts(fs, (uint32_t) q->cid & 0xFFFFFFFF,
- q->streamcount, q->data, q->streamsizes, &fontcount, &fonts);
-
- if ((n = ci_createfonts_out(p, s, fontcount, fonts)) == 0) ret = ST_PROTO_BUFF;
+ if (fdcount != 1) {
+ ret = ST_PROTO_ERROR;
+ } else {
+ data = calloc(q->streamcount, sizeof(byte *));
+
+ if (data != NULL) {
+ char *ptr = mmap(NULL, q->totalsize, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, 0);
+
+ if (ptr == MAP_FAILED) {
+ ret = ST_FILEIO;
+ } else {
+ int i;
+ byte *pp = (byte *) ptr;
+
+ for (i=0; i<q->streamcount; i++) {
+ data[i] = pp;
+ pp += q->streamsizes[i];
+ }
+
+ ret = FSCreateFonts(fs, (uint32_t) q->cid & 0xFFFFFFFF,
+ q->streamcount, data, q->streamsizes, &fontcount, &fonts);
+
+ munmap(ptr, q->totalsize);
+ }
+
+ } else {
+ ret = ST_MEMORY;
+ }
+ close(*fd);
+ }
+
+ if ((n = ci_createfonts_out(p, s, fontcount, fonts)) != 0) ret = ST_PROTO_BUFF;
if (fonts) free(fonts);
+ if (data) free(data);
}
return ret;
Index: handler.h
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/handler.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/handler.h 25 May 2004 02:47:24 -0000 1.2
+++ b/handler.h 30 May 2004 23:07:17 -0000 1.3
@@ -57,7 +57,9 @@
intptr_t cdata,
STFSProtoOpcode *opcode, /* on exit contains reply */
byte *p, /* protocol shared memory */
- uint32_t s); /* size of the protocol shared memory */
+ uint32_t s, /* size of the protocol shared memory */
+ int *fd,
+ int *nfd);
Index: saverestore.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/saverestore.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/saverestore.c 25 May 2004 02:47:24 -0000 1.4
+++ b/saverestore.c 30 May 2004 23:07:17 -0000 1.5
@@ -2761,8 +2761,11 @@
cur = header;
- *fontarray = calloc(*fontcount, sizeof(FSFontRecord *));
- *bfontarray = calloc(*bfontcount, sizeof(FSFontRecord *));
+ DebugStr(3, "%s: restored: fontcount: %d, fontslots: %d.", __func__, *fontcount, *fontslots);
+ DebugStr(3, "%s: restored: bfontcount: %d, bfontslots: %d.", __func__, *fontcount, *fontslots);
+
+ *fontarray = calloc(*fontslots, sizeof(FSFontRecord *));
+ *bfontarray = calloc(*bfontslots, sizeof(FSFontRecord *));
if (*fontarray == NULL || *bfontarray == NULL) {
ret = ST_MEMORY;
Index: stfs-door.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/stfs-door.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- a/stfs-door.c 27 May 2004 04:26:52 -0000 1.7
+++ b/stfs-door.c 30 May 2004 23:07:17 -0000 1.8
@@ -160,16 +160,19 @@
ret = ST_INTERNAL_ERROR;
goto cleanup;
}
+
+#if 0
- if ((stat(SHMEM_DIR, &st) == -1) &&
- (CreateDir(SHMEM_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ||
- chown(SHMEM_DIR, STFS_UID, STFS_GID))) {
- ErrorStr("Error creating STSF shared memory directory: %s.", SHMEM_DIR);
+ if ((stat(STSF_TEMPDIR, &st) == -1) &&
+ (CreateDir(STSF_TEMPDIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ||
+ chown(STSF_TEMPDIR, STFS_UID, STFS_GID))) {
+ ErrorStr("Error creating STSF shared memory directory: %s.", STSF_TEMPDIR);
ret = ST_FILEIO;
goto cleanup;
}
+#endif
- strlcpy(filename, SHMEM_DIR, PATH_MAX);
+ strlcpy(filename, STSF_TEMPDIR, PATH_MAX);
strlcat(filename, "/", PATH_MAX);
strlcat(filename, SHMEM_PATTERN, PATH_MAX);
@@ -361,11 +364,28 @@
ro.ret = ST_PROTO_ERROR;
} else {
SharedMemoryHeader *hdr = (SharedMemoryHeader *) fsc->shmaddr;
+ int filedes = 0;
+ int nfiledes = 0;
+
+ if (ndesc == 1) {
+ filedes = dp->d_data.d_desc.d_descriptor;
+ nfiledes = 1;
+ }
ro.x.p.opcode = ri->x.p.opcode;
ro.ret = FSHandleRequest(fs, ckey, (intptr_t) fsc, &ro.x.p.opcode,
- (byte *) fsc->shmaddr + hdr->proto_offset, hdr->proto_size);
+ (byte *) fsc->shmaddr + hdr->proto_offset, hdr->proto_size, &filedes, &nfiledes);
+
+ if (nfiledes == 1) {
+ ret_ndesc = 1;
+ desc.d_attributes = DOOR_DESCRIPTOR | DOOR_RELEASE;
+ desc.d_data.d_desc.d_descriptor = filedes;
+ pdesc = &desc;
+ DebugStr(1, "%s: returning filedes: %d.", __func__, filedes);
+
+ }
+
if (ro.x.p.opcode == FS_CLOSE_OUT) {
DebugStr(1, "%s: deallocating the client after receiving FS_CLOSE, nthr: %d", __func__, fsc->nthr);
// close(fsc->fd); /* Close the client's door */
@@ -545,32 +565,47 @@
struct dirent *dp;
struct stat st;
- if (!dirp) {
- if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
- unlink(path);
+ if (stat(path, &st) != 0 || st.st_uid != uid || st.st_gid != gid || !S_ISDIR(st.st_mode) || dirp == NULL) {
+ DelTree(path);
+ } else {
+
+ while(1) {
+ char *cp;
+
+ if ((dp = readdir(dirp)) == NULL) break;
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue;
+ cp = malloc(strlen(path) + strlen(dp->d_name) + 2);
+ strcpy(cp, path); strcat(cp, "/"); strcat(cp, dp->d_name);
+ if (stat(cp, &st) == 0) {
+ if (st.st_uid != uid || st.st_gid != gid) {
+ DelTree(cp);
+ } else if (S_ISDIR(st.st_mode)) {
+ CheckTempDir(cp, uid, gid);
+ }
+ }
+ free(cp);
}
- return;
}
- while(1) {
- char *cp;
+ if (dirp != NULL) {
+ closedir(dirp);
+ }
+}
+static STStatus CreateSTSFDir(char *path, uid_t uid, gid_t gid)
+{
+ struct stat st;
+ STStatus t = ST_OK;
- if ((dp = readdir(dirp)) == NULL) break;
- if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue;
- cp = malloc(strlen(path) + strlen(dp->d_name) + 2);
- strcpy(cp, path); strcat(cp, "/"); strcat(cp, dp->d_name);
- if (stat(cp, &st) == 0) {
- if (st.st_uid != uid || st.st_gid != gid) {
- DelTree(cp);
- } else if (S_ISDIR(st.st_mode)) {
- CheckTempDir(cp, uid, gid);
- }
+ if (stat(path, &st) != 0) {
+ if (CreateDir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) || chown(path, uid, gid)) {
+ t = ST_FILEIO;
+ ErrorStr("Error creating STSF temporary directory: %s.", path);
}
- free(cp);
}
- closedir(dirp);
- rmdir(path);
+ return t;
}
+
+
static STStatus system_init (FontServer *fs) {
@@ -655,15 +690,13 @@
}
/* Check /var/tmp/stsf presense and permissions before switching UID */
- DelTree(SHMEM_DIR);
- DelTree(TEMP_FONT_DIR);
CheckTempDir(STSF_TEMPDIR, STFS_UID, STFS_GID);
-
+ CreateSTSFDir(STSF_TEMPDIR, STFS_UID, STFS_GID);
+ CreateSTSFDir(STSF_TEMPFONTDIR, STFS_UID, STFS_GID);
setegid(STFS_GID); /* daemon */
seteuid(STFS_UID); /* daemon */
-
t = FontServerNew(fs, fontpath, scalerpath);
DebugStr(9, "FontServerNew() => %s (%d)", ErrorCodeName(t), t);
Index: stpfc.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/stpfc.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/stpfc.c 12 Apr 2004 05:57:26 -0000 1.2
+++ b/stpfc.c 30 May 2004 23:07:17 -0000 1.3
@@ -88,7 +88,6 @@
int sflag = 0;
char *outfile = NULL;
char *fontpath = NULL;
- int freestr = 0;
int dl = 0;
char *stdebug;
@@ -129,10 +128,7 @@
}
if (outfile == NULL) {
- if ((outfile = JoinPathname(PFC_DIR, PFC_FILE)) == NULL) {
- return 3;
- }
- freestr = 1;
+ outfile = PFC_FILENAME;
}
printf("fontpath: %s\n", fontpath);
@@ -156,10 +152,6 @@
FontServerDispose(fs);
- if (freestr) {
- free(outfile);
- }
-
return 0;
}
- Previous message: [stsf-commit] stsf/STClientLibrary/src STSysCtl.c, 1.1.1.1,
1.2 libtest.c, 1.3, 1.4 serverconnection.c, 1.8,
1.9 sysctlvars.h, 1.1.1.1, 1.2
- Next message: [stsf-commit]
stsf/interface stprivate.h, 1.1, 1.2 sttypes.tmpl, 1.7, 1.8
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the stsf-commit
mailing list