コード例 #1
0
ファイル: local.c プロジェクト: chixq/shadowsocks-libev
void close_and_free_server(EV_P_ struct server *server) {
    if (server != NULL) {
        ev_io_stop(EV_A_ &server->send_ctx->io);
        ev_io_stop(EV_A_ &server->recv_ctx->io);
        close(server->fd);
        free_server(server);
    }
}
コード例 #2
0
static void close_and_free_server(EV_P_ server_t *server)
{
	if (NULL != server)
	{
		ev_io_stop(EV_A_ & server->send_ctx->io);
		ev_io_stop(EV_A_ & server->recv_ctx->io);
		close(server->fd);
		free_server(server);
	}
}
コード例 #3
0
ファイル: redir.c プロジェクト: michalliu/shadowsocks-libev
static void
close_and_free_server(EV_P_ server_t *server)
{
    if (server != NULL) {
        ev_io_stop(EV_A_ & server->send_ctx->io);
        ev_io_stop(EV_A_ & server->recv_ctx->io);
        ev_timer_stop(EV_A_ & server->delayed_connect_watcher);
        close(server->fd);
        free_server(server);
    }
}
コード例 #4
0
ファイル: list.c プロジェクト: DanielOaks/irc2-mirror
/*
 * taken the code from ExitOneClient() for this and placed it here.
 * - avalon
 * remove client **AND** _related structures_ from lists,
 * *free* them too. -krys
 */
void	remove_client_from_list(aClient *cptr)
{
	checklist();
	/* is there another way, at this point? */
	/* servers directly connected have hopcount=1, but so do their
	 * users, hence the check for IsServer --B. */
	if (cptr->hopcount == 0 ||
		(cptr->hopcount == 1 && IsServer(cptr)))
		istat.is_localc--;
	else
		istat.is_remc--;
	if (cptr->prev)
		cptr->prev->next = cptr->next;
	else
	    {
		client = cptr->next;
		client->prev = NULL;
	    }
	if (cptr->next)
		cptr->next->prev = cptr->prev;

	if (cptr->user)
	    {
		istat.is_users--;
		/* decrement reference counter, and eventually free it */
		cptr->user->bcptr = NULL;
		(void)free_user(cptr->user);
	    }

	if (cptr->serv)
	{
		cptr->serv->bcptr = NULL;
		free_server(cptr->serv);
	}

	if (cptr->service)
		/*
		** has to be removed from the list of aService structures,
		** no reference counter for services, thus this part of the
		** code can safely be included in free_service()
		*/
		free_service(cptr);

#ifdef	DEBUGMODE
	if (cptr->fd == -2)
		cloc.inuse--;
	else
		crem.inuse--;
#endif

	(void)free_client(cptr);
	numclients--;
	return;
}
コード例 #5
0
ファイル: nfs4-cat.c プロジェクト: rbalint/libnfs
/*
 * This callback is invoked when others (the nfsv4 server) initiates a
 * NFSv4 CALLBACK sessions to us.
 * We accept() the connection and create a local rpc server context
 * for the callback protocol.
 */
