Ejemplo n.º 1
0
void handle_client(FILE *fp, int sockfd, char *cmd)
{
   int n;
   char sendline[MAXLINE];
   char recvline[MAXLINE+1];
   int quit = 0;

   while (!quit) {
      if (cmd) {
	 strcpy(sendline, cmd);       /* one shot command */
	 quit = 1;
      } else if (fgets(sendline, MAXLINE, fp) == NULL) {
	 break;
      }
      n = strlen(sendline);
      if (net_send(sockfd, sendline, n) != n)
         error_abort("handle_client: write error on socket");

      while ((n = net_recv(sockfd, recvline, sizeof(recvline))) > 0) {
	  recvline[n] = 0;
	  fputs(recvline, stdout);
      }
      if (n < 0) {
	 char msg[200];
         sprintf(msg, "handle_client: net_recv error: %s\n", strerror(-n));
	 error_abort(msg);
     }
   }
}
Ejemplo n.º 2
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_setuid(void) {
	struct passwd *passwd;
	gid_t groups[128];
	int ngroups;

	if(strisempty(g.option.user)) {
		return;
	}
	passwd = strisdigit(g.option.user) ? getpwuid((uid_t)strtol(g.option.user, NULL, 10)) : getpwnam(g.option.user);
	if(!passwd) {
		error_abort("%s", strerror(errno));
	}
	ngroups = sizeof(groups);
	if(getgrouplist(g.option.user, passwd->pw_gid, groups, &ngroups) == -1) {
		error_abort("getgrouplist: %s", strerror(errno));
	}
	if(setgroups(ngroups, groups) == -1) {
		error_abort("setgroups: %s", strerror(errno));
	}
	if(setgid(passwd->pw_gid) == -1) {
		error_abort("setgid: %s", strerror(errno));
	}
	if(setuid(passwd->pw_uid) == -1) {
		error_abort("setuid: %s", strerror(errno));
	}
}
Ejemplo n.º 3
0
/** フォルダ名とファイル名をパス名に結合する.
 * @param pathname	結合したパス名の格納先.
 * @param folder	フォルダ名
 * @param name		ファイル名
 */
void make_pathname(char* pathname, const char* folder, const char* name)
{
	size_t folder_len = strlen(folder);
	if (folder_len >= _MAX_DRIVE + _MAX_DIR)
		error_abort("too long folder name", folder);
	if (strlen(name) >= _MAX_FNAME)
		error_abort("too long file name", name);

	if (folder_len == 2 && folder[1] == ':')
		_makepath(pathname, folder, NULL, name, NULL);
	else
		_makepath(pathname, NULL, folder, name, NULL);
}
Ejemplo n.º 4
0
ErrorReport::~ErrorReport()
#if __cplusplus >= 201100 || _MSC_VER >= 1900
    noexcept(false)
