Exemplo n.º 1
0
static int start_child_process_with_core(const char* cmd) {
	struct rlimit r;
	errno = 0;

	if(getrlimit(RLIMIT_CORE, &r) == -1) {
		E_WARNING(E_STRLOC ": gerlimit() failed with '%s'\n", strerror(errno));
		return -1;
	}

	rlim_t old = r.rlim_cur;
	r.rlim_cur = RLIM_INFINITY;

	if(setrlimit(RLIMIT_CORE, &r) == -1) {
		E_WARNING(E_STRLOC ": setrlimit() failed with '%s'\n", strerror(errno));
		return -1;
	}

	int ret = start_child_process(cmd);

	r.rlim_cur = old;
	if(setrlimit(RLIMIT_CORE, &r) == -1) {
		E_WARNING(E_STRLOC ": setrlimit() failed with '%s'\n", strerror(errno));
		return -1;
	}

	return ret;
}
Exemplo n.º 2
0
void tests_setup(void)
{
    int ret = 0;

    /*
     * Create a temporary folder to store our files.
     * We do not use mkdtemp to avoid putting our temporary files in the wrong place.
     * In any case, mkdir fails if the folder already exists.
     */
    ret = mkdir(temporary_folder, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
    if (ret < 0)
    {
        printf("could not create folder %s\n", temporary_folder);
        correctly_initialized = false;
        return;
    }
    /* OpenSSL is needed for our new protocol over TLS. */
    SSL_library_init();
    SSL_load_error_strings();

    /*
     * First we start a new process to have a server for our tests.
     */
    ret = start_child_process();
    if (ret < 0)
    {
        correctly_initialized = false;
        return;
    }
    /*
     * If the initialization went without problems, then at this point
     * there is a second process waiting for connections.
     */
    ssl_client_init();
}
Exemplo n.º 3
0
/**
 * start the child processes
 * @return	0 on success or -1 on failure
 */
int start_child_processes()
{
	int  i;
	int rv;

	for (i = 0; i < PROCESS_NUM; i++) {
		rv = start_child_process(i);
		if (rv == -1)
			return -1;
	}

	return 0;
}
Exemplo n.º 4
0
static int post_config(
    apr_pool_t *pconf,
    AVAHI_GCC_UNUSED apr_pool_t *plog,
    AVAHI_GCC_UNUSED apr_pool_t *ptemp,
    server_rec *s) {

    void *flag;
    struct global_config_data *d = GET_CONFIG_DATA(s);

    /* All post_config hooks are called twice, we're only interested in the second call. */

    apr_pool_userdata_get(&flag, MOD_DNSSD_USERDATA_KEY, s->process->pool);
    if (!flag) {
        apr_pool_userdata_set((void*) 1, MOD_DNSSD_USERDATA_KEY, apr_pool_cleanup_null, s->process->pool);
        return OK;
    }

    if (d->enabled)
        return start_child_process(pconf, s, d);

    return OK;
}
Exemplo n.º 5
0
int main(int argc, char **argv) 
{
    int port;

    char buffer[100];
	memset(buffer, 0, 100);

	if (argc < 3){
		fprintf(stderr, "Error - chybi parametr -p\n");
		return -1;
	}
    else if (argc > 3) { 
    	fprintf(stderr, "Error - Bylo zadano prilis mnoho argumentu\n");
        return -1;
    } else {
		if (strcmp (argv[1],"-p") == 0) {
		    if((port = atoi(argv[2])) == 0){
		    	fprintf(stderr, "Error - chyba parametru -p\n");
		    	return -1;
		    }
		}
	}

	//kontrola jestli byl zadan parametr p

  	int sock, sock_client;
  	struct sockaddr_in sin;

	if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0){
		fprintf(stderr, "Error - nebylo mozne vytvorit socket\n");
		return -1;
	}

	sin.sin_family = PF_INET;
	// localhost
	sin.sin_addr.s_addr = INADDR_ANY;
	sin.sin_port = htons(port);
  	
  	if(bind(sock, (struct sockaddr*)&sin, sizeof(sin)) < 0){
  		fprintf(stderr, "Error - chyba na navazani na local\n");
  		close(sock);
  		return -1;
  	}
		
	if ((listen(sock, 400)) == -1) {
		fprintf(stderr, "Error - chyba v naslouchani pro socket\n");
    	close(sock);
    	return -1;
    }
	
	socklen_t len = sizeof(sin);
	//dokud je otevreny
 	while (sock > 0){
		if((sock_client = accept(sock, (struct sockaddr*)&sin, &len)) < 0){
			fprintf(stderr, "Error - chyba pri prijimani spojeni\n");
			close(sock);
			return -1;		
		}

		pid_t child = fork();

		if(child == 0){ // child proces
			start_child_process(sock_client);

			close(sock_client);
			return 0;
		}
		else if(child > 0){
			// parent proces
		  	continue;			
		}
		else {
			fprintf(stderr, "Error - chyba forku\n");
			close(sock);
			return -1;
		}
	}
	
	close(sock);
	return 0;
}
Exemplo n.º 6
0
/**
 * timer handler
 * @param value send by the timer when the timer alarmed
 */
void timeout(union sigval v)
{
	printf("hello:id = %d\n", v.sival_int);
	start_child_process(v.sival_int);
}