*/
#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><gio/gunixconnection.h></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/gnetworking.h>
-#include <gio/gsocket.h>
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-
G_DEFINE_TYPE_WITH_CODE (GUnixConnection, g_unix_connection,
G_TYPE_SOCKET_CONNECTION,
g_socket_connection_factory_register_type (g_define_type_id,
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]);
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]);
#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,
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,
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;
}
#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,