From b3a20a96eb2b91a5b0b8a8fb506e20a2fb50ebe8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:10:11 -0500 Subject: libthread: add threadmaybackground Programs that want to background themselves now need to define threadmaybackground returning 1. This avoids a confusing (to people and debuggers) extra parent process for all the threaded programs that will never want to background themselves. --- src/cmd/9pfuse/main.c | 6 ++++++ src/cmd/9pserve.c | 6 ++++++ src/cmd/auth/factotum/main.c | 6 ++++++ src/cmd/auth/ssh-agent.c | 6 ++++++ src/cmd/fossil/fossil.c | 6 ++++++ src/cmd/import.c | 6 ++++++ src/cmd/ndb/dns.c | 6 ++++++ src/cmd/plumb/plumber.c | 6 ++++++ src/cmd/smugfs/main.c | 6 ++++++ src/cmd/upas/fs/fs.c | 6 ++++++ src/cmd/upas/nfs/main.c | 6 ++++++ src/cmd/venti/srv/venti.c | 6 ++++++ 12 files changed, 72 insertions(+) (limited to 'src/cmd') diff --git a/src/cmd/9pfuse/main.c b/src/cmd/9pfuse/main.c index 69d1ad75..4fa330a0 100644 --- a/src/cmd/9pfuse/main.c +++ b/src/cmd/9pfuse/main.c @@ -98,6 +98,12 @@ usage(void) void fusereader(void*); void watchfd(void*); +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/9pserve.c b/src/cmd/9pserve.c index 255bcbb2..e26eef14 100644 --- a/src/cmd/9pserve.c +++ b/src/cmd/9pserve.c @@ -137,6 +137,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + uchar vbuf[128]; extern int _threaddebuglevel; void diff --git a/src/cmd/auth/factotum/main.c b/src/cmd/auth/factotum/main.c index b3ace12c..6dfc2a40 100644 --- a/src/cmd/auth/factotum/main.c +++ b/src/cmd/auth/factotum/main.c @@ -20,6 +20,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/auth/ssh-agent.c b/src/cmd/auth/ssh-agent.c index c3b0c7ef..e944e390 100644 --- a/src/cmd/auth/ssh-agent.c +++ b/src/cmd/auth/ssh-agent.c @@ -90,6 +90,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/fossil/fossil.c b/src/cmd/fossil/fossil.c index 002e8510..c5672c86 100644 --- a/src/cmd/fossil/fossil.c +++ b/src/cmd/fossil/fossil.c @@ -59,6 +59,12 @@ readCmdPart(char *file, char ***pcmd, int *pncmd) *pncmd = ncmd; } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char* argv[]) { diff --git a/src/cmd/import.c b/src/cmd/import.c index 0be2f5b6..7da70966 100644 --- a/src/cmd/import.c +++ b/src/cmd/import.c @@ -51,6 +51,12 @@ fatal(char *fmt, ...) threadexitsall("fatal"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/ndb/dns.c b/src/cmd/ndb/dns.c index cb317052..723989b9 100644 --- a/src/cmd/ndb/dns.c +++ b/src/cmd/ndb/dns.c @@ -121,6 +121,12 @@ checkaddress(void) fprint(2, "warning: announce mismatch %s %s\n", udpaddr, tcpaddr); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/plumb/plumber.c b/src/cmd/plumb/plumber.c index c99282f0..5ead2e93 100644 --- a/src/cmd/plumb/plumber.c +++ b/src/cmd/plumb/plumber.c @@ -26,6 +26,12 @@ makeports(Ruleset *rules[]) addport(rules[i]->port); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/smugfs/main.c b/src/cmd/smugfs/main.c index e1c2745f..31c9a752 100644 --- a/src/cmd/smugfs/main.c +++ b/src/cmd/smugfs/main.c @@ -51,6 +51,12 @@ smuglogin(void) printerrors = 0; } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/upas/fs/fs.c b/src/cmd/upas/fs/fs.c index dc6ff3ba..32968e67 100644 --- a/src/cmd/upas/fs/fs.c +++ b/src/cmd/upas/fs/fs.c @@ -155,6 +155,12 @@ notifyf(void *a, char *s) noted(NDFLT); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/upas/nfs/main.c b/src/cmd/upas/nfs/main.c index c72a4849..68ae141b 100644 --- a/src/cmd/upas/nfs/main.c +++ b/src/cmd/upas/nfs/main.c @@ -26,6 +26,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/venti/srv/venti.c b/src/cmd/venti/srv/venti.c index 1725537a..67fda91e 100644 --- a/src/cmd/venti/srv/venti.c +++ b/src/cmd/venti/srv/venti.c @@ -23,6 +23,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { -- cgit v1.2.3 From 8b9aaf2e3f7f6e2733e52db4dd1dcb46a91e4972 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:18:30 -0500 Subject: devdraw: add /usr/X11R7 for NetBSD Fixes #362. --- src/cmd/devdraw/mkwsysrules.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/cmd') diff --git a/src/cmd/devdraw/mkwsysrules.sh b/src/cmd/devdraw/mkwsysrules.sh index 122e9123..56dff55a 100644 --- a/src/cmd/devdraw/mkwsysrules.sh +++ b/src/cmd/devdraw/mkwsysrules.sh @@ -7,6 +7,8 @@ if [ "x$X11" = "x" ]; then X11=/usr/X11R6 elif [ -d /usr/local/X11R6 ]; then X11=/usr/local/X11R6 + elif [ -d /usr/X11R7 ]; then + X11=/usr/X11R7 elif [ -d /usr/X ]; then X11=/usr/X elif [ -d /usr/openwin ]; then # for Sun -- cgit v1.2.3 From 0a7fe606818a7906cdc57ea14cb57b416be6c1de Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Fri, 20 Mar 2020 18:52:41 +0000 Subject: 9term: use openpty on NetBSD Fixes #376. --- src/cmd/9term/NetBSD.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/cmd') diff --git a/src/cmd/9term/NetBSD.c b/src/cmd/9term/NetBSD.c index eec79c28..18294803 100644 --- a/src/cmd/9term/NetBSD.c +++ b/src/cmd/9term/NetBSD.c @@ -1 +1,17 @@ +#define getpts not_using_this_getpts #include "bsdpty.c" +#undef getpts + +#include + +int +getpts(int fd[], char *slave) +{ + if(openpty(&fd[1], &fd[0], NULL, NULL, NULL) >= 0){ + fchmod(fd[1], 0620); + strcpy(slave, ttyname(fd[0])); + return 0; + } + sysfatal("no ptys: %r"); + return 0; +} -- cgit v1.2.3 From 74577741c856c145811061a438d5a52ea7055f39 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:12:04 -0500 Subject: tcolors: add threadmaybackground --- src/cmd/draw/tcolors.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/cmd') diff --git a/src/cmd/draw/tcolors.c b/src/cmd/draw/tcolors.c index 9aa4de79..05674947 100644 --- a/src/cmd/draw/tcolors.c +++ b/src/cmd/draw/tcolors.c @@ -44,6 +44,12 @@ dither[16] = { extern int chattydrawclient; +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { -- cgit v1.2.3 From dbc153f51e2af8fabe43b0c408d27f2dd6b09925 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 10:40:25 -0500 Subject: 9term: add threadmaybackground --- src/cmd/9term/9term.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/cmd') diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c index b28f44fa..d7391cf5 100644 --- a/src/cmd/9term/9term.c +++ b/src/cmd/9term/9term.c @@ -47,6 +47,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { -- cgit v1.2.3 From ac487c754e009b0f3c01c2a8ad5bda2143da4a6b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 14:42:47 -0500 Subject: acme: allow @ in file names For upspin and other tools that put email addresses in names. --- src/cmd/acme/look.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c index 35667c6c..a7172b50 100644 --- a/src/cmd/acme/look.c +++ b/src/cmd/acme/look.c @@ -378,7 +378,7 @@ search(Text *ct, Rune *r, uint n) int isfilec(Rune r) { - static Rune Lx[] = { '.', '-', '+', '/', ':', 0 }; + static Rune Lx[] = { '.', '-', '+', '/', ':', '@', 0 }; if(isalnum(r)) return TRUE; if(runestrchr(Lx, r)) -- cgit v1.2.3 From 7f6458b045e04b97dd06b3171ac67e9ecde32429 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 5 Jan 2021 23:35:33 -0500 Subject: stats: add threadmaybackground --- src/cmd/devdraw/mac-screen.m | 5 +++- src/cmd/draw/stats.c | 6 ++++ src/cmd/sam/cmd.c | 70 ++++++++++++++++++++++---------------------- src/cmd/sam/parse.h | 6 ++-- src/cmd/sam/sam.h | 2 -- 5 files changed, 49 insertions(+), 40 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/devdraw/mac-screen.m b/src/cmd/devdraw/mac-screen.m index ad9c029e..9e51eec6 100644 --- a/src/cmd/devdraw/mac-screen.m +++ b/src/cmd/devdraw/mac-screen.m @@ -238,11 +238,14 @@ rpc_attach(Client *c, char *label, char *winsize) char *s; NSArray *allDevices; - const NSWindowStyleMask Winstyle = NSWindowStyleMaskTitled + NSWindowStyleMask Winstyle = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; + if(label == nil || *label == '\0') + Winstyle &= ~NSWindowStyleMaskTitled; + s = winsize; sr = [[NSScreen mainScreen] frame]; r = [[NSScreen mainScreen] visibleFrame]; diff --git a/src/cmd/draw/stats.c b/src/cmd/draw/stats.c index 3b6471b7..d74b95e3 100644 --- a/src/cmd/draw/stats.c +++ b/src/cmd/draw/stats.c @@ -675,6 +675,12 @@ keyboardthread(void *v) void machproc(void*); void updateproc(void*); +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/sam/cmd.c b/src/cmd/sam/cmd.c index 386fe8d4..7176a827 100644 --- a/src/cmd/sam/cmd.c +++ b/src/cmd/sam/cmd.c @@ -3,41 +3,41 @@ static char linex[]="\n"; static char wordx[]=" \t\n"; -struct cmdtab cmdtab[]={ +struct Cmdtab cmdtab[]={ /* cmdc text regexp addr defcmd defaddr count token fn */ - '\n', 0, 0, 0, 0, aDot, 0, 0, nl_cmd, - 'a', 1, 0, 0, 0, aDot, 0, 0, a_cmd, - 'b', 0, 0, 0, 0, aNo, 0, linex, b_cmd, - 'B', 0, 0, 0, 0, aNo, 0, linex, b_cmd, - 'c', 1, 0, 0, 0, aDot, 0, 0, c_cmd, - 'd', 0, 0, 0, 0, aDot, 0, 0, d_cmd, - 'D', 0, 0, 0, 0, aNo, 0, linex, D_cmd, - 'e', 0, 0, 0, 0, aNo, 0, wordx, e_cmd, - 'f', 0, 0, 0, 0, aNo, 0, wordx, f_cmd, - 'g', 0, 1, 0, 'p', aDot, 0, 0, g_cmd, - 'i', 1, 0, 0, 0, aDot, 0, 0, i_cmd, - 'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd, - 'm', 0, 0, 1, 0, aDot, 0, 0, m_cmd, - 'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd, - 'p', 0, 0, 0, 0, aDot, 0, 0, p_cmd, - 'q', 0, 0, 0, 0, aNo, 0, 0, q_cmd, - 'r', 0, 0, 0, 0, aDot, 0, wordx, e_cmd, - 's', 0, 1, 0, 0, aDot, 1, 0, s_cmd, - 't', 0, 0, 1, 0, aDot, 0, 0, m_cmd, - 'u', 0, 0, 0, 0, aNo, 2, 0, u_cmd, - 'v', 0, 1, 0, 'p', aDot, 0, 0, g_cmd, - 'w', 0, 0, 0, 0, aAll, 0, wordx, w_cmd, - 'x', 0, 1, 0, 'p', aDot, 0, 0, x_cmd, - 'y', 0, 1, 0, 'p', aDot, 0, 0, x_cmd, - 'X', 0, 1, 0, 'f', aNo, 0, 0, X_cmd, - 'Y', 0, 1, 0, 'f', aNo, 0, 0, X_cmd, - '!', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd, - '>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, - '<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, - '|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, - '=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd, - 'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd, - 0, 0, 0, 0, 0, 0, 0, 0 + {'\n', 0, 0, 0, 0, aDot, 0, 0, nl_cmd}, + {'a', 1, 0, 0, 0, aDot, 0, 0, a_cmd}, + {'b', 0, 0, 0, 0, aNo, 0, linex, b_cmd}, + {'B', 0, 0, 0, 0, aNo, 0, linex, b_cmd}, + {'c', 1, 0, 0, 0, aDot, 0, 0, c_cmd}, + {'d', 0, 0, 0, 0, aDot, 0, 0, d_cmd}, + {'D', 0, 0, 0, 0, aNo, 0, linex, D_cmd}, + {'e', 0, 0, 0, 0, aNo, 0, wordx, e_cmd}, + {'f', 0, 0, 0, 0, aNo, 0, wordx, f_cmd}, + {'g', 0, 1, 0, 'p', aDot, 0, 0, g_cmd}, + {'i', 1, 0, 0, 0, aDot, 0, 0, i_cmd}, + {'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd}, + {'m', 0, 0, 1, 0, aDot, 0, 0, m_cmd}, + {'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd}, + {'p', 0, 0, 0, 0, aDot, 0, 0, p_cmd}, + {'q', 0, 0, 0, 0, aNo, 0, 0, q_cmd}, + {'r', 0, 0, 0, 0, aDot, 0, wordx, e_cmd}, + {'s', 0, 1, 0, 0, aDot, 1, 0, s_cmd}, + {'t', 0, 0, 1, 0, aDot, 0, 0, m_cmd}, + {'u', 0, 0, 0, 0, aNo, 2, 0, u_cmd}, + {'v', 0, 1, 0, 'p', aDot, 0, 0, g_cmd}, + {'w', 0, 0, 0, 0, aAll, 0, wordx, w_cmd}, + {'x', 0, 1, 0, 'p', aDot, 0, 0, x_cmd}, + {'y', 0, 1, 0, 'p', aDot, 0, 0, x_cmd}, + {'X', 0, 1, 0, 'f', aNo, 0, 0, X_cmd}, + {'Y', 0, 1, 0, 'f', aNo, 0, 0, X_cmd}, + {'!', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd}, + {'>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd}, + {'<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd}, + {'|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd}, + {'=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd}, + {'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd}, + {0, 0, 0, 0, 0, 0, 0, 0}, }; Cmd *parsecmd(int); Addr *compoundaddr(void); @@ -402,7 +402,7 @@ Cmd * parsecmd(int nest) { int i, c; - struct cmdtab *ct; + Cmdtab *ct; Cmd *cp, *ncp; Cmd cmd; diff --git a/src/cmd/sam/parse.h b/src/cmd/sam/parse.h index d5fabf14..dd837a48 100644 --- a/src/cmd/sam/parse.h +++ b/src/cmd/sam/parse.h @@ -33,7 +33,8 @@ struct Cmd #define ctext g.text #define caddr g.addr -extern struct cmdtab{ +typedef struct Cmdtab Cmdtab; +struct Cmdtab { ushort cmdc; /* command character */ uchar text; /* takes a textual argument? */ uchar regexp; /* takes a regular expression? */ @@ -43,7 +44,8 @@ extern struct cmdtab{ uchar count; /* takes a count e.g. s2/// */ char *token; /* takes text terminated by one of these */ int (*fn)(File*, Cmd*); /* function to call with parse tree */ -}cmdtab[]; +}; +extern Cmdtab cmdtab[]; enum Defaddr{ /* default addresses */ aNo, diff --git a/src/cmd/sam/sam.h b/src/cmd/sam/sam.h index aae39b4a..6e018156 100644 --- a/src/cmd/sam/sam.h +++ b/src/cmd/sam/sam.h @@ -37,7 +37,6 @@ typedef struct Address Address; typedef struct Block Block; typedef struct Buffer Buffer; typedef struct Disk Disk; -typedef struct Discdesc Discdesc; typedef struct File File; typedef struct List List; typedef struct Range Range; @@ -342,7 +341,6 @@ void warn_S(Warn, String*); int whichmenu(File*); void writef(File*); Posn writeio(File*); -Discdesc *Dstart(void); extern Rune samname[]; /* compiler dependent */ extern Rune *left[]; -- cgit v1.2.3 From 0a513e65607223d11ba94003256b13ef5779e7e8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 3 Jan 2021 00:54:20 -0500 Subject: sam: rm dregs --- src/cmd/sam/README | 29 -------- src/cmd/sam/_libc.h | 40 ------------ src/cmd/sam/err | 39 ----------- src/cmd/sam/plan9.c | 185 ---------------------------------------------------- 4 files changed, 293 deletions(-) delete mode 100644 src/cmd/sam/README delete mode 100644 src/cmd/sam/_libc.h delete mode 100644 src/cmd/sam/err delete mode 100644 src/cmd/sam/plan9.c (limited to 'src/cmd') diff --git a/src/cmd/sam/README b/src/cmd/sam/README deleted file mode 100644 index b78a89da..00000000 --- a/src/cmd/sam/README +++ /dev/null @@ -1,29 +0,0 @@ -This is sam (not including samterm) from the 4th edition of Plan 9, -with changes so that it can be compiled under unix. -(Tested on Solaris 7 and Debian 3.0r1.) - -Some extra libraries are needed. First, fetch libutf-2.0 and libfmt-2.0 -from - http://pdos.lcs.mit.edu/~rsc/software/ - -(Beware that in libfmt/fmt.c there is a line that says: - 'u', __ifmt, /* in Plan 9, __flagfmt */ -Thus, sam will have to fmtinstall the other thing. Other ported programs -may have to do the same. The fmt library should probably print messages -about bad format characters to stderr, since no one seems to check the -return codes.) - -Compile and install those two libraries. -Set PREFIX in the Makefile to match, then compile sam. - -Your C compiler will emit many complaints of the form: - sam.c:496: warning: passing arg 1 of `bufread' from incompatible pointer type - -This is because the Plan 9 compiler has a slightly different (better, -ala Oberon) type system than ISO C. Popular compilers generate the right -code, so in an act of civil disobediance I changed just enough to get -it to compile, but left the type errors in. Now the next C standard can -adopt this extension, because at least one important C program uses it! - --- Scott Schwartz, 4 July 2003 - diff --git a/src/cmd/sam/_libc.h b/src/cmd/sam/_libc.h deleted file mode 100644 index 65618918..00000000 --- a/src/cmd/sam/_libc.h +++ /dev/null @@ -1,40 +0,0 @@ -#define __USE_UNIX98 // for pread/pwrite, supposedly -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utf.h" -#include "fmt.h" - -#define nil 0 -#define dup dup2 -#define exec execv -#define seek lseek -#define getwd getcwd -#define USED(a) -#define SET(a) - -enum { - OREAD = 0, - OWRITE = 1, - ORDWR = 2, - OCEXEC = 4, - ORCLOSE = 8 -}; - -enum { - ERRMAX = 255 -}; - -void exits(const char *); -void _exits(const char *); -int notify (void(*f)(void *, char *)); -int create(char *, int, int); -int errstr(char *, int); diff --git a/src/cmd/sam/err b/src/cmd/sam/err deleted file mode 100644 index 2a36c23b..00000000 --- a/src/cmd/sam/err +++ /dev/null @@ -1,39 +0,0 @@ -address.c: In function `filematch': -address.c:159: warning: passing arg 1 of `bufreset' from incompatible pointer type -address.c:160: warning: passing arg 1 of `bufinsert' from incompatible pointer type -file.c: In function `mergeextend': -file.c:117: warning: passing arg 1 of `bufread' from incompatible pointer type -file.c: In function `fileinsert': -file.c:275: warning: passing arg 1 of `bufinsert' from incompatible pointer type -file.c: In function `filedelete': -file.c:301: warning: passing arg 1 of `bufdelete' from incompatible pointer type -file.c: In function `fileundelete': -file.c:324: warning: passing arg 1 of `bufread' from incompatible pointer type -file.c: In function `filereadc': -file.c:339: warning: passing arg 1 of `bufread' from incompatible pointer type -file.c: In function `fileload': -file.c:405: warning: passing arg 1 of `bufload' from incompatible pointer type -file.c: In function `fileundo': -file.c:528: warning: passing arg 1 of `bufdelete' from incompatible pointer type -file.c:546: warning: passing arg 1 of `bufinsert' from incompatible pointer type -file.c: In function `fileclose': -file.c:604: warning: passing arg 1 of `bufclose' from incompatible pointer type -io.c: In function `readio': -io.c:90: warning: passing arg 1 of `bufload' from incompatible pointer type -io.c: In function `writeio': -io.c:152: warning: passing arg 1 of `bufread' from incompatible pointer type -mesg.c: In function `inmesg': -mesg.c:248: warning: passing arg 1 of `bufread' from incompatible pointer type -mesg.c: In function `snarf': -mesg.c:568: warning: passing arg 1 of `bufread' from incompatible pointer type -mesg.c: In function `setgenstr': -mesg.c:612: warning: passing arg 1 of `bufread' from incompatible pointer type -sam.c: In function `readcmd': -sam.c:496: warning: passing arg 1 of `bufread' from incompatible pointer type -sam.c: In function `copy': -sam.c:676: warning: passing arg 1 of `bufread' from incompatible pointer type -xec.c: In function `s_cmd': -xec.c:234: warning: passing arg 1 of `bufread' from incompatible pointer type -xec.c:243: warning: passing arg 1 of `bufread' from incompatible pointer type -xec.c: In function `display': -xec.c:401: warning: passing arg 1 of `bufread' from incompatible pointer type diff --git a/src/cmd/sam/plan9.c b/src/cmd/sam/plan9.c deleted file mode 100644 index 0a3fe070..00000000 --- a/src/cmd/sam/plan9.c +++ /dev/null @@ -1,185 +0,0 @@ -#include "sam.h" - -Rune samname[] = L"~~sam~~"; - -Rune *left[]= { - L"{[(<«", - L"\n", - L"'\"`", - 0 -}; -Rune *right[]= { - L"}])>»", - L"\n", - L"'\"`", - 0 -}; - -char RSAM[] = "sam"; -char SAMTERM[] = "/bin/aux/samterm"; -char HOME[] = "HOME"; -char TMPDIR[] = "/tmp"; -char SH[] = "rc"; -char SHPATH[] = "/bin/rc"; -char RX[] = "rx"; -char RXPATH[] = "/bin/rx"; -char SAMSAVECMD[] = "/bin/rc\n/sys/lib/samsave"; - -void -dprint(char *z, ...) -{ - char buf[BLOCKSIZE]; - va_list arg; - - va_start(arg, z); - vseprint(buf, &buf[BLOCKSIZE], z, arg); - va_end(arg); - termwrite(buf); -} - -void -print_ss(char *s, String *a, String *b) -{ - dprint("?warning: %s: `%.*S' and `%.*S'\n", s, a->n, a->s, b->n, b->s); -} - -void -print_s(char *s, String *a) -{ - dprint("?warning: %s `%.*S'\n", s, a->n, a->s); -} - -char* -getuser(void) -{ - static char user[64]; - int fd; - - if(user[0] == 0){ - fd = open("/dev/user", 0); - if(fd<0 || read(fd, user, sizeof user-1)<=0) - strcpy(user, "none"); - close(fd); - } - return user; -} - -int -statfile(char *name, ulong *dev, uvlong *id, long *time, long *length, long *appendonly) -{ - Dir *dirb; - - dirb = dirstat(name); - if(dirb == nil) - return -1; - if(dev) - *dev = dirb->type|(dirb->dev<<16); - if(id) - *id = dirb->qid.path; - if(time) - *time = dirb->mtime; - if(length) - *length = dirb->length; - if(appendonly) - *appendonly = dirb->mode & DMAPPEND; - free(dirb); - return 1; -} - -int -statfd(int fd, ulong *dev, uvlong *id, long *time, long *length, long *appendonly) -{ - Dir *dirb; - - dirb = dirfstat(fd); - if(dirb == nil) - return -1; - if(dev) - *dev = dirb->type|(dirb->dev<<16); - if(id) - *id = dirb->qid.path; - if(time) - *time = dirb->mtime; - if(length) - *length = dirb->length; - if(appendonly) - *appendonly = dirb->mode & DMAPPEND; - free(dirb); - return 1; -} - -void -notifyf(void *a, char *s) -{ - USED(a); - if(bpipeok && strcmp(s, "sys: write on closed pipe") == 0) - noted(NCONT); - if(strcmp(s, "interrupt") == 0) - noted(NCONT); - panicking = 1; - rescue(); - noted(NDFLT); -} - -int -newtmp(int num) -{ - int i, fd; - static char tempnam[30]; - - i = getpid(); - do - snprint(tempnam, sizeof tempnam, "%s/%d%.4s%dsam", TMPDIR, num, getuser(), i++); - while(access(tempnam, 0) == 0); - fd = create(tempnam, ORDWR|OCEXEC|ORCLOSE, 0000); - if(fd < 0){ - remove(tempnam); - fd = create(tempnam, ORDWR|OCEXEC|ORCLOSE, 0000); - } - return fd; -} - -int -waitfor(int pid) -{ - int msg; - Waitmsg *w; - - while((w = wait()) != nil){ - if(w->pid != pid){ - free(w); - continue; - } - msg = (w->msg[0] != '\0'); - free(w); - return msg; - } - return -1; -} - -void -samerr(char *buf) -{ - sprint(buf, "%s/sam.err", TMPDIR); -} - -void* -emalloc(ulong n) -{ - void *p; - - p = malloc(n); - if(p == 0) - panic("malloc fails"); - memset(p, 0, n); - return p; -} - -void* -erealloc(void *p, ulong n) -{ - p = realloc(p, n); - if(p == 0) - panic("realloc fails"); - return p; -} -- cgit v1.2.3 From 1c845e0bd5ff897dc5e90f2c24db4ecd81a8f60c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 5 Jan 2021 23:38:09 -0500 Subject: acme, sam, samterm: remove weird switch usage For whatever reason all three of these programs contain switches like: switch(x) { case 1: if(cond) case 2: f(); } Like Duff's device, this is legal C but more obscure than it really needs to be. This commit assumes those are intended as written and simply writes them more clearly. I did consider that maybe they are mistakes, but in the case of sam/regexp.c, my rewrite in this commit matches the acme/regx.c that has been in plan9port since I added acme in 2003. (I didn't bother to dig up the old Plan 9 releases.) Assuming acme/regx.c has been correct for the past two decades, this commit should be correct too. --- src/cmd/acme/edit.c | 6 ++++-- src/cmd/sam/cmd.c | 6 ++++-- src/cmd/sam/regexp.c | 2 +- src/cmd/samterm/flayer.c | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/acme/edit.c b/src/cmd/acme/edit.c index 81f80300..82a19b0d 100644 --- a/src/cmd/acme/edit.c +++ b/src/cmd/acme/edit.c @@ -635,9 +635,11 @@ simpleaddr(void) case '.': case '$': case '\'': - if(addr.type!='"') + if(addr.type=='"') + break; + /* fall through */ case '"': - editerror("bad address syntax"); + editerror("bad address syntax"); break; case 'l': case '#': diff --git a/src/cmd/sam/cmd.c b/src/cmd/sam/cmd.c index 7176a827..13bd17e0 100644 --- a/src/cmd/sam/cmd.c +++ b/src/cmd/sam/cmd.c @@ -559,9 +559,11 @@ simpleaddr(void) case '.': case '$': case '\'': - if(addr.type!='"') + if(addr.type=='"') + break; + /* fall through */ case '"': - error(Eaddress); + error(Eaddress); break; case 'l': case '#': diff --git a/src/cmd/sam/regexp.c b/src/cmd/sam/regexp.c index 2e369fe1..57c639d9 100644 --- a/src/cmd/sam/regexp.c +++ b/src/cmd/sam/regexp.c @@ -700,11 +700,11 @@ bexecute(File *f, Posn startp) break; case 1: /* expired; wrap to end */ if(sel.p[0].p1>=0) - case 3: goto Return; list[0][0].inst = list[1][0].inst = 0; p = f->b.nc; goto doloop; + case 3: default: goto Return; } diff --git a/src/cmd/samterm/flayer.c b/src/cmd/samterm/flayer.c index e9fde31c..a8e70d0c 100644 --- a/src/cmd/samterm/flayer.c +++ b/src/cmd/samterm/flayer.c @@ -169,8 +169,8 @@ newvisibilities(int redraw) break; case V(Some, Some): - if(l->f.b==0 && redraw) case V(None, Some): + if(ov == None || (l->f.b==0 && redraw)) flprepare(l); if(l->f.b && redraw){ flrefresh(l, l->entire, 0); -- cgit v1.2.3 From fdcf3d70c24886dddb5fd7052dfada67d33d5c75 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 09:58:44 -0500 Subject: auxstats: do not postnote 0 --- src/cmd/auxstats/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/auxstats/main.c b/src/cmd/auxstats/main.c index 3fd77ac4..a37c9723 100644 --- a/src/cmd/auxstats/main.c +++ b/src/cmd/auxstats/main.c @@ -21,7 +21,8 @@ notifyf(void *v, char *msg) if(strstr(msg, "child")) noted(NCONT); - postnote(PNPROC, pid, msg); + if(pid) + postnote(PNPROC, pid, msg); exits(nil); } -- cgit v1.2.3 From c3ae85a004c8714fc653629a983327d9a15b36da Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 09:59:54 -0500 Subject: rc: do not exit on EINTR from read This happens if lldb attaches to rc. --- src/cmd/rc/io.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/rc/io.c b/src/cmd/rc/io.c index c2e9d7b4..907ba86f 100644 --- a/src/cmd/rc/io.c +++ b/src/cmd/rc/io.c @@ -1,4 +1,5 @@ #include +#include #include "rc.h" #include "exec.h" #include "io.h" @@ -257,7 +258,15 @@ int emptybuf(io *f) { int n; - if(f->fd==-1 || (n = Read(f->fd, f->buf, NBUF))<=0) return EOF; + if(f->fd==-1) + return EOF; +Loop: + errno = 0; + n = Read(f->fd, f->buf, NBUF); + if(n < 0 && errno == EINTR) + goto Loop; + if(n <= 0) + return EOF; f->bufp = f->buf; f->ebuf = f->buf+n; return *f->bufp++&0xff; -- cgit v1.2.3 From 6a80119eb509bd948d87ad1b84b0a82855a3c691 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 10:01:25 -0500 Subject: sam: remove backward ?: The exit code here is ignored anyway. --- src/cmd/sam/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/sam/shell.c b/src/cmd/sam/shell.c index c6efdd57..92bd5277 100644 --- a/src/cmd/sam/shell.c +++ b/src/cmd/sam/shell.c @@ -90,7 +90,7 @@ plan9(File *f, int type, String *s, int nest) free(c); } } - exits(retcode? "error" : 0); + exits(0); } if(pid==-1){ fprint(2, "Can't fork?!\n"); -- cgit v1.2.3 From 3ccd61629b641613bcccbc51125330efab9c89a7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 10:05:50 -0500 Subject: sam: avoid out-of-bounds read in rterm Usually r->nused < r->nalloc and the read is in bounds. But it could in theory be right on the line and reading past the end of the allocation. Make it safe but preserve as much of the old semantics as possible. This use of rterm appears to be only for optimization purposes so the result does not matter for correctness. --- src/cmd/sam/rasp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/sam/rasp.c b/src/cmd/sam/rasp.c index c96101df..55d16cfb 100644 --- a/src/cmd/sam/rasp.c +++ b/src/cmd/sam/rasp.c @@ -283,8 +283,8 @@ rterm(List *r, Posn p1) for(p = 0,i = 0; inused && p+L(i)<=p1; p+=L(i++)) ; - if(i==r->nused && (i==0 || !T(i-1))) - return 0; + if(i==r->nused) + return i > 0 && T(i-1); return T(i); } -- cgit v1.2.3 From 20c14efad6487b0a09ecd661680321afa240bc0b Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:30:08 +0000 Subject: xd: fix swizz8 loop counting --- src/cmd/xd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/xd.c b/src/cmd/xd.c index 9f83e1cf..2cfbcfd1 100644 --- a/src/cmd/xd.c +++ b/src/cmd/xd.c @@ -327,7 +327,7 @@ swizz8(void) *q++ = *p++; p = data; q = swdata; - for(i=0; i<8; i++){ + for(i=0; i<2; i++){ p[0] = q[7]; p[1] = q[6]; p[2] = q[5]; -- cgit v1.2.3 From 4e6bb208eb96baae65fd6b1bf99aaa1115b9a9ba Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:35:40 +0000 Subject: eqn: enlarge errbuf to account for large tokens --- src/cmd/eqn/e.h | 2 +- src/cmd/eqn/input.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/eqn/e.h b/src/cmd/eqn/e.h index 07dc4df6..f2a71849 100644 --- a/src/cmd/eqn/e.h +++ b/src/cmd/eqn/e.h @@ -20,7 +20,7 @@ extern int class[LAST][LAST]; #undef sprintf /* Snow Leopard */ -extern char errbuf[200]; +extern char errbuf[2000]; extern char *cmdname; #define ERROR sprintf(errbuf, #define FATAL ), error(1, errbuf) diff --git a/src/cmd/eqn/input.c b/src/cmd/eqn/input.c index a0c0c34e..b146171b 100644 --- a/src/cmd/eqn/input.c +++ b/src/cmd/eqn/input.c @@ -255,7 +255,7 @@ void yyerror(char *s) error(0, s); /* temporary */ } -char errbuf[200]; +char errbuf[2000]; void eprint(void) /* try to print context around error */ { -- cgit v1.2.3 From 0144f87dc6c7f2f6becbd55519e433a9b36a466f Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:38:41 +0000 Subject: htmlroff: fix array bounds --- src/cmd/htmlroff/roff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/htmlroff/roff.c b/src/cmd/htmlroff/roff.c index 34b794be..f52e0734 100644 --- a/src/cmd/htmlroff/roff.c +++ b/src/cmd/htmlroff/roff.c @@ -257,7 +257,7 @@ copyarg(void) int c; Rune *r; - if(_readx(buf, sizeof buf, ArgMode, 0) < 0) + if(_readx(buf, MaxLine, ArgMode, 0) < 0) return nil; r = runestrstr(buf, L("\\\"")); if(r){ @@ -280,7 +280,7 @@ readline(int m) static Rune buf[MaxLine]; Rune *r; - if(_readx(buf, sizeof buf, m, 1) < 0) + if(_readx(buf, MaxLine, m, 1) < 0) return nil; r = erunestrdup(buf); return r; -- cgit v1.2.3 From a72478870ae66b7ac1e73b1d22b578cd31852f33 Mon Sep 17 00:00:00 2001 From: David Arroyo Date: Sun, 31 Jan 2021 00:51:32 -0500 Subject: 9p: parse lines in rdwr command Use bio(3) to read at most one line of input per iteration, even if there is more than one line available in the input buffer. This makes it easier to interact with line-oriented ctl files like that of factotum(4) from shell scripts, without the need to control when and how much data is flushed to a pipe. --- src/cmd/9p.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/9p.c b/src/cmd/9p.c index 75511a19..a5b97f85 100644 --- a/src/cmd/9p.c +++ b/src/cmd/9p.c @@ -302,8 +302,10 @@ void xrdwr(int argc, char **argv) { char buf[4096]; + char *p; int n; CFid *fid; + Biobuf *b; ARGBEGIN{ default: @@ -313,6 +315,8 @@ xrdwr(int argc, char **argv) if(argc != 1) usage(); + if((b = Bfdopen(0, OREAD)) == nil) + sysfatal("out of memory"); fid = xopen(argv[0], ORDWR); for(;;){ fsseek(fid, 0, 0); @@ -322,15 +326,15 @@ xrdwr(int argc, char **argv) if(write(1, buf, n) < 0 || write(1, "\n", 1) < 0) sysfatal("write error: %r"); } - n = read(0, buf, sizeof buf); - if(n <= 0) + if((p = Brdstr(b, '\n', 1)) == nil) break; - if(buf[n-1] == '\n') - n--; - if(fswrite(fid, buf, n) != n) + n = strlen(p); + if(fswrite(fid, p, n) != n) fprint(2, "write: %r\n"); + free(p); } fsclose(fid); + Bterm(b); threadexitsall(0); } -- cgit v1.2.3 From f62d4c4143c9a21e488fca658590e1546700586f Mon Sep 17 00:00:00 2001 From: Connor Taffe Date: Tue, 26 Jan 2021 15:14:18 -0600 Subject: 9pfuse: support MacFUSE >=4 MacFUSE 4 removes support for passing device fd to the mount command. Adds support for the receiving the fd over a socket instead, and updates command paths and filesystem name. --- src/cmd/9pfuse/fuse.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/9pfuse/fuse.c b/src/cmd/9pfuse/fuse.c index 4c9aac9b..ea8e3bbf 100644 --- a/src/cmd/9pfuse/fuse.c +++ b/src/cmd/9pfuse/fuse.c @@ -798,16 +798,19 @@ mountfuse(char *mtpt) } return fd; #elif defined(__APPLE__) - int i, pid, fd, r; + int i, pid, fd, r, p[2]; char buf[20]; struct vfsconf vfs; char *f, *v; if(getvfsbyname(v="osxfusefs", &vfs) < 0 && + getvfsbyname(v="macfuse", &vfs) < 0 && getvfsbyname(v="osxfuse", &vfs) < 0 && getvfsbyname(v="fusefs", &vfs) < 0){ if(access((v="osxfusefs", f="/Library/Filesystems/osxfusefs.fs" "/Support/load_osxfusefs"), 0) < 0 && + access((v="macfuse", f="/Library/Filesystems/macfuse.fs" + "/Contents/Resources/load_macfuse"), 0) < 0 && access((v="osxfuse", f="/Library/Filesystems/osxfuse.fs" "/Contents/Resources/load_osxfuse"), 0) < 0 && access((v="osxfuse", f="/opt/local/Library/Filesystems/osxfuse.fs" @@ -837,6 +840,32 @@ mountfuse(char *mtpt) } } + /* MacFUSE >=4 dropped support for passing fd */ + if (strcmp(v, "macfuse") == 0) { + if(socketpair(AF_UNIX, SOCK_STREAM, 0, p) < 0) + return -1; + pid = fork(); + if(pid < 0) + return -1; + if(pid == 0){ + close(p[1]); + snprint(buf, sizeof buf, "%d", p[0]); + putenv("_FUSE_COMMFD", buf); + putenv("_FUSE_COMMVERS", "2"); + putenv("_FUSE_CALL_BY_LIB", "1"); + putenv("_FUSE_DAEMON_PATH", + "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfus"); + execl("/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse", + "mount_macfuse", mtpt, nil); + fprint(2, "exec mount_macfuse: %r\n"); + _exit(1); + } + close(p[0]); + fd = recvfd(p[1]); + close(p[1]); + return fd; + } + /* Look for available FUSE device. */ /* * We need to truncate `fs` from the end of the vfs name if -- cgit v1.2.3