GSettings: fix check for delaying backend subscription
[platform/upstream/glib.git] / gio / gunixconnection.c
index d5d8ec0..b5da60a 100644 (file)
  */
 
 #include "config.h"
+
 #include "gunixconnection.h"
+#include "gnetworking.h"
+#include "gsocket.h"
+#include "gsocketcontrolmessage.h"
 #include "gunixcredentialsmessage.h"
+#include "gunixfdmessage.h"
 #include "glibintl.h"
 
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
 /**
  * SECTION:gunixconnection
  * @title: GUnixConnection
  * It contains functions to do some of the UNIX socket specific
  * functionality like passing file descriptors.
  *
- * Note that <filename>&lt;gio/gunixconnection.h&gt;</filename> belongs to
- * the UNIX-specific GIO interfaces, thus you have to use the
- * <filename>gio-unix-2.0.pc</filename> pkg-config file when using it.
+ * Note that `<gio/gunixconnection.h>` belongs to the UNIX-specific
+ * GIO interfaces, thus you have to use the `gio-unix-2.0.pc`
+ * pkg-config file when using it.
  *
  * Since: 2.22
  */
 
-#include <gio/gsocketcontrolmessage.h>
-#include <gio/gunixfdmessage.h>
-#include <gio/gsocket.h>
-#include <unistd.h>
-
-#ifdef __linux__
-/* for getsockopt() and setsockopt() */
-#include <sys/types.h>          /* See NOTES */
-#include <sys/socket.h>
-#include <errno.h>
-#include <string.h>
-#endif
-
-
 G_DEFINE_TYPE_WITH_CODE (GUnixConnection, g_unix_connection,
                         G_TYPE_SOCKET_CONNECTION,
   g_socket_connection_factory_register_type (g_define_type_id,
@@ -161,7 +156,10 @@ g_unix_connection_receive_fd (GUnixConnection  *connection,
       gint i;
 
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                  _("Expecting 1 control message, got %d"), nscm);
+        ngettext("Expecting 1 control message, got %d",
+                 "Expecting 1 control message, got %d",
+                 nscm),
+        nscm);
 
       for (i = 0; i < nscm; i++)
         g_object_unref (scms[i]);
@@ -192,7 +190,10 @@ g_unix_connection_receive_fd (GUnixConnection  *connection,
       gint i;
 
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                  _("Expecting one fd, but got %d\n"), nfd);
+                   ngettext("Expecting one fd, but got %d\n",
+                            "Expecting one fd, but got %d\n",
+                            nfd),
+                   nfd);
 
       for (i = 0; i < nfd; i++)
         close (fds[i]);
@@ -480,16 +481,14 @@ g_unix_connection_receive_credentials (GUnixConnection      *connection,
 #ifdef __linux__
   {
     gint opt_val;
-    socklen_t opt_len;
 
     turn_off_so_passcreds = FALSE;
     opt_val = 0;
-    opt_len = sizeof (gint);
-    if (getsockopt (g_socket_get_fd (socket),
-                    SOL_SOCKET,
-                    SO_PASSCRED,
-                    &opt_val,
-                    &opt_len) != 0)
+    if (!g_socket_get_option (socket,
+                             SOL_SOCKET,
+                             SO_PASSCRED,
+                             &opt_val,
+                             NULL))
       {
         g_set_error (error,
                      G_IO_ERROR,
@@ -498,24 +497,13 @@ g_unix_connection_receive_credentials (GUnixConnection      *connection,
                      strerror (errno));
         goto out;
       }
-    if (opt_len != sizeof (gint))
-      {
-        g_set_error (error,
-                     G_IO_ERROR,
-                     G_IO_ERROR_FAILED,
-                     _("Unexpected option length while checking if SO_PASSCRED is enabled for socket. "
-                       "Expected %d bytes, got %d"),
-                     (gint) sizeof (gint), (gint) opt_len);
-        goto out;
-      }
     if (opt_val == 0)
       {
-        opt_val = 1;
-        if (setsockopt (g_socket_get_fd (socket),
-                        SOL_SOCKET,
-                        SO_PASSCRED,
-                        &opt_val,
-                        sizeof opt_val) != 0)
+        if (!g_socket_set_option (socket,
+                                 SOL_SOCKET,
+                                 SO_PASSCRED,
+                                 TRUE,
+                                 NULL))
           {
             g_set_error (error,
                          G_IO_ERROR,
@@ -563,7 +551,9 @@ g_unix_connection_receive_credentials (GUnixConnection      *connection,
           g_set_error (error,
                        G_IO_ERROR,
                        G_IO_ERROR_FAILED,
-                       _("Expecting 1 control message, got %d"),
+                       ngettext("Expecting 1 control message, got %d",
+                                "Expecting 1 control message, got %d",
+                                nscm),
                        nscm);
           goto out;
         }
@@ -602,13 +592,11 @@ g_unix_connection_receive_credentials (GUnixConnection      *connection,
 #ifdef __linux__
   if (turn_off_so_passcreds)
     {
-      gint opt_val;
-      opt_val = 0;
-      if (setsockopt (g_socket_get_fd (socket),
-                      SOL_SOCKET,
-                      SO_PASSCRED,
-                      &opt_val,
-                      sizeof opt_val) != 0)
+      if (!g_socket_set_option (socket,
+                               SOL_SOCKET,
+                               SO_PASSCRED,
+                               FALSE,
+                               NULL))
         {
           g_set_error (error,
                        G_IO_ERROR,