fprintf(stderr, "AFCDeviceInfoOpen: %08x\n", err);
AFCPlatformInit();
char *strings[3] = {
" CommandPostNotificationNamecom.apple.itunes-mobdev.syncWillStart\r\n",
"CommandPostNotificationNamecom.apple.itunes-mobdev.syncDidStart\r\n",
"CommandPostNotificationNamecom.apple.itunes-mobdev.syncDidFinish\r\n",
};
int pipe1[2], pipe2[2];
if (pipe(pipe1) != 0) {
printf("pipe()\n");
exit(1);
}
if (pipe(pipe2) != 0) {
printf("pipe()\n");
exit(1);
}
// int fd_r = fds[0];
// int fd_w = fds[1];
// printf("created pipe with fds %d and %d\n", fd_r, fd_w);
pid_t pid;
if ((pid = fork()) == 0) {
printf("starting child process\n");
char *proc = "/System/Library/PrivateFrameworks/MobileDevice.framework/Resources/AppleMobileDeviceHelper.app/Contents/MacOS/AppleMobileDeviceHelper";
char *argv[5];
char argv2[10];
char argv3[10];
sprintf(argv2, "%d", pipe2[0]);
sprintf(argv3, "%d", pipe1[1]);
close(pipe1[0]); // close read
close(pipe2[1]); // close write
argv[0] = proc;
argv[1] = "--pipe";
argv[2] = argv2;
argv[3] = argv3;
argv[4] = NULL;
if (execv(proc, argv) == -1) {
printf("unable to start child: %d\n", errno);
}
}
int status;
printf("forked with pid %d\n", pid);
// write(fd_w, strings[0], strlen(strings[0]));
err = write(pipe1[1], strings[0], strlen(strings[0]));
err = write(pipe1[1], strings[1], strlen(strings[1]));
//err = send(pipe1[1], strings[1], strlen(strings[1]), MSG_OOB);
// waitpid (pid, &status, 0);
//size_t len, int flags);
//write(fd_w, strings[1], strlen(strings[1]));
char buffer[1024];
int err;
err = read(pipe2[0], buffer, 1024);
fprintf(stdout, "err = %d buf = [%s]\n", err, buffer);