~ubuntu-branches/ubuntu/hardy/exim4/hardy-proposed

« back to all changes in this revision

Viewing changes to src/log.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Haber
  • Date: 2005-07-02 06:08:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050702060834-qk17pd52kb9nt3bj
Tags: 4.52-1
* new upstream version 4.51. (mh)
  * adapt 70_remove_exim-users_references
  * remove 37_gnutlsparams
  * adapt 36_pcre
  * adapt 31_eximmanpage
* fix package priorities to have them in sync with override again. (mh)
* Fix error in nb (Norwegian) translation.
  Thanks to Helge Hafting. (mh). Closes: #315775
* Standards-Version: 3.6.2, no changes needed. (mh)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Cambridge: exim/exim-src/src/log.c,v 1.6 2005/06/28 10:23:35 ph10 Exp $ */
 
2
 
1
3
/*************************************************
2
4
*     Exim - an Internet mail transport agent    *
3
5
*************************************************/
4
6
 
5
 
/* Copyright (c) University of Cambridge 1995 - 2004 */
 
7
/* Copyright (c) University of Cambridge 1995 - 2005 */
6
8
/* See the file NOTICE for conditions of use and distribution. */
7
9
 
8
10
/* Functions for writing log files. The code for maintaining datestamped
35
37
 
36
38
static int    mainlogfd = -1;
37
39
static int    rejectlogfd = -1;
38
 
static int    processlogfd = -1;
39
40
static ino_t  mainlog_inode = 0;
40
41
static ino_t  rejectlog_inode = 0;
41
42
 
313
314
 
314
315
if (*fd >= 0)
315
316
  {
316
 
  fcntl(*fd, F_SETFD, fcntl(*fd, F_GETFD) | FD_CLOEXEC);
 
317
  (void)fcntl(*fd, F_SETFD, fcntl(*fd, F_GETFD) | FD_CLOEXEC);
317
318
  return;
318
319
  }
319
320
 
320
321
/* Open was not successful: try creating the file. If this is a root process,
321
322
we must do the creating in a subprocess set to exim:exim in order to ensure
322
323
that the file is created with the right ownership. Otherwise, there can be a
323
 
race if an exim process is trying to write to the log at the same time. The use
324
 
of SIGUSR1 by the exiwhat utility can provoke a lot of simultaneous writing. */
 
324
race if another Exim process is trying to write to the log at the same time.
 
325
The use of SIGUSR1 by the exiwhat utility can provoke a lot of simultaneous
 
326
writing. */
325
327
 
326
328
euid = geteuid();
327
329
 
349
351
    _exit((create_log(buffer) < 0)? 1 : 0);
350
352
    }
351
353
 
352
 
  /* Wait for the subprocess. If it succeeded retry the open. */
353
 
 
354
 
  while (waitpid(pid, &status, 0) != pid);
355
 
  if (status == 0) *fd = Uopen(buffer, O_APPEND|O_WRONLY, LOG_MODE);
 
354
  /* If we created a subprocess, wait for it. If it succeeded retry the open. */
 
355
 
 
356
  if (pid > 0)
 
357
    {
 
358
    while (waitpid(pid, &status, 0) != pid);
 
359
    if (status == 0) *fd = Uopen(buffer, O_APPEND|O_WRONLY, LOG_MODE);
 
360
    }
 
361
 
 
362
  /* If we failed to create a subprocess, we are in a bad way. We fall through
 
363
  with *fd still < 0, and errno set, letting the code below handle the error. */
356
364
  }
357
365
 
358
366
/* If we now have an open file, set the close-on-exec flag and return. */
359
367
 
360
368
if (*fd >= 0)
361
369
  {
362
 
  fcntl(*fd, F_SETFD, fcntl(*fd, F_GETFD) | FD_CLOEXEC);
 
370
  (void)fcntl(*fd, F_SETFD, fcntl(*fd, F_GETFD) | FD_CLOEXEC);
363
371
  return;
364
372
  }
365
373
 
806
814
      uschar *nowstamp = tod_stamp(tod_log_datestamp);
