]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/m_getdefs.c
1 /* m_getdefs.c - read the user's MH environment */
3 static char ident
[] = "@(#)$Id: m_getdefs.c,v 1.8 1993/09/03 17:38:51 jromine Exp $";
18 struct passwd
*getpwuid ();
20 #endif /* !__STDC__ */
24 #define FOpen(f,m,e,c) fopen (f, m)
25 #define FClose(f) fclose (f)
27 static FILE *FOpen ();
38 #if defined (notdef) || defined (COMPAT)
40 #endif /* notdef or COMPAT */
43 register struct passwd
*pw
;
49 if (mypath
= getenv ("HOME"))
50 mypath
= getcpy (mypath
);
52 if ((pw
= getpwuid (getuid ())) == NULL
53 || pw
-> pw_dir
== NULL
54 || *pw
-> pw_dir
== 0)
55 adios (NULLCP
, "no HOME envariable");
57 mypath
= getcpy (pw
-> pw_dir
);
58 if ((cp
= mypath
+ strlen (mypath
) - 1) > mypath
&& *cp
== '/')
62 if ((cp
= getenv ("MH")) && *cp
) {
63 defpath
= path (cp
, TFILE
);
64 if ((ib
= FOpen (defpath
, "r", "MHFD", 0)) == NULL
)
65 adios (defpath
, "unable to read");
67 (void) m_putenv ("MH", defpath
);
70 defpath
= concat (mypath
, "/", mh_profile
, NULLCP
);
72 if ((ib
= FOpen (defpath
, "r", "MHFD", 0)) == NULL
)
73 switch (pid
= vfork ()) {
75 adios ("fork", "unable to");
78 (void) setgid (getgid ());
79 (void) setuid (getuid ());
81 execlp (installproc
, "install-mh", "-auto", NULLCP
);
82 fprintf (stderr
, "unable to exec ");
88 || (ib
= fopen (defpath
, "r")) == NULL
)
89 adios (NULLCP
, "[install-mh aborted]");
93 #if defined (notdef) || defined (COMPAT)
95 #endif /* notdef or COMPAT */
96 m_readefs (&m_defs
, ib
, mh_profile
, 0);
99 if ((pp
= m_find ("path")) != NULL
&& *pp
) {
101 (void) sprintf (buf
, "%s/%s", mypath
, pp
);
103 (void) strcpy (buf
, pp
);
104 if (stat(buf
, &st
) == NOTOK
) {
106 adios (buf
, "error opening");
107 cp
= concat ("Your MH-directory \"", buf
,
108 "\" doesn't exist; Create it? ", NULLCP
);
110 adios (NULLCP
, "unable to access MH-directory \"%s\"", buf
);
113 adios (NULLCP
, "unable to create", buf
);
118 if (strcmp (ctx
, "/dev/null") == 0)
119 return; /* called by install-mh */
121 if (access (ctxpath
= getcpy (m_maildir (ctx
)), 0) == NOTOK
)
122 switch (pid
= fork ()) {
124 adios ("fork", "unable to");
127 (void) setgid (getgid ());
128 (void) setuid (getuid ());
129 fprintf (stderr
, "install-mh -compat\n");
131 execlp (installproc
, "install-mh", "-compat", NULLCP
);
132 fprintf (stderr
, "unable to exec ");
133 perror (installproc
);
137 if (pidwait (pid
, OK
) || access (ctxpath
, 0) == NOTOK
)
138 adios (NULLCP
, "[install-mh aborted]");
140 if ((ib
= fopen (defpath
, "r")) == NULL
)
141 adios (defpath
, "unable to read");
142 m_readefs (&m_defs
, ib
, mh_profile
, 0);
148 if ((cp
= getenv ("MHCONTEXT")) == NULL
|| *cp
== 0)
150 if ((ib
= FOpen (ctxpath
= getcpy (m_maildir (cp
)), "r", "MHCONTEXTFD", 1))
152 #ifdef notdef /* XXX */
154 adios (ctxpath
, "unable to read");
158 m_readefs ((struct node
**) 0, ib
, cp
, 1);
170 static FILE *FOpen (filename
, mode
, envariable
, ctx
)
171 register char *filename
,
182 if ((cp
= getenv (envariable
)) == NULL
|| *cp
== 0)
185 if ((fd
= atoi (cp
)) <= fileno (stderr
)) {
186 advise (NULLCP
, "bad value for $%s: %s", envariable
, cp
);
187 (void) unputenv (envariable
);
188 return fopen (filename
, mode
);
195 if (fstat (fd
, &st1
) == NOTOK
) {
197 if ((fp
= fopen (filename
, mode
))
198 && !strcmp (mode
, "r")
199 && fileno (fp
) > fileno (stderr
)) {
200 (void) sprintf (buffer
, "%d", fileno (fp
));
201 if (!m_putenv (envariable
, buffer
))
203 fd_ctx
= fileno (fp
);
205 fd_def
= fileno (fp
);
208 if ((cp
= getenv ("MHFDEBUG")) && *cp
)
209 fprintf (stderr
, "FOpen of %s sets %d\n", filename
, fileno (fp
));
213 (void) lseek (fd
, (off_t
)0, 0);
214 return fdopen (fd
, mode
);
218 static int FClose (f
)
229 if ((d1
= fileno (f
)) != fd_def
&& d1
!= fd_ctx
)
236 (void) dup2 (d2
, d1
);
245 if ((cp
= getenv ("MHFDEBUG")) && *cp
)
246 fprintf (stderr
, "FClose emulating close of %d (%d)\n", d1
, d2
);
249 #endif /* OVERHEAD */