Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for simple log outputs as alternative to email #147

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion anacron/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct job_rec1 {
char *ident;
char *command;
char *mailto;
int inherit_outputs;
int no_mail_output;

int tab_line;
int arg_num;
Expand Down
17 changes: 8 additions & 9 deletions anacron/runjob.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ static void
run_job(const job_rec *jr)
/* This is called to start the job, after the fork */
{
/* If outputs are not inherited from the parent, pipe outputs to temp file */
if (!jr->inherit_outputs) {
/* If mail functionality is not disabled, pipe outputs to temp file */
if (!jr->no_mail_output) {
/* setup stdout and stderr */
xclose(1);
xclose(2);
Expand Down Expand Up @@ -303,11 +303,10 @@ launch_job(job_rec *jr)

setup_env(jr);

/* Outputs are inherited if INHERIT_OUTPUTS is defined and non-empty */
jr->inherit_outputs = getenv("INHERIT_OUTPUTS") != NULL && *getenv("INHERIT_OUTPUTS");
jr->no_mail_output = getenv("NO_MAIL_OUTPUT") != NULL && *getenv("NO_MAIL_OUTPUT");
JohnnyJayJay marked this conversation as resolved.
Show resolved Hide resolved

/* Set up email functionality if outputs should *not* be inherited */
if (!jr->inherit_outputs) {
/* Set up email functionality if it isn't disabled */
if (!jr->no_mail_output) {
/* Get the destination email address if set, or current user otherwise */
mailto = getenv("MAILTO");
if (mailto == NULL) {
Expand Down Expand Up @@ -389,7 +388,7 @@ tend_job(job_rec *jr, int status)

update_timestamp(jr);
unlock(jr);
if (!jr->inherit_outputs && file_size(jr->output_fd) > jr->mail_header_size) mail_output = 1;
if (!jr->no_mail_output && file_size(jr->output_fd) > jr->mail_header_size) mail_output = 1;
JohnnyJayJay marked this conversation as resolved.
Show resolved Hide resolved
else mail_output = 0;

m = mail_output ? " (produced output)" : "";
Expand All @@ -407,8 +406,8 @@ tend_job(job_rec *jr, int status)
jr->job_pid = 0;
running_jobs--;
if (mail_output) launch_mailer(jr);
/* output_fd and input_fd are only set if outputs are not inherited */
if (!jr->inherit_outputs) {
/* output_fd and input_fd are only set if mail functionality is enabled */
if (!jr->no_mail_output) {
xclose(jr->output_fd);
xclose(jr->input_fd);
}
Expand Down
2 changes: 1 addition & 1 deletion man/anacrontab.5
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ and
variables are expanded, so setting them as in the following example works as expected: [email protected] ($USER is replaced by the system user) )
.PP
If
.I INHERIT_OUTPUTS
.I NO_MAIL_OUTPUT
is defined (and non-empty), anacron's output includes the outputs of job processes and the mail functionality is disabled.
JohnnyJayJay marked this conversation as resolved.
Show resolved Hide resolved
.PP
.PP
Expand Down