예제 #1
0
int shlogd_main(int argc, char **argv)
{
  int err;
  int fd;

#ifdef SHLOGD_APPLICATION
  daemon(0, 1);
#endif

  strncpy(process_path, argv[0], PATH_MAX);
  proc_peer = shapp_init(PROCESS_NAME, NULL, SHAPP_LOCAL);

  process_socket_port = PROCESS_PORT; 

  fd = shnet_sk();
  if (fd == -1) {
    perror("shsk");
    return;
  }
  
  err = shnet_bindsk(fd, NULL, process_socket_port);
  if (err) {
    perror("shbindport");
    shclose(fd);
    return (err);
  }

  process_socket_fd = fd;

  daemon_server(0);

  shpeer_free(&proc_peer);
}
예제 #2
0
int main(int argc, char *argv[])
{
	char ch;
	char pathname[256];
	
	if (1 == argc) {
		print_usage();
		return -1;
	} else {
		while (-1 != (ch = getopt(argc, argv, "c:hv"))) {
			switch (ch) {
				case 'c':
						snprintf(pathname, sizeof(pathname), "%s", optarg);
						break;
				case 'h':
						print_usage();
						return 0; 
						break;
				case 'v':
						fprintf(stderr, "%s\n", VERSION_INFO);
						return 0; 
						break;
				default:
						return -1; 
						break;
			}
		}
	}
	
	if (-1 == load_profile(pathname))
		return -1;
	print_param(&g_confvalue);
	if (-1 == create_dir(g_confvalue.log_path, 0644))
		return -1;
	snprintf(g_log_path, sizeof(g_log_path), "%s", g_confvalue.log_path);

	//process();
	daemon_server();

	return 0;
}
예제 #3
0
void sharelog_server(int parent_pid)
{
  unsigned int port = (unsigned int)process_socket_port;
  char buff[TEST_BUFFER_SIZE];
  ssize_t b_read, b_write;
  int cli_fd;
  int err;
  int fd;

  err = shfs_proc_lock(process_path, "");
  if (err) {
    printf ("Terminating.. '%s' server '%s' is already running.\n", "shlogd", process_path);
    return;
  }

  fd = shnet_sk();
  if (fd == -1) {
    perror("shsk");
    return;
  }
  
  err = shnet_bindsk(fd, NULL, port);
  if (err) {
    perror("shbindport");
    shclose(fd);
    return;
  }

  process_socket_fd = fd;
  daemon_server(parent_pid);

#if 0
  cli_fd = shnet_accept(fd);
  if (cli_fd == -1) {
    perror("shnet_accept");
    shclose(fd);
    return;
  }

  printf ("Received new connection on port %d.\n", port);

  memset(buff, 0, sizeof(buff));
  memset(buff, 'a', sizeof(buff) - 1);
  b_write = shnet_write(cli_fd, buff, sizeof(buff));
  if (b_write <= 0) {
    shclose(cli_fd);
    shnet_close(fd);
    perror("shnet_write");
return;
  }
  printf ("%d of %d bytes written to port %d on fd %d..\n", b_write, sizeof(buff), port, cli_fd); 

  memset(buff, 0, sizeof(buff));
  b_read = shnet_read(cli_fd, buff, sizeof(buff));
  if (b_read <= 0) {
    perror("shread");
    shnet_close(cli_fd);
    shnet_close(fd);
    return;
  }

  printf ("MESSAGE: %-*.*s\n", b_read, b_read, buff);
  printf ("%d of %d bytes read from port %d on fd %d..\n", b_read, sizeof(buff), port, cli_fd); 
  
  err = shnet_close(fd);
  if (err) {
    perror("shnet_close");
    shnet_close(cli_fd);
    shnet_close(fd);
    return;
  }

  shnet_close(cli_fd);
#endif

  shclose(fd);

}