title: Beside umask what else affects permissions of new directories?
body: <p>I noticed that if you interrup <code>rsync</code>, some new directories remain having permissions <code>drwx------</code>, although current umask is <code>0022</code>.</p>
  
  <p>I launched <code>gdb</code> and tried to explicitly call <code>umask(0)</code> right before calling <code>mkdir()</code>, but it had no effect: I expected new dirs to have <code>drwxrwxrwx</code>, but they still had <code>drwx------</code>.</p>
  
  <p>(In newer versions of rsync they're no longer <code>drwx------</code>, but still unaffected by umask)</p>
  
  <p>If I change the command to <code>/bin/mkdir</code>, calling <code>umask()</code> starts working. It seems that <code>rsync</code> is using some magic.</p>
  
  <p>Here's a test script:
  (For some reason the breakpoint on <code>mkdir()</code> only works when copying from ssh)</p>
  
  <pre><code>(
  rm -rf /tmp/3 &amp;&amp; mkdir -p /tmp/3 &amp;&amp; cd /tmp/3 &amp;&amp;
  #gdb -q -nx --args /bin/mkdir foo &lt;&lt;EOF
  gdb -q -nx --args rsync -r --include=/profile.d --exclude="*" localhost:/etc/ ./ &lt;&lt;'EOF'
  set width 0
  set height 0
  set pagination no
  set breakpoint pending on
  b mkdir
  b mkdirat
  run
  del
  print (char*)$rdi
  call umask(0)
  call mkdir("test")
  fin
  shell ls -l
  p/o umask(0)
  k
  EOF
  )
  </code></pre>
  
  <p>_</p>
  
  <pre><code>Reading symbols from /usr/bin/rsync...Reading symbols from /usr/bin/rsync...(no debugging symbols found)...done.
  (no debugging symbols found)...done.
  Missing separate debuginfos, use: debuginfo-install rsync-3.0.9-15.el7.x86_64
  (gdb) (gdb) (gdb) (gdb) (gdb) Breakpoint 1 at 0x6c70
  (gdb) Function "mkdirat" not defined.
  Breakpoint 2 (mkdirat) pending.
  (gdb) Starting program: /usr/bin/rsync -r --include=/profile.d --exclude=\* localhost:/etc/ ./
  Detaching after fork from child process 15444.
  Detaching after fork from child process 15464.
  
  Breakpoint 1, 0x00007ffff76ee720 in mkdir () from /lib64/libc.so.6
  (gdb) Delete all breakpoints? (y or n) [answered Y; input not from terminal]
  </code></pre>
  
  <p>mkdir argument:</p>
  
  <pre><code>(gdb) $1 = 0x7fffffff9330 "profile.d"
  </code></pre>
  
  <p>previous umask value:</p>
  
  <pre><code>(gdb) $2 = 0
  </code></pre>
  
  <p>result of <code>mkdir("test")</code></p>
  
  <pre><code>(gdb) $3 = 0
  </code></pre>
  
  <p>_</p>
  
  <pre><code>(gdb) Run till exit from #0  0x00007ffff76ee720 in mkdir () from /lib64/libc.so.6
  0x000055555556845f in recv_generator ()
  (gdb) total 8
  drwx------ 2 il il 4096 Jan 28 20:02 profile.d
  drwx------ 2 il il 4096 Jan 28 20:02 test
  (gdb) $4 = 0
  (gdb) Kill the program being debugged? (y or n) [answered Y; input not from terminal]
  rsync: connection unexpectedly closed (31 bytes received so far) [sender]
  rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
  (gdb) quit
  [il@basinsrv ~]$ rsync: connection unexpectedly closed (51 bytes received so far) [receiver]
  rsync error: error in rsync protocol data stream (code 12) at io.c(605) [receiver=3.0.9]
  </code></pre>