[stsf-commit] stsf/STFontServer/loader stfsloader.c,1.1.1.1,1.2

Alexander Gelfenbain stsf-commit at pdx.freedesktop.org
Mon May 24 19:47:27 PDT 2004


Committed by: adg


Index: stfsloader.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/loader/stfsloader.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/stfsloader.c	26 Mar 2004 19:19:56 -0000	1.1.1.1
+++ b/stfsloader.c	25 May 2004 02:47:24 -0000	1.2
@@ -53,10 +53,11 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <signal.h>
 
+#include "fscomm.h"
 #include "sttypes.h"
 #include "stprivate.h"
-#include "stfsproto.h"
 #include "stfsloader.h"
 #include "stsfutil.h"
 #include "path.h"
@@ -65,84 +66,97 @@
 //#define STFONTSERVERD_PATH "../src/stfontserverd"
 #define STFONTSERVERD_NAME "stfontserverd"
 
-/* There should be HLENGTH bytes allocated before the buffer 
- */
-int fsexchange(int doorfd, byte *buf, int bufsize, int sopcode, int snbytes, int *ropcode, int *rnbytes)
+static int fsexchange(int doorfd, char **buf, size_t *bufsize, door_desc_t **desc_ptr, uint_t *desc_num)
 {
     door_arg_t arg;
+    int ret;
 
-    if (snbytes > bufsize) return 1;
-
-    SET_OPCODE(buf - HLENGTH, sopcode);
-    SET_PACKLEN(buf - HLENGTH, B2C32U(snbytes));
-
-    arg.data_ptr = (char *) buf - HLENGTH;
-    arg.data_size = snbytes + HLENGTH;
-    arg.desc_ptr = NULL;
-    arg.desc_num = 0;
-    arg.rbuf = (char *) buf - HLENGTH;
-    arg.rsize = bufsize + HLENGTH;
+    arg.data_ptr = *buf;
+    arg.data_size = *bufsize;
+    arg.desc_ptr = desc_ptr == NULL ? NULL : *desc_ptr;
+    arg.desc_num = desc_num == NULL ? 0 : *desc_num;
+    arg.rbuf = *buf;
+    arg.rsize = *bufsize;
 
-    door_call(doorfd, &arg);
+    sighold(SIGINT); sighold(SIGPIPE); sighold(SIGALRM); sighold(SIGPOLL);
+    ret = door_call(doorfd, &arg);
+    sigrelse(SIGINT); sigrelse(SIGPIPE); sigrelse(SIGALRM); sigrelse(SIGPOLL);
 
-    *rnbytes = C32U2B(GET_PACKLEN(arg.rbuf));
-    *ropcode = GET_OPCODE(arg.rbuf) & OPCODEMASK;
+    if (ret == -1) {
+        ErrorStr("%s: door_call error.", __func__);
+        perror("door_call");
+        return 1;
+    }
 
-    if (arg.rbuf != (char *) buf - HLENGTH) {
-       munmap((char *) buf - HLENGTH, bufsize + HLENGTH);
-       buf = (byte *) arg.rbuf + HLENGTH;
-       bufsize = arg.rsize - HLENGTH;
+    if (arg.rbuf != *buf) {
+       DebugStr(1, "door_call allocated rbuf");
+       munmap(*buf, *bufsize);
+       *buf = arg.rbuf;
+       *bufsize = arg.rsize;
     }
-    
-    printf("fsexhange2: sopcode: %s, snbytes: %d, ropcode: %s, rnbytes: %d", 
-           ProtoOpcodeName(sopcode), snbytes, ProtoOpcodeName(*ropcode), *rnbytes);
 
-    if (DebugLevel > 2) {
-        HexDump(buf + HLENGTH, *rnbytes);
+    if (desc_ptr != NULL && desc_num != NULL) {
+        *desc_ptr = arg.desc_ptr;
+        *desc_num = arg.desc_num;
     }
 
     return 0;
 }
 
+
 #define PBUFSIZE 1024
 
 int checkserver(void)
 {
     int fd = open(STFS_DOOR, O_RDWR);
-    byte *pbuf = NULL;  /* buffer for protocol */
-    int pbufsize = PBUFSIZE;
+    char *pbuf = NULL;  /* buffer for protocol */
+    size_t pbufsize = PBUFSIZE;
     int opcode, nbytes;
     int ret;
+    DoorHandshakeIn *hin;
+    DoorHandshakeOut *hout;
 
     if (fd == -1) {
         ret = 1;
         goto cleanup;
     }
 
-    if ((pbuf = (byte *) mmap(0, pbufsize + HLENGTH, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == MAP_FAILED) {
+    if ((pbuf = mmap(0, pbufsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == MAP_FAILED) {
         perror("mmap");
         ret = 1;
         goto cleanup;
     }
-    pbuf += HLENGTH;
 
-    fsexchange(fd, pbuf, pbufsize, STFS_VERSION, 0, &opcode, &nbytes);
+    hin = (DoorHandshakeIn *) pbuf;
 
-    
-    if (opcode != STFS_VERSION_R) {
+
+    hin->opcode = HANDSHAKE_VERIFY;
+    hin->cid = -1;               /* special client ID for HANDSHAKE_VERIFY */
+    hin->major = STSF_VERSION_MAJOR;
+    hin->minor = STSF_VERSION_MINOR;
+    hin->update = STSF_VERSION_UPDATE;
+    hin->proto = STFS_PROTOCOL_VERSION;
+
+    if (fsexchange(fd, &pbuf, &pbufsize, NULL, NULL)) {
+        ErrorStr("%s: fsexchange failed.", __func__);
+        ret = ST_PROTO_ERROR;
+        goto cleanup; 
+    }
+
+    hout = (DoorHandshakeOut *) pbuf;
+
+    if (hout->opcode != HANDSHAKE_VERIFY_REPLY || hout->ret != ST_OK) {
         unlink(STFS_DOOR);
         ret = 1;
         goto cleanup;
     }
 
     /* XXX need to check the STFS version number here */
-
     ret = 0;
 
-
 cleanup:
     if (pbuf != NULL) {
-        munmap((char *) pbuf - HLENGTH, pbufsize + HLENGTH);
+        munmap((char *) pbuf, pbufsize);
     }
 
     if (fd != -1) {




More information about the stsf-commit mailing list