static void client_accept(evutil_socket_t s, short events, void *private_data)
{
	struct client *client = private_data;
        struct server *server;
        struct sockaddr_storage ss;
        socklen_t len = sizeof(ss);
        int fd;
        
        server = malloc(sizeof(struct server));
        if (server == NULL) {
                fprintf(stderr, "failed to malloc server structure\n");
                exit(10);
        }
        memset(server, 0, sizeof(*server));
        server->next = server_list;
        server_list = server;

        if ((fd = accept(s, (struct sockaddr *)&ss, &len)) < 0) {
                free_server(server);
                fprintf(stderr, "accept failed\n");
                exit(10);
        }
        evutil_make_socket_nonblocking(fd);

        server->rpc = rpc_init_server_context(fd);
        if (server->rpc == NULL) {
                free_server(server);
                fprintf(stderr, "Failed to create server rpc context\n");
                exit(10);
        }

        rpc_register_service(server->rpc, NFS4_CALLBACK, NFS_CB,
                             pt, sizeof(pt) / sizeof(pt[0]));

        server->read_event = event_new(base, fd, EV_READ|EV_PERSIST,
                                       server_io, server);
        server->write_event = event_new(base, fd, EV_WRITE|EV_PERSIST,
                                        server_io, server);
        update_events(server->rpc, server->read_event, server->write_event);
}
コード例 #6
0
void close_and_free_server(EV_P_ struct server *server) {
    if (server != NULL) {
        ev_io_stop(EV_A_ &server->send_ctx->io);
        ev_io_stop(EV_A_ &server->recv_ctx->io);
        ev_timer_stop(EV_A_ &server->send_ctx->watcher);
        ev_timer_stop(EV_A_ &server->recv_ctx->watcher);
        close(server->fd);
        free_server(server);
    }
    if (verbose) {
        LOGD("current server connection: %d", server_conn);
    }
}
コード例 #7
0
ファイル: cfgparse.c プロジェクト: zhangyong3/radproxy
static void free_proxy(struct radproxy_desc *p)
{
	int i = 0;
	if (p) {
		for (i = 0;i < p->server_cnt; ++i) {
			struct radproxy_backend_server *s = p->servers[i];
			if (!s) continue;

			free_server(s);
		}

		free(p);
	}
}
コード例 #8
0
ファイル: main.c プロジェクト: raczzoli/media-server
int main()
{
	int server_port			= 0;
	char *tmp_port_val		= NULL;
	int server_descriptor	= 0;
	
	if (config_load(CONFIG_PATH) != 0)
	{
		return EXIT_FAILURE;
	}
	
	if (module_load(MODULES_PATH) != 0)
	{
		free_server();
		return EXIT_FAILURE;
	}
	
	tmp_port_val = (char*)config_get_entry_value("port");
	if (tmp_port_val == NULL)
	{
		server_port = DEFAULT_SERVER_PORT;
		log_message("%s%d%s\n", "No port number was specified in server.conf! Using default (", server_port, ").");
	}
	else if ((server_port = atoi(tmp_port_val)) < 1)
	{
		server_port = DEFAULT_SERVER_PORT;
		log_message("%s%d%s\n", "Invalid port number was specified in server.conf! Using default (", server_port, ").");
	}
	
	if ((server_descriptor = connection_init(server_port)) > 0)
	{
		
	}
	
	free_server();
	return 0;
}
コード例 #9
0
ファイル: server.c プロジェクト: nezharen/shadowsocks-libev
static void close_and_free_server(EV_P_ struct server *server)
{
    if (server != NULL) {
        if (server->query != NULL) {
            resolv_cancel(server->query);
            server->query = NULL;
        }
        ev_io_stop(EV_A_ & server->send_ctx->io);
        ev_io_stop(EV_A_ & server->recv_ctx->io);
        ev_timer_stop(EV_A_ & server->recv_ctx->watcher);
        close(server->fd);
        free_server(server);
        if (verbose) {
            server_conn--;
            LOGI("current server connection: %d", server_conn);
        }
    }
}
コード例 #10
0
int main(void)
{
	struct Node *n1;
	struct Node *n2;

	n1 = new_node(1);
	n2 = new_node(2);

	append_data(n2, 1, "This is n1's secret data");
	append_data(n1, 2, "This is n2's secret data");

	register_node(n1);
	register_node(n2);

	printf("n1's data: %s\n", server_get_data(n1));
	printf("n2's data: %s\n", server_get_data(n2));

	free_node(n1);
	free_node(n2);
	free_server();

	return 0;
}
コード例 #11
0
ファイル: fifo.c プロジェクト: CESNET/torque
int scheduling_cycle(

  int sd)

  {
  server_info *sinfo;  /* ptr to the server/queue/job/node info */
  job_info *jinfo;  /* ptr to the job to see if it can run */
  int ret = SUCCESS;  /* return code from is_ok_to_run_job() */
  char log_msg[MAX_LOG_SIZE]; /* used to log an message about job */
  char comment[MAX_COMMENT_SIZE]; /* used to update comment of job */

  sched_log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_REQUEST, "", "Entering Schedule");

  update_cycle_status();

  /* create the server / queue / job / node structures */

  if ((sinfo = query_server(sd)) == NULL)
    {
    fprintf(stderr, "Problem with creating server data strucutre\n");

    return(0);
    }

  if (init_scheduling_cycle(sinfo) == 0)
    {
    sched_log(
      PBSEVENT_DEBUG,
      PBS_EVENTCLASS_SERVER,
      sinfo -> name,
      "init_scheduling_cycle failed.");

    free_server(sinfo, 1);

    return(0);
    }

  /* main scheduling loop */

  while ((jinfo = next_job(sinfo, 0)))
    {
    sched_log(
      PBSEVENT_DEBUG2,
      PBS_EVENTCLASS_JOB,
      jinfo->name,
      "Considering job to run");

    if ((ret = is_ok_to_run_job(sd, sinfo, jinfo->queue, jinfo)) == SUCCESS)
      {
      run_update_job(sd, sinfo, jinfo->queue, jinfo);
      }
    else
      {
      if (jinfo->can_never_run)
        {
        sched_log(
          PBSEVENT_JOB,
          PBS_EVENTCLASS_JOB,
          jinfo->name,
          "Job Deleted because it would never run");

        pbs_deljob(sd, jinfo->name, "Job could never run");
        }

      jinfo->can_not_run = 1;

      if (translate_job_fail_code(ret, comment, log_msg))
        {
        /* if the comment doesn't get changed, its because it hasn't changed.
         * if the reason for the job has not changed, we do not need to log it
         */

        if (update_job_comment(sd, jinfo, comment) == 0)
          {
          sched_log(
            PBSEVENT_SCHED,
            PBS_EVENTCLASS_JOB,
            jinfo->name,
            log_msg);
          }
        }

      if ((ret != NOT_QUEUED) && cstat.strict_fifo)
        {
        update_jobs_cant_run(
          sd,
          jinfo->queue->jobs,
          jinfo,
          COMMENT_STRICT_FIFO,
          START_AFTER_JOB);
        }
      }
    }

  if (cstat.fair_share)
    update_last_running(sinfo);

  free_server(sinfo, 1); /* free server and queues and jobs */

  sched_log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_REQUEST, "", "Leaving schedule\n");

  return 0;
  }
