gsocket: Don't g_error() if file-descriptor is not a socket
authorStef Walter <stefw@redhat.com>
Tue, 17 Mar 2015 12:06:02 +0000 (13:06 +0100)
committerStef Walter <stefw@redhat.com>
Thu, 2 Jul 2015 10:24:11 +0000 (12:24 +0200)
This code was out of date with current coding practices.

Nowadays it's common to receive file descriptors over environment
variables from other processes like systemd. The unit files that
control these file descriptors are configurable by sysadmins.

It is not (necessarily) a programmer error when g_socket_details_from_fd()
is called with a file descriptor that is not a socket. It can also
be a system and/or configuration error.

https://bugzilla.gnome.org/show_bug.cgi?id=746339

gio/gsocket.c

index 7d6e91d..6856d0e 100644 (file)
@@ -318,24 +318,6 @@ g_socket_details_from_fd (GSocket *socket)
   if (!g_socket_get_option (socket, SOL_SOCKET, SO_TYPE, &value, NULL))
     {
       errsv = get_socket_errno ();
-
-      switch (errsv)
-       {
-#ifdef ENOTSOCK
-        case ENOTSOCK:
-#else
-#ifdef WSAENOTSOCK
-        case WSAENOTSOCK:
-#endif
-#endif
-        case EBADF:
-         /* programmer error */
-         g_error ("creating GSocket from fd %d: %s\n",
-                  fd, socket_strerror (errsv));
-        default:
-          break;
-       }
-
       goto err;
     }
 
@@ -1060,6 +1042,9 @@ g_socket_new (GSocketFamily     family,
  * On success, the returned #GSocket takes ownership of @fd. On failure, the
  * caller must close @fd themselves.
  *
+ * Since GLib 2.46, it is no longer a fatal error to call this on a non-socket
+ * descriptor.  Instead, a GError will be set with code %G_IO_ERROR_FAILED
+ *
  * Returns: a #GSocket or %NULL on error.
  *     Free the returned object with g_object_unref().
  *