9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] drawterm patches
@ 2022-01-27 23:59 Eli Cohen
  2022-01-28  0:08 ` [9front] " Eli Cohen
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Cohen @ 2022-01-27 23:59 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

I have attached a couple more drawterm patches that may be of
interest, and a Make.alsa configuration file

the alsa patches change devaudio.c a little bit to add audiodevread
support which (only) devaudio-alsa.c uses

the bindflags patch adds -R and -C options to not bind /mnt/term/root
and /mnt/term/cmd respectively for a slightly more secure drawterm
session. I tried to do the same for -I with /mnt/term/net to disallow
using drawterm's networking but then it just wouldn't connect at all

[-- Attachment #2: drawterm.bindflags.patch --]
[-- Type: text/x-patch, Size: 2442 bytes --]

diff --git a/cpu.c b/cpu.c
index 9cb2a2f..58bdd7a 100644
--- a/cpu.c
+++ b/cpu.c
@@ -243,7 +243,7 @@ ncpu(char *host, char *cmd)
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-GBO] "
+	fprint(2, "usage: %s [-GBORC] "
 		"[-h host] [-u user] [-a authserver] [-s secstore] "
 		"[-e 'crypt hash'] [-k keypattern] "
 		"[-p] [-t timeout] "
@@ -260,7 +260,12 @@ extern void cpubody(void);
 void
 cpumain(int argc, char **argv)
 {
-	char *s;
+	char *s, *root;
+	int bindcmd, bindroot;
+
+	bindroot = 1;
+	root = nil;
+	bindcmd = 1;
 
 	user = getenv("USER");
 	if((pass = getenv("PASS")) != nil)
@@ -305,11 +310,8 @@ cpumain(int argc, char **argv)
 		user = EARGF(usage());
 		break;
 	case 'r':
-		s = smprint("/root/%s", EARGF(usage()));
-		cleanname(s);
-		if(bind(s, "/root", MREPL) < 0)
-			panic("bind /root: %r");
-		free(s);
+		root = smprint("/root/%s", EARGF(usage()));
+		cleanname(root);
 		break;
 	case 'c':
 		cmd = estrdup(EARGF(usage()));
@@ -325,10 +327,29 @@ cpumain(int argc, char **argv)
 			*/
 		geometry = EARGF(usage());
 		break;
+	case 'R':
+		bindroot = 0;
+		break;
+	case 'C':
+		bindcmd = 0;
+		break;
 	default:
 		usage();
 	}ARGEND;
 
+	if (bindcmd)
+		bind("#C", "/", MAFTER);
+
+	if (bindroot || (root != nil))
+		if(bind("#U", "/root", MREPL) < 0)
+			panic("bind #U: %r");
+
+	if (root != nil) {
+		if(bind(root, "/root", MREPL) < 0)
+			panic("bind /root: %r");
+		free(root);
+	}
+
 	if(argc != 0)
 		usage();
 
diff --git a/drawterm.1 b/drawterm.1
index 4113738..c7d1443 100644
--- a/drawterm.1
+++ b/drawterm.1
@@ -6,7 +6,7 @@ drawterm  \- connection to cpu, fs, and auth servers
 .SH SYNOPSIS
 .B drawterm
 [
-.B -GBO
+.B -GBORC
 ] [
 .B -h
 .I host
@@ -65,6 +65,22 @@ Use the old
 to connect to the cpu server rather than 
 .IR rcpu (1)\fR.
 
+.TP
+.B -R
+Do not bind terminal root at
+.I /mnt/term/root
+unless
+.B -r \fIroot
+is also specified.
+
+.TP
+.B -C
+Do not bind
+.I /mnt/term/cmd
+for
+.IR os (1)
+command.
+
 .TP
 .B -h \fIhost
 Connect to \fIhost\fR for cpu.
diff --git a/main.c b/main.c
index e66c81a..889704f 100644
--- a/main.c
+++ b/main.c
@@ -51,11 +51,8 @@ main(int argc, char **argv)
 		panic("bind #e: %r");
 	if(bind("#I", "/net", MBEFORE) < 0)
 		panic("bind #I: %r");
-	if(bind("#U", "/root", MREPL) < 0)
-		panic("bind #U: %r");
 	bind("#A", "/dev", MAFTER);
 	bind("#N", "/dev", MAFTER);
-	bind("#C", "/", MAFTER);
 
 	if(open("/dev/cons", OREAD) != 0)
 		panic("open0: %r");

[-- Attachment #3: drawterm.alsa.patch --]
[-- Type: text/x-patch, Size: 2864 bytes --]

diff --git a/kern/devaudio-alsa.c b/kern/devaudio-alsa.c
index 30dfd60..9c0405b 100644
--- a/kern/devaudio-alsa.c
+++ b/kern/devaudio-alsa.c
@@ -25,22 +25,22 @@ void
 audiodevopen(void)
 {
 	if(snd_pcm_open(&playback, "default", SND_PCM_STREAM_PLAYBACK, 0) < 0)
-		error("snd_pcm_open playback");
+		error("snd_pcm_open(playback)");
 
 	if(snd_pcm_set_params(playback, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, 2, speed, 1, 500000) < 0)
-		error("snd_pcm_set_params playback");
+		error("snd_pcm_set_params(playback)");
 
 	if(snd_pcm_prepare(playback) < 0)
-		error("snd_pcm_prepare playback");
+		error("snd_pcm_prepare(playback)");
 
 	if(snd_pcm_open(&capture, "default", SND_PCM_STREAM_CAPTURE, 0) < 0)
-		error("snd_pcm_open capture");
+		error("snd_pcm_open(capture)");
 
 	if(snd_pcm_set_params(capture, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, 2, speed, 1, 500000) < 0)
-		error("snd_pcm_set_params capture");
+		error("snd_pcm_set_params(capture)");
 
 	if(snd_pcm_prepare(capture) < 0)
-		error("snd_pcm_prepare capture");
+		error("snd_pcm_prepare(capture)");
 }
 
 void
@@ -85,7 +85,7 @@ audiodevwrite(void *v, int n)
 		if (frames < 0)
 			frames = snd_pcm_recover(playback, frames, 0);
 		if (frames < 0)
-			error((char*)snd_strerror(frames));
+			error("snd_pcm_writei");
 		m = frames*4;
 	}
 
@@ -100,9 +100,11 @@ audiodevread(void *v, int n)
 	do {
 		frames = snd_pcm_readi(capture, v, n/4);
 	} while(frames == -EAGAIN);
-
 	if (frames < 0)
-		error((char*)snd_strerror(frames));
+		frames = snd_pcm_recover(capture, frames, 0);
+	if (frames < 0)
+		error("snd_pcm_readi");
 
 	return frames*4;
 }
+
diff --git a/kern/devaudio.c b/kern/devaudio.c
index 1655262..0009994 100644
--- a/kern/devaudio.c
+++ b/kern/devaudio.c
@@ -14,6 +14,7 @@ enum
 	Aclosed		= 0,
 	Aread,
 	Awrite,
+	Ardwr,
 
 	Speed		= 44100,
 	Ncmd		= 50,		/* max volume command words */
@@ -31,7 +32,7 @@ static	struct
 {
 	QLock	lk;
 	Rendez	vous;
-	int	amode;		/* Aclosed/Aread/Awrite for /audio */
+	int	amode;		/* Aclosed/Aread/Awrite/Ardwr for /audio */
 } audio;
 
 #define aqlock(a) qlock(&(a)->lk)
@@ -114,6 +115,8 @@ audioopen(Chan *c, int omode)
 		amode = Awrite;
 		if((omode&7) == OREAD)
 			amode = Aread;
+		else if((omode&7) == ORDWR)
+			amode = Ardwr;
 		aqlock(&audio);
 		if(waserror()){
 			aqunlock(&audio);
@@ -178,7 +181,7 @@ audioread(Chan *c, void *v, long n, vlong off)
 		return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
 
 	case Qaudio:
-		if(audio.amode != Aread)
+		if(audio.amode != Aread && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){
@@ -324,7 +327,7 @@ audiowrite(Chan *c, void *vp, long n, vlong off)
 		break;
 
 	case Qaudio:
-		if(audio.amode != Awrite)
+		if(audio.amode != Awrite && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){

[-- Attachment #4.1: Type: text/plain, Size: 367 bytes --]

from postmaster@4ess:
The following attachment had content that we can't
prove to be harmless.  To avoid possible automatic
execution, we changed the content headers.
The original header was:

	Content-Type: application/octet-stream; name="Make.alsa"
	Content-Disposition: attachment; filename="Make.alsa"
	Content-Transfer-Encoding: base64
	Content-ID: <f_kyxmxisx2>

[-- Attachment #4.2: Make.alsa.suspect --]
[-- Type: application/octet-stream, Size: 536 bytes --]

# Unix
#PTHREAD=	# for Mac
PTHREAD=-pthread
AR=ar
AS=as
RANLIB=ranlib
X11=/usr/X11R6
CC=gcc
CFLAGS=-Wall -Wno-missing-braces -ggdb -I$(ROOT) -I$(ROOT)/include -I$(ROOT)/kern -c -I$(X11)/include -D_THREAD_SAFE $(PTHREAD) -O2
O=o
OS=posix
GUI=x11
LDADD=-L$(X11)/lib64 -L$(X11)/lib -lX11 -ggdb -lm -lasound
LDFLAGS=$(PTHREAD)
TARG=drawterm
# AUDIO=none
AUDIO=alsa

all: default

libmachdep.a:
	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
	(cd posix-$$arch &&  make)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [9front] Re: drawterm patches
  2022-01-27 23:59 [9front] drawterm patches Eli Cohen
@ 2022-01-28  0:08 ` Eli Cohen
  2022-01-28  0:24   ` Eli Cohen
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Cohen @ 2022-01-28  0:08 UTC (permalink / raw)
  To: 9front

sorry, wait... I don't think the alsa patch is quite right after further testing

On Thu, Jan 27, 2022 at 3:59 PM Eli Cohen <echoline@gmail.com> wrote:
>
> I have attached a couple more drawterm patches that may be of
> interest, and a Make.alsa configuration file
>
> the alsa patches change devaudio.c a little bit to add audiodevread
> support which (only) devaudio-alsa.c uses
>
> the bindflags patch adds -R and -C options to not bind /mnt/term/root
> and /mnt/term/cmd respectively for a slightly more secure drawterm
> session. I tried to do the same for -I with /mnt/term/net to disallow
> using drawterm's networking but then it just wouldn't connect at all

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [9front] Re: drawterm patches
  2022-01-28  0:08 ` [9front] " Eli Cohen
