- // retrieve mailbox file and read external form
- AuthorizationExternalForm extForm;
- int fd;
- if (sscanf(mboxFdText, "auth %d", &fd) != 1)
- return errAuthorizationInvalidRef;
- if (lseek(fd, 0, SEEK_SET) ||
- read(fd, &extForm, sizeof(extForm)) != sizeof(extForm)) {
- close(fd);
- return errAuthorizationInvalidRef;
- }
+ static AuthorizationExternalForm extForm;
+ static OSStatus result = errAuthorizationInvalidRef;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ // retrieve the pipe and read external form
+ int fd;
+ if (sscanf(mboxFdText, "auth %d", &fd) != 1) {
+ return;
+ }
+ ssize_t numOfBytes = read(fd, &extForm, sizeof(extForm));
+ close(fd);
+ if (numOfBytes == sizeof(extForm)) {
+ result = errAuthorizationSuccess;
+ }
+ });
+
+ if (result) {
+ // we had some trouble with reading the extform
+ return result;
+ }