masqmail

changeset 262:fc1c6425c024

s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/ The constants are all to bulky. We should have different, meaningful exit codes anyway.
author markus schnalke <meillo@marmaro.de>
date Thu, 02 Dec 2010 17:11:25 -0300
parents 0afe18a9ee03
children e9e73505ab2c
files src/child.c src/conf.c src/connect.c src/fail_msg.c src/listen.c src/local.c src/masqmail.c src/online.c src/permissions.c src/smtpsend.c
diffstat 10 files changed, 53 insertions(+), 53 deletions(-) [+]
line diff
     1.1 --- a/src/child.c	Thu Dec 02 16:52:39 2010 -0300
     1.2 +++ b/src/child.c	Thu Dec 02 17:11:25 2010 -0300
     1.3 @@ -54,7 +54,7 @@
     1.4  				execve(*argv, argv, NULL);
     1.5  			}
     1.6  			logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
     1.7 -			_exit(EXIT_FAILURE);
     1.8 +			_exit(1);
     1.9  		} else if (pid == -1) {
    1.10  			return -1;
    1.11  		} else {
     2.1 --- a/src/conf.c	Thu Dec 02 16:52:39 2010 -0300
     2.2 +++ b/src/conf.c	Thu Dec 02 17:11:25 2010 -0300
     2.3 @@ -39,13 +39,13 @@
     2.4  		conf.mail_uid = passwd->pw_uid;
     2.5  	else {
     2.6  		fprintf(stderr, "user %s not found! (terminating)\n", DEF_MAIL_USER);
     2.7 -		exit(EXIT_FAILURE);
     2.8 +		exit(1);
     2.9  	}
    2.10  	if ((group = getgrnam(DEF_MAIL_GROUP)))
    2.11  		conf.mail_gid = group->gr_gid;
    2.12  	else {
    2.13  		fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP);
    2.14 -		exit(EXIT_FAILURE);
    2.15 +		exit(1);
    2.16  	}
    2.17  }
    2.18  
    2.19 @@ -79,7 +79,7 @@
    2.20  	}
    2.21  
    2.22  	fprintf(stderr, "cannot parse value '%s'\n", rval);
    2.23 -	exit(EXIT_FAILURE);
    2.24 +	exit(1);
    2.25  }
    2.26  
    2.27  /* make a list from each line in a file */
    2.28 @@ -91,7 +91,7 @@
    2.29  
    2.30  	if ((fptr = fopen(fname, "rt")) == NULL) {
    2.31  		logwrite(LOG_ALERT, "could not open %s for reading: %s\n", fname, strerror(errno));
    2.32 -		exit(EXIT_FAILURE);
    2.33 +		exit(1);
    2.34  	}
    2.35  
    2.36  	gchar buf[256];
    2.37 @@ -185,7 +185,7 @@
    2.38  #endif
    2.39  		} else {
    2.40  			logwrite(LOG_ALERT, "unknown resolver %s\n", item);
    2.41 -			exit(EXIT_FAILURE);
    2.42 +			exit(1);
    2.43  		}
    2.44  		g_free(item);
    2.45  	}
    2.46 @@ -240,7 +240,7 @@
    2.47  
    2.48  	if ((addr.s_addr = inet_addr(buf)) == INADDR_NONE) {
    2.49  		fprintf(stderr, "'%s' is not a valid address (must be ip)\n", buf);
    2.50 -		exit(EXIT_FAILURE);
    2.51 +		exit(1);
    2.52  	}
    2.53  
    2.54  	if (*p) {
    2.55 @@ -251,7 +251,7 @@
    2.56  			n = i ? ~((1 << (32 - i)) - 1) : 0;
    2.57  		else {
    2.58  			fprintf(stderr, "'%d' is not a valid net mask (must be >= 0 and <= 32)\n", i);
    2.59 -			exit(EXIT_FAILURE);
    2.60 +			exit(1);
    2.61  		}
    2.62  	} else
    2.63  		n = 0;
     3.1 --- a/src/connect.c	Thu Dec 02 16:52:39 2010 -0300
     3.2 +++ b/src/connect.c	Thu Dec 02 17:11:25 2010 -0300
     3.3 @@ -110,7 +110,7 @@
     3.4  
     3.5  	if (res_func_list == NULL) {
     3.6  		logwrite(LOG_ALERT, "res_funcs == NULL !!!\n");
     3.7 -		exit(EXIT_FAILURE);
     3.8 +		exit(1);
     3.9  	}
    3.10  
    3.11  	foreach(res_func_list, res_node) {
    3.12 @@ -120,7 +120,7 @@
    3.13  
    3.14  		if (res_func == NULL) {
    3.15  			logwrite(LOG_ALERT, "res_func == NULL !!!\n");
    3.16 -			exit(EXIT_FAILURE);
    3.17 +			exit(1);
    3.18  		}
    3.19  
    3.20  		errno = 0;
     4.1 --- a/src/fail_msg.c	Thu Dec 02 16:52:39 2010 -0300
     4.2 +++ b/src/fail_msg.c	Thu Dec 02 17:11:25 2010 -0300
     4.3 @@ -100,8 +100,8 @@
     4.4  
     4.5  				fclose(out);
     4.6  				waitpid(pid, &status, 0);
     4.7 -				if ((WEXITSTATUS(status) != EXIT_SUCCESS) || WIFSIGNALED(status)) {
     4.8 -					if (WEXITSTATUS(status) != EXIT_SUCCESS)
     4.9 +				if ((WEXITSTATUS(status) != 0) || WIFSIGNALED(status)) {
    4.10 +					if (WEXITSTATUS(status) != 0)
    4.11  						logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
    4.12  					if (WIFSIGNALED(status))
    4.13  						logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
     5.1 --- a/src/listen.c	Thu Dec 02 16:52:39 2010 -0300
     5.2 +++ b/src/listen.c	Thu Dec 02 17:11:25 2010 -0300
     5.3 @@ -38,7 +38,7 @@
     5.4  
     5.5  	pid = waitpid(0, &status, 0);
     5.6  	if (pid > 0) {
     5.7 -		if (WEXITSTATUS(status) != EXIT_SUCCESS)
     5.8 +		if (WEXITSTATUS(status) != 0)
     5.9  			logwrite(LOG_WARNING, "process %d exited with %d\n", pid, WEXITSTATUS(status));
    5.10  		if (WIFSIGNALED(status))
    5.11  			logwrite(LOG_WARNING, "process with pid %d got signal: %d\n", pid, WTERMSIG(status));
    5.12 @@ -79,7 +79,7 @@
    5.13  
    5.14  		smtp_in(in, out, rem_host, ident);
    5.15  
    5.16 -		_exit(EXIT_SUCCESS);
    5.17 +		_exit(0);
    5.18  	} else if (pid < 0) {
    5.19  		logwrite(LOG_WARNING, "could not fork for incoming smtp connection: %s\n", strerror(errno));
    5.20  	}
    5.21 @@ -118,7 +118,7 @@
    5.22  		}
    5.23  		if (listen(sock, 1) < 0) {
    5.24  			logwrite(LOG_ALERT, "listen: (terminating): %s\n", strerror(errno));
    5.25 -			exit(EXIT_FAILURE);
    5.26 +			exit(1);
    5.27  		}
    5.28  		logwrite(LOG_NOTICE, "listening on interface %s:%d\n", iface->address, iface->port);
    5.29  		DEBUG(5) debugf("sock = %d\n", sock);
    5.30 @@ -133,11 +133,11 @@
    5.31  	if (!conf.run_as_user) {
    5.32  		if (setegid(conf.mail_gid) != 0) {
    5.33  			logwrite(LOG_ALERT, "could not change gid to %d: %s\n", conf.mail_gid, strerror(errno));
    5.34 -			exit(EXIT_FAILURE);
    5.35 +			exit(1);
    5.36  		}
    5.37  		if (seteuid(conf.mail_uid) != 0) {
    5.38  			logwrite(LOG_ALERT, "could not change uid to %d: %s\n", conf.mail_uid, strerror(errno));
    5.39 -			exit(EXIT_FAILURE);
    5.40 +			exit(1);
    5.41  		}
    5.42  	}
    5.43  
    5.44 @@ -173,7 +173,7 @@
    5.45  		if ((sel_ret = select(FD_SETSIZE, &read_fd_set, NULL, NULL, qival > 0 ? &tm : NULL)) < 0) {
    5.46  			if (errno != EINTR) {
    5.47  				logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno));
    5.48 -				exit(EXIT_FAILURE);
    5.49 +				exit(1);
    5.50  			} else {
    5.51  				if (sighup_seen) {
    5.52  					logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n");
    5.53 @@ -184,7 +184,7 @@
    5.54  
    5.55  					execv(argv[0], &(argv[0]));
    5.56  					logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno));
    5.57 -					exit(EXIT_FAILURE);
    5.58 +					exit(1);
    5.59  				}
    5.60  			}
    5.61  		} else if (sel_ret > 0) {
    5.62 @@ -208,7 +208,7 @@
    5.63  			if ((pid = fork()) == 0) {
    5.64  				queue_run();
    5.65  
    5.66 -				_exit(EXIT_SUCCESS);
    5.67 +				_exit(0);
    5.68  			} else if (pid < 0) {
    5.69  				logwrite(LOG_ALERT, "could not fork for queue run");
    5.70  			}
     6.1 --- a/src/local.c	Thu Dec 02 16:52:39 2010 -0300
     6.2 +++ b/src/local.c	Thu Dec 02 17:11:25 2010 -0300
     6.3 @@ -132,7 +132,7 @@
     6.4  				logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
     6.5  				logwrite(LOG_ALERT, "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
     6.6  				         getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
     6.7 -				exit(EXIT_FAILURE);
     6.8 +				exit(1);
     6.9  			}
    6.10  		} else {
    6.11  			logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
     7.1 --- a/src/masqmail.c	Thu Dec 02 16:52:39 2010 -0300
     7.2 +++ b/src/masqmail.c	Thu Dec 02 17:11:25 2010 -0300
     7.3 @@ -138,17 +138,17 @@
     7.4  	if (!conf.run_as_user) {
     7.5  		if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) {
     7.6  			fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
     7.7 -			exit(EXIT_FAILURE);
     7.8 +			exit(1);
     7.9  		}
    7.10  	}
    7.11  
    7.12  	/* reparent to init only if init is not already the parent */
    7.13  	if (getppid() != 1) {
    7.14  		if ((pid = fork()) > 0) {
    7.15 -			exit(EXIT_SUCCESS);
    7.16 +			exit(0);
    7.17  		} else if (pid < 0) {
    7.18  			logwrite(LOG_ALERT, "could not fork!\n");
    7.19 -			exit(EXIT_FAILURE);
    7.20 +			exit(1);
    7.21  		}
    7.22  	}
    7.23  
    7.24 @@ -193,7 +193,7 @@
    7.25  	if (getpeername(0, (struct sockaddr *) (&saddr), &dummy) == 0) {
    7.26  		peername = g_strdup(inet_ntoa(saddr.sin_addr));
    7.27  	} else if (errno != ENOTSOCK)
    7.28 -		exit(EXIT_FAILURE);
    7.29 +		exit(1);
    7.30  
    7.31  	smtp_in(stdin, stderr, peername, NULL);
    7.32  }
    7.33 @@ -208,7 +208,7 @@
    7.34  
    7.35  	if (return_path && !is_privileged_user(conf.orig_uid)) {
    7.36  		fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP);
    7.37 -		exit(EXIT_FAILURE);
    7.38 +		exit(1);
    7.39  	}
    7.40  
    7.41  	if (!conf.run_as_user) {
    7.42 @@ -224,7 +224,7 @@
    7.43  			msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name));
    7.44  		else {
    7.45  			logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
    7.46 -			exit(EXIT_FAILURE);
    7.47 +			exit(1);
    7.48  		}
    7.49  	}
    7.50  
    7.51 @@ -246,34 +246,34 @@
    7.52  					fclose(stdout);
    7.53  					fclose(stderr);
    7.54  					if (deliver(msg)) {
    7.55 -						exit(EXIT_SUCCESS);
    7.56 +						exit(0);
    7.57  					} else
    7.58 -						exit(EXIT_FAILURE);
    7.59 +						exit(1);
    7.60  				} else if (pid < 0) {
    7.61  					logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid);
    7.62  				}
    7.63  			}
    7.64  		} else {
    7.65  			fprintf(stderr, "Could not write spool file\n");
    7.66 -			exit(EXIT_FAILURE);
    7.67 +			exit(1);
    7.68  		}
    7.69  	} else {
    7.70  		switch (err) {
    7.71  		case AERR_EOF:
    7.72  			fprintf(stderr, "unexpected EOF.\n");
    7.73 -			exit(EXIT_FAILURE);
    7.74 +			exit(1);
    7.75  		case AERR_NORCPT:
    7.76  			fprintf(stderr, "no recipients.\n");
    7.77 -			exit(EXIT_FAILURE);
    7.78 +			exit(1);
    7.79  		case AERR_SIZE:
    7.80  			fprintf(stderr, "max message size exceeded.\n");
    7.81 -			exit(EXIT_FAILURE);
    7.82 +			exit(1);
    7.83  		default:
    7.84  			/* should never happen: */
    7.85  			fprintf(stderr, "Unknown error (%d)\r\n", err);
    7.86 -			exit(EXIT_FAILURE);
    7.87 +			exit(1);
    7.88  		}
    7.89 -		exit(EXIT_FAILURE);
    7.90 +		exit(1);
    7.91  	}
    7.92  }
    7.93  
    7.94 @@ -399,7 +399,7 @@
    7.95  	gchar *M_cmd = NULL;
    7.96  	gboolean opt_t = FALSE;
    7.97  	gboolean opt_i = FALSE;
    7.98 -	gint exit_code = EXIT_SUCCESS;
    7.99 +	gint exit_code = 0;
   7.100  	gchar *conf_file = CONF_FILE;
   7.101  	gchar *route_name = NULL;
   7.102  	gchar *f_address = NULL;
   7.103 @@ -464,18 +464,18 @@
   7.104  			conf_file = get_optarg(argv, &arg, opt+1);
   7.105  			if (!conf_file) {
   7.106  				fprintf(stderr, "-C requires a filename as argument.\n");
   7.107 -				exit(EXIT_FAILURE);
   7.108 +				exit(1);
   7.109  			}
   7.110  
   7.111  		} else if (strncmp(opt, "d", 1) == 0) {
   7.112  			if (getuid() != 0) {
   7.113  				fprintf(stderr, "only root may set the debug level.\n");
   7.114 -				exit(EXIT_FAILURE);
   7.115 +				exit(1);
   7.116  			}
   7.117  			char *lvl = get_optarg(argv, &arg, opt+1);
   7.118  			if (!lvl) {
   7.119  				fprintf(stderr, "-d requires a number argument.\n");
   7.120 -				exit(EXIT_FAILURE);
   7.121 +				exit(1);
   7.122  			}
   7.123  			debug_level = atoi(lvl);
   7.124  
   7.125 @@ -484,7 +484,7 @@
   7.126  			gchar *address = get_optarg(argv, &arg, opt+1);
   7.127  			if (!address) {
   7.128  				fprintf(stderr, "-f requires an address argument\n");
   7.129 -				exit(EXIT_FAILURE);
   7.130 +				exit(1);
   7.131  			}
   7.132  			f_address = g_strdup(address);
   7.133  
   7.134 @@ -492,7 +492,7 @@
   7.135  			full_sender_name = get_optarg(argv, &arg, opt+1);
   7.136  			if (!full_sender_name) {
   7.137  				fprintf(stderr, "-F requires a name argument\n");
   7.138 -				exit(EXIT_FAILURE);
   7.139 +				exit(1);
   7.140  			}
   7.141  
   7.142  		} else if (strcmp(opt, "i") == 0) {
   7.143 @@ -542,7 +542,7 @@
   7.144  
   7.145  		} else {
   7.146  			fprintf(stderr, "unrecognized option `-%s'\n", opt);
   7.147 -			exit(EXIT_FAILURE);
   7.148 +			exit(1);
   7.149  		}
   7.150  	}
   7.151  
   7.152 @@ -552,7 +552,7 @@
   7.153  
   7.154  	if (mta_mode == MODE_VERSION) {
   7.155  		mode_version();
   7.156 -		exit(EXIT_SUCCESS);
   7.157 +		exit(0);
   7.158  	}
   7.159  
   7.160  	/* initialize random generator */
   7.161 @@ -619,17 +619,17 @@
   7.162  	if (!conf.run_as_user) {
   7.163  		if (setgid(0) != 0) {
   7.164  			fprintf(stderr, "could not set gid to 0. Is the setuid bit set? : %s\n", strerror(errno));
   7.165 -			exit(EXIT_FAILURE);
   7.166 +			exit(1);
   7.167  		}
   7.168  		if (setuid(0) != 0) {
   7.169  			fprintf(stderr, "could not gain root privileges. Is the setuid bit set? : %s\n", strerror(errno));
   7.170 -			exit(EXIT_FAILURE);
   7.171 +			exit(1);
   7.172  		}
   7.173  	}
   7.174  
   7.175  	if (!logopen()) {
   7.176  		fprintf(stderr, "could not open log file\n");
   7.177 -		exit(EXIT_FAILURE);
   7.178 +		exit(1);
   7.179  	}
   7.180  
   7.181  	DEBUG(1) debugf("masqmail %s starting\n", VERSION);
   7.182 @@ -649,7 +649,7 @@
   7.183  		g_free(f_address);
   7.184  		if (!return_path) {
   7.185  			fprintf(stderr, "invalid RFC821 address: %s\n", f_address);
   7.186 -			exit(EXIT_FAILURE);
   7.187 +			exit(1);
   7.188  		}
   7.189  	}
   7.190  
   7.191 @@ -671,7 +671,7 @@
   7.192  		break;
   7.193  
   7.194  	case MODE_BI:
   7.195 -		exit(EXIT_SUCCESS);
   7.196 +		exit(0);
   7.197  		break;  /* well... */
   7.198  
   7.199  	case MODE_MCMD:
     8.1 --- a/src/online.c	Thu Dec 02 16:52:39 2010 -0300
     8.2 +++ b/src/online.c	Thu Dec 02 17:11:25 2010 -0300
     8.3 @@ -64,7 +64,7 @@
     8.4  	}
     8.5  	fclose(in);
     8.6  	waitpid(pid, &status, 0);
     8.7 -	if (WEXITSTATUS(status) != EXIT_SUCCESS) {
     8.8 +	if (WEXITSTATUS(status) != 0) {
     8.9  		g_free(name);
    8.10  		name = NULL;
    8.11  	}
     9.1 --- a/src/permissions.c	Thu Dec 02 16:52:39 2010 -0300
     9.2 +++ b/src/permissions.c	Thu Dec 02 17:11:25 2010 -0300
     9.3 @@ -75,11 +75,11 @@
     9.4  
     9.5  	if (setegid(gid) != 0) {
     9.6  		logwrite(LOG_ALERT, "could not change gid to %d: %s\n", gid, strerror(errno));
     9.7 -		exit(EXIT_FAILURE);
     9.8 +		exit(1);
     9.9  	}
    9.10  	if (seteuid(uid) != 0) {
    9.11  		logwrite(LOG_ALERT, "could not change uid to %d: %s\n", uid, strerror(errno));
    9.12 -		exit(EXIT_FAILURE);
    9.13 +		exit(1);
    9.14  	}
    9.15  }
    9.16  
    9.17 @@ -89,7 +89,7 @@
    9.18  	if (!conf.run_as_user) {
    9.19  		if (!is_privileged_user(old_uid)) {
    9.20  			fprintf(stderr, "must be root, %s or in group %s for %s.\n", DEF_MAIL_USER, DEF_MAIL_GROUP, task_name);
    9.21 -			exit(EXIT_FAILURE);
    9.22 +			exit(1);
    9.23  		}
    9.24  
    9.25  		set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
    10.1 --- a/src/smtpsend.c	Thu Dec 02 16:52:39 2010 -0300
    10.2 +++ b/src/smtpsend.c	Thu Dec 02 17:11:25 2010 -0300
    10.3 @@ -101,7 +101,7 @@
    10.4  
    10.5  		if ((ret = accept_message(stdin, msg, ACC_DOT_IGNORE)) == AERR_OK) {
    10.6  			if ((ret = smtp_deliver(server_name, server_port, resolve_list, msg, NULL, NULL)) == smtp_ok) {
    10.7 -				exit(EXIT_SUCCESS);
    10.8 +				exit(0);
    10.9  			}
   10.10  			fprintf(stderr, "deliver failed: %d\n", ret);
   10.11  		}