netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
server_child.c File Reference

functions to handle child processes More...

`#include <errno.h>`
`#include <pthread.h>`
`#include <signal.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/time.h>`
`#include <sys/types.h>`
`#include <sys/wait.h>`
`#include <unistd.h>`
`#include <atalk/compat.h>`
`#include <atalk/constant_time.h>`
`#include <atalk/errchk.h>`
`#include <atalk/logger.h>`
`#include <atalk/server_child.h>`
`#include <atalk/util.h>`

## Macros
#define | WEXITSTATUS(stat_val)
#define | WIFEXITED(stat_val)
#define | WIFSTOPPED(status)
#define | WIFSIGNALED(status)
#define | WTERMSIG(status)
#define | HASH(i)

## Functions
static void | hash_child (afp_child_t **htable, afp_child_t *child)
static void | unhash_child (afp_child_t *child)
afp_child_t * | server_child_resolve (server_child_t *childs, id_t pid)
server_child_t * | server_child_alloc (int connections)
afp_child_t * | server_child_add (server_child_t *children, pid_t pid, int ipc_fd, int hint_fd)
| add a child
int | server_child_remove (server_child_t *children, pid_t pid)
void | server_child_free (server_child_t *children)
| free everything
void | server_child_kill (server_child_t *children, int sig)
static int | kill_child (afp_child_t *child)
int | server_child_set_session_token (server_child_t *children, pid_t pid, uid_t uid, const void *token, size_t token_len)
| Store an opaque reconnect token for a child session.
int | server_child_transfer_session (server_child_t *children, uid_t uid, const void *token, size_t token_len, int afp_socket, uint16_t DSI_requestID)
| Try to find an old session and pass socket.
void | server_child_kill_one_by_id (server_child_t *children, pid_t pid, uid_t uid, uint32_t idlen, char *id, uint32_t boottime)
| see if there is a process for the same mac
void | server_child_login_done (server_child_t *children, pid_t pid, uid_t uid, const char *client_address)
void | server_reset_signal (void)

## Detailed Description

functions to handle child processes

handle inserting, removing, and freeing of children. this does it via a hash table. it incurs some overhead over a linear append/remove in total removal and kills, but it makes single-entry removals a fast operation. as total removals occur during child initialization and kills during server shutdown, this is probably a win for a lot of connections and unimportant for a small number of connections.

## Macro Definition Documentation

## ◆ HASH

#define HASH | ( |  | i | ) |

Value:
((((i) >> 8) ^ (i)) & (CHILD_HASHSIZE - 1))
CHILD_HASHSIZE
#define CHILD_HASHSIZE
Definition server_child.h:20

## ◆ WEXITSTATUS

#define WEXITSTATUS | ( |  | stat_val | ) |

Value:
((unsigned)(stat_val) >> 8)

## ◆ WIFEXITED

#define WIFEXITED | ( |  | stat_val | ) |

Value:
(((stat_val) & 255) == 0)

## ◆ WIFSIGNALED

#define WIFSIGNALED | ( |  | status | ) |

Value:
(!WIFSTOPPED(status) && !WIFEXITED(status))
WIFEXITED
#define WIFEXITED(stat_val)
Definition cnid_metad.c:60
WIFSTOPPED
#define WIFSTOPPED(status)
Definition cnid_metad.c:63
status
static char * status
Definition pap.c:93

## ◆ WIFSTOPPED

#define WIFSTOPPED | ( |  | status | ) |

Value:
(((status) & 0xff) == 0x7f)

## ◆ WTERMSIG

#define WTERMSIG | ( |  | status | ) |

Value:
((status) & 0x7f)

## Function Documentation

## ◆ hash_child()

void hash_child | ( | afp_child_t ** | htable,
|  | afp_child_t * | child )
| inline static

## ◆ kill_child()

int kill_child | ( | afp_child_t * | child | ) |
| static

send kill to a child processes

## ◆ server_child_add()

afp_child_t * server_child_add | ( | server_child_t * | children,
|  | pid_t | pid,
|  | int | ipc_fd,
|  | int | hint_fd )

add a child

Returns
  pointer to struct server_child_data on success, NULL on error

## ◆ server_child_alloc()

server_child_t * server_child_alloc | ( | int | connections | ) |

initialize server_child structure

## ◆ server_child_free()

void server_child_free | ( | server_child_t * | children | ) |

free everything

by using a hash table, this increases the cost of this part over a linked list by the size of the hash table

## ◆ server_child_kill()

void server_child_kill | ( | server_child_t * | children,
|  | int | sig )

send signal to all child processes

## ◆ server_child_kill_one_by_id()

void server_child_kill_one_by_id | ( | server_child_t * | children,
|  | pid_t | pid,
|  | uid_t | uid,
|  | uint32_t | idlen,
|  | char * | id,
|  | uint32_t | boottime )

see if there is a process for the same mac

if the times don't match mac has been rebooted

## ◆ server_child_login_done()

void server_child_login_done | ( | server_child_t * | children,
|  | pid_t | pid,
|  | uid_t | uid,
|  | const char * | client_address )

## ◆ server_child_remove()

int server_child_remove | ( | server_child_t * | children,
|  | pid_t | pid )

remove a child and free it

## ◆ server_child_resolve()

afp_child_t * server_child_resolve | ( | server_child_t * | childs,
|  | id_t | pid )

## ◆ server_child_set_session_token()

int server_child_set_session_token | ( | server_child_t * | children,
|  | pid_t | pid,
|  | uid_t | uid,
|  | const void * | token,
|  | size_t | token_len )

Store an opaque reconnect token for a child session.

Returns
  0 on success, -1 on error

## ◆ server_child_transfer_session()

int server_child_transfer_session | ( | server_child_t * | children,
|  | uid_t | uid,
|  | const void * | token,
|  | size_t | token_len,
|  | int | afp_socket,
|  | uint16_t | DSI_requestID )

Try to find an old session and pass socket.

Returns
  -1 on error, 0 if no matching session was found, 1 if session was found and socket passed

## ◆ server_reset_signal()

void server_reset_signal | ( | void |  | ) |

reset children signals

## ◆ unhash_child()

void unhash_child | ( | afp_child_t * | child | ) |
| inline static