The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [pups] screen 3.9.9 vs. 2.11BSD write() to fifo and/or select() on socket
@ 2002-02-14 16:33 Steven M. Schultz
  0 siblings, 0 replies; 5+ messages in thread
From: Steven M. Schultz @ 2002-02-14 16:33 UTC (permalink / raw)


Hi -

> From: David W Talmage <talmage at cmf.nrl.navy.mil>
> I thought that I'd read in the FM that they do.  I see now that I was 
> mistaken,perhaps delusional.  I see now that <sys/stat.h> contains the gospel:
> 
> #define S_IFIFO 0010000         /* named pipe (fifo) - Not used by 2.11BSD */

	:)

	Adding FIFOs to the kernel would make an interesting project though -
	perhaps when I become inspired/motivated I'll give it a try.

> Sounds like I'm in for some deep hacking if I continue with this.  Will 
> overlays help me here?

	Overlays will help if the code comes out to more than 64KB.   Alas,
	overlays will _not_ help the dataspace requirements.   The last time
	I looked at 'screen' I saw things like "char buf[32768];' sprinkled
	thru the code.   So you might be in for some serious hacking to trim
	back the sizes of arrays/buffers/etc.   It probably would also be
	a good idea to 'string'ify the program (there are tools to assist
	doing this - take a look at how sendmail and lint are built).

> I wonder if setitimer() will fare any better.  alarm() is obsolete.

	The gospel according to /usr/src/lib/libc/gen/alarm.c says:

/*
 * Backwards compatible alarm.
 */
#include <sys/time.h>
#include <unistd.h>

unsigned int
alarm(secs)
	unsigned int secs;
{
	struct itimerval it, oitv;
	register struct itimerval *itp = &it;

	timerclear(&itp->it_interval);
	itp->it_value.tv_sec = secs;
	itp->it_value.tv_usec = 0;
	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
		return (-1);
	if (oitv.it_value.tv_usec)
		oitv.it_value.tv_sec++;
	return (oitv.it_value.tv_sec);
}

	<g>

> I'll send a progress report if I decide to continue this project.  Thanks for 
> your help, Mr. Schultz.

	What I think you're seeing is the race condition that fork() has - 
	there is no guarantee which process (parent or child) runs first.
	The test program does the fork() and the child runs to completion
	before the parent enters the select().  At that point the parent
	will wait until the alarm goes off.

	One thing you might try is create two separate programs.  One would
	create the socket and wait for the other program to connect and send
	a string.  If that works it shows that the UNIX domainsockets are
	working as expected and that the fork() race is indeed the problem.
	IF the client/server tests fail then there is something wrong in the
	UNIX domain socket handling that needs to be addressed.

	Good Luck!

	Cheers,
	Steven Schultz



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

* [pups] screen 3.9.9 vs. 2.11BSD write() to fifo and/or select()  on socket
  2002-02-14  0:25 Steven M. Schultz
  2002-02-14  8:22 ` Lars Brinkhoff
@ 2002-02-14 15:27 ` David W Talmage
  1 sibling, 0 replies; 5+ messages in thread
From: David W Talmage @ 2002-02-14 15:27 UTC (permalink / raw)


"Steven M. Schultz" <sms at 2BSD.COM> wrote:
>> From: David W Talmage <talmage at cmf.nrl.navy.mil>
>> Would someone please advise me about fifos and sockets in 2.11BSD?
>...
>	Don't use fifos - they don't exist (as you probably have found
>	out by now :))

I thought that I'd read in the FM that they do.  I see now that I was 
mistaken, perhaps delusional.  I see now that <sys/stat.h> contains the gospel:

#define S_IFIFO 0010000         /* named pipe (fifo) - Not used by 2.11BSD */


>> I'm having 
>> trouble porting screen 3.9.9, the multiplexing terminal emulator, to 2.11BSD
> ...
>	an attempt at porting it and ran into the address space problems - seems
>	that screen wants to use lots of large buffers, has lots of strings
>	(all the help, etc) and so on. 

Sounds like I'm in for some deep hacking if I continue with this.  Will 
overlays help me here?

>...
>> screen can use sockets instead of fifos.  That portion of the configure 
script
>> fails as well.  It fails in that it does not return from the select() on the
> 
>> socket until the alarm goes off.  See socketstest.c, below.
>...
>	With the child exited the select() will block until interrupted by
>	the alarm() call.

I wonder if setitimer() will fare any better.  alarm() is obsolete.