807
815
      if (Ustrncmp (mainlog_datestamp, nowstamp, Ustrlen(nowstamp)) != 0)
808
816
        {
809
 
        close(mainlogfd);             /* Close the file */
 
817
        (void)close(mainlogfd);       /* Close the file */
810
818
        mainlogfd = -1;               /* Clear the file descriptor */
811
819
        mainlog_inode = 0;            /* Unset the inode */
812
820
        mainlog_datestamp = NULL;     /* Clear the datestamp */
822
830
      {
823
831
      if (Ustat(mainlog_name, &statbuf) < 0 || statbuf.st_ino != mainlog_inode)
824
832
        {
825
 
        close(mainlogfd);
 
833
        (void)close(mainlogfd);
826
834
        mainlogfd = -1;
827
835
        mainlog_inode = 0;
828
836
        }
928
936
      uschar *nowstamp = tod_stamp(tod_log_datestamp);
929
937
      if (Ustrncmp (rejectlog_datestamp, nowstamp, Ustrlen(nowstamp)) != 0)
930
938
        {
931
 
        close(rejectlogfd);             /* Close the file */
 
939
        (void)close(rejectlogfd);       /* Close the file */
932
940
        rejectlogfd = -1;               /* Clear the file descriptor */
933
941
        rejectlog_inode = 0;            /* Unset the inode */
934
942
        rejectlog_datestamp = NULL;     /* Clear the datestamp */
945
953
      if (Ustat(rejectlog_name, &statbuf) < 0 ||
946
954
           statbuf.st_ino != rejectlog_inode)
947
955
        {
948
 
        close(rejectlogfd);
 
956
        (void)close(rejectlogfd);
949
957
        rejectlogfd = -1;
950
958
        rejectlog_inode = 0;
951
959
        }
975
983
 
976
984
if ((flags & LOG_PROCESS) != 0)
977
985
  {
978
 
  if (processlogfd < 0)
979
 
    open_log(&processlogfd, lt_process);  /* No return on error */
 
986
  int processlogfd;
 
987
  open_log(&processlogfd, lt_process);  /* No return on error */
980
988
  if ((rc = write(processlogfd, log_buffer, length)) != length)
981
989
    {
982
990
    log_write_failed(US"process log", length, rc);
983
991
    /* That function does not return */
984
992
    }
 
993
  (void)close(processlogfd);
985
994
  }
986
995
 
987
996
 
988
997
/* Handle the panic log, which is not kept open like the others. If it fails to
989
998
open, there will be a recursive call to log_write(). We detect this above and
990
999
attempt to write to the system log as a last-ditch try at telling somebody. In
991
 
all cases, try to write to log_stderr. */
 
1000
all cases except mua_wrapper, try to write to log_stderr. */
992
1001
 
993
1002
if ((flags & LOG_PANIC) != 0)
994
1003
  {
995
 
  if (log_stderr != NULL && log_stderr != debug_file)
 
1004
  if (log_stderr != NULL && log_stderr != debug_file && !mua_wrapper)
996
1005
    fprintf(log_stderr, "%s", CS log_buffer);
997
1006
 
998
1007
  if ((logging_mode & LOG_MODE_SYSLOG) != 0)
1022
1031
      flags |= LOG_PANIC_DIE;
1023
1032
      }
1024
1033
 
1025
 
    close(paniclogfd);
 
1034
    (void)close(paniclogfd);
1026
1035
    }
1027
1036
 
1028
1037
  /* Give up if the DIE flag is set */
1042
1051
log_close_all(void)
1043
1052
{
1044
1053
if (mainlogfd >= 0)
1045
 
  { close(mainlogfd); mainlogfd = -1; }
1046
 
if (processlogfd >= 0)
1047
 
  { close(processlogfd); processlogfd = -1; }
 
1054
  { (void)close(mainlogfd); mainlogfd = -1; }
1048
1055
if (rejectlogfd >= 0)
1049
 
  { close(rejectlogfd); rejectlogfd = -1; }
 
1056
  { (void)close(rejectlogfd); rejectlogfd = -1; }
1050
1057
closelog();
1051
1058
syslog_open = FALSE;
1052
1059
}