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 threadmaybackground(void)
69 threadmain(int argc, char* argv[])
74 fmtinstall('D', dirfmt);
75 fmtinstall('F', fcallfmt);
76 fmtinstall('M', dirmodefmt);
80 * Insulate from the invoker's environment.
83 if(rfork(RFNAMEG) < 0)
85 if(rfork(RFREND|RFNOTEG|RFNAMEG) < 0)
87 sysfatal("rfork: %r");
90 open("/dev/null", OREAD);
92 open("/dev/null", OWRITE);
105 cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
113 currfsysname = foptname = p;
114 readCmdPart(p, &cmd, &ncmd);
117 mempcnt = atoi(EARGF(usage()));
118 if(mempcnt <= 0 || mempcnt >= 100)
141 for(i = 0; i < ncmd; i++)
142 if(cliExec(cmd[i]) == 0)
143 fprint(2, "%s: %r\n", cmd[i]);
146 if(tflag && consTTY() == 0)