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.

46 lines
922 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. $signal = ($mode eq "s");
  10. $id = semget(0x1234, 1, ($signal ? 0 : &IPC_CREAT) | 0644);
  11. die "Can't get semaphore: $!\n" unless defined($id);
  12. print "semaphore id: $id\n";
  13. if ($signal) {
  14. while (<STDIN>) {
  15. print "Signalling\n";
  16. unless (semop($id, pack("sss", 0, 1, 0))) {
  17. die "Can't signal semaphore: $!\n";
  18. }
  19. }
  20. }
  21. else {
  22. $SIG{'INT'} = $SIG{'QUIT'} = "leave";
  23. for (;;) {
  24. unless (semop($id, pack("sss", 0, -1, 0))) {
  25. die "Can't wait for semaphore: $!\n";
  26. }
  27. print "Unblocked\n";
  28. }
  29. }
  30. &leave;
  31. sub leave {
  32. if (!$signal) {
  33. $x = semctl($id, 0, &IPC_RMID, 0);
  34. if (!defined($x) || $x < 0) {
  35. die "Can't remove semaphore: $!\n";
  36. }
  37. }
  38. exit;
  39. }