ref: 3b0a41f6a9e80a255b2c7e7652940daa06150ebe
parent: ea597253dfff146087a67c5a4661d8eae94239b8
author: cinap_lenrek <cinap_lenrek@flatbox.9hal>
date: Fri Mar 9 04:11:12 EST 2012
plumber: use 16K stack, make libplumb thread safe
--- a/sys/src/cmd/plumb/fsys.c
+++ b/sys/src/cmd/plumb/fsys.c
@@ -10,7 +10,7 @@
enum
{- Stack = 8*1024
+ Stack = 16*1024
};
typedef struct Dirtab Dirtab;
--- a/sys/src/libplumb/mesg.c
+++ b/sys/src/libplumb/mesg.c
@@ -2,8 +2,6 @@
#include <libc.h>
#include "plumb.h"
-static char attrbuf[4096];
-
int
plumbopen(char *name, int omode)
{@@ -70,20 +68,20 @@
/* quote attribute value, if necessary */
static char*
-quote(char *s)
+quote(char *s, char *buf, char *bufe)
{char *t;
int c;
if(s == nil){- attrbuf[0] = '\0';
- return attrbuf;
+ buf[0] = '\0';
+ return buf;
}
if(strpbrk(s, " '=\t") == nil)
return s;
- t = attrbuf;
+ t = buf;
*t++ = '\'';
- while(t < attrbuf+sizeof attrbuf-2){+ while(t < bufe-2){c = *s++;
if(c == '\0')
break;
@@ -93,7 +91,7 @@
}
*t++ = '\'';
*t = '\0';
- return attrbuf;
+ return buf;
}
char*
@@ -101,13 +99,16 @@
{int n;
Plumbattr *a;
- char *s, *t;
+ char *s, *t, *buf, *bufe;
if(attr == nil)
return nil;
+ if((buf = malloc(4096)) == nil)
+ return nil;
+ bufe = buf + 4096;
n = 0;
for(a=attr; a!=nil; a=a->next)
- n += Strlen(a->name) + 1 + Strlen(quote(a->value)) + 1;
+ n += Strlen(a->name) + 1 + Strlen(quote(a->value, buf, bufe)) + 1;
s = malloc(n);
if(s == nil)
return nil;
@@ -118,11 +119,13 @@
*t++ = ' ';
strcpy(t, a->name);
strcat(t, "=");
- strcat(t, quote(a->value));
+ strcat(t, quote(a->value, buf, bufe));
t += strlen(t);
}
if(t > s+n)
abort();
+ free(buf);
+
return s;
}
@@ -236,9 +239,12 @@
plumbunpackattr(char *p)
{Plumbattr *attr, *prev, *a;
- char *q, *v;
+ char *q, *v, *buf, *bufe;
int c, quoting;
+ if((buf = malloc(4096)) == nil)
+ return nil;
+ bufe = buf + 4096;
attr = prev = nil;
while(*p!='\0' && *p!='\n'){while(*p==' ' || *p=='\t')
@@ -262,10 +268,10 @@
a->name[q-p] = '\0';
/* process quotes in value */
q++; /* skip '=' */
- v = attrbuf;
+ v = buf;
quoting = 0;
while(*q!='\0' && *q!='\n'){- if(v >= attrbuf+sizeof attrbuf)
+ if(v >= bufe)
break;
c = *q++;
if(quoting){@@ -287,14 +293,14 @@
}
*v++ = c;
}
- a->value = malloc(v-attrbuf+1);
+ a->value = malloc(v-buf+1);
if(a->value == nil){free(a->name);
free(a);
break;
}
- memmove(a->value, attrbuf, v-attrbuf);
- a->value[v-attrbuf] = '\0';
+ memmove(a->value, buf, v-buf);
+ a->value[v-buf] = '\0';
a->next = nil;
if(prev == nil)
attr = a;
@@ -303,6 +309,8 @@
prev = a;
p = q;
}
+ free(buf);
+
return attr;
}
--
⑨