Пример #1
0
	END	========== LOCAL ============	END
	POINT					POINT
			REMOTE
#endif




#include "ndmagents.h"


int
ndmis_reinit_remote (struct ndm_session *sess)
{
	struct ndm_image_stream *is = &sess->plumb.image_stream;

	NDMOS_MACRO_ZEROFILL(&is->remote);

	ndmchan_initialize (&is->remote.listen_chan, "image-stream-listen");
	ndmchan_initialize (&is->remote.sanity_chan, "image-stream-sanity");
	ndmchan_initialize (&is->chan, "image-stream");
	ndmchan_setbuf (&is->chan, is->buf, sizeof is->buf);

	return 0;
}
Пример #2
0
	END	========== LOCAL ============	END
	POINT					POINT
			REMOTE
#endif




#include "ndmagents.h"


int
ndmis_reinit_remote (struct ndm_session *sess)
{
	struct ndm_image_stream *is = sess->plumb.image_stream;
	struct ndm_tape_agent * ta = sess->tape_acb;

	NDMOS_MACRO_ZEROFILL (&is->remote);

	ndmchan_initialize (&is->remote.listen_chan, "image-stream-listen");
	ndmchan_initialize (&is->remote.sanity_chan, "image-stream-sanity");
	ndmchan_initialize (&is->chan, "image-stream");
	if (!is->buf) {
		is->buflen = ta->mover_state.record_size;
		is->buf = NDMOS_API_MALLOC (is->buflen);
		if (!is->buf) {
			return -1;
		}
		NDMOS_MACRO_ZEROFILL_SIZE (is->buf, is->buflen);
	}
	ndmchan_setbuf (&is->chan, is->buf, is->buflen);

	return 0;
}
Пример #3
0
/* Initialize -- Set data structure to know value, ignore current value */
int
ndmda_initialize (struct ndm_session *sess)
{
        sess->data_acb = NDMOS_API_MALLOC (sizeof(struct ndm_data_agent));
	if (!sess->data_acb)
		return -1;
        NDMOS_MACRO_ZEROFILL (sess->data_acb);

	sess->data_acb->data_state.state = NDMP9_DATA_STATE_IDLE;
	ndmchan_initialize (&sess->data_acb->formatter_error, "dfp-error");
	ndmchan_initialize (&sess->data_acb->formatter_wrap, "dfp-wrap");
	ndmchan_initialize (&sess->data_acb->formatter_image, "dfp-image");
	ndmda_fh_initialize (sess);

	return 0;
}
Пример #4
0
static void
ndma_proxy_session (struct ndm_session *sess, int proxy_port)
{
	int			conn_sock, len, rc;
	struct sockaddr		sa;
	int			proxy_sock;
	int			fd;

	sess->proxy_starting = TRUE;
	sess->proxy_connections = 0;

	proxy_sock = socket (AF_INET, SOCK_STREAM, 0);
	if (proxy_sock < 0) {
		fprintf(stdout, "opening socket: %s\n", strerror(errno));
		exit(1);
	}

	ndmalogf (sess, 0, 2, "set sess->protocol_listen");

	ndmos_condition_listen_socket (sess, proxy_sock);

	NDMOS_MACRO_SET_SOCKADDR(&sa, 0, proxy_port);

	if (bind (proxy_sock, &sa, sizeof sa) < 0) {
		int err = errno;
		ndmalogf (sess, 0, 2, "Can't bind the socket(%d): %s\n", proxy_port, strerror(err));
		if (err == EADDRINUSE) {
		    fprintf(stdout, "INUSE\n");
		    fflush(stdout);
		    exit(0);
		} else {
		    fprintf(stdout, "while binding tcp port %d: %s\n", proxy_port, strerror(err));
		    fflush(stdout);
		    exit(1);
		}
	}

	if (listen (proxy_sock, 5) < 0) {
		fprintf(stdout, "listening on socket: %s\n", strerror(errno));
		exit(1);
	}

	/* set up to listen on this new socket */
	ndmchan_initialize(&sess->listen_chan, "proxy-listen");
	ndmchan_start_listen(&sess->listen_chan, proxy_sock);

	/* tell our invoker that we are OK */
	if (full_write(1, "OK\n", 3) != 3) {
		fprintf(stderr, "ndmp-proxy writing to stdout: %s\n", strerror(errno));
		exit(1);
	}

	/* send an EOF on stdout */
	close(1);

	/* open /dev/null on fds 0 and 1 */
	fd = open("/dev/null", O_RDONLY);
	if (fd < 0) {
	    fprintf(stderr, "cannot open /dev/null\n");
	    /* ignore the error */
	} else if (fd != 1) {
	    dup2(fd, 1);
	    close(fd);
	}

	fd = open("/dev/null", O_WRONLY);
	if (fd < 0) {
	    fprintf(stderr, "cannot open /dev/null\n");
	    /* ignore the error */
	} else if (fd != 0) {
	    dup2(fd, 0);
	    close(fd);
	}
}
Пример #5
0
int
ndmda_pipe_fork_exec (struct ndm_session *sess, char *cmd, int is_backup)
{
	struct ndm_data_agent *	da = &sess->data_acb;
	struct ndmchan *	ch;
	int			errpipe[2];
	int			datpipe[2];
	int			wrppipe[2];
	int			nullfd;
	int			rc = -1;

	ndmalogf (sess, 0, 2, "Starting %s", cmd);

	nullfd = open ("/dev/null", 2);
	if (nullfd < 0) {
		return rc;
	}

	rc = pipe (errpipe);
	if (rc < 0) {
		close (nullfd);
		return rc;
	}

	rc = pipe (datpipe);
	if (rc < 0) {
		close (nullfd);
		close (errpipe[0]);
		close (errpipe[1]);
		return rc;
	}

	rc = pipe (wrppipe);
	if (rc < 0) {
		close (nullfd);
		close (errpipe[0]);
		close (errpipe[1]);
		close (datpipe[0]);
		close (datpipe[1]);
		return rc;
	}

	rc = fork();
	if (rc < 0) {
		close (nullfd);
		close (errpipe[0]);
		close (errpipe[1]);
		close (datpipe[0]);
		close (datpipe[1]);
		close (wrppipe[0]);
		close (wrppipe[1]);
		return rc;
	}

	if (rc == 0) {
		/* child */
		dup2 (errpipe[1], 2);
		dup2 (wrppipe[1], 3);
		close (errpipe[0]);
		close (wrppipe[0]);

		if (is_backup) {
			dup2 (nullfd, 0);
			dup2 (datpipe[1], 1);
			close (datpipe[0]);
		} else {
			dup2 (datpipe[0], 0);
			dup2 (nullfd, 1);
			close (datpipe[1]);
		}

		/*
		 * 0 -- formatter stdin
		 * 1 -- formatter stdout
		 * 2 -- formatter stderr
		 * 3 -- formatter wrap chan (wraplib.c)
		 */
		for (rc = 4; rc < 100; rc++) {
			close(rc);
		}

		execl ("/bin/sh", "sh", "-c", cmd, NULL);

		fprintf (stderr, "EXEC FAILED %s\n", cmd);
		exit(127);
	}

	/* parent */
	close (nullfd);

	ch = &da->formatter_error;
	ndmchan_initialize (ch, "dfp-error");
	ndmchan_setbuf (ch, da->fmt_error_buf, sizeof da->fmt_error_buf);
	close (errpipe[1]);
	ndmos_condition_pipe_fd (sess, errpipe[0]);
	ndmchan_start_read (ch, errpipe[0]);

	ch = &da->formatter_wrap;
	ndmchan_initialize (ch, "dfp-wrap");
	ndmchan_setbuf (ch, da->fmt_wrap_buf, sizeof da->fmt_wrap_buf);
	close (wrppipe[1]);
	ndmos_condition_pipe_fd (sess, wrppipe[0]);
	ndmchan_start_read (ch, wrppipe[0]);

	ch = &da->formatter_image;
	ndmchan_initialize (ch, "dfp-image");
	ndmchan_setbuf (ch, da->fmt_image_buf, sizeof da->fmt_image_buf);

	if (is_backup) {
		ndmalogf (sess, 0, 2, "backup...");
		close (datpipe[1]);
		ndmos_condition_pipe_fd (sess, datpipe[0]);
		ndmchan_start_read (ch, datpipe[0]);
	} else {
		ndmalogf (sess, 0, 2, "recover...");
		close (datpipe[0]);
		ndmos_condition_pipe_fd (sess, datpipe[1]);
		ndmchan_start_write (ch, datpipe[1]);
	}

	da->formatter_pid = rc;

	return rc;	/* PID */
}