cvmfs/util/posix.cc
int MakeSocket(const string &path, const int mode) {
  struct sockaddr_un sock_addr;
  assert(path.length() < sizeof(sock_addr.sun_path));
  sock_addr.sun_family = AF_UNIX;
  strncpy(sock_addr.sun_path, path.c_str(), sizeof(sock_addr.sun_path));

  const int socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
  assert(socket_fd != -1);

#ifndef __APPLE__
  // fchmod on a socket is not allowed under Mac OS X
  // using default 0770 here
  if (fchmod(socket_fd, mode) != 0)
    goto make_socket_failure;
#endif

  if (bind(socket_fd, (struct sockaddr *)&sock_addr,
           sizeof(sock_addr.sun_family) + sizeof(sock_addr.sun_path)) < 0)
  {
    if ((errno == EADDRINUSE) && (unlink(path.c_str()) == 0)) {
      // Second try, perhaps the file was left over
      if (bind(socket_fd, (struct sockaddr *)&sock_addr,
               sizeof(sock_addr.sun_family) + sizeof(sock_addr.sun_path)) < 0)
      {
        LogCvmfs(kLogCvmfs, kLogDebug, "binding socket failed (%d)", errno);
        goto make_socket_failure;
      }
    } else {
      LogCvmfs(kLogCvmfs, kLogDebug, "binding socket failed (%d)", errno);
      goto make_socket_failure;
    }
  }

  return socket_fd;

 make_socket_failure:
  close(socket_fd);
  return -1;
}
/**
 * Creates and binds to a named socket.
 */
Creates and binds to a named socket.
Creates and binds to a named socket .
int MakeSocket(const string &path, const int mode) {
  struct sockaddr_un sock_addr;
  assert(path.length() < sizeof(sock_addr.sun_path));
  sock_addr.sun_family = AF_UNIX;
  strncpy(sock_addr.sun_path, path.c_str(), sizeof(sock_addr.sun_path));
  const int socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
  assert(socket_fd != -1);
#ifndef __APPLE__
  if (fchmod(socket_fd, mode) != 0)
    goto make_socket_failure;
#endif
  if (bind(socket_fd, (struct sockaddr *)&sock_addr,
           sizeof(sock_addr.sun_family) + sizeof(sock_addr.sun_path)) < 0)
  {
    if ((errno == EADDRINUSE) && (unlink(path.c_str()) == 0)) {
      if (bind(socket_fd, (struct sockaddr *)&sock_addr,
               sizeof(sock_addr.sun_family) + sizeof(sock_addr.sun_path)) < 0)
      {
        LogCvmfs(kLogCvmfs, kLogDebug, "binding socket failed (%d)", errno);
        goto make_socket_failure;
      }
    } else {
      LogCvmfs(kLogCvmfs, kLogDebug, "binding socket failed (%d)", errno);
      goto make_socket_failure;
    }
  }
  return socket_fd;
 make_socket_failure:
  close(socket_fd);
  return -1;
}
int MakeSocket ( const string & path , const int mode ) { struct sockaddr_un sock_addr ; assert ( path . length ( ) < sizeof ( sock_addr . sun_path ) ) ; sock_addr . sun_family = AF_UNIX ; strncpy ( sock_addr . sun_path , path . c_str ( ) , sizeof ( sock_addr . sun_path ) ) ; const int socket_fd = socket ( AF_UNIX , SOCK_STREAM , 0 ) ; assert ( socket_fd != -1 ) ; #ifndef __APPLE__ if ( fchmod ( socket_fd , mode ) != 0 ) goto make_socket_failure ; #endif if ( bind ( socket_fd , ( struct sockaddr * ) & sock_addr , sizeof ( sock_addr . sun_family ) + sizeof ( sock_addr . sun_path ) ) < 0 ) { if ( ( errno == EADDRINUSE ) && ( unlink ( path . c_str ( ) ) == 0 ) ) { if ( bind ( socket_fd , ( struct sockaddr * ) & sock_addr , sizeof ( sock_addr . sun_family ) + sizeof ( sock_addr . sun_path ) ) < 0 ) { LogCvmfs ( kLogCvmfs , kLogDebug , " " , errno ) ; goto make_socket_failure ; } } else { LogCvmfs ( kLogCvmfs , kLogDebug , " " , errno ) ; goto make_socket_failure ; } } return socket_fd ; make_socket_failure : close ( socket_fd ) ; return -1 ; }
Creates and binds to a named socket.
Creates and binds to a named socket .
// fchmod on a socket is not allowed under Mac OS X // using default 0770 here // Second try, perhaps the file was left over