I'll send a progress report if I decide to continue this project.  Thanks for 
your help, Mr. Schultz.

David Talmage





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

* [pups] screen 3.9.9 vs. 2.11BSD write() to fifo and/or select() on socket
  2002-02-14  0:25 Steven M. Schultz
@ 2002-02-14  8:22 ` Lars Brinkhoff
  2002-02-14 15:27 ` David W Talmage
  1 sibling, 0 replies; 5+ messages in thread
From: Lars Brinkhoff @ 2002-02-14  8:22 UTC (permalink / raw)


"Steven M. Schultz" <sms at 2BSD.COM> writes:
> 	p11 2.9?   Wow, I've an old patched/hacked 2.5 because I can't seem
> 	to find p11's home now - begemot.org doesn't mention anything about
> 	"p11".

ftp://ftp.fokus.gmd.de/pub/cats/usr/harti/p11/

-- 
Lars Brinkhoff          http://lars.nocrew.org/     Linux, GCC, PDP-10,
Brinkhoff Consulting    http://www.brinkhoff.se/    HTTP programming



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

* [pups] screen 3.9.9 vs. 2.11BSD write() to fifo and/or select() on socket
@ 2002-02-14  0:25 Steven M. Schultz
  2002-02-14  8:22 ` Lars Brinkhoff
  2002-02-14 15:27 ` David W Talmage
  0 siblings, 2 replies; 5+ messages in thread
From: Steven M. Schultz @ 2002-02-14  0:25 UTC (permalink / raw)


Hi!

> From: David W Talmage <talmage at cmf.nrl.navy.mil>
> Would someone please advise me about fifos and sockets in 2.11BSD?

	Ok ;)

	Don't use fifos - they don't exist (as you probably have found
	out by now :))

> I'm having 
> trouble porting screen 3.9.9, the multiplexing terminal emulator, to 2.11BSD 

	fifos and sockets are just the tip of the iceberg when it comes
	to 'screen'.   Eons ago (when screen was a fairly new program) I made
	an attempt at porting it and ran into the address space problems - seems
	that screen wants to use lots of large buffers, has lots of strings
	(all the help, etc) and so on. 

> because of them.  I'm running Mr. Schultz's 2.11BSD with all patches up to 
> #442 on Mr. Brandt's p11 emulator version 2.9.  FWIW, I have INET in my kernel
> but I've ifconfig-ed only lo0.

	Thanks for the "ownership" label but I think of it more as being
	a 'steward' and coordinator than anything else

	p11 2.9?   Wow, I've an old patched/hacked 2.5 because I can't seem
	to find p11's home now - begemot.org doesn't mention anything about
	"p11".

> The fifo test portion of the configure script fails when writing to the fifo.  
> The write() returns -1 and sets errno == 79, "Inappropriate file type or 

	Right, FIFOs don't exist.  One of those things I never could find
	the need or time for ;)

> format".  This happens when I run the test as root, as I must in order to use 
> mknod() to create the fifo.  See fifotest.c, below.

	If 2.11's mknod can create fifos that is _news_ to me.   I don't recall
	seeing (or adding) that capability.

> screen can use sockets instead of fifos.  That portion of the configure script
> fails as well.  It fails in that it does not return from the select() on the 
> socket until the alarm goes off.  See socketstest.c, below.

	Now that is very strange.   Unix domain sockets do work (syslogd
	uses them for example) so I'm at a loss to explain why the test
	program isn't working.

	One thing I did do is after running "./a.out&" was do an immediate
	'ps'.   That should see 2 a.out processes due to the 'fork()' call.
	I only say one.  This tells me that the alarm was started (obviously
	since alarm(5) is the first thing executed) but the child process
	raced thru and exited before the parent got to the select() call.

	With the child exited the select() will block until interrupted by
	the alarm() call.

	Steven Schultz
	sms at 2bsd.com



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

* [pups] screen 3.9.9 vs. 2.11BSD write() to fifo and/or select() on socket
@ 2002-02-13 22:24 David W Talmage
  0 siblings, 0 replies; 5+ messages in thread
From: David W Talmage @ 2002-02-13 22:24 UTC (permalink / raw)


Would someone please advise me about fifos and sockets in 2.11BSD?  I'm having 
trouble porting screen 3.9.9, the multiplexing terminal emulator, to 2.11BSD 
because of them.  I'm running Mr. Schultz's 2.11BSD with all patches up to 
#442 on Mr. Brandt's p11 emulator version 2.9.  FWIW, I have INET in my kernel 
but I've ifconfig-ed only lo0.

