DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T i

⟦3b0b1d019⟧ TextFile

    Length: 858 (0x35a)
    Types: TextFile
    Names: »ipcsem«

Derivation

└─⟦4f9d7c866⟧ Bits:30007245 EUUGD6: Sikkerheds distributionen
    └─⟦b5330643c⟧ »./cops/perl-4.019/perl.tar.Z« 
        └─⟦2b9a58213⟧ 
            └─⟦this⟧ »perl-4.019/eg/sysvipc/ipcsem« 

TextFile

#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
	if 0;

require 'sys/ipc.ph';
require 'sys/msg.ph';

$| = 1;

$mode = shift;
die "usage: ipcmsg {r|s}\n" unless $mode =~ /^[rs]$/;
$signal = ($mode eq "s");

$id = semget(0x1234, 1, ($signal ? 0 : &IPC_CREAT) | 0644);
die "Can't get semaphore: $!\n" unless defined($id);
print "semaphore id: $id\n";

if ($signal) {
	while (<STDIN>) {
		print "Signalling\n";
		unless (semop($id, 0, pack("sss", 0, 1, 0))) {
			die "Can't signal semaphore: $!\n";
		}
	}
}
else {
	$SIG{'INT'} = $SIG{'QUIT'} = "leave";
	for (;;) {
		unless (semop($id, 0, pack("sss", 0, -1, 0))) {
			die "Can't wait for semaphore: $!\n";
		}
		print "Unblocked\n";
	}
}

&leave;

sub leave {
	if (!$signal) {
		$x = semctl($id, 0, &IPC_RMID, 0);
		if (!defined($x) || $x < 0) {
			die "Can't remove semaphore: $!\n";
		}
	}
	exit;
}