コード例 #12
0
ファイル: net.c プロジェクト: loudambiance/rirc
//server_disconnect(server *s, char *mesg, int flags)
void
server_disconnect(server *s, int err, int kill, char *mesg)
{
	/* When err flag is set:
	 *   Disconnect initiated by remote host
	 *
	 * When kill flag is set:
	 *   Free the server, update ccur
	 */

	/* Server connection in progress, cancel the connection attempt */
	if (s->connecting) {

		connection_thread *ct = s->connecting;

		if ((pthread_cancel(ct->tid)))
			fatal("pthread_cancel");

		/* There's a chance the thread is canceled with an open socket */
		if (ct->socket_tmp)
			close(ct->socket_tmp);

		free(ct);
		s->connecting = NULL;

		newlinef(s->channel, 0, "--", "Connection to '%s' port %s canceled", s->host, s->port);
	}

	/* Server is/was connected, close socket, send quit message if non-erroneous disconnect */
	else if (s->soc >= 0) {

		if (err) {
			/* If disconnecting due to error, attempt a reconnect */

			newlinef(s->channel, 0, "ERROR", "%s", mesg);
			newlinef(s->channel, 0, "--", "Attempting reconnect in %ds", RECONNECT_DELTA);

			s->reconnect_time = time(NULL) + RECONNECT_DELTA;
			s->reconnect_delta = RECONNECT_DELTA;
		} else if (mesg) {
			sendf(NULL, s, "QUIT :%s", mesg);
		}

		close(s->soc);

		/* Set all server attributes back to default */
		memset(s->usermodes, 0, MODE_SIZE);
		s->soc = -1;
		s->iptr = s->input;
		s->nptr = config.nicks;
		s->latency_delta = 0;

		/* Reset the nick that reconnects will attempt to register with */
		auto_nick(&(s->nptr), s->nick);

		/* Print message to all open channels and reset their attributes */
		channel *c = s->channel;
		do {
			newline(c, 0, "-!!-", "(disconnected)");

			reset_channel(c);

		} while ((c = c->next) != s->channel);
	}

	/* Server was waiting to reconnect, cancel future attempt */
	else if (s->reconnect_time) {
		newlinef(s->channel, 0, "--", "Auto reconnect attempt canceled");

		s->reconnect_time = 0;
		s->reconnect_delta = 0;
	}

	if (kill) {
		DLL_DEL(server_head, s);
		free_server(s);
	}
}
コード例 #13
0
ファイル: list.c プロジェクト: DanielOaks/irc2-mirror
/*
** free_user
**	Decrease user reference count by one and release block,
**	if count reaches 0
*/
void	free_user(anUser *user)
{
	aServer *serv;
	aClient *cptr = user->bcptr;

	if (--user->refcnt <= 0)
	{
		/* Loop: This would be second deallocation of this structure.
		 * XXX: Remove loop detection before 2.11.0 - jv
		 */

		if (user->refcnt == -211001)
		{
			sendto_flag(SCH_ERROR,
				"* %p free_user loop (%s!%s@%s) %p *",
				(void *)cptr, cptr ? cptr->name : "<noname>",
				user->username, user->host, user);

			return;
		}
		
		/*
		 * sanity check
		 */
		if (user->joined || user->refcnt < 0 ||
		    user->invited || user->channel || user->uwas ||
		    user->bcptr)
		{
			char buf[512];
			/*too many arguments for dumpcore() and sendto_flag()*/
			sprintf(buf, "%p %p %p %p %d %d %p (%s)",
				(void *)user, (void *)user->invited,
				(void *)user->channel, (void *)user->uwas,
				user->joined, user->refcnt,
				(void *)user->bcptr,
				(user->bcptr) ? user->bcptr->name :"none");
#ifdef DEBUGMODE
			dumpcore("%p user (%s!%s@%s) %s",
				(void *)cptr, cptr ? cptr->name : "<noname>",
				user->username, user->host, buf);
#else
			sendto_flag(SCH_ERROR,
				"* %p user (%s!%s@%s) %s *",
				(void *)cptr, cptr ? cptr->name : "<noname>",
				user->username, user->host, buf);
#endif
		}

		if ((serv = user->servp))
		{
			user->servp = NULL; /* to avoid some impossible loop */
			user->refcnt = -211000; /* For loop detection */
			free_server(serv);
		}

		if (user->away)
		{
			istat.is_away--;
			istat.is_awaymem -= (strlen(user->away) + 1);
			MyFree(user->away);
		}
		MyFree(user);
#ifdef	DEBUGMODE
		users.inuse--;
#endif
	    }
}
コード例 #14
0
ファイル: cfgparse.c プロジェクト: zhangyong3/radproxy
static struct radproxy_backend_server *parse_server(int linenum, char *args[], int argc)
{
	int j = 0;
	struct radproxy_backend_server *s;
	char *p;
	const char *errmsg;
	if (argc < 2) {
		errmsg = "not enough paramter";
		goto error;
	}

