Semaphore bug on PPC

Tony Breeds tony at bakeyournoodle.com
Mon Feb 6 10:28:48 EST 2006


Hi Rusty,
	The attached patch fixes a semaphore creation problem on PPC.
I've tested it in x86, ppc32 and ppc64 and all seems good.

Yours Tony

   linux.conf.au       http://linux.conf.au/ || http://lca2006.linux.org.au/
   Jan 23-28 2006      The Australian Linux Technical Conference!

-------------- next part --------------
# HG changeset patch
# User Tony Breeds <tony at bakeyournoodle.com>
# Node ID 9e20fec32a29580dd5473302ad5cd225462cc5c1
# Parent  2359d02cdec272fc8ef8952fa3579fb4543a1e02
Fix semaphore bug on PowrePC (32 and 64).

diff -r 2359d02cdec2 -r 9e20fec32a29 ccontrol-lock.c
--- a/ccontrol-lock.c	Wed Jan  4 23:43:12 2006
+++ b/ccontrol-lock.c	Sun Feb  5 23:08:21 2006
@@ -44,6 +44,12 @@
 		id = semget(key, 1, 0);
 		errno = saved_errno;
 	} else {
+		union semun {
+			int val;
+			struct semid_ds *ds;
+			unsigned short *array;
+			struct seminfo *__buf;
+		} semctl_arg;
 		struct semid_ds ds;
 
 		verbose(sec, "Created slow lock", NULL);
@@ -51,11 +57,13 @@
 		ds.sem_perm.uid = geteuid();
 		ds.sem_perm.gid = getegid();
 		ds.sem_perm.mode = 0600;
+		semctl_arg.ds = &ds;
 		
-		if (semctl(id, 0, IPC_SET, &ds) < 0)
+		if (semctl(id, 0, IPC_SET, semctl_arg) < 0)
 			fatal("cannot set semaphore permissions",
 			      errno, NULL);
-		if (semctl(id, 0, SETVAL, sec.cpus) < 0)
+		semctl_arg.val = sec.cpus;
+		if (semctl(id, 0, SETVAL, semctl_arg) < 0)
 			fatal("cannot set semaphore value", errno, NULL);
 	}
 	fcntl_lock(fd, false, 0);


More information about the ccontrol mailing list