/* m_getdefs.c - read the user's MH environment */
static char ident
[] = "@(#)$Id: m_getdefs.c,v 1.6 1992/12/15 00:20:22 jromine Exp $";
struct passwd
*getpwuid ();
#define FOpen(f,m,e,c) fopen (f, m)
#define FClose(f) fclose (f)
#if defined (notdef) || defined (COMPAT)
#endif /* notdef or COMPAT */
register struct passwd
*pw
;
if (mypath
= getenv ("HOME"))
mypath
= getcpy (mypath
);
if ((pw
= getpwuid (getuid ())) == NULL
adios (NULLCP
, "no HOME envariable");
mypath
= getcpy (pw
-> pw_dir
);
if ((cp
= mypath
+ strlen (mypath
) - 1) > mypath
&& *cp
== '/')
if ((cp
= getenv ("MH")) && *cp
) {
defpath
= path (cp
, TFILE
);
if ((ib
= FOpen (defpath
, "r", "MHFD", 0)) == NULL
)
adios (defpath
, "unable to read");
(void) m_putenv ("MH", defpath
);
defpath
= concat (mypath
, "/", mh_profile
, NULLCP
);
if ((ib
= FOpen (defpath
, "r", "MHFD", 0)) == NULL
)
switch (pid
= vfork ()) {
adios ("fork", "unable to");
(void) setgid (getgid ());
(void) setuid (getuid ());
execlp (installproc
, "install-mh", "-auto", NULLCP
);
fprintf (stderr
, "unable to exec ");
|| (ib
= fopen (defpath
, "r")) == NULL
)
adios (NULLCP
, "[install-mh aborted]");
#if defined (notdef) || defined (COMPAT)
#endif /* notdef or COMPAT */
m_readefs (&m_defs
, ib
, mh_profile
, 0);
if ((pp
= m_find ("path")) != NULL
&& *pp
) {
(void) sprintf (buf
, "%s/%s", mypath
, pp
);
if (stat(buf
, &st
) == NOTOK
) {
adios (buf
, "error opening");
cp
= concat ("Your MH-directory \"", buf
,
"\" doesn't exist; Create it? ", NULLCP
);
adios (NULLCP
, "unable to access MH-directory \"%s\"", buf
);
adios (NULLCP
, "unable to create", buf
);
if (strcmp (ctx
, "/dev/null") == 0)
return; /* called by install-mh */
if (access (ctxpath
= getcpy (m_maildir (ctx
)), 0) == NOTOK
)
adios ("fork", "unable to");
(void) setgid (getgid ());
(void) setuid (getuid ());
fprintf (stderr
, "install-mh -compat\n");
execlp (installproc
, "install-mh", "-compat", NULLCP
);
fprintf (stderr
, "unable to exec ");
if (pidwait (pid
, OK
) || access (ctxpath
, 0) == NOTOK
)
adios (NULLCP
, "[install-mh aborted]");
if ((ib
= fopen (defpath
, "r")) == NULL
)
adios (defpath
, "unable to read");
m_readefs (&m_defs
, ib
, mh_profile
, 0);
if ((cp
= getenv ("MHCONTEXT")) == NULL
|| *cp
== 0)
if ((ib
= FOpen (ctxpath
= getcpy (m_maildir (cp
)), "r", "MHCONTEXTFD", 1))
adios (ctxpath
, "unable to read");
m_readefs ((struct node
**) 0, ib
, cp
, 1);
static FILE *FOpen (filename
, mode
, envariable
, ctx
)
if ((cp
= getenv (envariable
)) == NULL
|| *cp
== 0)
if ((fd
= atoi (cp
)) <= fileno (stderr
)) {
advise (NULLCP
, "bad value for $%s: %s", envariable
, cp
);
(void) unputenv (envariable
);
return fopen (filename
, mode
);
if (fstat (fd
, &st1
) == NOTOK
) {
if ((fp
= fopen (filename
, mode
))
&& fileno (fp
) > fileno (stderr
)) {
(void) sprintf (buffer
, "%d", fileno (fp
));
if (!m_putenv (envariable
, buffer
))
if ((cp
= getenv ("MHFDEBUG")) && *cp
)
fprintf (stderr
, "FOpen of %s sets %d\n", filename
, fileno (fp
));
(void) lseek (fd
, (off_t
)0, 0);
return fdopen (fd
, mode
);
if ((d1
= fileno (f
)) != fd_def
&& d1
!= fd_ctx
)
if ((cp
= getenv ("MHFDEBUG")) && *cp
)
fprintf (stderr
, "FClose emulating close of %d (%d)\n", d1
, d2
);