• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: recvmsg() in Tiger
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: recvmsg() in Tiger


  • Subject: Re: recvmsg() in Tiger
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Fri, 13 May 2005 11:02:37 +0200


I was using recvmsg() on a pipe in Panther. Tiger tells me that a pipe is not a socket, which is correct.
The advice I got (thanks to all who replied) was: either use a normal read() with a pipe or use real sockets with recvmsg().
Well, kind of obvious (I had hoped for some Tiger magic to turn a pipe into a socket).


I am using authopen (which asks for an administrator password if needed) to open a device (e.g. /dev/rdisk0s9) and get back the file-descriptor of the opened device.
I got the code from someone (forgot from whom) and only partly understand what's going on.
Here is the (almost complete - error handling removed for brevity) code:


int comms[2];
pipe(comms);
pid_t pid = fork();
switch(pid)
{
    case 0:
	;const char *path = "/usr/libexec/authopen" ;
	char *const envp[] = { NULL };
	dup2(comms[1], STDOUT_FILENO);
	close(comms[0]);
	close(comms[1]);
	execle( path, path, "-stdoutpipe", path_name, NULL, envp );
	_exit(1);
};

signal(SIGPIPE, SIG_IGN);
close(comms[1]);

co_t 				control ;
char				dummyData;	

struct iovec		iov;
iov.iov_base 		= &dummyData;
iov.iov_len  		= sizeof(dummyData);

struct msghdr 		msg ;
msg.msg_name       	= NULL;
msg.msg_namelen    	= 0;
msg.msg_iov        	= &iov;
msg.msg_iovlen     	= 1;
msg.msg_control    	= (caddr_t)&control;
msg.msg_controllen 	= sizeof(control);
msg.msg_flags	   	= MSG_WAITALL;

ssize_t bytesRead = recvmsg( comms[0], &msg, 0 );
if ( bytesRead == -1 ) // error
{
// happens in Tiger - returns immediately not waiting for data to come as in panther
// Error recvmsg( 6 ) --> Socket operation on non-socket


NSLog(@"%s Error recvmsg( %d ) --> %s",__FUNCTION__, comms[0], strerror(errno) );
return NO ;
};


close(comms[0]);

we expect (and get in Panther):

bytesRead = sizeof( dummyData ) = 1
msg.msg_flags = 0
msg.msg_control != NULL

either msg.msg_controllen = 0 in which case we stop, or:

msg.msg_controllen = sizeof(control)
control.hdr.cmsg_level = SOL_SOCKET
control.hdr.cmsg_type = SCM_RIGHTS
control.fd >= 0  <------------ this is the file decriptor we need


I guess I will have to use sockets, but I do not know how to create one, and secondly, how to redirect stdout to the socket.


Maybe a kind soul will have an insight and some mercy.


Kind regards,

Gerriet.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: recvmsg() in Tiger
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: Core Data and Non-standard attributes
  • Next by Date: Re: AXIsProcessTrusted / AXMakeProcessTrusted
  • Previous by thread: Re: recvmsg() in Tiger
  • Next by thread: Re: recvmsg() in Tiger
  • Index(es):
    • Date
    • Thread