	s = calloc(1, sizeof(*s));
	if (!s)
		return NULL;

	s->name = strdup(args[0]);
	p = (char*)strrchr(args[1], ':');
	if (!p) {
		errmsg = "no port";
		goto error;
	}

	*p++ = '\0';

	if (0 != radproxy_name2addr(args[1], &s->addr)) {
		errmsg = "server addr error";
		goto error;
	}

	s->addr.port = atoi(p);
	for (j = 2; args[j] != NULL && j < argc; j++) {
		if (strcasecmp(args[j], "state") == 0 ||
				strcasecmp(args[j], "sign") == 0 ||
					strcasecmp(args[j], "nostate") == 0 ) {
			if (strcasecmp(args[j], "state") == 0) {
				s->option |= OPTION_STATE;
			} else if (strcasecmp(args[j], "nostate") == 0) {
				s->option |= OPTION_NO_STATE;
			} else if (strcasecmp(args[j], "sign") == 0) {
				s->option |= OPTION_SIGN;
			} else {
				printf("unknow keyword '%s' in server\n", args[j]);
			}

			continue;
		}

		if (argc-j <2) {
			errmsg = "need more paramter";
			goto error;
		}

		if (strcasecmp(args[j], "weight") == 0) {
			s->weight = atoi(args[j+1]);
			if (s->weight < 0) {
				errmsg = "weight cannot be negative";
				goto error;
			}
		} else if (strcasecmp(args[j], "timeout") == 0) {
			s->timeout = atoi(args[j+1]);
		} else if (strcasecmp(args[j], "try") == 0) {
			s->maxtry = atoi(args[j+1]);
				errmsg = "'try' must be positive";
		} else if (strcasecmp(args[j], "secret") == 0) {
			s->secret = strdup(args[j+1]);
		} else {
			printf("unknow keyword '%s' in server\n", args[j]);
			goto error;
		}

		j++;
	}

