| Mercury Monitor Reference Manual |
|---|
Inter-Process CommunicationInter-Process Communication — Local authentication and shared memory management |
#include <monitor/monitor.h>
mon_ipc_creds;
#define MON_IPC_PID_UNKNOWN
#define MON_IPC_GID_UNKNOWN
int mon_ipc_auth_client_init (int fd,
void **state);
void mon_ipc_auth_client_end (void *state);
int mon_ipc_auth_client_step (int fd,
void *state);
int mon_ipc_auth_server_init (int fd,
mon_ipc_creds *creds,
void **state);
void mon_ipc_auth_server_end (void *state);
int mon_ipc_auth_server_step (int fd,
void *state);
int mon_ipc_recv_fd (int source_fd,
mon_buffer *dst,
int *fd_received);
int mon_ipc_send_fd (int target_fd,
mon_buffer *src,
int fd_to_send);
typedef struct {
pid_t pid;
uid_t uid;
gid_t gid;
} mon_ipc_creds;
Structure describing process credentials.
| pid_t pid; | the process ID. |
| uid_t uid; | the effective user ID. |
| gid_t gid; | the effective group ID. |
#define MON_IPC_PID_UNKNOWN ((pid_t)0)
Value used when the process ID could not be determined.
#define MON_IPC_GID_UNKNOWN ((gid_t)-1)
Value used when the group ID could not be determined.
int mon_ipc_auth_client_init (int fd,
void **state);Initialize local authentication on the client side. Returns 0 if no further action needed, MON_CONTINUE if further steps are neccessary, or an error code. If MON_CONTINUE is returned, state contains an opaque pointer containing information about the internal state of authentication.
| fd : | file descriptor to authenticate. |
| state : | authentication state. |
| Returns : | 0 if succesful, MON_CONTINUE if more steps needed or an error code. |
void mon_ipc_auth_client_end (void *state);
Free the internal client authentication state.
| state : | the authentication state. |
int mon_ipc_auth_client_step (int fd,
void *state);Performs the next step of client authentication.
| fd : | the file descriptor to authenticate. |
| state : | the internal authentication state. |
| Returns : | If 0 is returned, the authentication was successful. If MON_CONTINUE is returned, the function must be called again. If fd is a non-blocking socket, MON_WANT_READ or MON_WANT_WRITE might be returned indicating that the function must be called again when the file descriptor is available for reading or writing respectively. Any other returned value indicates an authentication failure. |
int mon_ipc_auth_server_init (int fd,
mon_ipc_creds *creds,
void **state);Initialize local authentication on the server side. Returns 0 if no further action needed, MON_CONTINUE if further steps are neccessary, or an error code. If MON_CONTINUE is returned, state contains an opaque pointer containing information about the internal state of authentication.
| fd : | file descriptor to authenticate. |
| creds : | pointer to a mon_ipc_creds structure which will hold the peer's credentials if the authentication is successful. |
| state : | authentication state. |
| Returns : | 0 if succesful, MON_CONTINUE if more steps needed or an error code. |
void mon_ipc_auth_server_end (void *state);
Free the internal server authentication state.
| state : | the authentication state. |
int mon_ipc_auth_server_step (int fd,
void *state);Performs the next step of client authentication.
| fd : | the file descriptor to authenticate. |
| state : | the internal authentication state. |
| Returns : | If 0 is returned, the authentication was successful. If MON_CONTINUE is returned, the function must be called again. If fd is a non-blocking socket, MON_WANT_READ or MON_WANT_WRITE might be returned indicating that the function must be called again when the file descriptor is available for reading or writing respectively. Any other returned value indicates an authentication failure. |
int mon_ipc_recv_fd (int source_fd,
mon_buffer *dst,
int *fd_received);Receives data from a local process. This function handles receiving of file descriptors too.
| source_fd : | a UNIX domain socket. |
| dst : | a mon_buffer to store received data at. |
| fd_received : | contains the received file descriptor or -1 if the other process did not send any. |
| Returns : | 0 if successful or an error code. |
int mon_ipc_send_fd (int target_fd,
mon_buffer *src,
int fd_to_send);Sends data together with a file descriptor to a local process through an UNIX domain socket.
| target_fd : | a UNIX domain socket. |
| src : | a mon_buffer with the data to send. |
| fd_to_send : | the file descriptor to send. |
| Returns : | 0 if successful or an error code. |
| << IO Event Handling | Logging >> |