Re: authopen or not
Re: authopen or not
- Subject: Re: authopen or not
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 24 Jul 2004 22:05:59 +0200
From: Steve Checkoway <email@hidden>
Subject: Re: authopen or not
Date: Sat, 24 Jul 2004 06:42:01 -0700
To: Cocoa Developers <email@hidden>
On Jul 24, 2004, at 5:48 AM, Gerriet M. Denkmann wrote:
but what about the dup2() mentioned in the authopen man page?
Or is fork(), and execle() the way to go?
I've never used this, but from reading the man page, I'd say that the
best way to go about it is to create a pipe (using pipe(2)), fork, dup2
redirecting stdout to the writing end of the pipe (close the reading
end) and then exec authopen. From the parent, you close the write end
of the pipe, and then use the read end with your calls to popen.
Yes, this was the way to go. Thanks very much for pointing me in the
right direction!
With some inspirations from MoreAuthSample (thanks to Finlay for this
link) I made this:
int comms[2] ;
pipe(comms);
pid_t pid = fork();
switch(pid)
{
case 0: // Child
;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", "/dev/rdisk0s9", NULL, envp );
_exit(1);
case -1: // error
close(comms[0]);
close(comms[1]);
return -93;
}
typedef struct
{
struct cmsghdr hdr;
int fd;
} co_t ;
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;
recvmsg( comms[0], &msg, 0 );
int fileDescriptorForDisk0S9 = control.fd ;
This is just a sketch. A real program would do more error checking etc.
Gerriet.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.