Subject: Re: How to lock inbox folder?

From: "Daniel M. Barton" <[email-masked]>
Date: Mon, 23 Oct 1995 14:12:15 -0400 (EDT)

Thanks for the replies.  I'll try and modify the code as you suggested.  
How about adding a pine flag to select which behavior the user wants?  
You could default to "last to start", and make it a choice to have "first 
to start".  I know, I know, you'll add it to the list... :-)

On a related note, if I've left myself in pine at work, and then kill the 
pine process from another shell, will I hurt anything?  Other than a 
message I might be creating?

Thanks for your help!

Daniel

---------------------------------------------------------------
|  Daniel M. Barton              Internet:  [email-masked]  |
|  MCI Internet Services         World Wide Web:              |
|  Cary, North Carolina, USA        http://infopage.mci.net   |
---------------------------------------------------------------

On Fri, 20 Oct 1995, Terry Gray wrote:

> Years ago Pine and imapd did what you want, but we got lots of complaints
> from people who's PC had wedged and they powered off, leaving a hung pine
> or imapd for awhile holding the lock.  So we changed to "last one wins".
> 
> The preferred way to solve the problem is to switch to Tenex format, which
> allows all sessions to have R/W access (except expunging can only be done
> when there is a single client).  If Tenex format is not an option because
> of legacy mailer access requirements, hacking the c-client source would be
> necessary.
> 
> -teg
> 
> On 20 Oct 1995, Daniel Barton wrote:
> 
> > The normal behavior of pine on my SunOS system is that if multiple pine
> > sessions open the same inbox, the last to open it gets the folder lock.
> >
> > How can I change this behavior so that the first session holds the folder
> > lock and future sessions get read-only?  I couldn't find anything in the FAQ.
> >
> > Thanks, Daniel
> >
> > ---------------------------------------------------------------
> > |  Daniel M. Barton              Internet:  [email-masked]  |
> > |  MCI Internet Services         World Wide Web:              |
> > |  Cary, North Carolina, USA        http://infopage.mci.net   |
> > ---------------------------------------------------------------
> >
> >
> 
> 

On Fri, 20 Oct 1995, Mark Crispin wrote:

