summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-12-07 15:15:02 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-12-07 15:15:02 +0100
commit1a900513fb137143e1c1f8177975952bc404f5a9 (patch)
treefd305c969cb2dbea6ead1cd713df0b885beb8f9a
parent5e59c57bb110403f83a41ad88415e108c6cb1f6a (diff)
downloadplan9front-1a900513fb137143e1c1f8177975952bc404f5a9.tar.xz
libndb: open internal file-descriptors with OCEXEC flag
-rw-r--r--sys/src/libndb/csgetval.c4
-rw-r--r--sys/src/libndb/csipinfo.c16
-rw-r--r--sys/src/libndb/dnsquery.c3
-rw-r--r--sys/src/libndb/ndbhash.c20
-rw-r--r--sys/src/libndb/ndbopen.c2
5 files changed, 22 insertions, 23 deletions
diff --git a/sys/src/libndb/csgetval.c b/sys/src/libndb/csgetval.c
index a1f6a9052..b6e28ff6e 100644
--- a/sys/src/libndb/csgetval.c
+++ b/sys/src/libndb/csgetval.c
@@ -25,10 +25,10 @@ csgetvalue(char *netroot, char *attr, char *val, char *rattr, Ndbtuple **pp)
snprint(line, sizeof(line), "%s/cs", netroot);
else
strcpy(line, "/net/cs");
- fd = open(line, ORDWR);
+ fd = open(line, ORDWR|OCEXEC);
if(fd < 0)
return nil;
- seek(fd, 0, 0);
+
snprint(line, sizeof(line), "!%s=%s %s=*", attr, val, rattr);
if(write(fd, line, strlen(line)) < 0){
close(fd);
diff --git a/sys/src/libndb/csipinfo.c b/sys/src/libndb/csipinfo.c
index 53c33f328..38a927443 100644
--- a/sys/src/libndb/csipinfo.c
+++ b/sys/src/libndb/csipinfo.c
@@ -23,10 +23,10 @@ csipinfo(char *netroot, char *attr, char *val, char **list, int n)
snprint(line, sizeof(line), "%s/cs", netroot);
else
strcpy(line, "/net/cs");
- fd = open(line, ORDWR);
+ fd = open(line, ORDWR|OCEXEC);
if(fd < 0)
- return 0;
- seek(fd, 0, 0);
+ return nil;
+
e = line + sizeof(line);
p = seprint(line, e, "!ipinfo %s=%s", attr, val);
for(i = 0; i < n; i++){
@@ -37,11 +37,11 @@ csipinfo(char *netroot, char *attr, char *val, char **list, int n)
if(write(fd, line, strlen(line)) < 0){
close(fd);
- return 0;
+ return nil;
}
seek(fd, 0, 0);
- first = last = 0;
+ first = last = nil;
for(;;){
n = read(fd, line, sizeof(line)-2);
if(n <= 0)
@@ -50,15 +50,15 @@ csipinfo(char *netroot, char *attr, char *val, char **list, int n)
line[n+1] = 0;
t = _ndbparseline(line);
- if(t == 0)
+ if(t == nil)
continue;
- if(first)
+ if(first != nil)
last->entry = t;
else
first = t;
last = t;
- while(last->entry)
+ while(last->entry != nil)
last = last->entry;
}
close(fd);
diff --git a/sys/src/libndb/dnsquery.c b/sys/src/libndb/dnsquery.c
index 1bf1ff8b3..da2312e4d 100644
--- a/sys/src/libndb/dnsquery.c
+++ b/sys/src/libndb/dnsquery.c
@@ -29,7 +29,7 @@ dnsquery(char *net, char *val, char *type)
net = "/net";
snprint(buf, sizeof(buf), "%s/dns", net);
- if((fd = open(buf, ORDWR)) < 0)
+ if((fd = open(buf, ORDWR|OCEXEC)) < 0)
return nil;
/* zero out the error string */
@@ -84,7 +84,6 @@ doquery(int fd, char *dn, char *type)
int n;
Ndbtuple *t, *first, *last;
- seek(fd, 0, 0);
snprint(buf, sizeof(buf), "!%s %s", dn, type);
if(write(fd, buf, strlen(buf)) < 0)
return nil;
diff --git a/sys/src/libndb/ndbhash.c b/sys/src/libndb/ndbhash.c
index ff481231f..5987c3ea3 100644
--- a/sys/src/libndb/ndbhash.c
+++ b/sys/src/libndb/ndbhash.c
@@ -57,42 +57,42 @@ hfopen(Ndb *db, char *attr)
/* try opening the data base if it's closed */
if(db->mtime==0 && ndbreopen(db) < 0)
- return 0;
+ return nil;
/* if the database has changed, throw out hash files and reopen db */
if((d = dirfstat(Bfildes(&db->b))) == nil || db->qid.path != d->qid.path
|| db->qid.vers != d->qid.vers){
if(ndbreopen(db) < 0){
free(d);
- return 0;
+ return nil;
}
}
free(d);
if(db->nohash)
- return 0;
+ return nil;
/* see if a hash file exists for this attribute */
- for(hf = db->hf; hf; hf= hf->next){
+ for(hf = db->hf; hf != nil; hf= hf->next){
if(strcmp(hf->attr, attr) == 0)
return hf;
}
/* create a new one */
hf = (Ndbhf*)malloc(sizeof(Ndbhf));
- if(hf == 0)
- return 0;
+ if(hf == nil)
+ return nil;
memset(hf, 0, sizeof(Ndbhf));
/* compare it to the database file */
strncpy(hf->attr, attr, sizeof(hf->attr)-1);
sprint(buf, "%s.%s", db->file, hf->attr);
- hf->fd = open(buf, OREAD);
+ hf->fd = open(buf, OREAD|OCEXEC);
if(hf->fd >= 0){
hf->len = 0;
hf->off = 0;
p = hfread(hf, 0, 2*NDBULLEN);
- if(p){
+ if(p != nil){
hf->dbmtime = NDBGETUL(p);
hf->hlen = NDBGETUL(p+NDBULLEN);
if(hf->dbmtime == db->mtime){
@@ -105,7 +105,7 @@ hfopen(Ndb *db, char *attr)
}
free(hf);
- return 0;
+ return nil;
}
/*
@@ -162,7 +162,7 @@ match(Ndbtuple *t, char *attr, char *val)
if(strcmp(attr, nt->attr) == 0
&& strcmp(val, nt->val) == 0)
return nt;
- return 0;
+ return nil;
}
/*
diff --git a/sys/src/libndb/ndbopen.c b/sys/src/libndb/ndbopen.c
index 36dd9a864..cae6e7aa0 100644
--- a/sys/src/libndb/ndbopen.c
+++ b/sys/src/libndb/ndbopen.c
@@ -99,7 +99,7 @@ ndbreopen(Ndb *db)
}
/* try the open again */
- fd = open(db->file, OREAD);
+ fd = open(db->file, OREAD|OCEXEC);
if(fd < 0)
return -1;
d = dirfstat(fd);