Mail command always holding the message for 60 seconds

I am trying to use mail command inside a centos container. The following is how the mail client is configured (and no sendmail service or server needed inside the container).

########### Dockerfile ##################
FROM centos
COPY submit.mc /tmp

RUN yum -y install m4 sendmail sendmail-cf mailx &&
rm -f /etc/mail/sendmail.cf /etc/mail/sendmail.mc &&
m4 /tmp/submit.mc > /etc/mail/submit.cf

########### end of Dockerfile ############

The submit.mc has something like the following:

include(/usr/share/sendmail-cf/m4/cf.m4')dnl VERSIONID(linux submit’) dnl affects one comment line
MASQUERADE_AS(myactualdomain.com')dnl define(confCF_VERSION’, Submit')dnl define(OSTYPE’,')dnl define(confDOMAIN_NAME’,myactualdomain')dnl define(confTIME_ZONE’, USE_TZ')dnl define(confDONT_INIT_GROUPS’, True')dnl define(confPID_FILE’, /var/run/sm-client.pid')dnl define(RELAY_MAILER’,esmtp')dnl define(RELAY_MAILER_ARGS’,TCP $h 25')dnl EXPOSED_USER(root’)dnl
FEATURE(use_ct_file')dnl MASQUERADE_AS(myactualdomain’)dnl
FEATURE(allmasquerade')dnl FEATURE(masquerade_envelope)dnl FEATURE(always_add_domain’)dnl
FEATURE(msp',mymailserver’)dnl

In the submit.mc above, please replace the myactualdomain with the real one. mymailserver is the the mail server to accept SMTP request,

Inside the container, if we run the following command:

mail -v user@domain.com < file.txt

we can see mail command will be waiting for 60 seconds.

I did strace insode the container, and I see the following:


 0.000040 [00007f31281a15a0] open("/etc/hosts", O_RDONLY) = 3 <0.000014>
 0.000036 [00007f31281a1154] fstat(3, {st_dev=makedev(202, 1), st_ino=402675, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=174, st_atime=2018/03/06-19:54:53.506328851, st_mtime=2018/03/06-19:54:53.506328851, st_ctime=2018/03/06-19:54:53.522328851}) = 0 <0.000008>
 0.000050 [00007f31281a17e0] read(3, "127.0.0.1\tlocalhost\n::1\tlocalhos"..., 4096) = 174 <0.000008>
 0.000032 [00007f31281a1e90] close(3) = 0 <0.000008>
 0.000037 [00007f31281a15a0] open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 3 <0.000013>
 0.000032 [00007f31281a1154] fstat(3, {st_dev=makedev(202, 1), st_ino=152385, st_mode=S_IFREG|0644, st_nlink=6, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=118, st_atime=2018/01/30-08:49:58, st_mtime=2018/01/30-08:49:58, st_ctime=2018/03/06-18:14:12.126328851}) = 0 <0.000007>
 0.000037 [00007f31281a1154] fstat(3, {st_dev=makedev(202, 1), st_ino=152385, st_mode=S_IFREG|0644, st_nlink=6, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=118, st_atime=2018/01/30-08:49:58, st_mtime=2018/01/30-08:49:58, st_ctime=2018/03/06-18:14:12.126328851}) = 0 <0.000008>
 0.000035 [00007f31281aa99a] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f312a226000 <0.000010>
 0.000028 [00007f31281a17e0] read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0"..., 4096) = 118 <0.000014>
 0.000032 [00007f31281b0380] lseek(3, -62, SEEK_CUR) = 56 <0.000008>
 0.000024 [00007f31281a17e0] read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0"..., 4096) = 62 <0.000008>
 0.000025 [00007f31281a1e90] close(3) = 0 <0.000008>
 0.000023 [00007f31281aaa27] munmap(0x7f312a226000, 4096) = 0 <0.000014>
 0.000038 [00007f31281b14c7] socket(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 3 <0.000012>
 0.000028 [00007f31281b1070] connect(3, {sa_family=AF_LOCAL, sun_path="/dev/log"}, 110) = -1 ENOENT (No such file or directory) <0.000013>
 0.000033 [00007f31281a1e90] close(3) = 0 <0.000030>
 0.000058 [00007f31280ed4a0] rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 <0.000008>
 0.000028 [00007f31280ed37d] rt_sigaction(SIGALRM, {0x5647fff85cb0, [], SA_RESTORER|SA_RESTART, 0x7f31280ed270}, {SIG_DFL, [], 0}, 8) = 0 <0.000007>
 0.000027 [00007f3128176f47] alarm(60) = 0 <0.000009>
 0.000024 [00007f31280ed4a0] rt_sigprocmask(SIG_UNBLOCK, [ALRM], [ALRM], 8) = 0 <0.000008>
 0.000024 [00007f31280ed4a0] rt_sigprocmask(SIG_UNBLOCK, [ALRM], [], 8) = 0 <0.000008>
 0.000024 [00007f3128177130] pause() = ? ERESTARTNOHAND (To be restarted if no handler) <60.000027>
60.000094 [00007f3128177130] --- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
 0.000020 [00007f3128176f47] alarm(0) = 0 <0.000008>
 0.000025 [00007f3128176f47] alarm(0) = 0 <0.000007>
 0.000022 [00007f31280ed279] rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call) <0.000008>
 0.000036 [00007f31281a1105] stat("/etc/mail/service.switch", 0x7ffc29f73c00) = -1 ENOENT (No such file or directory) <0.000014>

we see there is alram(60) and a system call paus(), which holds the process for 60.000027 seconds.

I could not figure out what the process was waiting on or what it was doing.

I figured out what caused waiting… The issue is that the call getcanonname doesn’t return anything inside the container (as the hostname is a random string), which leads the sleep(60) in the daemon.c (in the sendmail source code)