xref: /illumos-gate/usr/src/cmd/mail/done.c (revision dd23d762c65e503874085a3893fbd3df9688da30)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1995 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #include "mail.h"
31 #include <sysexits.h>
32 
33 /*
34  * remap the bin/mail exit code to sendmail recognizable
35  * exit code when in deliver mode.
36  */
37 static int
38 maperrno(err)
39 int err;
40 {
41 	int rc;
42 
43 	switch (sav_errno) {
44 	case 0:
45 		rc = EX_OK;
46 		break;
47 	case EPERM:
48 	case EACCES:
49 	case ENOSPC:
50         case EDQUOT:
51 		rc = EX_CANTCREAT;
52 		break;
53 	case EAGAIN:
54 		rc = EX_TEMPFAIL;
55 		break;
56 	case ENOENT:
57 	case EISDIR:
58 	case ENOTDIR:
59 		rc = EX_OSFILE;
60 		break;
61 	default:
62 		rc = EX_IOERR;
63 		break;
64 	}
65 	return(rc);
66 }
67 
68 /* Fix for bug 1207994 */
69 void
70 sig_done(needtmp)
71 int 	needtmp;
72 {
73 	static char pn[] = "sig_done";
74 	Dout(pn, 0, "got signal %d\n", needtmp);
75 	done(0);
76 }
77 
78 
79 void done(needtmp)
80 int	needtmp;
81 {
82 	static char pn[] = "done";
83 	unlock();
84 	if (!maxerr) {
85 		maxerr = error;
86 		Dout(pn, 0, "maxerr set to %d\n", maxerr);
87 		if ((debug > 0) && (keepdbgfile == 0)) {
88 			unlink (dbgfname);
89 		}
90 	}
91 	if (maxerr && sending)
92 		mkdead();
93 	if (tmpf)
94 		fclose(tmpf);
95 	if (!needtmp && lettmp) {
96 		Dout(pn, 0, "temp file removed\n");
97 		unlink(lettmp);
98 	}
99 
100 	if (deliverflag) {
101 		/* bug fix for 1104684 */
102 		exit(maperrno(sav_errno));
103 	}
104 	exit(maxerr);
105 	/* NOTREACHED */
106 }
107