	if (s->timeout <=0) {
		s->timeout = 3000;
		printf("'timeout' is not positive, reset to 3000\n");
	}

	if (s->maxtry <= 0) {
		s->maxtry = 2;
		printf("'try' is not positive, reset to 2\n");
	}

	if (s->weight <= 0) {
		s->weight = 1;
		printf("'weight' is not positive, reset to 1\n");
	}

	if (s->addr.port <= 0) {
		errmsg = "port number error";
		goto error;
	} else if (s->name == NULL) {
		errmsg = "server need a name";
		goto error;
	} else if (s->secret == NULL) {
		errmsg = "server need a secret";
		goto error;
	}

	return s;

error:
	if (errmsg)
		printf("line %d: %s\n", linenum, errmsg);
	free_server(s);
	return NULL;
}
コード例 #15
0
ファイル: ftpserver.c プロジェクト: awh44/FTP
int main(int argc, char *argv[])
{
	status_t error;

	server_t server;
	error = initialize_server(&server);
	if (error)
	{
		goto exit0;
	}

	char start_up_message[] = "Config file read. Starting rest of server up.\n";
	error = write_log(server.log, start_up_message, sizeof start_up_message);
	if (error)
	{
		goto exit0;
	}

	uint16_t port;
	error = parse_command_line(argc, argv, &port);
	if (error)
	{
		goto exit0;
	}

	char socket_message[] = "Setting up socket.\n";
	error = write_log(server.log, socket_message, sizeof socket_message);
	if (error)
	{
		goto exit0;
	}
	int listen_sock = socket(AF_INET, SOCK_STREAM, 0);
	if (listen_sock < 0)
	{
		error = SOCKET_OPEN_ERROR;
		goto exit0;
	}

	struct sockaddr_in sad;
	memset(&sad, 0, sizeof sad);
	sad.sin_family = AF_INET;
	sad.sin_addr.s_addr = INADDR_ANY;
	sad.sin_port = htons(port);

	if (bind(listen_sock, (struct sockaddr *) &sad, sizeof sad) < 0)
	{
		error = BIND_ERROR;
		goto exit1;
	}

	if (listen(listen_sock, MAX_USERS) < 0)
	{
		error = LISTEN_ERROR;
		goto exit1;
	}

	struct sockaddr_in cad;
	socklen_t clilen = sizeof cad;
	while (1)
	{
		int connection_sock = accept(listen_sock, (struct sockaddr *) &cad, &clilen);
		if (connection_sock < 0)
		{
			char *error_str = get_error_message(ACCEPT_ERROR);
			write_log(server.log, error_str, strlen(error_str));
			printf("%s", error_str);
		}
		else
		{
			char join_message[] = "Client joined.\n";
			write_log(server.log, join_message, sizeof join_message);
			printf("%s", join_message);

			//use calloc to make sure the state flags are all set to 0.
			user_session_t *args = calloc(1, sizeof *args);
			args->command_sock = connection_sock;
			args->server = &server;

			pthread_t thread;
			if (pthread_create(&thread, NULL, client_handler, args) != 0)
			{
				error = send_response(connection_sock, SERVICE_NOT_AVAILABLE, "Could not establish a session.", server.log, 0);

				char *error_str = get_error_message(PTHREAD_CREATE_ERROR);
				write_log(server.log, error_str, strlen(error_str));
				printf("%s", error_str);
			}
			else
				pthread_detach(thread);
		}
	}

	char closing_message[] = "Server closing down.\n";
exit1:
	write_log(server.log, closing_message, sizeof closing_message);
	close(listen_sock);
exit0:
	free_server(&server);
	print_error_message(error);
	return error;
}
コード例 #16
0
/*
 *
 * query_server - creates a structure of arrays consisting of a server
 *   and all the queues and jobs that reside in that server
 *
 *   pbs_sd - connection to pbs_server
 *
 * returns a pointer to the server_info struct
 *
 */
