Blame docs/reference/glib/html/glib-UNIX-specific-utilities-and-integration.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>UNIX-specific utilities and integration: GLib Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GLib Reference Manual">
Packit ae235b
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
Packit ae235b
<link rel="prev" href="glib-Testing.html" title="Testing">
Packit ae235b
<link rel="next" href="glib-Windows-Compatibility-Functions.html" title="Windows Compatibility Functions">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Top  | 
Packit ae235b
                  Description
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

UNIX-specific utilities and integration

Packit ae235b

UNIX-specific utilities and integration — pipes, signal handling

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_open_pipe ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_set_fd_nonblocking ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
guint
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_signal_add ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
guint
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_signal_add_full ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GSource *
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_signal_source_new ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
(*GUnixFDSourceFunc) ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
guint
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_fd_add ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
guint
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_fd_add_full ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GSource *
Packit ae235b
Packit ae235b
Packit ae235b
g_unix_fd_source_new ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
#define
Packit ae235b
G_UNIX_ERROR
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Includes

Packit ae235b
#include <glib-unix.h>
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Description

Packit ae235b

Most of GLib is intended to be portable; in contrast, this set of

Packit ae235b
functions is designed for programs which explicitly target UNIX,
Packit ae235b
or are using it to build higher level abstractions which would be
Packit ae235b
conditionally compiled if the platform matches G_OS_UNIX.

Packit ae235b

To use these functions, you must explicitly include the

Packit ae235b
"glib-unix.h" header.

Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b

g_unix_open_pipe ()

Packit ae235b
gboolean
Packit ae235b
g_unix_open_pipe (gint *fds,
Packit ae235b
                  gint flags,
Packit ae235b
                  GError **error);
Packit ae235b

Similar to the UNIX pipe() call, but on modern systems like Linux

Packit ae235b
uses the pipe2() system call, which atomically creates a pipe with
Packit ae235b
the configured flags. The only supported flag currently is
Packit ae235b
FD_CLOEXEC. If for example you want to configure O_NONBLOCK, that
Packit ae235b
must still be done separately with fcntl().

Packit ae235b

This function does not take O_CLOEXEC, it takes FD_CLOEXEC as if

Packit ae235b
for fcntl(); these are different on Linux/glibc.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

fds

Packit ae235b

Array of two integers

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

flags

Packit ae235b

Bitfield of file descriptor flags, as for fcntl()

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

error

Packit ae235b

a GError

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE on success, FALSE if not (and errno will be set).

Packit ae235b
Packit ae235b

Since: 2.30

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_set_fd_nonblocking ()

Packit ae235b
gboolean
Packit ae235b
g_unix_set_fd_nonblocking (gint fd,
Packit ae235b
                           gboolean nonblock,
Packit ae235b
                           GError **error);
Packit ae235b

Control the non-blocking state of the given file descriptor,

Packit ae235b
according to nonblock
Packit ae235b
. On most systems this uses O_NONBLOCK, but
Packit ae235b
on some older ones may use O_NDELAY.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

fd

Packit ae235b

A file descriptor

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

nonblock

Packit ae235b

If TRUE, set the descriptor to be non-blocking

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

error

Packit ae235b

a GError

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if successful

Packit ae235b
Packit ae235b

Since: 2.30

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_signal_add ()

Packit ae235b
guint
Packit ae235b
g_unix_signal_add (gint signum,
Packit ae235b
                   GSourceFunc handler,
Packit ae235b
                   gpointer user_data);
Packit ae235b

A convenience function for g_unix_signal_source_new(), which

Packit ae235b
attaches to the default GMainContext.  You can remove the watch
Packit ae235b
using g_source_remove().

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

signum

Packit ae235b

Signal number

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

handler

Packit ae235b

Callback

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

Data for handler

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

An ID (greater than 0) for the event source

Packit ae235b
Packit ae235b

Since: 2.30

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_signal_add_full ()

Packit ae235b
guint
Packit ae235b
g_unix_signal_add_full (gint priority,
Packit ae235b
                        gint signum,
Packit ae235b
                        GSourceFunc handler,
Packit ae235b
                        gpointer user_data,
Packit ae235b
                        GDestroyNotify notify);
Packit ae235b

A convenience function for g_unix_signal_source_new(), which

Packit ae235b
attaches to the default GMainContext.  You can remove the watch
Packit ae235b
using g_source_remove().

Packit ae235b

[rename-to g_unix_signal_add]

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

priority

Packit ae235b

the priority of the signal source. Typically this will be in

Packit ae235b
the range between G_PRIORITY_DEFAULT and G_PRIORITY_HIGH.

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

signum

Packit ae235b

Signal number

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

handler

Packit ae235b

Callback

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

Data for handler

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

notify

Packit ae235b

GDestroyNotify for handler

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

An ID (greater than 0) for the event source

Packit ae235b
Packit ae235b

Since: 2.30

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_signal_source_new ()

Packit ae235b
GSource *
Packit ae235b
g_unix_signal_source_new (gint signum);
Packit ae235b

Create a GSource that will be dispatched upon delivery of the UNIX

Packit ae235b
signal signum
Packit ae235b
.  In GLib versions before 2.36, only SIGHUP, SIGINT,
Packit ae235b
SIGTERM can be monitored.  In GLib 2.36, SIGUSR1 and SIGUSR2
Packit ae235b
were added. In GLib 2.54, SIGWINCH was added.

Packit ae235b

Note that unlike the UNIX default, all sources which have created a

