Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rts: various speedups #58

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ haswaitp.h
installer
iopause.h
load
makefifo
makelib
matchtest
multilog
Expand Down
12 changes: 6 additions & 6 deletions envdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ int main(int argc,const char *const *argv)
if (sa.len) {
sa.len = byte_chr(sa.s,sa.len,'\n');
while (sa.len) {
if (sa.s[sa.len - 1] != ' ')
if (sa.s[sa.len - 1] != '\t')
break;
--sa.len;
if (sa.s[sa.len - 1] != ' ')
if (sa.s[sa.len - 1] != '\t')
break;
--sa.len;
}
for (i = 0;i < sa.len;++i)
if (!sa.s[i])
sa.s[i] = '\n';
if (!sa.s[i])
sa.s[i] = '\n';
if (!stralloc_0(&sa)) nomem();
if (!pathexec_env(saname.s,sa.s)) nomem();
}
Expand Down
42 changes: 21 additions & 21 deletions envini.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ static void parse(void)
++start;
if (end > start) {
if (sa.s[start] == '[' && sa.s[end-1] == ']') {
if (!stralloc_copyb(&section,sa.s+start+1,end-start-2)) nomem();
if (!stralloc_append(&section,'_')) nomem();
if (!stralloc_copyb(&section,sa.s+start+1,end-start-2)) nomem();
if (!stralloc_append(&section,'_')) nomem();
}
else if (sa.s[start] == ';')
;
;
else {
i = start;
while (i < end && sa.s[i] != '=' && !is_space(sa.s[i]))
++i;
if (!stralloc_copys(&name,prefix)) nomem();
if (!stralloc_cat(&name,&section)) nomem();
if (!stralloc_catb(&name,sa.s+start,i-start)) nomem();
if (!stralloc_0(&name)) nomem();
while (i < end && is_space(sa.s[i]))
++i;
if (i >= end || sa.s[i++] != '=')
continue; /* Ignore misformatted lines */
while (i < end && is_space(sa.s[i]))
++i;
if (!stralloc_copyb(&value,sa.s+i,end-i)) nomem();
if (!stralloc_0(&value)) nomem();
if (!pathexec_env(name.s,value.s)) nomem();
i = start;
while (i < end && sa.s[i] != '=' && !is_space(sa.s[i]))
++i;
if (!stralloc_copys(&name,prefix)) nomem();
if (!stralloc_cat(&name,&section)) nomem();
if (!stralloc_catb(&name,sa.s+start,i-start)) nomem();
if (!stralloc_0(&name)) nomem();
while (i < end && is_space(sa.s[i]))
++i;
if (i >= end || sa.s[i++] != '=')
continue; /* Ignore misformatted lines */
while (i < end && is_space(sa.s[i]))
++i;
if (!stralloc_copyb(&value,sa.s+i,end-i)) nomem();
if (!stralloc_0(&value)) nomem();
if (!pathexec_env(name.s,value.s)) nomem();
}
}
}
Expand All @@ -81,8 +81,8 @@ int main(int argc,const char *const *argv)

while ((opt = getopt(argc,argv,"p:")) != opteof)
switch (opt) {
case 'p': prefix = optarg; break;
default: die_usage();
case 'p': prefix = optarg; break;
default: die_usage();
}
argv += optind;

Expand Down
24 changes: 12 additions & 12 deletions installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,36 +94,36 @@ void doit(stralloc *line)
case 'd':
if (mkdir(target.s,0700) == -1)
if (errno != error_exist)
strerr_die3sys(111,FATAL,"unable to mkdir ",target.s);
strerr_die3sys(111,FATAL,"unable to mkdir ",target.s);
break;

case 'c':
fdin = open_read(name);
if (fdin == -1) {
if (opt)
return;
else
strerr_die3sys(111,FATAL,"unable to read ",name);
if (opt)
return;
else
strerr_die3sys(111,FATAL,"unable to read ",name);
}
buffer_init(&bufin,buffer_unixread,fdin,inbuf,sizeof(inbuf));

fdout = open_trunc(target.s);
if (fdout == -1)
strerr_die3sys(111,FATAL,"unable to write ",target.s);
strerr_die3sys(111,FATAL,"unable to write ",target.s);
buffer_init(&bufout,buffer_unixwrite,fdout,outbuf,sizeof(outbuf));

switch(buffer_copy(&bufout,&bufin)) {
case -2:
strerr_die3sys(111,FATAL,"unable to read ",name);
case -3:
strerr_die3sys(111,FATAL,"unable to write ",target.s);
case -2:
strerr_die3sys(111,FATAL,"unable to read ",name);
case -3:
strerr_die3sys(111,FATAL,"unable to write ",target.s);
}

