)]}'
{
  "commit": "4a19542e5f694cd408a32c3d9dc593ba9366e2d7",
  "tree": "12f5fd603b516b4e24ec4850d5589273d24be569",
  "parents": [
    "f23513e8d96cf5e6cf8d2ff0cb5dd6bbc33995e4"
  ],
  "author": {
    "name": "Ulrich Drepper",
    "email": "drepper@redhat.com",
    "time": "Sun Jul 15 23:40:34 2007 -0700"
  },
  "committer": {
    "name": "Linus Torvalds",
    "email": "torvalds@woody.linux-foundation.org",
    "time": "Mon Jul 16 09:05:45 2007 -0700"
  },
  "message": "O_CLOEXEC for SCM_RIGHTS\n\nPart two in the O_CLOEXEC saga: adding support for file descriptors received\nthrough Unix domain sockets.\n\nThe patch is once again pretty minimal, it introduces a new flag for recvmsg\nand passes it just like the existing MSG_CMSG_COMPAT flag.  I think this bit\nis not used otherwise but the networking people will know better.\n\nThis new flag is not recognized by recvfrom and recv.  These functions cannot\nbe used for that purpose and the asymmetry this introduces is not worse than\nthe already existing MSG_CMSG_COMPAT situations.\n\nThe patch must be applied on the patch which introduced O_CLOEXEC.  It has to\nremove static from the new get_unused_fd_flags function but since scm.c cannot\nlive in a module the function still hasn\u0027t to be exported.\n\nHere\u0027s a test program to make sure the code works.  It\u0027s so much longer than\nthe actual patch...\n\n#include \u003cerrno.h\u003e\n#include \u003cerror.h\u003e\n#include \u003cfcntl.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cunistd.h\u003e\n#include \u003csys/socket.h\u003e\n#include \u003csys/un.h\u003e\n\n#ifndef O_CLOEXEC\n# define O_CLOEXEC 02000000\n#endif\n#ifndef MSG_CMSG_CLOEXEC\n# define MSG_CMSG_CLOEXEC 0x40000000\n#endif\n\nint\nmain (int argc, char *argv[])\n{\n  if (argc \u003e 1)\n    {\n      int fd \u003d atol (argv[1]);\n      printf (\"child: fd \u003d %d\\n\", fd);\n      if (fcntl (fd, F_GETFD) \u003d\u003d 0 || errno !\u003d EBADF)\n        {\n          puts (\"file descriptor valid in child\");\n          return 1;\n        }\n      return 0;\n\n    }\n\n  struct sockaddr_un sun;\n  strcpy (sun.sun_path, \"./testsocket\");\n  sun.sun_family \u003d AF_UNIX;\n\n  char databuf[] \u003d \"hello\";\n  struct iovec iov[1];\n  iov[0].iov_base \u003d databuf;\n  iov[0].iov_len \u003d sizeof (databuf);\n\n  union\n  {\n    struct cmsghdr hdr;\n    char bytes[CMSG_SPACE (sizeof (int))];\n  } buf;\n  struct msghdr msg \u003d { .msg_iov \u003d iov, .msg_iovlen \u003d 1,\n                        .msg_control \u003d buf.bytes,\n                        .msg_controllen \u003d sizeof (buf) };\n  struct cmsghdr *cmsg \u003d CMSG_FIRSTHDR (\u0026msg);\n\n  cmsg-\u003ecmsg_level \u003d SOL_SOCKET;\n  cmsg-\u003ecmsg_type \u003d SCM_RIGHTS;\n  cmsg-\u003ecmsg_len \u003d CMSG_LEN (sizeof (int));\n\n  msg.msg_controllen \u003d cmsg-\u003ecmsg_len;\n\n  pid_t child \u003d fork ();\n  if (child \u003d\u003d -1)\n    error (1, errno, \"fork\");\n  if (child \u003d\u003d 0)\n    {\n      int sock \u003d socket (PF_UNIX, SOCK_STREAM, 0);\n      if (sock \u003c 0)\n        error (1, errno, \"socket\");\n\n      if (bind (sock, (struct sockaddr *) \u0026sun, sizeof (sun)) \u003c 0)\n        error (1, errno, \"bind\");\n      if (listen (sock, SOMAXCONN) \u003c 0)\n        error (1, errno, \"listen\");\n\n      int conn \u003d accept (sock, NULL, NULL);\n      if (conn \u003d\u003d -1)\n        error (1, errno, \"accept\");\n\n      *(int *) CMSG_DATA (cmsg) \u003d sock;\n      if (sendmsg (conn, \u0026msg, MSG_NOSIGNAL) \u003c 0)\n        error (1, errno, \"sendmsg\");\n\n      return 0;\n    }\n\n  /* For a test suite this should be more robust like a\n     barrier in shared memory.  */\n  sleep (1);\n\n  int sock \u003d socket (PF_UNIX, SOCK_STREAM, 0);\n  if (sock \u003c 0)\n    error (1, errno, \"socket\");\n\n  if (connect (sock, (struct sockaddr *) \u0026sun, sizeof (sun)) \u003c 0)\n    error (1, errno, \"connect\");\n  unlink (sun.sun_path);\n\n  *(int *) CMSG_DATA (cmsg) \u003d -1;\n\n  if (recvmsg (sock, \u0026msg, MSG_CMSG_CLOEXEC) \u003c 0)\n    error (1, errno, \"recvmsg\");\n\n  int fd \u003d *(int *) CMSG_DATA (cmsg);\n  if (fd \u003d\u003d -1)\n    error (1, 0, \"no descriptor received\");\n\n  char fdname[20];\n  snprintf (fdname, sizeof (fdname), \"%d\", fd);\n  execl (\"/proc/self/exe\", argv[0], fdname, NULL);\n  puts (\"execl failed\");\n  return 1;\n}\n\n[akpm@linux-foundation.org: Fix fastcall inconsistency noted by Michael Buesch]\n[akpm@linux-foundation.org: build fix]\nSigned-off-by: Ulrich Drepper \u003cdrepper@redhat.com\u003e\nCc: Ingo Molnar \u003cmingo@elte.hu\u003e\nCc: Michael Buesch \u003cmb@bu3sch.de\u003e\nCc: Michael Kerrisk \u003cmtk-manpages@gmx.net\u003e\nAcked-by: David S. Miller \u003cdavem@davemloft.net\u003e\nSigned-off-by: Andrew Morton \u003cakpm@linux-foundation.org\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@linux-foundation.org\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "e6991c1b587432109c3b7e99cef941d62ba9b57b",
      "old_mode": 33188,
      "old_path": "fs/open.c",
      "new_id": "be6a457f4226374b9d462cd8ee4332326ea22097",
      "new_mode": 33188,
      "new_path": "fs/open.c"
    },
    {
      "type": "modify",
      "old_id": "a59001e9ea58bb2cd91c999d6b0f9dba6ac06f7e",
      "old_mode": 33188,
      "old_path": "include/linux/file.h",
      "new_id": "0114fbc78061249fc765e8197fb06f5a512a6ea9",
      "new_mode": 33188,
      "new_path": "include/linux/file.h"
    },
    {
      "type": "modify",
      "old_id": "fe195c97a89d9d00346312b8c79fb11ed818c0bf",
      "old_mode": 33188,
      "old_path": "include/linux/socket.h",
      "new_id": "f852e1afd65a74ee34400b7bc4d9ef668d38a62c",
      "new_mode": 33188,
      "new_path": "include/linux/socket.h"
    },
    {
      "type": "modify",
      "old_id": "9a0f5f2b90c80653acbe2282d3820e8502307429",
      "old_mode": 33188,
      "old_path": "net/compat.c",
      "new_id": "d74d82155d78e20cd008a289751bcaca70b27f7a",
      "new_mode": 33188,
      "new_path": "net/compat.c"
    },
    {
      "type": "modify",
      "old_id": "292ad8d5ad76262c46fc33248376cd0401658722",
      "old_mode": 33188,
      "old_path": "net/core/scm.c",
      "new_id": "44c4ec2c8769b1a922d69a6f0e5882bc6f58f001",
      "new_mode": 33188,
      "new_path": "net/core/scm.c"
    },
    {
      "type": "modify",
      "old_id": "f4530196a70a30c10f87450ad47bdfaa9e28f925",
      "old_mode": 33188,
      "old_path": "net/socket.c",
      "new_id": "b7111425004656a3e35be074a2372af43da29e6c",
      "new_mode": 33188,
      "new_path": "net/socket.c"
    }
  ]
}