@ 2022-01-28  0:24   ` Eli Cohen
  2022-01-28  0:44     ` Eli Cohen
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Cohen @ 2022-01-28  0:24 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

this one seems to work better, at least on my system

On Thu, Jan 27, 2022 at 4:08 PM Eli Cohen <echoline@gmail.com> wrote:
>
> sorry, wait... I don't think the alsa patch is quite right after further testing
>
> On Thu, Jan 27, 2022 at 3:59 PM Eli Cohen <echoline@gmail.com> wrote:
> >
> > I have attached a couple more drawterm patches that may be of
> > interest, and a Make.alsa configuration file
> >
> > the alsa patches change devaudio.c a little bit to add audiodevread
> > support which (only) devaudio-alsa.c uses
> >
> > the bindflags patch adds -R and -C options to not bind /mnt/term/root
> > and /mnt/term/cmd respectively for a slightly more secure drawterm
> > session. I tried to do the same for -I with /mnt/term/net to disallow
> > using drawterm's networking but then it just wouldn't connect at all

[-- Attachment #2: drawterm.alsa.patch --]
[-- Type: text/x-patch, Size: 2350 bytes --]

diff --git a/kern/devaudio-alsa.c b/kern/devaudio-alsa.c
index 30dfd60..2042139 100644
--- a/kern/devaudio-alsa.c
+++ b/kern/devaudio-alsa.c
@@ -76,17 +76,20 @@ int
 audiodevwrite(void *v, int n)
 {
 	snd_pcm_sframes_t frames;
-	int tot, m;
+	int tot, m, fr;
 
 	for(tot = 0; tot < n; tot += m){
+		fr = (n-tot)/4;
 		do {
-			frames = snd_pcm_writei(playback, v+tot, (n-tot)/4);
-		} while(frames == -EAGAIN);
+			frames = snd_pcm_writei(playback, v+tot, fr);
+			if (frames < 0 && snd_pcm_recover(playback, frames, 0) == 0)
+				frames = fr;
+			if (frames < 0)
+				break;
+		} while(frames != fr);
 		if (frames < 0)
-			frames = snd_pcm_recover(playback, frames, 0);
-		if (frames < 0)
-			error((char*)snd_strerror(frames));
-		m = frames*4;
+			error("snd_pcm_writei");
+		m = n-tot;
 	}
 
 	return tot;
@@ -100,9 +103,11 @@ audiodevread(void *v, int n)
 	do {
 		frames = snd_pcm_readi(capture, v, n/4);
 	} while(frames == -EAGAIN);
-
+	if (frames < 0 && snd_pcm_recover(capture, frames, 0) == 0)
+		frames = n/4;
 	if (frames < 0)
-		error((char*)snd_strerror(frames));
+		error("snd_pcm_readi");
 
 	return frames*4;
 }
