-/* Process tids requests forever. Should not return except on error. */
-int tids_start (TIDS_INSTANCE *tids,
- TIDS_REQ_FUNC *req_handler,
- TIDS_AUTH_FUNC *auth_handler,
- const char *hostname,
- unsigned int port,
- void *cookie)
-{
- int listen = -1;
- int conn = -1;
- pid_t pid;
-
- tids->tids_port = port;
- if (0 > (listen = tids_listen(tids, port)))
- perror ("Error from tids_listen()");
-
- /* store the caller's request handler & cookie */
- tids->req_handler = req_handler;
- tids->auth_handler = auth_handler;
- tids->hostname = hostname;
- tids->cookie = cookie;
-
- tr_info("Trust Path Query Server starting on host %s:%d.", hostname, port);
-
- while(1) { /* accept incoming conns until we are stopped */
-
- if (0 > (conn = accept(listen, NULL, NULL))) {
- perror("Error from TIDS Server accept()");
- return 1;
- }
-
- if (0 > (pid = fork())) {
- perror("Error on fork()");
- return 1;
- }
-
- if (pid == 0) {
- close(listen);
- tids_handle_connection(tids, conn);
- close(conn);
- exit(0); /* exit to kill forked child process */
- } else {
- close(conn);
- }
-
- /* clean up any processes that have completed */
- while (waitpid(-1, 0, WNOHANG) > 0);
- }
-
- return 1; /* should never get here, loops "forever" */
-}
-