Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    RedsStream *st[2];
    int sv[2];
    int ret, fd = -1;
    char c;

    spice_return_val_if_fail(server_init() == 0, -1);

    if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv) == -1) {
        spice_error("socketpair failed %s", strerror(errno));
        return -1;
    }

    st[0] = reds_stream_new(server, sv[0]);
    spice_assert(reds_stream_is_plain_unix(st[0]));
    st[1] = reds_stream_new(server, sv[1]);
    spice_assert(reds_stream_is_plain_unix(st[1]));

    /* send stdin, for the fun of it */
    ret = reds_stream_send_msgfd(st[0], 0);
    spice_assert(ret == 1);
    ret = sock_fd_read(sv[1], &c, 1, &fd);
    spice_assert(c == '@');
    spice_assert(ret == 1);
    spice_assert(fd != -1);
    close(fd);

    /* send invalid fd behaviour */
    ret = reds_stream_send_msgfd(st[0], -1);
    spice_assert(ret == 1);
    ret = sock_fd_read(sv[1], &c, 1, &fd);
    spice_assert(c == '@');
    spice_assert(ret == 1);
    spice_assert(fd == -1);

    /* batch test */
    ret = reds_stream_send_msgfd(st[0], 0);
    spice_assert(ret == 1);
    ret = reds_stream_send_msgfd(st[0], 0);
    spice_assert(ret == 1);
    ret = sock_fd_read(sv[1], &c, 1, &fd);
    spice_assert(c == '@');
    spice_assert(ret == 1);
    spice_assert(fd != -1);
    close(fd);
    ret = sock_fd_read(sv[1], &c, 1, &fd);
    spice_assert(c == '@');
    spice_assert(ret == 1);
    spice_assert(fd != -1);
    close(fd);

    reds_stream_free(st[0]);
    reds_stream_free(st[1]);

    return 0;
}
Ejemplo n.º 2
0
void new_client_cb(struct ev_loop* loop,ev_io * w, int revents){
	int sd;
	char buf[1024];
	
	//log=fopen("/home/auser/log.txt","a");
	
	ssize_t size=sock_fd_read(w->fd,buf,sizeof(buf),&sd);
	if(size<0){
	//	fprintf(log,"Error buffer read\n");
	//	fclose(log);
		return ;
	}
	if(sd<0){
	//	fprintf(log,"Error fd read\n");
	//	fclose(log);
		return ;
	}
	
	//fprintf(log,"Worker %d. Client %d connect\n",id,sd);
	//fclose(log);

	ev_io * w_read=new struct ev_io;
	ev_io_init(w_read,read_data_cb,sd,EV_READ);
	ev_io_start(loop,w_read);
}
Ejemplo n.º 3
0
/* 
 * Reads a new file descriptor from the service 
 */
int get_new_fd(int sock)
{
  char buf[BUF_SZ];
  int newfd;
  ssize_t size = sock_fd_read(sock, buf, sizeof(buf), &newfd);
  if(size > 0)
    return newfd;
  return -1;
}
void child_read(int sock)
{
    int fd;
    char buf[16];
    ssize_t size;
    sleep(1);
    
    size = sock_fd_read(sock, buf, sizeof(buf), &fd);
    if (size > 0)
    {
        printf ("read size: %d, fd: %d, buffer: %s\n", (int)size, fd, buf);
    }
}
Ejemplo n.º 5
0
void child(int sock) {

	int fd;
	char buf[16];
	ssize_t size;

	long long count[1];
	int result,read_result;

	sleep(1);

	for (;;) {
		/* read fd from socket */
		size = sock_fd_read(sock, buf, sizeof(buf), &fd);

	        if (size <= 0)
			break;

		if (!quiet) printf ("read fd of %d, size %d\n", fd, (int)size);
		if (fd != -1) {
			ioctl(fd, PERF_EVENT_IOC_RESET, 0);
			ioctl(fd, PERF_EVENT_IOC_ENABLE,0);

			result=instructions_million();
			ioctl(fd, PERF_EVENT_IOC_DISABLE,0);
			read_result=read(fd,&count,sizeof(long long));

			if (read_result!=sizeof(long long)) {
				fprintf(stderr,"\tImproper return from read: %d\n",read_result);
				test_fail(test_string);
			}

			if (result==CODE_UNIMPLEMENTED) {
				fprintf(stderr,"\tCode unimplemented\n");
				test_fail(test_string);
			}

			if (!quiet) {
				printf("Read %lld instructions\n",count[0]);
			}

			close(fd);
		}
	}
}
Ejemplo n.º 6
0
void
child(int sock)
{
  int fd;
  char    buf[16];
  ssize_t size;

  sleep(1);
  for (;;) {
    size = sock_fd_read(sock, buf, sizeof(buf), &fd);
    if (size <= 0)
      break;
    printf ("read %d\n", (int) size);
    if (fd != -1) {
      write(fd, "hello, world\n", 13);
      close(fd);
    }
  }
}
Ejemplo n.º 7
0
struct client *client_create(int sock_fd)
{
	struct client *client;
	ssize_t size;
	client = calloc(1, sizeof(struct client));
	if (!client)
		error(1, errno, "cannot allocate memory");