close(fdin);
if (buffer_flush(&bufout) == -1)
strerr_die3sys(111,FATAL,"unable to write ",target.s);
strerr_die3sys(111,FATAL,"unable to write ",target.s);
if (fsync(fdout) == -1)
strerr_die3sys(111,FATAL,"unable to write ",target.s);
strerr_die3sys(111,FATAL,"unable to write ",target.s);
close(fdout);
break;

Expand Down
35 changes: 35 additions & 0 deletions makefifo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "alloc.h"
#include "fifo.h"
#include "stralloc.h"
#include "strerr.h"

#define FATAL "makefifo: fatal: "
#define WARNING "makefifo: warning: "

static void die_usage(void)
{
strerr_die1x(100,"makefifo: usage: makefifo fifo1 [fifo2 ...]");
}

static void die_nomem(void)
{
strerr_die2sys(100,FATAL,"out of memory");
}

int main(int argc, char **argv)
{
stralloc fn = {0,0,0};
int i;

if (argc < 2) die_usage();

for (i = 1;i < argc; ++i) {
if (!stralloc_copys(&fn,argv[i])) die_nomem();
if (!stralloc_0(&fn)) die_nomem();
if (fifo_make(fn.s,0600))
strerr_warn3sys(WARNING,"can't make fifo ",fn.s);
}

alloc_free(fn.s);
return 0;
}
2 changes: 2 additions & 0 deletions makefifo=x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unix.a
byte.a
34 changes: 17 additions & 17 deletions multilog.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ int filesfit(struct cyclog *d)
if (x->d_name[0] == '@')
if (str_len(x->d_name) >= 25)
if (str_start(x->d_name,fn.s)) {
unlink(x->d_name);
break;
unlink(x->d_name);
break;
}
}
if (errno) { closedir(dir); return -1; }
Expand All @@ -161,7 +161,7 @@ void finish(struct cyclog *d,const char *file,const char *code)
fnlen = fmt_tai64nstamp(fn.s);
fn.s[fnlen++] = '.';
do {
fn.s[fnlen++] = *code;
fn.s[fnlen++] = *code;
} while (*code++ != 0);