> On 20 Oct 1995, Daniel Barton wrote:
> > The normal behavior of pine on my SunOS system is that if multiple pine
> > sessions open the same inbox, the last to open it gets the folder lock.
> >
> > How can I change this behavior so that the first session holds the folder
> > lock and future sessions get read-only?  I couldn't find anything in the FAQ.
> 
> This is the old behavior, and it got changed because people complained
> about it (e.g. they left a Pine logged in at the office and found that
> they couldn't get read-write when they logged in from home).
> 
> If you really want the old behavior, look for code which looks like this
> in pine3.91/imap/c-client/bezerk.c and pine3.91/imap/c-client/mmdf.c
> 
> 				/* can get the lock? */
>     else if (flock (fd,LOCK_EX|LOCK_NB)) {
>       if (retry-- == KODRETRY) {/* no, first time through? */
> 				/* yes, get other process' PID */
> 	if (!fstat (fd,&sbuf) && (i = min (sbuf.st_size,MAILTMPLEN)) &&
> 	    (read (fd,tmp,i) == i) && !(tmp[i] = 0) && (i = atol (tmp))) {
> 	  kill ((int) i,SIGUSR2);
> 	  sprintf (tmp,"Trying to get mailbox lock from process %ld",i);
> 	  mm_log (tmp,WARN);
> 	}
> 	else retry = 0;		/* give up */
>       }
>       close (fd);		/* get a new handle next time around */
>       if (!stream->silent) {	/* nothing if silent stream */
> 	if (retry) sleep (1);	/* wait a second before trying again */
> 	else mm_log ("Mailbox is open by another process, access is readonly",
> 		     WARN);
>       }
>     }
> 
> Change that code to read as:
> 				/* can get the lock? */
>     else if (flock (fd,LOCK_EX|LOCK_NB)) {
>       mm_log ("Mailbox is open by another process, access is readonly",WARN);
> 
> 
> -- Mark --
> 
> DoD #0105, R90/6 pilot, FAX: (206) 685-4045  ICBM: N 47 39'35" W 122 18'39"
> Science does not emerge from voting, party politics, or public debate.
> 
>

---

From: Mark Crispin <[email-masked]>
Date: Mon, 23 Oct 1995 12:14:59 -0700 (PDT)

> to start".  I know, I know, you'll add it to the list... :-)

The problem with that is that you are pretty much stuck with making that
choice on a systemwide basis.  You can't just configure a single app for a
single user.  You also have to worry about things like IMAP.

> message I might be creating?

No, it shouldn't hurt anything.

---

From: "Daniel M. Barton" <[email-masked]>
Date: Mon, 23 Oct 1995 15:30:43 -0400 (EDT)

Ah, let me explain my scenario.  We have a userid on our system that is
shared between multiple people.  Any one of these people can log onto the
id and start pine.  The problem is that if one person is already in pine
another person can steal the folder lock.  Since it's a single userid,
there is only one .pinerc file and my scenario would work. 

We want whoever was in pine first to keep the inbox lock until they get 
out of it.  If there is ever a problem, a user can kill the running pine 
process.

Thanks, Daniel

---

From: Terry Gray <[email-masked]>
Date: Mon, 23 Oct 1995 12:42:18 -0700 (PDT)

Daniel,
Why don't you use Tenex format for the mailbox?  That avoids the locking
problem and even permits concurrent updates.

-teg

---

From: "Daniel M. Barton" <[email-masked]>
Date: Mon, 23 Oct 1995 16:28:09 -0400 (EDT)

I'm going to have to plead ignorance here, how do I set this up on my 
machine?  I'm not familiar with Tenex format.  Any pointers will be useful.

It does sound like I want to do.

Thanks!  Daniel

---

From: Mark Crispin <[email-masked]>
Date: Mon, 23 Oct 1995 13:47:17 -0700 (PDT)

> machine?  I'm not familiar with Tenex format.  Any pointers will be useful.

I think that the Pine Technical Notes have a section on it.

Basically, Tenex format is the format used by the "MM" program for many years.
It originated on the old Tenex operating system.  It has both the byte count
of the mailbox and pre-allocated flag space in out-of-band information (that
is, the internal header), so you can use random acces update-mode I/O to
manipulate mailboxes.  The only time you have to rewrite message data is when
doing an expunge, and even that is just blatting subsequent messages on top of
an expunge message.

There are two variants.  MTX format is actually closer to what the Tenex OS
really used, since it uses CR/LF newlines instead of Unix-style newlines.  MBX
is something new and experimental and not supported by Pine yet.  It has a 2K
binary header which contains additional mailbox particulars to fully support
IMAP4 protocol features.  There's a tool that converts between all of these
various formats.

The easiest way to use Tenex format is to create an empty file in your home
directory called mail.txt  The next time Pine is started, it will
automatically pull new mail from /usr/spool/mail into mail.txt and do the
format conversion as well.  All new mail delivered to /usr/spool/mail in the
future will also be snarf into mail.txt by Pine.

You may not want to do this if you intend to use some program other than Pine,
but if you're only using Pine you'll find that using Tenex format is usually a
performance win.  The main difference is that if you do a text search of all
messages in a big mailbox, it'll be slower with Tenex format.  This is because
Pine won't read the entire mailbox into memory with Tenex format.  On the
other hand, this can be a big win if Pine's memory use was a concern.

---

From: Vladimir Solnicky Vladimír Solnický <[email-masked]>
Date: Tue, 24 Oct 1995 11:18:07 +0100 (MET)

> future will also be snarf into mail.txt by Pine.

  And if I save some messages from mail.txt to another folders, will they
be saved in tenex or Berkeley format? What about saving to a new folder? 
And the last problem: Once I got a 50 MB long log mail and pine crashed on
it (cannot resize memory). I solved it with another tools (elm). Do you
think that it never happens with all mail in mail.txt for amounts less
then 100 MB (normally I have never had more then 11 MB, now I have 1.5
MB). Thanks for your answers.

Regards, V. S.

|  |  Bc. Vladimir Solnicky (Vladimír Solnický using ISO 8859-1 or 2)
|  |  Institute of Information             UTIA AV CR
 \/   Theory and Automation                Pod vodarenskou vezi 4
Department of Computing Systems            182 08 Praha 8-Liben
+42 2 6605/2212   fax: +42 2 66414677      Czech Republic
+42 2 6605/2364   e-mail: [email-masked]   ftp.utia.cas.cz
http://www.utia.cas.cz/user_data/vs/vs-home-{en|cz|ce}.html

---

From: "Daniel M. Barton" <[email-masked]>
Date: Tue, 24 Oct 1995 11:08:17 -0400 (EDT)

Works like a charm!  Thanks for your help!

Daniel

---

From: Mark Crispin <[email-masked]>
Date: Tue, 24 Oct 1995 09:14:06 -0700

> be saved in tenex or Berkeley format? What about saving to a new folder?

The simplest answer is that they should be saved in tenex format, although
it's actually rather more complex than that.  If you're worried about it
saving in multiple formats in the same folder, don't worry, it checks to
make sure that it doesn't do that.

> MB). Thanks for your answers.

The only way an out-of-memory crash can happen with tenex format is if a
single message is too large for available memory.  There isn't much that
it can do about that.

In Berkeley format, Pine reads the entire folder into memory, so a 50MB
Berkeley folder is likely to cause many (but not all) systems to choke.
The alternative to reading it all into memory is to use a scratch disk
file.  Here at UW, student users are likely to be at the limits of their
disk quotas on a regular basis; a memory image the size of their disk
quota isn't going to cause problems, but using double their disk quota for
a scratch file is.  Scylla and Charybdis.

Actually, a future version of Pine (not 3.92) will have the option of
using a scratch file for Berkeley format instead of reading it into
memory.  Besides chomping more disk, checkpointing and expunging will be
slower.  But it'll help out people with limited RAM.

-- Mark --

---

From: [email-masked] (Rich Wales)
Date: 27 Oct 1995 22:43:32 -0400

[email-masked] (Mark Crispin) wrote:

	The easiest way to use Tenex format is to create an
	empty file in your home directory called mail.txt.
	The next time Pine is started, it will automatically
	pull new mail from /usr/spool/mail into mail.txt
	and do the format conversion as well.  All new mail
	delivered to /usr/spool/mail in the future will also
	be snarf into mail.txt by Pine.

I use "procmail", together with my own set of filters, to deliver my
incoming mail into multiple Tenex-format inboxes.  Since Pine doesn't
actually read my new mail out of /usr/spool/mail, I assume the above
trick with "mail.txt" wouldn't work for me.

Another thing I found useful, to ensure that new saved-mail folders
would be created in Tenex format, was to create a ".mminit" file in
my home directory, with the following content:

		    set empty-folder-format tenex

Without this, I ran into the problem that when I saved a message to
a brand-new folder, it was created in "Bezerkley" (traditional UNIX)
format.  I tried building a custom version of Pine with the default
folder type set to Tenex, but then I poked around the C-client library
code and discovered I could accomplish the task with the above line in
the ".mminit" file.

Rich Wales <[email-masked]>
Kitchener, Ontario, Canada       http://home.opentext.com/~richw/

---

From: [email-masked] (Daniel Barton)
Date: 20 Oct 1995 17:37:38 GMT

Thanks, Daniel

---

From: Terry Gray <[email-masked]>
Date: Fri, 20 Oct 1995 16:22:28 -0700 (PDT)

-teg

---

From: Mark Crispin <[email-masked]>
Date: Fri, 20 Oct 1995 16:57:24 -0700

/* can get the lock? */

-- Mark --