server_info *query_server(int pbs_sd)
  {

  struct batch_status *server; /* info about the server */
  server_info *sinfo;  /* scheduler internal form of server info */
  queue_info **qinfo;  /* array of queues on the server */
  resource *res;  /* ptr to cycle through sources on server */
  int       local_errno = 0;

  /* get server information from pbs server */

  if ((server = pbs_statserver_err(pbs_sd, NULL, NULL, &local_errno)) == NULL)
    {
    fprintf(stderr, "pbs_statserver failed: %d\n", local_errno);
    return NULL;
    }

  /* convert batch_status structure into server_info structure */
  if ((sinfo = query_server_info(server)) == NULL)
    {
    pbs_statfree(server);
    return NULL;
    }

  /* get the nodes, if any */
  sinfo -> nodes = query_nodes(pbs_sd, sinfo);

  /* get the queues */
  if ((sinfo -> queues = query_queues(pbs_sd, sinfo)) == NULL)
    {
    pbs_statfree(server);
    free_server(sinfo, 0);
    return NULL;
    }

  /* count the queues and total up the individual queue states
   * for server totals. (total up all the state_count structs)
   */
  qinfo = sinfo -> queues;

  while (*qinfo != NULL)
    {
    sinfo -> num_queues++;
    total_states(&(sinfo -> sc), &((*qinfo) -> sc));
    qinfo++;
    }

  if ((sinfo -> jobs = (job_info **) malloc(sizeof(job_info *) * (sinfo -> sc.total + 1))) == NULL)
    {
    free_server(sinfo, 1);
    perror("Memory allocation error");
    return NULL;
    }

  set_jobs(sinfo);

  sinfo -> running_jobs =
    job_filter(sinfo -> jobs, sinfo -> sc.total, check_run_job, NULL);

  res = sinfo -> res;

  while (res != NULL)
    {
    if (res -> assigned == UNSPECIFIED)
      res -> assigned = calc_assn_resource(sinfo -> running_jobs, res -> name);

    res = res -> next;
    }

  sinfo -> timesharing_nodes =

    node_filter(sinfo -> nodes, sinfo -> num_nodes, is_node_timeshared, NULL);

  pbs_statfree(server);

  return sinfo;
  }