tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: python vs. semaphores



On Tue, Dec 14, 2021 at 02:08:39PM +0100, Thomas Klausner wrote:
> Is anyone aware of problems with semaphores on NetBSD, or has looked
> at this particular problem before?

Ok, my first test already gave me a bug.

The man page says that multiple consecutive sem_open calls (without
sem_close in between) should return the same address. They don't.

I've written an atf test. I don't know how to mark it as
currently-broken, so I'll attach it here (and to the bug report).

I don't think fixing this one will fix semaphores in Python though :)
 Thomas
? .gdbinit
? Atffile
? atf-run.log
? t_sched
? t_sem
Index: t_sem.c
===================================================================
RCS file: /cvsroot/src/tests/lib/librt/t_sem.c,v
retrieving revision 1.5
diff -u -r1.5 t_sem.c
--- t_sem.c	14 May 2020 08:34:19 -0000	1.5
+++ t_sem.c	14 Dec 2021 15:38:47 -0000
@@ -313,6 +313,31 @@
 	(void)sem_unlink("/sem_c");
 }
 
+ATF_TC_WITH_CLEANUP(sem_open_address);
+ATF_TC_HEAD(sem_open_address, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Validate that multiple sem_open calls "
+	    "return the same address");
+}
+ATF_TC_BODY(sem_open_address, tc)
+{
+	sem_t *sem, *sem2, *sem3;
+	sem = sem_open("/sem_d", O_CREAT | O_EXCL, 0777, 0);
+	ATF_REQUIRE(sem != SEM_FAILED);
+	sem2 = sem_open("/sem_d", O_CREAT | O_EXCL, 0777, 0);
+	ATF_REQUIRE(sem2 == SEM_FAILED && errno == EEXIST);
+	sem3 = sem_open("/sem_d", 0);
+	ATF_REQUIRE(sem3 != SEM_FAILED);
+	ATF_REQUIRE(sem == sem3);
+	ATF_REQUIRE_EQ(sem_close(sem3), 0);
+	ATF_REQUIRE_EQ(sem_close(sem), 0);
+	ATF_REQUIRE_EQ(sem_unlink("/sem_d"), 0);
+}
+ATF_TC_CLEANUP(sem_open_address, tc)
+{
+	(void)sem_unlink("/sem_d");
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -320,6 +345,7 @@
 	ATF_TP_ADD_TC(tp, child);
 	ATF_TP_ADD_TC(tp, pshared);
 	ATF_TP_ADD_TC(tp, invalid_ops);
+	ATF_TP_ADD_TC(tp, sem_open_address);
 
 	return atf_no_error();
 }


Home | Main Index | Thread Index | Old Index