#endif
{
    if (!msg.str().empty() && msg.str().back() != '\n') {
        msg << '\n';
    }

    if (custom_error_reporter != nullptr) {
        if (flags & Warning) {
            custom_error_reporter->warning(msg.str().c_str());
            return;
        } else {
            custom_error_reporter->error(msg.str().c_str());
            // error() should not have returned to us, but just in case
            // it does, make sure we don't continue.
            error_abort();
        }
    }

    // TODO: Add an option to error out on warnings too
    if (flags & Warning) {
        std::cerr << msg.str();
        return;
    }

#ifdef WITH_EXCEPTIONS
    if (std::uncaught_exception()) {
        // This should never happen - evaluating one of the arguments
        // to the error message would have to throw an
        // exception. Nonetheless, in case it does, preserve the
        // exception already in flight and suppress this one.
        return;
    } else if (flags & Runtime) {
        RuntimeError err(msg.str());
        throw err;
    } else if (flags & User) {
        CompileError err(msg.str());
        throw err;
    } else {
        InternalError err(msg.str());
        throw err;
    }
#else
    std::cerr << msg.str();
    error_abort();
#endif
}
Ejemplo n.º 5
0
/** メイン */
int main(int argc, char** argv)
{
	//--- コマンドライン上のオプションを解析する.
	while (argc > 1 && argv[1][0]=='-') {
		char* sw = &argv[1][1];
		if (strcmp(sw, "-help") == 0)
			goto show_help;
		else {
			do {
				switch (*sw) {
				case 'h': case '?':
show_help:			error_abort(gUsage2);
					break;
				default:
					errorf_abort("-%s: unknown option.\n", sw);
					break;
				}
			} while (*++sw);
		}
//next_arg:
		++argv;
		--argc;
	}

	//--- 引数に与えられたファイルを順番にゴミ箱へ送る.
	if (argc < 2) {
		// 引数なし. usageを表示して終了する.
		goto show_help;
	}
	for (int i = 1; i < argc; ++i)
		recycle_bin(argv[i]);
//	Sleep(100);
	return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
Archivo: pipe.c Proyecto: Ace-Tang/APUE
void pipe_create(pipe_t *pipe, int stages)
{
	int pipe_index, status;
	stage_t **link = &pipe->head, *stage;

	status = pthread_mutex_init(&pipe->mutex, NULL);
	pipe->stages = stages;
	pipe->actives = 0;

	for (pipe_index = 0; pipe_index < stages; pipe_index++)
	{
		stage = (stage_t *)malloc(sizeof (stage_t));
		if (stage == NULL)
			error_abort("stage alloc");
		status = pthread_cond_init(&stage->avail, NULL);
		status = pthread_cond_init(&stage->ready, NULL);
		status = pthread_mutex_init(&stage->mutex, NULL);
		stage->data_ready = 0;
		*link= stage;
		link = &stage->next;
	}
	//stage->next = NULL;
	*link = NULL;
	pipe->tail = stage;

	for (stage = pipe->head; stage->next != NULL; stage = stage->next)
	{
		status = pthread_create(&stage->pthread, NULL, stage_deal, (void *)stage);
	}
}
void
error_assert(const char *condition, const char *file, int line)
{
    error_message("ASSERTION FAILURE: %s [%s:%d]\n", condition,
                  source_basename(file), line);
    error_abort();
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
   int sockfd, port;
   char host[200];
   char msg[200], *p, *cmd;

   strcpy(host, SERV_HOST_ADDR);
   port = SERV_TCP_PORT;

   if (argc > 1) {
      strcpy(host, argv[1]); /* get host from command line */
      p = strchr(host, ':');
      if (p) {
	 *p++ = 0;
	 port = atoi(p);
      }
   }

   if (argc > 2) {
      cmd = argv[2];
   } else {
      cmd = NULL;
   }

   if ((sockfd = net_open(host, NULL, port)) < 0) {
      sprintf(msg, "client: tcp_open for host %s on %d failed\n", host, port);
      error_abort(msg);
   }

   handle_client(stdin, sockfd, cmd);	    /* do it all */
   net_close(sockfd);
   exit(0);
}
static void
signal_handler(int sig)
{
    /* Caught a signal, most likely a SIGABRT */
    error_message("HPROF SIGNAL %d TERMINATED PROCESS\n", sig);
    error_abort();
}
Ejemplo n.º 10
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_pcap(void) {
	char *ifname, errmsg[PCAP_ERRBUF_SIZE], expression[] = "tcp or icmp";
	struct bpf_program bpf;

	if(strisempty(g.option.ifname)) {
		ifname = pcap_lookupdev(errmsg);
		if(!ifname) {
			error_abort("%s", errmsg);
		}
		strncpy(g.option.ifname, ifname, sizeof(g.option.ifname) - 1);
	}
    g.pcap.pcap = pcap_create(g.option.ifname, errmsg);
	if(!g.pcap.pcap) {
		error_abort("%s", errmsg);
	}
    if(pcap_set_buffer_size(g.pcap.pcap, g.option.buffer * 1024 * 1024) != 0) {
        error_abort("%s", "can not set buffer size");
    }
    if(pcap_set_snaplen(g.pcap.pcap, DEFAULT_PCAP_SNAPLEN) != 0) {
        error_abort("%s", "can not set snaplen");
    }
    if(pcap_set_promisc(g.pcap.pcap, g.option.promisc) != 0) {
        error_abort("%s", "can not set promiscuous mode");
    }
    if(pcap_set_timeout(g.pcap.pcap, 1) != 0) {
        error_abort("%s", "can not set timeout");
    }
    if(pcap_activate(g.pcap.pcap) != 0) {
        error_abort("%s", pcap_geterr(g.pcap.pcap));
    }
	if(pcap_compile(g.pcap.pcap, &bpf, expression, 0, 0) == -1) {
		error_abort("%s '%s'", pcap_geterr(g.pcap.pcap), expression);
	}
	if(pcap_setfilter(g.pcap.pcap, &bpf) == -1){
		error_abort("%s", pcap_geterr(g.pcap.pcap));
	}
	pcap_freecode(&bpf);
	g.pcap.snapshot = pcap_snapshot(g.pcap.pcap);
	g.pcap.datalink = pcap_datalink(g.pcap.pcap);
	if(g.pcap.datalink != DLT_EN10MB && g.pcap.datalink != DLT_LINUX_SLL) {
		error_abort("not support datalink %s (%s)",
			pcap_datalink_val_to_name(g.pcap.datalink),
			pcap_datalink_val_to_description(g.pcap.datalink)
		);
	}
}
Ejemplo n.º 11
0
Archivo: pipe.c Proyecto: Ace-Tang/APUE
int my_strcmp(const char *str1, const char *str2)
{
	if (str1 == NULL || str2 == NULL)
		error_abort("string");

	while (*str1 != '\0' && *str1++ == *str2++);
	return (*str1 =='\0' && *str2 == '\n');
}
Ejemplo n.º 12
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_socket(void) {
	struct sockaddr_un sockaddr;

	g.soc = socket(PF_UNIX, SOCK_STREAM, 0);
	if(g.soc == -1) {
		error_abort("socket: %s", strerror(errno));
	}
	memset(&sockaddr, 0, sizeof(sockaddr));
	sockaddr.sun_family = PF_UNIX;
	strcpy(sockaddr.sun_path, g.option.socket);
	if(bind(g.soc, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1) {
        close(g.soc);
        g.soc = -1;
		error_abort("bind: %s", strerror(errno));
	}
}
Ejemplo n.º 13
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_session(void) {
	g.session.table = hashtable_create(TCPEEK_SESSION_TABLE_SIZE);
	if(!g.session.table) {
		error_abort("hashtable can't create.");
	}
	pthread_mutex_init(&g.session.mutex, NULL);
}
Ejemplo n.º 14
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_filter_and_stat(void) {
	char *expression;
	struct tcpeek_filter *filter;

	lnklist_iter_init(g.option.expression);
	while(lnklist_iter_hasnext(g.option.expression)) {
		expression = lnklist_iter_next(g.option.expression);
		filter = tcpeek_filter_create();
		if(tcpeek_filter_parse(filter, expression) == -1) {
			tcpeek_filter_destroy(filter);
			error_abort("filter '%s' parse error.", expression);
		}
		if(!lnklist_add(g.filter, filter, filter->stat ? lnklist_size(g.filter) : 0)) {
			tcpeek_filter_destroy(filter);
			error_abort("can't allocate.");
		}
	}
}
Ejemplo n.º 15
0
/** パス名を、フォルダ名とファイル名に分離する.
 * @param pathname	解析するパス名.
 * @param folder	分離したフォルダ名の格納先(不要ならNULL可). e.g. "a:\dir\dir\"
 * @param name		分離したファイル名の格納先(不要ならNULL可). e.g. "sample.cpp"
 */
void separate_pathname(const char* pathname, char* folder, char* name)
{
	if (strlen(pathname) >= _MAX_PATH)
		error_abort("too long pathname", pathname);
	char drv[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char base[_MAX_FNAME];
	char ext[_MAX_EXT];
	_splitpath(pathname, drv, dir, base, ext);
	if (folder != NULL)
		_makepath(folder, drv, dir, NULL, NULL);
	if (name != NULL)
		_makepath(name, NULL, NULL, base, ext);
}
static void
terminate_everything(jint exit_code)
{
    if ( exit_code > 0 ) {
        /* Could be a fatal error or assert error or a sanity error */
        error_message("HPROF TERMINATED PROCESS\n");
        if ( gdata->coredump || gdata->debug ) {
            /* Core dump here by request */
            error_abort();
        }
    }
    /* Terminate the process */
    error_exit_process(exit_code);
}
Ejemplo n.º 17
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_signal(void) {
	static int signals[] = {SIGINT, SIGTERM, SIGPIPE, SIGUSR1, SIGUSR2, SIGALRM, 0};
	struct sigaction sig;
	int offset;

	memset(&sig, 0, sizeof(sig));
	sig.sa_handler = tcpeek_signal_handler;
	for(offset = 0; signals[offset]; offset++) {
		if(sigaction(signals[offset], &sig, NULL) == -1){
			error_abort("sigaction: '%d' %s", signals[offset], strerror(errno));
		}
	}
}
Ejemplo n.º 18
0
static void canary_check(void *_data)
{
	uint8_t *data = _data;
	size_t nbytes;

	memcpy(&nbytes, data - sizeof(size_t) - sizeof(canary_block),
	       sizeof(size_t));

	if (memcmp(data - sizeof(canary_block), canary_block,
	           sizeof(canary_block)) != 0
	 || memcmp(data + nbytes, canary_block,
	           sizeof(canary_block)) != 0) {
		error_abort("Canary area check failed");
	}
}
Ejemplo n.º 19
0
int c_engine::init_engine()
{
	if (!al_init())
	{
		error_abort("al_init() - Failed!");
	}

	/// Load the config file
	ALLEGRO_CONFIG *al_config = NULL; 
	al_config = al_load_config_file(m_config_file.c_str());
	if (!al_config)
		error_abort("Couldn't open config file!");
	else 
	{
		std::stringstream ss; 
		const char *value = NULL; 
		value = al_get_config_value(al_config, "Display", "width"); 
		ss << value; 
		ss >> m_display_width; 
		value = al_get_config_value(al_config, "Display", "height");
		ss.clear(); 
		ss << value; 
		ss >> m_display_height;
	}


	/// Initialize the display
	m_al_display = al_create_display(m_display_width, m_display_height);
	if (!m_al_display)
	{
		error_abort("al_create_display() - Failed!"); 
	}
	
	
	return 0; 
}
Ejemplo n.º 20
0
Archivo: init.c Proyecto: fchiba/tcpeek
static void
tcpeek_init_addr(void) {
	struct ifaddrs *ifap, *ifa = NULL;

	if(getifaddrs(&ifap) != -1) {
		for(ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
			if(!ifa->ifa_addr) continue;
			if(strisequal(ifa->ifa_name, g.option.ifname) && ifa->ifa_addr->sa_family == AF_INET) {
				g.addr.unicast.s_addr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
				break;
			}
		}
	}
	freeifaddrs(ifap);
	if(!ifa) {
		error_abort("'%s' not found", g.option.ifname);
	}
}
Ejemplo n.º 21
0
static void crash_signal(int sig)
{
	error_abort("Segmentation violation");
}
Ejemplo n.º 22
0
static void alarm_signal(int sig)
{
	error_abort("Alarm expired");
}