ref: 0b55bc315e748a6f3b855a6611eab059729a748f
parent: abe048fea88c88c401d24783731d62fc5a193565
author: 9ferno <gophone2015@gmail.com>
date: Fri Oct 14 09:20:20 EDT 2022
remove service local variables
--- a/9p.c
+++ b/9p.c
@@ -1092,7 +1092,7 @@
08:50 < cinap_lenrek> works.
*/
void
-start9p(char *service, char **nets, int stdio)
+start9p(char **nets, int stdio)
{
int sfd;
--- a/all.h
+++ b/all.h
@@ -82,10 +82,10 @@
void freeblockbuf(Iobuf *buf);
void freeblocks(u64 blkno, u16 len, u16 tag, u64 qpath);
void fsok(int ok);
-void init(int doream, char *service);
+void init(int doream);
u64 newqpath();
u64 nperiblock(u16 tag);
-void ream(u64 size, char *service);
+void ream(u64 size);
void rel2abs(Dentry *d, u64 reli, Spanid *s);
void rmfile(u64 qpath, u64 dblkno);
void rmdirectory(u64 qpath, u64 dblkno);
@@ -92,8 +92,8 @@
void rootream(void);
Dentry *searchdir(u64 dblkno, u64 qpath, u16 uid, char *searchname, u64 searchidx, Iobuf **dbuf, Iobuf **buf);
void shutdown(void);
-void start9p(char *service, char **nets, int stdio);
-void superream(u64 size, u64 nblocks, char *service);
+void start9p(char **nets, int stdio);
+void superream(u64 size, u64 nblocks);
Tlock* tlocked(Iobuf*, Dentry*);
/* dentry routines */
--- a/config.c
+++ b/config.c
@@ -5,7 +5,7 @@
initconfig(u64 dblkno)
{
Iobuf *buf;
- char *tokens[128], cfg[Blocksize];
+ char *tokens[128], cfg[Blocksize], *nl;
s32 n, i;
buf = getbufchk(dblkno, 1, Breadonly, Tdata, Qpconfig);
@@ -59,6 +59,8 @@
panic("mafs: %s initconfig(): invalid size\n", service);
}else if(strcmp(tokens[i], "service") == 0){
strncpy(config.service, tokens[++i], Namelen);
+ if((nl=strchr(config.service, '\n')) != nil)
+ *nl = '\0';
}
}
if(chatty9p > 1)
@@ -98,7 +100,7 @@
"backup config %llud to %llud %llud\n"
"backup super %llud to %llud %llud\n"
"backup root %llud to %llud %llud\n"
- "service %s",
+ "service %s\n",
config.size,
config.nblocks,
config.config.srcbno,
--- a/mafs.c
+++ b/mafs.c
@@ -41,8 +41,8 @@
{
static char *nets[8];
int doream, stdio, netc;
- char buf[Namelen];
- int pid, ctl;
+ char buf[Namelen], *raw;
+ int pid, ctl, n;
progname = "mafs";
procname = "init";
@@ -73,7 +73,10 @@
doream = 1;
/* fall through */
case 'n':
- strncpy(service, EARGF(usage()), Namelen);
+ raw = EARGF(usage());
+ if((n=strlen(raw)) >= Namelen)
+ panic("service name is longer than %d characters\n", Namelen);
+ strncpy(service, raw, n);
break;
case 's': stdio++; break;
case 'a':
@@ -107,14 +110,15 @@
iobufinit();
/*
- * init the file system, ream it if needed, and get the block sizes
+ * init the file system, ream it if needed, and get the block sizes.
+ * service = config.service, if service is nil.
*/
- init(doream, service);
-
+ init(doream);
if(service[0] == '\0')
- start9p(config.service, nets, stdio);
- else
- start9p(service, nets, stdio);
+ strncpy(service, config.service, strlen(config.service));
+
+ start9p(nets, stdio);
+ dprint("after start9p");
/*
we have started another proc to process /srv/service
--- a/sub.c
+++ b/sub.c
@@ -365,7 +365,7 @@
}
void
-superream(u64 size, u64 nblocks, char *service)
+superream(u64 size, u64 nblocks)
{
Iobuf *sbuf;
Superb *s;
@@ -429,7 +429,7 @@
char magic[] = "mafs device\n";
/* TODO open the dev file OEXCL? */
void
-ream(u64 size, char *service)
+ream(u64 size)
{
char buf[Rawblocksize];
int i;
@@ -452,7 +452,7 @@
for(i = 0; i < Nbused; i++)
devwrite(i, buf, 1);
- superream(size, nblocks, service);
+ superream(size, nblocks);
iob = getbuf(Bmagicb, 1, Bmod);
snprint((s8*)iob->io->buf+256, Rawblocksize-256, "%s%d\n%llud\n",
@@ -491,7 +491,7 @@
}
void
-init(int doream, char *service)
+init(int doream)
{
u32 rbufsize, maxspansize;
u64 size;
@@ -504,7 +504,7 @@
panic("null size %s", devfile);
if(doream)
- ream(size, service);
+ ream(size);
else{
initconfig(Bconfig);
loadfrees(Bdfrees);