Skip to content

fix: Support chmod on /var/log/mail/* when dir is empty#4391

Merged
georglauterbach merged 3 commits intodocker-mailserver:masterfrom
mazzz1y:master
Mar 3, 2025
Merged

fix: Support chmod on /var/log/mail/* when dir is empty#4391
georglauterbach merged 3 commits intodocker-mailserver:masterfrom
mazzz1y:master

Conversation

@mazzz1y
Copy link
Copy Markdown
Contributor

@mazzz1y mazzz1y commented Mar 2, 2025

Description

To prevent SSD wear from logs, I mount /var/log/mail/ to tmpfs in my setup. I collect logs from standard output using Loki.

As a result, the /var/log/mail directory is empty whenever the container restarts. Attempting to change permissions on this directory using shell expansion leads to errors like:

chmod: missing operand after ‘640’
Try 'chmod --help' for more information.

Using find avoids running chmod if there is nothing to modify, preventing these errors. It's also more convenient than shell expansion, which can cause errors like "too many arguments".

Type of change

  • Improvement (non-breaking change that does improve existing functionality)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary, I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added information about changes made in this PR to CHANGELOG.md

@mazzz1y mazzz1y marked this pull request as ready for review March 2, 2025 12:33
@casperklein
Copy link
Copy Markdown
Member

LGTM.

However, I am wondering about the error message. Since we don't use shopt -s nullglob, /var/log/mail/* should be "expand" to /var/log/mail/* if there are no files in that directory:

# mkdir empty
# chmod 640 empty/*
chmod: cannot access 'empty/*': No such file or directory

# shopt -s nullglob
# chmod 640 empty/*
chmod: missing operand after ‘640’
Try 'chmod --help' for more information.

@polarathene
Copy link
Copy Markdown
Member

polarathene commented Mar 2, 2025

Thanks for spotting this, it'd trigger on first container setup too with a fresh volume mount that doesn't copy the images internal content.

Since we don't use shopt -s nullglob

We use it a few times in scripts. The setup call for getmail during initial container setup does set it which might continue to affect usage afterwards that follows outside the function? (I haven't verified, just a guess):

# If no matching filenames are found, and the shell option nullglob is disabled, the word is left unchanged.
# If the nullglob option is set, and no matches are found, the word is removed.
shopt -s nullglob

@polarathene polarathene added area/scripts kind/bug/fix A fix (PR) for a confirmed bug labels Mar 2, 2025
@casperklein
Copy link
Copy Markdown
Member

Thanks for pointing that out. You are right, I've overlooked that.

casperklein
casperklein previously approved these changes Mar 2, 2025
@casperklein casperklein added this to the v15.1.0 milestone Mar 2, 2025
Comment thread CHANGELOG.md Outdated
@polarathene polarathene changed the title fix: improve chmod for "/var/log/mail/*" fix: Support chmod on /var/log/mail/* when dir is empty Mar 2, 2025
@polarathene polarathene modified the milestones: v15.1.0, v15.0.1 Mar 2, 2025
Copy link
Copy Markdown
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge.

Might wait a day or two for any other v15 bug reports, then push this out as a bug fix release as v15.0.1? @casperklein @georglauterbach

I'm reluctant to delay until a 15.1 given what our release cadence typically is like.

@georglauterbach georglauterbach self-requested a review March 3, 2025 11:50
@georglauterbach
Copy link
Copy Markdown
Member

I'll review this today, please do not merge yet.

@polarathene
Copy link
Copy Markdown
Member

@georglauterbach the fix seems fine, it properly only applies to files, not that I think they'd be any directories in /var/log/mail/ itself.

The directory would be empty when given a fresh volume mount at container startup, or like the author during container restarts with tmpfs as well. Hence the error.

shopt -s nullglob should only accidentally be left enabled when the Getmail feature is enabled AFAIK. I assume that is a separate issue that should undo that to avoid surprises?

@georglauterbach
Copy link
Copy Markdown
Member

georglauterbach commented Mar 3, 2025

I just wanted to verify that there are not too many files, and no directories inside /var/log/mail. LGMT 👍🏼

The nullglob can be handled separately, but I do not see it as an issue, really.

Releasing v15.0.1 sounds like a good idea 👍🏼

@georglauterbach georglauterbach enabled auto-merge (squash) March 3, 2025 21:12
@georglauterbach georglauterbach merged commit 1756ba0 into docker-mailserver:master Mar 3, 2025
@casperklein
Copy link
Copy Markdown
Member

The nullglob can be handled separately, but I do not see it as an issue, really.

It's an issue, but not a big one. OPs error message would be different, if getmail was not enabled. See my first post.

I think that should be streamlined. We could move the nullglob command to the top of start-mailserver.sh, making it consequently available to all code that is processed by start-mailserver.sh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts kind/bug/fix A fix (PR) for a confirmed bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants