main.c (157001) | main.c (159609) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1998-2005 Sendmail, Inc. and its suppliers. | 2 * Copyright (c) 1998-2006 Sendmail, Inc. and its suppliers. |
3 * All rights reserved. 4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. --- 9 unchanged lines hidden (view full) --- 20SM_UNUSED(static char copyright[]) = 21"@(#) Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers.\n\ 22 All rights reserved.\n\ 23 Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.\n\ 24 Copyright (c) 1988, 1993\n\ 25 The Regents of the University of California. All rights reserved.\n"; 26#endif /* ! lint */ 27 | 3 * All rights reserved. 4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. --- 9 unchanged lines hidden (view full) --- 20SM_UNUSED(static char copyright[]) = 21"@(#) Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers.\n\ 22 All rights reserved.\n\ 23 Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.\n\ 24 Copyright (c) 1988, 1993\n\ 25 The Regents of the University of California. All rights reserved.\n"; 26#endif /* ! lint */ 27 |
28SM_RCSID("@(#)$Id: main.c,v 8.942 2005/12/26 04:39:13 ca Exp $") | 28SM_RCSID("@(#)$Id: main.c,v 8.944 2006/04/21 23:56:42 ca Exp $") |
29 30 31#if NETINET || NETINET6 32# include <arpa/inet.h> 33#endif /* NETINET || NETINET6 */ 34 35/* for getcfname() */ 36#include <sendmail/pathnames.h> --- 474 unchanged lines hidden (view full) --- 511 ** These cannot be in initialized data space. 512 */ 513 514 setdefaults(&BlankEnvelope); 515 initmacros(&BlankEnvelope); 516 517 /* reset macro */ 518 set_op_mode(OpMode); | 29 30 31#if NETINET || NETINET6 32# include <arpa/inet.h> 33#endif /* NETINET || NETINET6 */ 34 35/* for getcfname() */ 36#include <sendmail/pathnames.h> --- 474 unchanged lines hidden (view full) --- 511 ** These cannot be in initialized data space. 512 */ 513 514 setdefaults(&BlankEnvelope); 515 initmacros(&BlankEnvelope); 516 517 /* reset macro */ 518 set_op_mode(OpMode); |
519 if (OpMode == MD_DAEMON) 520 DaemonPid = CurrentPid; /* needed for finis() to work */ |
|
519 520 pw = sm_getpwuid(RealUid); 521 if (pw != NULL) 522 (void) sm_strlcpy(rnamebuf, pw->pw_name, sizeof rnamebuf); 523 else 524 (void) sm_snprintf(rnamebuf, sizeof rnamebuf, "Unknown UID %d", 525 (int) RealUid); 526 --- 1787 unchanged lines hidden (view full) --- 2314 sm_exc_newthread(fatal_error); 2315 2316 /* disconnect from our controlling tty */ 2317 disconnect(2, &MainEnvelope); 2318 } 2319 2320 dtype[0] = '\0'; 2321 if (OpMode == MD_DAEMON) | 521 522 pw = sm_getpwuid(RealUid); 523 if (pw != NULL) 524 (void) sm_strlcpy(rnamebuf, pw->pw_name, sizeof rnamebuf); 525 else 526 (void) sm_snprintf(rnamebuf, sizeof rnamebuf, "Unknown UID %d", 527 (int) RealUid); 528 --- 1787 unchanged lines hidden (view full) --- 2316 sm_exc_newthread(fatal_error); 2317 2318 /* disconnect from our controlling tty */ 2319 disconnect(2, &MainEnvelope); 2320 } 2321 2322 dtype[0] = '\0'; 2323 if (OpMode == MD_DAEMON) |
2322 { | |
2323 (void) sm_strlcat(dtype, "+SMTP", sizeof dtype); | 2324 (void) sm_strlcat(dtype, "+SMTP", sizeof dtype); |
2324 DaemonPid = CurrentPid; 2325 } | |
2326 if (QueueIntvl > 0) 2327 { 2328 (void) sm_strlcat2(dtype, 2329 queuepersistent 2330 ? "+persistent-queueing@" 2331 : "+queueing@", 2332 pintvl(QueueIntvl, true), 2333 sizeof dtype); --- 535 unchanged lines hidden (view full) --- 2869 2870void 2871finis(drop, cleanup, exitstat) 2872 bool drop; 2873 bool cleanup; 2874 volatile int exitstat; 2875{ 2876 char pidpath[MAXPATHLEN]; | 2325 if (QueueIntvl > 0) 2326 { 2327 (void) sm_strlcat2(dtype, 2328 queuepersistent 2329 ? "+persistent-queueing@" 2330 : "+queueing@", 2331 pintvl(QueueIntvl, true), 2332 sizeof dtype); --- 535 unchanged lines hidden (view full) --- 2868 2869void 2870finis(drop, cleanup, exitstat) 2871 bool drop; 2872 bool cleanup; 2873 volatile int exitstat; 2874{ 2875 char pidpath[MAXPATHLEN]; |
2876 pid_t pid; |
|
2877 2878 /* Still want to process new timeouts added below */ 2879 sm_clear_events(); 2880 (void) sm_releasesignal(SIGALRM); 2881 2882 if (tTd(2, 1)) 2883 { 2884 sm_dprintf("\n====finis: stat %d e_id=%s e_flags=", --- 52 unchanged lines hidden (view full) --- 2937 sm_syslog(LOG_DEBUG, CurEnv->e_id, "finis, pid=%d", 2938 (int) CurrentPid); 2939 if (exitstat == EX_TEMPFAIL || 2940 CurEnv->e_errormode == EM_BERKNET) 2941 exitstat = EX_OK; 2942 2943 /* XXX clean up queues and related data structures */ 2944 cleanup_queues(); | 2877 2878 /* Still want to process new timeouts added below */ 2879 sm_clear_events(); 2880 (void) sm_releasesignal(SIGALRM); 2881 2882 if (tTd(2, 1)) 2883 { 2884 sm_dprintf("\n====finis: stat %d e_id=%s e_flags=", --- 52 unchanged lines hidden (view full) --- 2937 sm_syslog(LOG_DEBUG, CurEnv->e_id, "finis, pid=%d", 2938 (int) CurrentPid); 2939 if (exitstat == EX_TEMPFAIL || 2940 CurEnv->e_errormode == EM_BERKNET) 2941 exitstat = EX_OK; 2942 2943 /* XXX clean up queues and related data structures */ 2944 cleanup_queues(); |
2945 pid = getpid(); |
|
2945#if SM_CONF_SHM | 2946#if SM_CONF_SHM |
2946 cleanup_shm(DaemonPid == getpid()); | 2947 cleanup_shm(DaemonPid == pid); |
2947#endif /* SM_CONF_SHM */ 2948 2949 /* close locked pid file */ 2950 close_sendmail_pid(); 2951 | 2948#endif /* SM_CONF_SHM */ 2949 2950 /* close locked pid file */ 2951 close_sendmail_pid(); 2952 |
2952 if (DaemonPid == getpid() || PidFilePid == getpid()) | 2953 if (DaemonPid == pid || PidFilePid == pid) |
2953 { 2954 /* blow away the pid file */ 2955 expand(PidFile, pidpath, sizeof pidpath, CurEnv); 2956 (void) unlink(pidpath); 2957 } 2958 2959 /* reset uid for process accounting */ 2960 endpwent(); --- 309 unchanged lines hidden (view full) --- 3270 "disconnect: sm_io_reopen(\"%s\") failed: %s", 3271 SM_PATH_DEVNULL, sm_errstring(errno)); 3272#endif /* 0 */ 3273 } 3274 if (droplev > 0) 3275 { 3276 fd = open(SM_PATH_DEVNULL, O_WRONLY, 0666); 3277 if (fd == -1) | 2954 { 2955 /* blow away the pid file */ 2956 expand(PidFile, pidpath, sizeof pidpath, CurEnv); 2957 (void) unlink(pidpath); 2958 } 2959 2960 /* reset uid for process accounting */ 2961 endpwent(); --- 309 unchanged lines hidden (view full) --- 3271 "disconnect: sm_io_reopen(\"%s\") failed: %s", 3272 SM_PATH_DEVNULL, sm_errstring(errno)); 3273#endif /* 0 */ 3274 } 3275 if (droplev > 0) 3276 { 3277 fd = open(SM_PATH_DEVNULL, O_WRONLY, 0666); 3278 if (fd == -1) |
3279 { |
|
3278 sm_syslog(LOG_ERR, e->e_id, 3279 "disconnect: open(\"%s\") failed: %s", 3280 SM_PATH_DEVNULL, sm_errstring(errno)); | 3280 sm_syslog(LOG_ERR, e->e_id, 3281 "disconnect: open(\"%s\") failed: %s", 3282 SM_PATH_DEVNULL, sm_errstring(errno)); |
3283 } |
|
3281 (void) sm_io_flush(smioout, SM_TIME_DEFAULT); | 3284 (void) sm_io_flush(smioout, SM_TIME_DEFAULT); |
3282 (void) dup2(fd, STDOUT_FILENO); 3283 (void) dup2(fd, STDERR_FILENO); 3284 (void) close(fd); | 3285 if (fd >= 0) 3286 { 3287 (void) dup2(fd, STDOUT_FILENO); 3288 (void) dup2(fd, STDERR_FILENO); 3289 (void) close(fd); 3290 } |
3285 } 3286 3287 /* drop our controlling TTY completely if possible */ 3288 if (droplev > 1) 3289 { 3290 (void) setsid(); 3291 errno = 0; 3292 } --- 1112 unchanged lines hidden --- | 3291 } 3292 3293 /* drop our controlling TTY completely if possible */ 3294 if (droplev > 1) 3295 { 3296 (void) setsid(); 3297 errno = 0; 3298 } --- 1112 unchanged lines hidden --- |