Packit ae235b
watch will be dispatched, regardless of which underlying thread
Packit ae235b
invoked g_unix_signal_source_new().

Packit ae235b

For example, an effective use of this function is to handle SIGTERM

Packit ae235b
cleanly; flushing any outstanding files, and then calling
Packit ae235b
g_main_loop_quit().  It is not safe to do any of this a regular
Packit ae235b
UNIX signal handler; your handler may be invoked while malloc() or
Packit ae235b
another library function is running, causing reentrancy if you
Packit ae235b
attempt to use it from the handler.  None of the GLib/GObject API
Packit ae235b
is safe against this kind of reentrancy.

Packit ae235b

The interaction of this source when combined with native UNIX

Packit ae235b
functions like sigprocmask() is not defined.

Packit ae235b

The source will not initially be associated with any GMainContext

Packit ae235b
and must be added to one with g_source_attach() before it will be
Packit ae235b
executed.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

signum

Packit ae235b

A signal number

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

A newly created GSource

Packit ae235b
Packit ae235b

Since: 2.30

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

GUnixFDSourceFunc ()

Packit ae235b
gboolean
Packit ae235b
(*GUnixFDSourceFunc) (gint fd,
Packit ae235b
                      GIOCondition condition,
Packit ae235b
                      gpointer user_data);
Packit ae235b

The type of functions to be called when a UNIX fd watch source

Packit ae235b
triggers.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

fd

Packit ae235b

the fd that triggered the event

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

condition

Packit ae235b

the IO conditions reported on fd

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

user data passed to g_unix_fd_add()

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

FALSE if the source should be removed

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_fd_add ()

Packit ae235b
guint
Packit ae235b
g_unix_fd_add (gint fd,
Packit ae235b
               GIOCondition condition,
Packit ae235b
               GUnixFDSourceFunc function,
Packit ae235b
               gpointer user_data);
Packit ae235b

Sets a function to be called when the IO condition, as specified by

Packit ae235b
condition
Packit ae235b
 becomes true for fd
Packit ae235b
.

Packit ae235b

function

Packit ae235b
 will be called when the specified IO condition becomes
Packit ae235b
TRUE.  The function is expected to clear whatever event caused the
Packit ae235b
IO condition to become true and return TRUE in order to be notified
Packit ae235b
when it happens again.  If function
Packit ae235b
 returns FALSE then the watch
Packit ae235b
will be cancelled.

Packit ae235b

The return value of this function can be passed to g_source_remove()

Packit ae235b
to cancel the watch at any time that it exists.

Packit ae235b

The source will never close the fd -- you must do it yourself.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

fd

Packit ae235b

a file descriptor

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

condition

Packit ae235b

IO conditions to watch for on fd

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

function

Packit ae235b

a GUnixFDSourceFunc

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

data to pass to function

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the ID (greater than 0) of the event source

Packit ae235b
Packit ae235b

Since: 2.36

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_fd_add_full ()

Packit ae235b
guint
Packit ae235b
g_unix_fd_add_full (gint priority,
Packit ae235b
                    gint fd,
Packit ae235b
                    GIOCondition condition,
Packit ae235b
                    GUnixFDSourceFunc function,
Packit ae235b
                    gpointer user_data,
Packit ae235b
                    GDestroyNotify notify);
Packit ae235b

Sets a function to be called when the IO condition, as specified by

Packit ae235b
condition
Packit ae235b
 becomes true for fd
Packit ae235b
.

Packit ae235b

This is the same as g_unix_fd_add(), except that it allows you to

Packit ae235b
specify a non-default priority and a provide a GDestroyNotify for
Packit ae235b
user_data
Packit ae235b
.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

priority

Packit ae235b

the priority of the source

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

fd

Packit ae235b

a file descriptor

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

condition

Packit ae235b

IO conditions to watch for on fd

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

function

Packit ae235b

a GUnixFDSourceFunc

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

data to pass to function

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

notify

Packit ae235b

function to call when the idle is removed, or NULL

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the ID (greater than 0) of the event source

Packit ae235b
Packit ae235b

Since: 2.36

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_unix_fd_source_new ()

Packit ae235b
GSource *
Packit ae235b
g_unix_fd_source_new (gint fd,
Packit ae235b
                      GIOCondition condition);
Packit ae235b

Creates a GSource to watch for a particular IO condition on a file

Packit ae235b
descriptor.

Packit ae235b

The source will never close the fd -- you must do it yourself.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

fd

Packit ae235b

a file descriptor

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

condition

Packit ae235b

IO conditions to watch for on fd

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the newly created GSource

Packit ae235b
Packit ae235b

Since: 2.36

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b

G_UNIX_ERROR

Packit ae235b
#define G_UNIX_ERROR (g_unix_error_quark())
Packit ae235b
Packit ae235b

Error domain for API in the g_unix_ namespace. Note that there is no

Packit ae235b
exported enumeration mapping errno. Instead, all functions ensure that
Packit ae235b
errno is relevant. The code for all G_UNIX_ERROR is always 0, and the
Packit ae235b
error message is always generated via g_strerror().

Packit ae235b

It is expected that most code will not look at errno from these APIs.

Packit ae235b
Important cases where one would want to differentiate between errors are
Packit ae235b
already covered by existing cross-platform GLib API, such as e.g. GFile
Packit ae235b
wrapping ENOENT. However, it is provided for completeness, at least.

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Generated by GTK-Doc V1.27
Packit ae235b
</body>
Packit ae235b
</html>