Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
951 B

  1. #!/usr/bin/perl
  2. eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  3. if $running_under_some_shell;
  4. require 'sys/ipc.ph';
  5. require 'sys/msg.ph';
  6. $| = 1;
  7. $mode = shift;
  8. die "usage: ipcmsg {r|s}\n" unless $mode =~ /^[rs]$/;
  9. $send = ($mode eq "s");
  10. $id = msgget(0x1234, ($send ? 0 : &IPC_CREAT) | 0644);
  11. die "Can't get message queue: $!\n" unless defined($id);
  12. print "message queue id: $id\n";
  13. if ($send) {
  14. while (<STDIN>) {
  15. chop;
  16. unless (msgsnd($id, pack("LA*", $., $_), 0)) {
  17. die "Can't send message: $!\n";
  18. }
  19. }
  20. }
  21. else {
  22. $SIG{'INT'} = $SIG{'QUIT'} = "leave";
  23. for (;;) {
  24. unless (msgrcv($id, $_, 512, 0, 0)) {
  25. die "Can't receive message: $!\n";
  26. }
  27. ($type, $message) = unpack("La*", $_);
  28. printf "[%d] %s\n", $type, $message;
  29. }
  30. }
  31. &leave;
  32. sub leave {
  33. if (!$send) {
  34. $x = msgctl($id, &IPC_RMID, 0);
  35. if (!defined($x) || $x < 0) {
  36. die "Can't remove message queue: $!\n";
  37. }
  38. }
  39. exit;
  40. }