UnixUtils

Most of GLib is intended to be portable; in contrast, this set of functions is designed for programs which explicitly target UNIX, or are using it to build higher level abstractions which would be conditionally compiled if the platform matches G_OS_UNIX.

To use these functions, you must explicitly include the "glib-unix.h" header.

Members

Static functions

fdAdd
uint fdAdd(int fd, GIOCondition condition, GUnixFDSourceFunc funct, void* userData)

Sets a function to be called when the IO condition, as specified by condition becomes true for fd. function will be called when the specified IO condition becomes TRUE. The function is expected to clear whatever event caused the IO condition to become true and return TRUE in order to be notified when it happens again. If function returns FALSE then the watch will be cancelled. The return value of this function can be passed to g_source_remove() to cancel the watch at any time that it exists. The source will never close the fd -- you must do it yourself. Since 2.36

fdAddFull
uint fdAddFull(int priority, int fd, GIOCondition condition, GUnixFDSourceFunc funct, void* userData, GDestroyNotify notify)

Sets a function to be called when the IO condition, as specified by condition becomes true for fd. This is the same as g_unix_fd_add(), except that it allows you to specify a non-default priority and a provide a GDestroyNotify for user_data. Since 2.36

fdSourceNew
Source fdSourceNew(int fd, GIOCondition condition)

Creates a GSource to watch for a particular IO condition on a file descriptor. The source will never close the fd -- you must do it yourself. Since 2.36

openPipe
int openPipe(int[] fds, int flags)

Similar to the UNIX pipe() call, but on modern systems like Linux uses the pipe2() system call, which atomically creates a pipe with the configured flags. The only supported flag currently is FD_CLOEXEC. If for example you want to configure O_NONBLOCK, that must still be done separately with fcntl(). Note This function does *not* take O_CLOEXEC, it takes FD_CLOEXEC as if for fcntl(); these are different on Linux/glibc. Since 2.30

setFdNonblocking
int setFdNonblocking(int fd, int nonblock)

Control the non-blocking state of the given file descriptor, according to nonblock. On most systems this uses O_NONBLOCK, but on some older ones may use O_NDELAY. Since 2.30

signalAdd
uint signalAdd(int signum, GSourceFunc handler, void* userData)

A convenience function for g_unix_signal_source_new(), which attaches to the default GMainContext. You can remove the watch using g_source_remove(). Since 2.30

signalAddFull
uint signalAddFull(int priority, int signum, GSourceFunc handler, void* userData, GDestroyNotify notify)

A convenience function for g_unix_signal_source_new(), which attaches to the default GMainContext. You can remove the watch using g_source_remove(). Since 2.30

signalSourceNew
Source signalSourceNew(int signum)

Create a GSource that will be dispatched upon delivery of the UNIX signal signum. In GLib versions before 2.36, only SIGHUP, SIGINT, SIGTERM can be monitored. In GLib 2.36, SIGUSR1 and SIGUSR2 were added. Note that unlike the UNIX default, all sources which have created a watch will be dispatched, regardless of which underlying thread invoked g_unix_signal_source_new(). For example, an effective use of this function is to handle SIGTERM cleanly; flushing any outstanding files, and then calling g_main_loop_quit(). It is not safe to do any of this a regular UNIX signal handler; your handler may be invoked while malloc() or another library function is running, causing reentrancy if you attempt to use it from the handler. None of the GLib/GObject API is safe against this kind of reentrancy. The interaction of this source when combined with native UNIX functions like sigprocmask() is not defined. The source will not initially be associated with any GMainContext and must be added to one with g_source_attach() before it will be executed. Since 2.30

Meta