9 date 93.09.03.17.38.51; author jromine; state Exp;
14 date 93.08.25.17.20.41; author jromine; state Exp;
19 date 92.12.15.00.20.22; author jromine; state Exp;
24 date 92.11.04.00.33.19; author jromine; state Exp;
29 date 92.02.03.17.50.47; author jromine; state Exp;
34 date 92.02.03.16.34.55; author jromine; state Exp;
39 date 92.01.31.21.52.45; author jromine; state Exp;
44 date 92.01.31.21.52.30; author jromine; state Exp;
55 @declare FOpen,FClose static #ifdef OVERHEAD
58 @/* m_getdefs.c - read the user's MH environment */
60 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.7 1993/08/25 17:20:41 jromine Exp jromine $";
66 #include <sys/types.h>
75 struct passwd *getpwuid ();
77 #endif /* !__STDC__ */
81 #define FOpen(f,m,e,c) fopen (f, m)
82 #define FClose(f) fclose (f)
84 static FILE *FOpen ();
95 #if defined (notdef) || defined (COMPAT)
97 #endif /* notdef or COMPAT */
100 register struct passwd *pw;
105 if (mypath == NULL) {
106 if (mypath = getenv ("HOME"))
107 mypath = getcpy (mypath);
109 if ((pw = getpwuid (getuid ())) == NULL
110 || pw -> pw_dir == NULL
111 || *pw -> pw_dir == 0)
112 adios (NULLCP, "no HOME envariable");
114 mypath = getcpy (pw -> pw_dir);
115 if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
119 if ((cp = getenv ("MH")) && *cp) {
120 defpath = path (cp, TFILE);
121 if ((ib = FOpen (defpath, "r", "MHFD", 0)) == NULL)
122 adios (defpath, "unable to read");
124 (void) m_putenv ("MH", defpath);
127 defpath = concat (mypath, "/", mh_profile, NULLCP);
129 if ((ib = FOpen (defpath, "r", "MHFD", 0)) == NULL)
130 switch (pid = vfork ()) {
132 adios ("fork", "unable to");
135 (void) setgid (getgid ());
136 (void) setuid (getuid ());
138 execlp (installproc, "install-mh", "-auto", NULLCP);
139 fprintf (stderr, "unable to exec ");
140 perror (installproc);
144 if (pidwait (pid, OK)
145 || (ib = fopen (defpath, "r")) == NULL)
146 adios (NULLCP, "[install-mh aborted]");
150 #if defined (notdef) || defined (COMPAT)
152 #endif /* notdef or COMPAT */
153 m_readefs (&m_defs, ib, mh_profile, 0);
156 if ((pp = m_find ("path")) != NULL && *pp) {
158 (void) sprintf (buf, "%s/%s", mypath, pp);
160 (void) strcpy (buf, pp);
161 if (stat(buf, &st) == NOTOK) {
163 adios (buf, "error opening");
164 cp = concat ("Your MH-directory \"", buf,
165 "\" doesn't exist; Create it? ", NULLCP);
167 adios (NULLCP, "unable to access MH-directory \"%s\"", buf);
170 adios (NULLCP, "unable to create", buf);
175 if (strcmp (ctx, "/dev/null") == 0)
176 return; /* called by install-mh */
178 if (access (ctxpath = getcpy (m_maildir (ctx)), 0) == NOTOK)
179 switch (pid = fork ()) {
181 adios ("fork", "unable to");
184 (void) setgid (getgid ());
185 (void) setuid (getuid ());
186 fprintf (stderr, "install-mh -compat\n");
188 execlp (installproc, "install-mh", "-compat", NULLCP);
189 fprintf (stderr, "unable to exec ");
190 perror (installproc);
194 if (pidwait (pid, OK) || access (ctxpath, 0) == NOTOK)
195 adios (NULLCP, "[install-mh aborted]");
197 if ((ib = fopen (defpath, "r")) == NULL)
198 adios (defpath, "unable to read");
199 m_readefs (&m_defs, ib, mh_profile, 0);
205 if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == 0)
207 if ((ib = FOpen (ctxpath = getcpy (m_maildir (cp)), "r", "MHCONTEXTFD", 1))
209 #ifdef notdef /* XXX */
211 adios (ctxpath, "unable to read");
215 m_readefs ((struct node **) 0, ib, cp, 1);
227 static FILE *FOpen (filename, mode, envariable, ctx)
228 register char *filename,
239 if ((cp = getenv (envariable)) == NULL || *cp == 0)
242 if ((fd = atoi (cp)) <= fileno (stderr)) {
243 advise (NULLCP, "bad value for $%s: %s", envariable, cp);
244 (void) unputenv (envariable);
245 return fopen (filename, mode);
252 if (fstat (fd, &st1) == NOTOK) {
254 if ((fp = fopen (filename, mode))
255 && !strcmp (mode, "r")
256 && fileno (fp) > fileno (stderr)) {
257 (void) sprintf (buffer, "%d", fileno (fp));
258 if (!m_putenv (envariable, buffer))
260 fd_ctx = fileno (fp);
262 fd_def = fileno (fp);
265 if ((cp = getenv ("MHFDEBUG")) && *cp)
266 fprintf (stderr, "FOpen of %s sets %d\n", filename, fileno (fp));
270 (void) lseek (fd, (off_t)0, 0);
271 return fdopen (fd, mode);
275 static int FClose (f)
286 if ((d1 = fileno (f)) != fd_def && d1 != fd_ctx)
293 (void) dup2 (d2, d1);
302 if ((cp = getenv ("MHFDEBUG")) && *cp)
303 fprintf (stderr, "FClose emulating close of %d (%d)\n", d1, d2);
306 #endif /* OVERHEAD */
312 @off_t fixes for BSD44
317 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.6 1992/12/15 00:20:22 jromine Exp jromine $";
332 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.5 1992/11/04 00:33:19 jromine Exp jromine $";
338 (void) lseek (fd, 0L, 0);
349 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.4 1992/02/03 17:50:47 jromine Exp jromine $";
359 #endif notdef or COMPAT
362 #endif notdef or COMPAT
382 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.3 1992/02/03 16:34:55 jromine Exp jromine $";
385 (void) putenv ("MH", defpath);
388 if (!putenv (envariable, buffer))
399 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.2 1992/01/31 21:52:45 jromine Exp jromine $";
412 static char ident[] = "@@(#)$Id: m_getfld.c,v 1.9 1992/01/24 18:03:41 jromine Exp $";
426 || *pw -> pw_dir == NULL)
432 if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == NULL)
435 if ((cp = getenv (envariable)) == NULL || *cp == NULL)