7 int mempcnt; /* for 9fsys.c */
9 char* foptname = "/none/such";
14 fprint(2, "usage: %s [-Dt] [-c cmd] [-f partition] [-m %%]\n", argv0);
15 threadexitsall("usage");
19 readCmdPart(char *file, char ***pcmd, int *pncmd)
21 char buf[1024+1], *f[1024];
31 if((fd = open(file, OREAD)) < 0)
32 sysfatal("open %s: %r", file);
33 if(seek(fd, 127*1024, 0) != 127*1024)
34 sysfatal("seek %s 127kB: %r", file);
35 n = readn(fd, buf, sizeof buf-1);
37 sysfatal("short read of %s at 127kB", file);
39 sysfatal("read %s: %r", file);
41 if(memcmp(buf, "fossil config\n", 6+1+6+1) != 0)
42 sysfatal("bad config magic in %s", file);
43 nf = getfields(buf+6+1+6+1, f, nelem(f), 1, "\n");
47 cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
48 /* expand argument '*' to mean current file */
49 if((p = strchr(f[i], '*')) && (p==f[i]||isspace(p[-1])) && (p[1]==0||isspace(p[1]))){
50 memmove(tbuf, f[i], p-f[i]);
51 strecpy(tbuf+(p-f[i]), tbuf+sizeof tbuf, file);
52 strecpy(tbuf+strlen(tbuf), tbuf+sizeof tbuf, p+1);
55 cmd[ncmd++] = vtstrdup(f[i]);
63 threadmain(int argc, char* argv[])
68 fmtinstall('D', dirfmt);
69 fmtinstall('F', fcallfmt);
70 fmtinstall('M', dirmodefmt);
74 * Insulate from the invoker's environment.
77 if(rfork(RFNAMEG) < 0)
79 if(rfork(RFREND|RFNOTEG|RFNAMEG) < 0)
81 sysfatal("rfork: %r");
84 open("/dev/null", OREAD);
86 open("/dev/null", OWRITE);
99 cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
107 currfsysname = foptname = p;
108 readCmdPart(p, &cmd, &ncmd);
111 mempcnt = atoi(EARGF(usage()));
112 if(mempcnt <= 0 || mempcnt >= 100)
135 for(i = 0; i < ncmd; i++)
136 if(cliExec(cmd[i]) == 0)
137 fprint(2, "%s: %r\n", cmd[i]);
140 if(tflag && consTTY() == 0)