if (link(file,fn.s) == 0) break;
Expand Down Expand Up @@ -419,7 +419,7 @@ void c_init(char **script)
else if (script[i][0] == 'w') {
code_finished = script[i] + 1;
if (!stralloc_ready(&fn,str_len(code_finished)+TIMESTAMP+1))
strerr_die2sys(111,FATAL,"unable to allocate memory");
strerr_die2sys(111,FATAL,"unable to allocate memory");
}
else if ((script[i][0] == '.') || (script[i][0] == '/')) {
d->num = num;
Expand Down Expand Up @@ -469,7 +469,7 @@ int flushread(int fd,char *buf,int len)
if (flagforcerotate) {
for (j = 0;j < cnum;++j)
if (c[j].bytes > 0)
fullcurrent(&c[j]);
fullcurrent(&c[j]);
flagforcerotate = 0;
}

Expand Down Expand Up @@ -524,8 +524,8 @@ void doit(char **script)
return;
if (flagtimestamp) {
linelen = (flagtimestamp == 't')
? fmt_tai64nstamp(line)
: fmt_accustamp(line);
? fmt_tai64nstamp(line)
: fmt_accustamp(line);
line[linelen++] = ' ';
}
if (buffer_gets(&ssin,line+linelen,MAXLINE-linelen,'\n',&linelen) < 0)
Expand All @@ -538,11 +538,11 @@ void doit(char **script)
for (i = 0;(action = script[i]) != 0;++i)
switch(*action) {
case 'F':
match = match_fnmatch;
break;
match = match_fnmatch;
break;
case 'S':
match = match_simple;
break;
match = match_simple;
break;
case '+':
if (!flagselected)
if (match(action + 1,line,linelen))
Expand Down Expand Up @@ -590,19 +590,19 @@ void doit(char **script)
while (linelen == MAXLINE) {
linelen = 0;
if (buffer_gets(&ssin,line,MAXLINE,'\n',&linelen) < 0) {
flageof = 1;
break;
flageof = 1;
break;
}
if (linelen == 0)
break;
break;
for (j = 0;j < cnum;++j)
if (c[j].flagselected)
buffer_put(&c[j].ss,line,linelen);
if (c[j].flagselected)
buffer_put(&c[j].ss,line,linelen);
}

for (j = 0;j < cnum;++j)
if (c[j].flagselected) {
ch = '\n';
ch = '\n';
buffer_PUTC(&c[j].ss,ch);
}

Expand Down
14 changes: 7 additions & 7 deletions pathexec_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ void pathexec(const char *const *argv)
if (!plus.s[i]) {
split = str_chr(plus.s + j,'=');
for (t = 0;t < elen;++t)
if (byte_equal(plus.s + j,split,e[t]))
if (e[t][split] == '=') {
--elen;
e[t] = e[elen];
break;
}
if (byte_equal(plus.s + j,split,e[t]))
if (e[t][split] == '=') {
--elen;
e[t] = e[elen];
break;
}
if (plus.s[j + split])
e[elen++] = plus.s + j;
e[elen++] = plus.s + j;
j = i + 1;
}
e[elen] = 0;
Expand Down
7 changes: 4 additions & 3 deletions programs.do
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependon envdir envini envuidgid fghack installer matchtest multilog pgrphack \
readproctitle setlock setuidgid setuser sleeper softlimit supervise svc \
svok svscan svscanboot svstat svup tai64n tai64nlocal
dependon envdir envini envuidgid fghack installer makefifo matchtest \
multilog pgrphack readproctitle setlock setuidgid setuser \
sleeper softlimit supervise svc svok svscan svscanboot svstat \
svup tai64n tai64nlocal
14 changes: 7 additions & 7 deletions readproctitle.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ int main(int argc,char **argv)
for (;;)
switch(read(0,&ch,1)) {
case 1:
if (ch) {
for (i = 4;i < len;++i) buf[i - 1] = buf[i];
buf[len - 1] = ch;
}
break;
if (ch) {
for (i = 4;i < len;++i) buf[i - 1] = buf[i];
buf[len - 1] = ch;
}
break;
case 0:
_exit(0);
_exit(0);
case -1:
if (errno != error_intr) _exit(111);
if (errno != error_intr) _exit(111);
}
}
35 changes: 35 additions & 0 deletions rts.tests/10-makefifo.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--- makefifo works
makefifo: warning: can't make fifo fifo0: file already exists
makefifo: warning: can't make fifo fifo1: file already exists
makefifo: warning: can't make fifo fifo2: file already exists
makefifo: warning: can't make fifo fifo3: file already exists
makefifo: warning: can't make fifo fifo4: file already exists
makefifo: warning: can't make fifo fifo5: file already exists
makefifo: warning: can't make fifo fifo6: file already exists
makefifo: warning: can't make fifo fifo7: file already exists
makefifo: warning: can't make fifo fifo8: file already exists
makefifo: warning: can't make fifo fifo9: file already exists
makefifo: warning: can't make fifo fifoA: file already exists
makefifo: warning: can't make fifo fifoB: file already exists
makefifo: warning: can't make fifo fifoC: file already exists
makefifo: warning: can't make fifo fifoD: file already exists
makefifo: warning: can't make fifo fifoE: file already exists
makefifo: warning: can't make fifo fifoF: file already exists
makefifo: warning: can't make fifo fifo0: file already exists
makefifo: usage: makefifo fifo1 [fifo2 ...]
ok 0
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok A
ok B
ok C
ok D
ok E
ok F
35 changes: 35 additions & 0 deletions rts.tests/10-makefifo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
echo '--- makefifo works'
rm -rf makefifo
mkdir makefifo
cd makefifo
makefifo fifo0 fifo1 fifo2
makefifo fifo3 fifo4 fifo0
makefifo fifo5 fifo6
makefifo fifo7 fifo1 fifo8
makefifo fifo9 fifo2 fifo3
makefifo fifoA fifo4
makefifo fifo5 fifoB fifoC
makefifo fifo6 fifoD fifo7
makefifo fifo8 fifoE
makefifo fifo9 fifoA fifoF
makefifo fifoB fifoC fifoD
makefifo fifoE fifoF
makefifo fifo0
makefifo
if [ -p fifo0 ]; then echo ok 0; fi
if [ -p fifo1 ]; then echo ok 1; fi
if [ -p fifo2 ]; then echo ok 2; fi
if [ -p fifo3 ]; then echo ok 3; fi
if [ -p fifo4 ]; then echo ok 4; fi
if [ -p fifo5 ]; then echo ok 5; fi
if [ -p fifo6 ]; then echo ok 6; fi
if [ -p fifo7 ]; then echo ok 7; fi
if [ -p fifo8 ]; then echo ok 8; fi
if [ -p fifo9 ]; then echo ok 9; fi
if [ -p fifoA ]; then echo ok A; fi
if [ -p fifoB ]; then echo ok B; fi
if [ -p fifoC ]; then echo ok C; fi
if [ -p fifoD ]; then echo ok D; fi
if [ -p fifoE ]; then echo ok E; fi
if [ -p fifoF ]; then echo ok F; fi
cd $TOP
Loading