+
diff --git a/kern/devaudio.c b/kern/devaudio.c
index 1655262..0009994 100644
--- a/kern/devaudio.c
+++ b/kern/devaudio.c
@@ -14,6 +14,7 @@ enum
 	Aclosed		= 0,
 	Aread,
 	Awrite,
+	Ardwr,
 
 	Speed		= 44100,
 	Ncmd		= 50,		/* max volume command words */
@@ -31,7 +32,7 @@ static	struct
 {
 	QLock	lk;
 	Rendez	vous;
-	int	amode;		/* Aclosed/Aread/Awrite for /audio */
+	int	amode;		/* Aclosed/Aread/Awrite/Ardwr for /audio */
 } audio;
 
 #define aqlock(a) qlock(&(a)->lk)
@@ -114,6 +115,8 @@ audioopen(Chan *c, int omode)
 		amode = Awrite;
 		if((omode&7) == OREAD)
 			amode = Aread;
+		else if((omode&7) == ORDWR)
+			amode = Ardwr;
 		aqlock(&audio);
 		if(waserror()){
 			aqunlock(&audio);
@@ -178,7 +181,7 @@ audioread(Chan *c, void *v, long n, vlong off)
 		return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
 
 	case Qaudio:
-		if(audio.amode != Aread)
+		if(audio.amode != Aread && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){
@@ -324,7 +327,7 @@ audiowrite(Chan *c, void *vp, long n, vlong off)
 		break;
 
 	case Qaudio:
-		if(audio.amode != Awrite)
+		if(audio.amode != Awrite && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [9front] Re: drawterm patches
  2022-01-28  0:24   ` Eli Cohen
@ 2022-01-28  0:44     ` Eli Cohen
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Cohen @ 2022-01-28  0:44 UTC (permalink / raw)
  To: 9front

it still may need some de-stupifying, but I just can't tell the
difference between bugs, being completely insane, and having an
internet connection and PC flagged to be unable to play DVDs etc

On Thu, Jan 27, 2022 at 4:24 PM Eli Cohen <echoline@gmail.com> wrote:
>
> this one seems to work better, at least on my system
>
> On Thu, Jan 27, 2022 at 4:08 PM Eli Cohen <echoline@gmail.com> wrote:
> >
> > sorry, wait... I don't think the alsa patch is quite right after further testing
> >
> > On Thu, Jan 27, 2022 at 3:59 PM Eli Cohen <echoline@gmail.com> wrote:
> > >
> > > I have attached a couple more drawterm patches that may be of
> > > interest, and a Make.alsa configuration file
> > >
> > > the alsa patches change devaudio.c a little bit to add audiodevread
> > > support which (only) devaudio-alsa.c uses
> > >
> > > the bindflags patch adds -R and -C options to not bind /mnt/term/root
> > > and /mnt/term/cmd respectively for a slightly more secure drawterm
> > > session. I tried to do the same for -I with /mnt/term/net to disallow
> > > using drawterm's networking but then it just wouldn't connect at all

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-28 22:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-27 23:59 [9front] drawterm patches Eli Cohen
2022-01-28  0:08 ` [9front] " Eli Cohen
2022-01-28  0:24   ` Eli Cohen
2022-01-28  0:44     ` Eli Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).