title: Issues with time() when running a C musl application in docker container on arm
body: <p>My application is unable to handle time operations like <a href="https://linux.die.net/man/2/time" rel="nofollow noreferrer">time(2)</a> when it runs in alpine docker container on an arm device.</p>
  <p>What I have:
  I am building a native c application which is statically linked to musl with toolchain from musl.cc (arm-linux-musleabihf-gcc). I am using latest alpine container (without image tag).</p>
  <p>How it behaves:</p>
  <ul>
  <li>Running binary directly on arm device works as expected</li>
  <li>Running in alpine container on x64 device works as expected</li>
  <li>Running in alpine container on arm device does <strong>not</strong> work</li>
  </ul>
  <p>What's going wrong:</p>
  <ul>
  <li><code>time(NULL);</code> returns ((time_t) -1) and error=1: &quot;Operation not permitted&quot;</li>
  <li>The timestamps in the log outputs have cranked timestamps</li>
  <li>SSH handshake fails because the validity of the remote certificate is in the future.</li>
  </ul>
  <p>However, if I execute <code>date</code> in container's ash the output is valid. Thus, there seems to be a problem that only occurs in alpine containers on the ARM architecture. Funnily enough, I'm switching from Ubuntu to Alpine as we had <a href="https://bugs.launchpad.net/cloud-images/+bug/1896443" rel="nofollow noreferrer">similar problems</a> there.</p>
  <p>Does anyone have any idea what I am doing wrong?</p>
  <p>Update #1:
  Same problem on ubuntu. So the problem seems to be on any docker basis image but only on arm devices.</p>
  <p>Update #2: Here is a minimal example
  <strong>TimeTest.c</strong></p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &quot;time.h&quot;
  #include &quot;errno.h&quot;
  
  int main()
  {
      printf(&quot;hallo\n&quot;);
  
      time_t myTime;
      time_t result = time(&amp;myTime);
  
      printf(&quot;result: %lld\n&quot;, result);
  
      if ((long)result &lt; 0)
      {
          printf(&quot;time() error=%d: %s\n&quot;, errno, strerror(errno));
      }
      else
      {
          struct tm* tm_info = localtime(&amp;myTime);
          printf(&quot;Current local time and date: %s\n&quot;, asctime(tm_info));
      }
  
      return 0;
  }
  </code></pre>
  <p><strong>CMakeLists.txt</strong></p>
  <pre><code>cmake_minimum_required (VERSION 3.8)
  project (&quot;TimeTest&quot;)
  if(BUILD_TARGET STREQUAL &quot;ARM_MUSL&quot;)
      set(CMAKE_SYSTEM_PROCESSOR arm)
      set(CMAKE_C_COMPILER /usr/bin/arm-linux-musleabi-gcc)
      set(CMAKE_EXE_LINKER_FLAGS &quot;${CMAKE_EXE_LINKER_FLAGS} -fno-stack-protector -mfloat-abi=softfp -static --static&quot;)
      set(CMAKE_LINK_SEARCH_END_STATIC TRUE)
  endif()
  add_executable (TimeTest &quot;TimeTest.c&quot;)
  </code></pre>
  <p><strong>Output on arm device</strong></p>
  <pre><code>pi@raspberrypi:/tmp $ docker run --rm -it -v /tmp/TimeTest:/TimeTest alpine ash
  / # /TimeTest
  hallo
  result: -4696377169665647048
  time() error=1: Operation not permitted
  </code></pre>