Userspace program cannot get data from ctl_enqueudata()
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=BSb2EayAE6DeVY8Gwl73VvqJ/vtXWzWYkuoZ5J3FO4jDqcQr9EjPVLJTQFD2i2t5//5pMlxR1NyzKEjTtHa7B4k8g4ppDnGycNP64gliyYOgWQvqM4EcJ8L1hKmdlDImpKSgXBBjT7rNkEtQ3kwBMjhcSsXCVnHMKf+JlQA8e/8= Hello, I am writing a small kext that sends data out to userspace via kernel control. However, the userspace program cannot receive the expected data. Anybody plese tell me what I did wrong? My code is very simple: it sends a variable length text to userspace. Todo that, I have a structure named MyLog, like below: -- struct MyLog { int length; /* text length */ uid_t uid; /* uid that generated this action */ unsigned int action; /* in kernel space: kauth_action_t action */ }; -- Then the ctrl_connect() method of kernel control is defined so whenever a userspace program connect to kernel control, ctl_connect() sends out few text. Please see below: -- static int ctl_connect(kern_ctl_ref ctl_ref, struct sockaddr_ctl *sac, void **unitinfo) { struct MyLog log; char *text = "Greeting from kernelspace!"; log.uid = 2006; log.action = 1010; log.length = strlen(text); /* put log information into queue */ ctl_enqueuedata(ctl_ref, sac->sc_unit, &log, sizeof(log), 0); /* then put the variable text into queue */ ctl_enqueuedata(ctl_ref, sac->sc_unit, text, strlen(text), 0); return 0; } -- My program in userspace connect to kernel, and trying to read data out, like this: --- struct MyLog log; n = recv(gSocket, &log, sizeof(log), MSG_WAITALL); if (n == -1) { printf("Failed on getting data from kernel\n"); return -1; } printf("Got packet of %d byte, variable length: %d\n", n, log.length); n = recv(gSocket, buffer, length, MSG_WAITALL); printf("Got exactly %d bytes\n", n); buffer[n] = '\0'; printf("Action %d on %s (%d)\n", log.action, buffer, log.uid); --- However, while I expect that my userspace program will get the text "Greeting from kernelspace", it does not. In fact, I only got data from the first recv() function, and my program printed out: --- Got packet of 16 byte, variable length: 16 --- So far, it is correct. But then it hangs up there, instead of succesfully execute the next recv()? Why that happens? In my kernel code, I already put all the neccessary data in the control buffer, no? (???) Then I tried to copy another data into the kernel buffer (use another command ctl_enqueudata() command). Then the userspace program quit the hangup status, and continue to print out data. But the data is not what I expected, like below: -- Got exactly 26 bytes Action 1010 on (2006) -- As you can see, the text "Greeting from kernelspace" is no where to be seen, although I got 26 bytes as I expected. The only problem is that the data is incorrect. It seems that the way I put the kernel data into the buffer is incorrect, or what else should be fixed? Thank you a lot, and have a nice weekend (I don't :-) H _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
NAHieu