X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/5fbb51949cbd9765421c5832c2d391f80f8183e9..3c90bbcdc7cf73298156f7bcd5f5e750e7814e72:/src/src/exim.c diff --git a/src/src/exim.c b/src/src/exim.c index 4e7aae69a..c0ef9150a 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -53,7 +53,7 @@ return store_get((int)size, TRUE); } static void -function_dummy_free(void *block) { block = block; } +function_dummy_free(void * block) {} static void * function_store_malloc(size_t size) @@ -62,7 +62,7 @@ return store_malloc((int)size); } static void -function_store_free(void *block) +function_store_free(void * block) { store_free(block); } @@ -279,7 +279,6 @@ Returns: nothing void sigalrm_handler(int sig) { -sig = sig; /* Keep picky compilers happy */ sigalrm_seen = TRUE; os_non_restarting_signal(SIGALRM, sigalrm_handler); } @@ -384,14 +383,20 @@ return 0; *************************************************/ #ifdef _POSIX_MONOTONIC_CLOCK -/* Amount CLOCK_MONOTONIC is behind realtime, at startup. */ +# ifdef CLOCK_BOOTTIME +# define EXIM_CLOCKTYPE CLOCK_BOOTTIME +# else +# define EXIM_CLOCKTYPE CLOCK_MONOTONIC +# endif + +/* Amount EXIM_CLOCK is behind realtime, at startup. */ static struct timespec offset_ts; static void exim_clock_init(void) { struct timeval tv; -if (clock_gettime(CLOCK_MONOTONIC, &offset_ts) != 0) return; +if (clock_gettime(EXIM_CLOCKTYPE, &offset_ts) != 0) return; (void)gettimeofday(&tv, NULL); offset_ts.tv_sec = tv.tv_sec - offset_ts.tv_sec; offset_ts.tv_nsec = tv.tv_usec * 1000 - offset_ts.tv_nsec; @@ -402,6 +407,29 @@ offset_ts.tv_nsec += 1000*1000*1000; #endif +void +exim_gettime(struct timeval * tv) +{ +#ifdef _POSIX_MONOTONIC_CLOCK +struct timespec now_ts; + +if (clock_gettime(EXIM_CLOCKTYPE, &now_ts) == 0) + { + now_ts.tv_sec += offset_ts.tv_sec; + if ((now_ts.tv_nsec += offset_ts.tv_nsec) >= 1000*1000*1000) + { + now_ts.tv_sec++; + now_ts.tv_nsec -= 1000*1000*1000; + } + tv->tv_sec = now_ts.tv_sec; + tv->tv_usec = now_ts.tv_nsec / 1000; + } +else +#endif + (void)gettimeofday(tv, NULL); +} + + /* Exim uses a time + a pid to generate a unique identifier in two places: its message IDs, and in file names for maildir deliveries. Because some OS now re-use pids within the same second, sub-second times are now being used. @@ -428,28 +456,9 @@ exim_wait_tick(struct timeval * tgt_tv, int resolution) struct timeval now_tv; long int now_true_usec; -#ifdef _POSIX_MONOTONIC_CLOCK -struct timespec now_ts; - -if (clock_gettime(CLOCK_MONOTONIC, &now_ts) == 0) - { - now_ts.tv_sec += offset_ts.tv_sec; - if ((now_ts.tv_nsec += offset_ts.tv_nsec) >= 1000*1000*1000) - { - now_ts.tv_sec++; - now_ts.tv_nsec -= 1000*1000*1000; - } - now_tv.tv_sec = now_ts.tv_sec; - now_true_usec = (now_ts.tv_nsec / (resolution * 1000)) * resolution; - now_tv.tv_usec = now_true_usec; - } -else -#endif - { - (void)gettimeofday(&now_tv, NULL); - now_true_usec = now_tv.tv_usec; - now_tv.tv_usec = (now_true_usec/resolution) * resolution; - } +exim_gettime(&now_tv); +now_true_usec = now_tv.tv_usec; +now_tv.tv_usec = (now_true_usec/resolution) * resolution; while (exim_tvcmp(&now_tv, tgt_tv) <= 0) { @@ -555,7 +564,7 @@ for (int i = 0; i <= 2; i++) { if (devnull < 0) devnull = open("/dev/null", O_RDWR); if (devnull < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", - string_open_failed(errno, "/dev/null", NULL)); + string_open_failed("/dev/null", NULL)); if (devnull != i) (void)dup2(devnull, i); } } @@ -1729,7 +1738,7 @@ make quite sure. */ setlocale(LC_ALL, "C"); -/* Get the offset between CLOCK_MONOTONIC and wallclock */ +/* Get the offset between CLOCK_MONOTONIC/CLOCK_BOOTTIME and wallclock */ #ifdef _POSIX_MONOTONIC_CLOCK exim_clock_init(); @@ -2149,7 +2158,7 @@ on the second character (the one after '-'), to save some effort. */ concept of *the* alias file, but since Sun's YP make script calls sendmail this way, some support must be provided. */ case 'i': - if (!*++argrest) bi_option = TRUE; + if (!*argrest) bi_option = TRUE; else badarg = TRUE; break; @@ -4102,10 +4111,8 @@ privilege by now. Before the chdir, we try to ensure that the directory exists. if (Uchdir(spool_directory) != 0) { - int dummy; - (void)directory_make(spool_directory, US"", SPOOL_DIRECTORY_MODE, FALSE); - dummy = /* quieten compiler */ Uchdir(spool_directory); - dummy = dummy; /* yet more compiler quietening, sigh */ + (void) directory_make(spool_directory, US"", SPOOL_DIRECTORY_MODE, FALSE); + (void) Uchdir(spool_directory); } /* Handle calls with the -bi option. This is a sendmail option to rebuild *the* @@ -4116,8 +4123,8 @@ script. */ if (bi_option) { - (void)fclose(config_file); - if (bi_command) + (void) fclose(config_file); + if (bi_command && *bi_command) { int i = 0; uschar *argv[3]; @@ -4128,11 +4135,11 @@ if (bi_option) setgroups(group_count, group_list); exim_setugid(real_uid, real_gid, FALSE, US"running bi_command"); - DEBUG(D_exec) debug_printf("exec %.256s %.256s\n", argv[0], - argv[1] ? argv[1] : US""); + DEBUG(D_exec) debug_printf("exec '%.256s' %s%.256s%s\n", argv[0], + argv[1] ? "'" : "", argv[1] ? argv[1] : US"", argv[1] ? "'" : ""); execv(CS argv[0], (char *const *)argv); - exim_fail("exim: exec failed: %s\n", strerror(errno)); + exim_fail("exim: exec '%s' failed: %s\n", argv[0], strerror(errno)); } else { @@ -4324,8 +4331,10 @@ else if (!(unprivileged || removed_privilege)) exim_fail("exim: changing group failed: %s\n", strerror(errno)); else + { DEBUG(D_any) debug_printf("changing group to %ld failed: %s\n", (long int)exim_gid, strerror(errno)); + } } /* Handle a request to scan a file for malware */ @@ -4749,16 +4758,16 @@ for (i = 0;;) configuration specifies something to use. When running in the test harness, any setting of unknown_login overrides the actual name. */ -if (originator_login == NULL || f.running_in_test_harness) +if (!originator_login || f.running_in_test_harness) { - if (unknown_login != NULL) + if (unknown_login) { originator_login = expand_string(unknown_login); - if (originator_name == NULL && unknown_username != NULL) + if (!originator_name && unknown_username) originator_name = expand_string(unknown_username); - if (originator_name == NULL) originator_name = US""; + if (!originator_name) originator_name = US""; } - if (originator_login == NULL) + if (!originator_login) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Failed to get user name for uid %d", (int)real_uid); } @@ -4766,8 +4775,7 @@ if (originator_login == NULL || f.running_in_test_harness) /* Ensure that the user name is in a suitable form for use as a "phrase" in an RFC822 address.*/ -originator_name = string_copy(parse_fix_phrase(originator_name, - Ustrlen(originator_name), big_buffer, big_buffer_size)); +originator_name = parse_fix_phrase(originator_name, Ustrlen(originator_name)); /* If a message is created by this call of Exim, the uid/gid of its originator are those of the caller. These values are overridden if an existing message is