screen's configure complains that it finds no usable fifo or socket.

The fifo test portion of the configure script fails when writing to the fifo.  
The write() returns -1 and sets errno == 79, "Inappropriate file type or 
format".  This happens when I run the test as root, as I must in order to use 
mknod() to create the fifo.  See fifotest.c, below.

screen can use sockets instead of fifos.  That portion of the configure script 
fails as well.  It fails in that it does not return from the select() on the 
socket until the alarm goes off.  See socketstest.c, below.

/* fifotest.c */
#include "confdefs.h"
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/*
#ifndef O_NONBLOCK
#define O_NONBLOCK O_NDELAY
#endif
#ifndef S_IFIFO
#define S_IFIFO 0010000
#endif
*/
char *fin = "/tmp/conftest254";

main()
{
  struct stat stb;
  int f;

  (void)alarm(5);
#ifdef POSIX
  if (mkfifo(fin, 0777)) {
#else
  if (mknod(fin, S_IFIFO|0777, 0)) {
#endif
printf("mknod failed\n");
perror("mknod");
    exit(1);
    }
  if (stat(fin, &stb) || (stb.st_mode & S_IFIFO) != S_IFIFO) {
  printf("stat failed\n");
    exit(1);
    }
  close(0);
#ifdef __386BSD__
  /*
   * The next test fails under 386BSD, but screen works using fifos.
   * Fifos in O_RDWR mode are only used for the BROKEN_PIPE case and for
   * the select() configuration test.
   */
  exit(0);
#endif
  if (open(fin, O_RDONLY | O_NONBLOCK)) {
    printf("open #1 failed\n");
    exit(1);
    }
  if (fork() == 0)
    {
      printf("f0\n");
      close(0);
      if (open(fin, O_WRONLY | O_NONBLOCK)) {
        printf("f0 open #2 failed\n");
        exit(1);
        }
      close(0);
      if (open(fin, O_WRONLY | O_NONBLOCK)) {
        printf("f0 open #3 failed\n");
        exit(1);
        }
      if (write(0, "TEST", 4) == -1) { /* FAILS HERE */
        printf("f0 write failed %d\n", errno);
        perror("write");
        exit(1);
        }
      exit(0);
    }
  printf("f1\n");
  f = 1;
  if (select(1, &f, 0, 0, 0) == -1) {
    printf("f1 select failed\n");
    exit(1);
    }
  exit(0);
}



/* socketstest.c */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>

char *son = "/tmp/conftest254";

main()
{
  int s1, s2, s3, l;
  struct sockaddr_un a;

  (void)alarm(5);
  if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
    }
  a.sun_family = AF_UNIX;
  strcpy(a.sun_path, son);
  (void) unlink(son);
  if (bind(s1, (struct sockaddr *) &a, strlen(son)+2) == -1) {
    perror("bind");
    exit(1);
    }
  if (listen(s1, 2)) {
    perror("listen");
    exit(1);
    }
  if (fork() == 0)
    {
      if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
        perror("f0 socket");
        kill(getppid(), 3);
        }
      (void)connect(s2, (struct sockaddr *)&a, strlen(son) + 2);
      if (write(s2, "HELLO", 5) == -1) {
        perror("f0 write");
        kill(getppid(), 3);
        }
      exit(0);
    }
  l = sizeof(a);
  if (close(0) == -1) {
    perror("close");
  }

  if (accept(s1, &a, &l)) {
    perror("accept");
    exit(1);
    }
  l = 1;
  if (select(1, &l, 0, 0, 0) == -1) { /* DOESN'T RETURN BEFORE SIG_ALARM */
    perror("select");
    exit(1);
    }
  exit(0);
}


-- 
David Talmage (talmage at cmf.nrl.navy.mil)
ITT Industries, Advanced Engineering & Sciences,
Advanced Technology Group





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

end of thread, other threads:[~2002-02-14 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-14 16:33 [pups] screen 3.9.9 vs. 2.11BSD write() to fifo and/or select() on socket Steven M. Schultz
  -- strict thread matches above, loose matches on Subject: below --
2002-02-14  0:25 Steven M. Schultz
2002-02-14  8:22 ` Lars Brinkhoff
2002-02-14 15:27 ` David W Talmage
2002-02-13 22:24 David W Talmage

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).