	client->d = display_create();
	client->w = window_create(client->d);
	client->sock_fd = sock_fd;

	init_shaders(client);

	glViewport(0, 0, client->w->width, client->w->height);
	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	eglSwapBuffers(client->d->x11.egl_display, client->w->x11.egl_surface);

	glUniform1i(client->tex_loc, 0);
	sleep(1);
	for (;;) {
/* glClear(GL_COLOR_BUFFER_BIT); */
/* eglSwapBuffers(client->d->x11.egl_display, client->w->x11.egl_surface); */
		struct cmd_buf buf;
		int myfd;
		size = sock_fd_read(client->sock_fd, &buf, sizeof(buf), &myfd);
		if (size <= 0)
			break;

		if (buf.type == CMD_TYPE_BUF) {
			add_texture(client, &buf, myfd);
		} else if (buf.type == CMD_TYPE_DIRT) {
			draw_screen(client);

			eglSwapBuffers(client->d->x11.egl_display, client->w->x11.egl_surface);
		}

	}
	return client;
}
Ejemplo n.º 8
0
void set_worker_free(struct ev_loop *loop, struct ev_io *w, int revents)
{
    // get socket of the pair
    int fd = w->fd;

    char tmp[1];
    int slave_socket;

    sock_fd_read(fd, tmp, sizeof(tmp), &slave_socket);

    // here we can restore watcher for the slave socket

    // complete all the work from the queue
    while ((slave_socket = safe_pop_front()) != -1)
    {
        process_slave_socket(slave_socket);
    }

    workers[fd] = true;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[]){

	int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
	if(sockfd < 0)
		perror("sock error");

	struct sockaddr_un serv;
	bzero((char *) &serv, sizeof(serv));
	serv.sun_family = AF_UNIX;
	strncpy(serv.sun_path, INTERNAL_PATH, sizeof(serv.sun_path) - 1 );
	//unlink(serv.sun_path);


	int g = connect(sockfd, (struct sockaddr*) &serv, sizeof(serv));
	if( g < 0)
		perror("failed to connect");

	int t=-1;
	int h[3];

	while(1){

		char ptr[16];
		t++;
		//printf("waiting for read fdsss\n");
		int n = sock_fd_read(sockfd, ptr, sizeof(ptr), &newsockfd[t]);
		if( n < 0 )
			perror("failed to get sockfd");
		//printf("socket fd recvd by service server %d\n", n);
		h[t] = t;
		pthread_create(&p[t], NULL, (void*) &serv_client, (void*)&h[t]);

	}

	int i;
	for(i=0;i<t;i++)
		pthread_join(p[i], NULL);

	return 0;
}
Ejemplo n.º 10
0
void do_work(struct ev_loop *loop, struct ev_io *w, int revents)
{

    // get appropriate slave socket and read from it
    int slave_socket;
    char tmp[1];

    sock_fd_read(w->fd, tmp, sizeof(tmp), &slave_socket);
    if (slave_socket == -1)
    {
        std::cout << "do_work: slave_socket == -1" << std::endl;
        exit(4);
    }


    // do it
    process_slave_socket(slave_socket);

    // write back to paired socket to update worker status
    sock_fd_write(w->fd, tmp, sizeof(tmp), slave_socket);

}
Ejemplo n.º 11
0
void
worker(int sock)
{
	int fd = -1;
	char buf[16];
	ssize_t size;
	char buf0[BUFSIZE];
	char buf1[BUFSIZE];
	char ls[LS][WS];
	int cnt0;
	int cnt1;
	const char file_name[] = "list.txt";
	int rsz;
	int k;
	std::ifstream in(file_name, std::ios::in | std::ios::binary);
	for (;;) {
		size = sock_fd_read(sock, buf, 1, &fd);
		if (fd != -1) {
			std::cout << "worker_pid = " << getpid() << std::endl;
			bzero((char *) &buf0, sizeof(buf0));
			bzero((char *) &buf1, sizeof(buf1));
			for (int i = 0; i < LS; i++)
				bzero((char *) ls[i], sizeof(ls[i]));

			rsz = recv(fd, buf0, BUFSIZE, MSG_NOSIGNAL);
			k = strlen(buf0) - 1;
			while(k >= 0 && (buf0[k] == 10 || buf0[k] == 13)) {
				buf0[k] = '\0';
				k = strlen(buf0) - 1;
			}

			sops.sem_op = -1;
			semop(semid, &sops, 1);
			cnt0 = read_cache(buf0, ls);
			sops.sem_op = 1;
			semop(semid, &sops, 1);

			if (cnt0 < LS) {
				cnt1 = read_file(in, buf0, ls, cnt0);

				sops.sem_op = -1;
				semop(semid, &sops, 1);
				write_cache(ls, cnt0, cnt1);
				sops.sem_op = 1;
				semop(semid, &sops, 1);
			} else
				cnt1 = cnt0;

			for (int i = 0; i < cnt1; i++) {
				strcat(buf1, ls[i]);
			}

			rsz = strlen(buf1);
			if (!rsz) {
				strcpy(buf1, "\n");
				rsz = 1;
			}

			send(fd, buf1, rsz, MSG_NOSIGNAL);
			close(fd);
		}
		in.seekg(0, std::ios::beg);
		sleep(5);
	}
	in.close();
}
Ejemplo n.º 12
0
void worker(int sock, char * path)
{
    int fd;
    char    buf[16];
    ssize_t size;

    sleep(1);
    for (;;) {
        size = sock_fd_read(sock, buf, sizeof(buf), &fd);
        if (size <= 0)
            break;
        //printf ("read %d\n", (int) size);
        if (fd != -1) {
                const unsigned int BUF_SIZE = 1024;
                char buffer [BUF_SIZE];
                int res = recv(fd, buffer, BUF_SIZE, MSG_NOSIGNAL);
                if ((res == 0) && (errno != EAGAIN)) {

                }
                else if (res > 0) {
			FILE *fp;
			unsigned char flag = 0, version = 1;
			char * pt1, *pt2, *pt3, *pt4;
			char resp[4096]= {0};
			char url[64] = {0};
			time_t rtime;
			char h_error_v1[] = "HTTP/1.0 404 Not found\r\nContent-Type: text/html\r\nContent-Length:0\r\n\r\n";//<html><header>Not found!</header><body><h1>Not found!</h1></body></html>";
			char h_error_v0[] = "HTTP/0.9 404 Not Found\r\n\r\n";
			//char header[] = "HTTP/%d.%d 200 OK\nDate: %s\nServer: Test\nContent-type: text/html\nContent-Length:";	//"\n\n"	
			memcpy(resp,h_error_v1,sizeof(h_error_v1));
			time(&rtime);
	             if(buffer[0] == 'q')
				exit(0);	
			      
			/*if(strstr(buffer, "text/html"))
				flag = 1;*/
			
			pt3 = strstr(buffer, "HTTP/");
			if(pt3 == NULL)
				flag = 0;
			if(*(pt3 + 5) == '0')
				version = 0;
			if(version)
				sprintf(resp, "%s",h_error_v1);
			else
				sprintf(resp, "%s",h_error_v0);

			if(strstr(buffer, "GET") == NULL)
				flag = 0;

			pt1 = memchr(buffer, '/', BUF_SIZE);
			if(pt1 != NULL && flag == 1){
				pt2 = pt1 + strcspn(pt1, " ?");

				if(1){
					char full_path[96] = {0};
					char buf[2048] = {0}; 
					int len = 0;
					//printf("len %d\n", (int)(pt2-pt1));
					memcpy(url, pt1, pt2-pt1);
					sprintf(full_path, "%s%s",path, url);
					//printf("file path: %s\n", full_path);
					fp = fopen(full_path,"r");
					if(fp != NULL){
						len = fread(buf, 1, sizeof(buf), fp);
						if(version)
							sprintf(resp, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nContent-Length:%d\r\n\r\n%s", /*ctime(&rtime),*/len,buf);
						else 	sprintf(resp, "HTTP/0.9 200 OK\r\nContent-Length:%d\r\n\r\n%s",len,buf);
						fclose(fp);
					}//fp
				}//pt2
			}//pt1
				
			 send(fd, resp, strlen(resp), MSG_NOSIGNAL);
		    }//res>0
                    shutdown(fd, SHUT_RDWR);
                    close(fd);
		     //printf("socket closed!\n");

                }
        }
 }
Ejemplo n.º 13
0
void worker(int sock, char * path)
{
    int fd;
    char    buf[16];
    ssize_t size;

    sleep(1);
    for (;;) {
        size = sock_fd_read(sock, buf, sizeof(buf), &fd);
        if (size <= 0)
            break;
        //printf ("read %d\n", (int) size);
        if (fd != -1) {
                const unsigned int BUF_SIZE = 1024;
                char buffer [BUF_SIZE];
                int res = recv(fd, buffer, BUF_SIZE, MSG_NOSIGNAL);
                if ((res == 0) && (errno != EAGAIN)) {

                }
                else if (res > 0) {
			FILE *fp;
			unsigned char flag = 0;
			char * pt1, *pt2;
			char resp[4096]= {0};
			char url[64] = {0};
			char h_error[] = "HTTP/1.0 404 Not found\nContent-type: text/html\nContent-Length:72\n\n<html><header>Not found!</header><body><h1>Not found!</h1></body></html>";
			char header[] = "HTTP/1.0 200 OK\nContent-type: text/html\nContent-Length:";	//"\n\n"	
			memcpy(resp,h_error,sizeof(h_error));
	
	             if(buffer[0] == 'q')
				exit(0);	
			      
			if(strstr(resp, "text/html"))
				flag = 1;
			pt1 = memchr(buffer, '/', BUF_SIZE);
			if(pt1 != NULL && flag == 1){
				pt2 = memchr(pt1, ' ', BUF_SIZE -  (pt1 - buffer));
				if(pt2 != NULL){
					char full_path[96] = {0};
					char buf[2048] = {0}; 
					int len = 0;
					//printf("len %d\n", (int)(pt2-pt1));
					memcpy(url, pt1, pt2-pt1);
					sprintf(full_path, "%s%s",path, url);
					//printf("file path: %s\n", full_path);
					fp = fopen(full_path,"r");
					if(fp != NULL){
						len = fread(buf, 1, sizeof(buf), fp);
						sprintf(resp, "%s%d\n\n%s", header,len,buf);
						fclose(fp);
					}//fp
				}//pt2
			}//pt1
				
			 send(fd, resp, strlen(resp), MSG_NOSIGNAL);
		    }//res>0
                    shutdown(fd, SHUT_RDWR);
                    close(fd);
		     //printf("socket closed!\n");

                }
        }
 }
Ejemplo n.º 14
0
static int
tst_ioctl(const char * fnp, int sg_fd, const char * fn2p, int sg_fd2,
          int sock, const char * cp)
{
    uint32_t cflags;
    struct sg_extended_info sei;
    struct sg_extended_info * seip;

    seip = &sei;
    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_RESERVED_SIZE;
    seip->reserved_sz = reserve_buff_sz;
    seip->sgat_elem_sz = 64 * 1024;;
    seip->valid_rd_mask |= SG_SEIM_RESERVED_SIZE;
    seip->valid_rd_mask |= SG_SEIM_RQ_REM_THRESH;
    seip->valid_rd_mask |= SG_SEIM_TOT_FD_THRESH;
    seip->valid_wr_mask |= SG_SEIM_CTL_FLAGS;
    seip->valid_rd_mask |= SG_SEIM_CTL_FLAGS; /* this or previous optional */
    seip->valid_rd_mask |= SG_SEIM_MINOR_INDEX;
    seip->valid_wr_mask |= SG_SEIM_SGAT_ELEM_SZ;
    seip->ctl_flags_wr_mask |= SG_CTL_FLAGM_TIME_IN_NS;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_TIME_IN_NS;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_OTHER_OPENS;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_ORPHANS;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_Q_TAIL;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_IS_SHARE;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_IS_MASTER;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_UNSHARE;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_MASTER_FINI;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_MASTER_ERR;
    seip->ctl_flags_rd_mask |= SG_CTL_FLAGM_CHECK_FOR_MORE;
    seip->ctl_flags |= SG_CTL_FLAGM_TIME_IN_NS;

    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
#if 1
    printf("%sSG_SET_GET_EXTENDED ioctl ok\n", cp);
    if (SG_SEIM_RESERVED_SIZE & seip->valid_rd_mask)
        printf("  %sreserved size: %u\n", cp, seip->reserved_sz);
    if (SG_SEIM_MINOR_INDEX & seip->valid_rd_mask)
        printf("  %sminor index: %u\n", cp, seip->minor_index);
    if (SG_SEIM_RQ_REM_THRESH & seip->valid_rd_mask)
        printf("  %srq_rem_sgat_thresh: %u\n", cp, seip->rq_rem_sgat_thresh);
    if (SG_SEIM_TOT_FD_THRESH & seip->valid_rd_mask)
        printf("  %stot_fd_thresh: %u\n", cp, seip->tot_fd_thresh);
    if ((SG_SEIM_CTL_FLAGS & seip->valid_rd_mask) ||
         (SG_SEIM_CTL_FLAGS & seip->valid_wr_mask)) {
        cflags = seip->ctl_flags;
        if (SG_CTL_FLAGM_TIME_IN_NS & seip->ctl_flags_rd_mask)
            printf("  %sTIME_IN_NS: %s\n", cp,
                   (SG_CTL_FLAGM_TIME_IN_NS & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_OTHER_OPENS & seip->ctl_flags_rd_mask)
            printf("  %sOTHER_OPENS: %s\n", cp,
                   (SG_CTL_FLAGM_OTHER_OPENS & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_ORPHANS & seip->ctl_flags_rd_mask)
            printf("  %sORPHANS: %s\n", cp,
                   (SG_CTL_FLAGM_ORPHANS & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_Q_TAIL & seip->ctl_flags_rd_mask)
            printf("  %sQ_TAIL: %s\n", cp,
                   (SG_CTL_FLAGM_Q_TAIL & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_IS_SHARE & seip->ctl_flags_rd_mask)
            printf("  %sIS_SHARE: %s\n", cp,
                   (SG_CTL_FLAGM_IS_SHARE & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_IS_MASTER & seip->ctl_flags_rd_mask)
            printf("  %sIS_MASTER: %s\n", cp,
                   (SG_CTL_FLAGM_IS_MASTER & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_UNSHARE & seip->ctl_flags_rd_mask)
            printf("  %sUNSHARE: %s\n", cp,
                   (SG_CTL_FLAGM_UNSHARE & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_MASTER_FINI & seip->ctl_flags_rd_mask)
            printf("  %sMASTER_FINI: %s\n", cp,
                   (SG_CTL_FLAGM_MASTER_FINI & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_MASTER_ERR & seip->ctl_flags_rd_mask)
            printf("  %sMASTER_ERR: %s\n", cp,
                   (SG_CTL_FLAGM_MASTER_ERR & cflags) ? "true" : "false");
        if (SG_CTL_FLAGM_CHECK_FOR_MORE & seip->ctl_flags_rd_mask)
            printf("  %sCHECK_FOR_MORE: %s\n", cp,
                   (SG_CTL_FLAGM_CHECK_FOR_MORE & cflags) ? "true" : "false");
    }
    if (SG_SEIM_MINOR_INDEX & seip->valid_rd_mask)
        printf("  %sminor_index: %u\n", cp, seip->minor_index);
    printf("\n");
#endif

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_INT_MASK;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_INT_MASK]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_BOOL_MASK;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_BOOL_MASK]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_VERS_NUM;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_VERS_NUM]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_FL_RQS;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_FL_RQS]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_DEV_FL_RQS;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_DEV_FL_RQS]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_TRC_SZ;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_TRC_SZ]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_READ_VAL;
    seip->valid_rd_mask |= SG_SEIM_READ_VAL;
    seip->read_value = SG_SEIRV_TRC_MAX_SZ;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("ioctl(SG_SET_GET_EXTENDED) failed, errno=%d %s\n", errno,
                strerror(errno));
        return 1;
    }
    printf("  %sread_value[SG_SEIRV_TRC_MAX_SZ]= %u\n", cp, seip->read_value);

    memset(seip, 0, sizeof(*seip));
    seip->valid_wr_mask |= SG_SEIM_SHARE_FD;
    seip->valid_rd_mask |= SG_SEIM_SHARE_FD;
#if 1
    seip->share_fd = sg_fd2;
#else
    seip->share_fd = sg_fd;
#endif
    if (do_fork && is_parent)
        goto bypass_share;
    if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) {
        pr2serr("%sioctl(SG_SET_GET_EXTENDED) shared_fd=%d, failed errno=%d "
                "%s\n", cp, sg_fd2, errno, strerror(errno));
    }
    printf("  %sshare successful, read back shared_fd= %d\n", cp,
           (int)seip->share_fd);
bypass_share:

    // printf("SG_IOSUBMIT value=0x%lx\n", SG_IOSUBMIT);
    // printf("SG_IORECEIVE value=0x%lx\n", SG_IORECEIVE);
    if (ioctl(sg_fd, SG_GET_TRANSFORM, NULL) < 0)
        pr2serr("ioctl(SG_GET_TRANSFORM) fail expected, errno=%d %s\n",
                errno, strerror(errno));
    else
        printf("%sSG_GET_TRANSFORM okay (does nothing)\n", cp);
    if (ioctl(sg_fd, SG_SET_TRANSFORM, NULL) < 0)
        pr2serr("ioctl(SG_SET_TRANSFORM) fail expected, errno=%d %s\n",
                errno, strerror(errno));
    else
        printf("%sSG_SET_TRANSFORM okay (does nothing)\n", cp);
    printf("\n");

    /* test sending a sg file descriptor between 2 processes using UNIX
     * sockets */
    if (do_fork && is_parent && fnp && (sock >= 0)) { /* master/READ side */
        int res;
        int fd_ma = open(fnp, O_RDWR);

        if (fd_ma < 0) {
            pr2serr("%s: opening %s failed: %s\n", __func__, fnp,
                    strerror(errno));
            return 1;
        }
        res = sock_fd_write(sock, "boo", 4, fd_ma);
        if (res < 0)
            pr2serr("%s: sock_fd_write() failed\n", __func__);
        else
            printf("%s: sock_fd_write() returned: %d\n", __func__, res);
    } else if (do_fork && !is_parent && fn2p && (sock >= 0)) {
        int res, fd_ma;
        /* int fd_sl = open(fn2p, O_RDWR); not needed */
        uint8_t b[32];

        fd_ma = -1;
        res = sock_fd_read(sock, b, sizeof(b), &fd_ma);
        if (res < 0)
            pr2serr("%s: sock_fd_read() failed\n", __func__);
        else
            printf("%s: sock_fd_read() returned: %d, fd_ma=%d\n", __func__,
                   res, fd_ma);
        /* yes it works! */
    }
    return 0;
}