Blame tests/init_fds.c

Packit Service 4684c1
/*
Packit Service 4684c1
 * Copyright (C) 2014 Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * Author: Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * This file is part of GnuTLS.
Packit Service 4684c1
 *
Packit Service 4684c1
 * GnuTLS is free software; you can redistribute it and/or modify it
Packit Service 4684c1
 * under the terms of the GNU General Public License as published by
Packit Service 4684c1
 * the Free Software Foundation; either version 3 of the License, or
Packit Service 4684c1
 * (at your option) any later version.
Packit Service 4684c1
 *
Packit Service 4684c1
 * GnuTLS is distributed in the hope that it will be useful, but
Packit Service 4684c1
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4684c1
 * General Public License for more details.
Packit Service 4684c1
 *
Packit Service 4684c1
 * You should have received a copy of the GNU General Public License
Packit Service 4684c1
 * along with GnuTLS; if not, write to the Free Software Foundation,
Packit Service 4684c1
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
#ifdef HAVE_CONFIG_H
Packit Service 4684c1
#include <config.h>
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#include <stdio.h>
Packit Service 4684c1
#include <unistd.h>
Packit Service 4684c1
#include <gnutls/gnutls.h>
Packit Service 4684c1
#include <gnutls/crypto.h>
Packit Service 4684c1
Packit Service 4684c1
#include "utils.h"
Packit Service 4684c1
Packit Service 4684c1
/* See <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760476>. */
Packit Service 4684c1
Packit Service 4684c1
void doit(void)
Packit Service 4684c1
{
Packit Service 4684c1
#ifndef _WIN32
Packit Service 4684c1
	int res;
Packit Service 4684c1
	unsigned i;
Packit Service 4684c1
	int serial = 0;
Packit Service 4684c1
	char buf[128];
Packit Service 4684c1
Packit Service 4684c1
	res = read(3, buf, 16);
Packit Service 4684c1
	if (res == 16)
Packit Service 4684c1
		serial = 1;
Packit Service 4684c1
Packit Service 4684c1
	/* close all descriptors */
Packit Service 4684c1
	for (i=3;i<1024;i++)
Packit Service 4684c1
		close(i);
Packit Service 4684c1
Packit Service 4684c1
	res = gnutls_global_init();
Packit Service 4684c1
	if (res != 0)
Packit Service 4684c1
		fail("global_init\n");
Packit Service 4684c1
Packit Service 4684c1
	if (serial != 0) {
Packit Service 4684c1
		res = read(3, buf, 16);
Packit Service 4684c1
		if (res != 16) {
Packit Service 4684c1
			fail("could not open fd, or OS doesn't assign fds in a serial way (%d)\n", res);
Packit Service 4684c1
		}
Packit Service 4684c1
	}
Packit Service 4684c1
Packit Service 4684c1
	res = gnutls_global_init();
Packit Service 4684c1
	if (res != 0)
Packit Service 4684c1
		fail("global_init2\n");
Packit Service 4684c1
Packit Service 4684c1
	gnutls_rnd_refresh();
Packit Service 4684c1
Packit Service 4684c1
	res = gnutls_rnd(GNUTLS_RND_RANDOM, buf, sizeof(buf));
Packit Service 4684c1
	if (res != 0)
Packit Service 4684c1
		fail("gnutls_rnd\n");
Packit Service 4684c1
Packit Service 4684c1
	gnutls_global_deinit();
Packit Service 4684c1
Packit Service 4684c1
	if (debug)
Packit Service 4684c1
		success("init-close success\n");
Packit Service 4684c1
#else
Packit Service 4684c1
	return;
Packit Service 4684c1
#endif
Packit Service 4684c1
}