From 594db4c93b1f04ddb422ad86a188a4fdcb19c570 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sun, 11 Jan 2015 23:01:19 +0000 Subject: [PATCH] Add cmdline option to append a log message. Bug 418 --- doc/doc-docbook/spec.xfpt | 7 +++++++ src/src/exim.c | 23 +++++++++++++++++++++-- test/confs/0602 | 13 +++++++++++++ test/log/0602 | 1 + test/scripts/0000-Basic/0602 | 5 +++++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/confs/0602 create mode 100644 test/log/0602 create mode 100644 test/scripts/0000-Basic/0602 diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 84950b541..9584e79d8 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -4646,6 +4646,13 @@ this option. .oindex "&%-X%&" This option is interpreted by Sendmail to cause debug information to be sent to the named file. It is ignored by Exim. + +.vitem &%-z%&&~<&'log line'&> +.oindex "&%-z%&" +This option writes its argument to Exim's logfile. +Use is restricted to administrators; the intent is for operational notes. +Quotes should be used to maintain a multi-word item as a single argument, +under most shells. .endlist .ecindex IIDclo1 diff --git a/src/src/exim.c b/src/src/exim.c index 6a4bf553f..3ac03e92e 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -1500,6 +1500,7 @@ uschar *ftest_domain = NULL; uschar *ftest_localpart = NULL; uschar *ftest_prefix = NULL; uschar *ftest_suffix = NULL; +uschar *log_oneline = NULL; uschar *malware_test_file = NULL; uschar *real_sender_address; uschar *originator_home = US"/"; @@ -3383,13 +3384,20 @@ for (i = 1; i < argc; i++) case 'X': if (*argrest == '\0') - { if (++i >= argc) { fprintf(stderr, "exim: string expected after -X\n"); exit(EXIT_FAILURE); } - } + break; + + case 'z': + if (*argrest == '\0') + if (++i < argc) log_oneline = argv[i]; else + { + fprintf(stderr, "exim: file name expected after %s\n", argv[i-1]); + exit(EXIT_FAILURE); + } break; /* All other initial characters are errors */ @@ -3832,6 +3840,17 @@ if (Ustrlen(syslog_processname) > 32) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "syslog_processname is longer than 32 chars: aborting"); +if (log_oneline) + { + if (admin_user) + { + log_write(0, LOG_MAIN, "%s", log_oneline); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + /* In some operating systems, the environment variable TMPDIR controls where temporary files are created; Exim doesn't use these (apart from when delivering to MBX mailboxes), but called libraries such as DBM libraries may require them. diff --git a/test/confs/0602 b/test/confs/0602 new file mode 100644 index 000000000..048175d5e --- /dev/null +++ b/test/confs/0602 @@ -0,0 +1,13 @@ +# Exim test configuration 0602 + +exim_path = EXIM_PATH +spool_directory = DIR/spool +log_file_path = DIR/spool/log/%slog +gecos_pattern = "" +gecos_name = CALLER_NAME + +# ----- Main settings ----- + +acl_smtp_rcpt = reject + +# End diff --git a/test/log/0602 b/test/log/0602 new file mode 100644 index 000000000..ffa899166 --- /dev/null +++ b/test/log/0602 @@ -0,0 +1 @@ +1999-03-02 09:44:33 This argument written, with newline, to log diff --git a/test/scripts/0000-Basic/0602 b/test/scripts/0000-Basic/0602 new file mode 100644 index 000000000..3afdf5e3d --- /dev/null +++ b/test/scripts/0000-Basic/0602 @@ -0,0 +1,5 @@ +# log line write +# +# +exim -z "This argument written, with newline, to log" +*** -- 2.25.1