gskfork

gskfork — Functions to call to clean up after forking.

Synopsis




int         (*GskForkFunc)                  (gpointer data);
gint        gsk_fork                        (GskForkFunc action,
                                             gpointer data,
                                             GError **error);
void        gsk_fork_add_cleanup_fd         (int fd);
void        gsk_fork_remove_cleanup_fd      (int fd);
void        gsk_fork_child_cleanup          (void);

Description

This provides a way to register file descriptors that should be closed by the background thread. It also contains a gsk-like wrapper to fork.. that is, a callback oriented fork interface.

Details

GskForkFunc ()

int         (*GskForkFunc)                  (gpointer data);

Function to call from the background process.

data : data passed through gsk_fork().
Returns : the exit status of this process.

gsk_fork ()

gint        gsk_fork                        (GskForkFunc action,
                                             gpointer data,
                                             GError **error);

Fork a new thread, cleaning up loose file-descriptors, then running the background function, and exiting with the return value of the background function.

action : function to call from the background process.
data : user-data to pass to action.
error : optional place to errors to be put.
Returns : the process-id of the background thread, or -1 on error.

gsk_fork_add_cleanup_fd ()

void        gsk_fork_add_cleanup_fd         (int fd);

Add a file-descriptor to the list that should be closed when fork() is run.

A file-descriptor must only be added once.

fd : a file descriptor that should be closed from a background thread.

gsk_fork_remove_cleanup_fd ()

void        gsk_fork_remove_cleanup_fd      (int fd);

Remove a file-descriptor from the list that should be closed when fork() is run.

fd : remove a file descriptor that was previously registered to be closed on fork with gsk_fork_add_cleanup_fd().

gsk_fork_child_cleanup ()

void        gsk_fork_child_cleanup          (void);

Do all cleanup that should follow a fork(2) system call from the child process.