[Bug 1173797] New: after repeated semop (...) funktion call the return value of the semop (...) is -1 call, errno is ERANGE.
http://bugzilla.opensuse.org/show_bug.cgi?id=1173797 Bug ID: 1173797 Summary: after repeated semop (...) funktion call the return value of the semop (...) is -1 call, errno is ERANGE. Classification: openSUSE Product: openSUSE.org Version: unspecified Hardware: Other OS: openSUSE 10.2 Status: NEW Severity: Normal Priority: P5 - None Component: Bugzilla Assignee: bnc-team-screening@forge.provo.novell.com Reporter: HaScFue@mail.de QA Contact: novbugzilla-bugs@forge.provo.novell.com Found By: --- Blocker: --- Created attachment 839408 --> http://bugzilla.opensuse.org/attachment.cgi?id=839408&action=edit The fist c-Programm In both appended C-programs I had programmed a handshake-mechanism between two programs by using linux-semaphoren. The handschake-mechanism is running in a loop with a loop counter. When the loop counter reached the value 32768 (=0X7FFF), then suddenly the return value of the semop (...) - call is -1, errno is ERANGE. ... struct sembuf semaphore [] = {(unsigned short) semNum, (short) -1, (short) SEM_UNDO}; if( semop (semid, semaphore, 1) == -1) { return -1; } ... Reproducible: yes, always. Steps to Reproduce: mv x.c.txt x.c mv y.c.txt y.c g++ -o x x.c g++ -o y y.c start compiled program x.c in first terminal-window ./x start compiled program y.c in first terminal-window ./y --> After 32768 loopings the in first terminal-window appears -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1173797 http://bugzilla.opensuse.org/show_bug.cgi?id=1173797#c1 --- Comment #1 from Hans Schwab <HaScFue@mail.de> --- Comment on attachment 839408 --> http://bugzilla.opensuse.org/attachment.cgi?id=839408 The fist c-Programm The second c-programm: /* y.c */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ipc.h> // IPC_NOWAIT = 0x800, SEM_UNDO = 0x1000 #include <sys/sem.h> #include <errno.h> enum {LOCK_SEMA=-1, UNLOCK_SEMA=1}; #define KEY 1234567L static int semid = -1; static int printSemaValue(int line, const char *pStr) { int semVal0(0), semVal1(0); semVal0 = semctl (semid, 0, GETVAL); if (semVal0 < 0) { printf ("In Line %d: retcode < 0 from semctl (%d, 0, GETVAL), errno = %d\n\n", __LINE__-2, semid, errno); return semVal0; } semVal1 = semctl (semid, 1, GETVAL); if (semVal1 < 0) { printf ("In Line %d: retcode < 0 from semctl (%d, 1, GETVAL), errno = %d\n\n", __LINE__-2, semid, errno); return semVal1; } printf ("\n"); printf ("semVal0 GETVAL %d\n", semVal0); printf ("semVal1 GETVAL %d\n%s, in Line %d\n", semVal1, pStr, line); return 1; } static int init_semaphore (void) { int semVal0(0), semVal1(0); semid = semget (KEY, 0, IPC_PRIVATE); if (semid < 0) { printf ("\n Line %d: sema was not created\n", __LINE__-2); return semid; } semVal0 = semctl (semid, 0, GETVAL); if (semVal0 < 0) { printf ("In Line %d: retcode < 0 from semctl (%d, 0, GETVAL), errno = %d\n\n", __LINE__-2, semid, errno); return semVal0; } semVal1 = semctl (semid, 1, GETVAL); if (semVal0 < 0) { printf ("In Line %d: retcode < 0 from semctl (%d, 1, GETVAL), errno = %d\n\n", __LINE__-2, semid, errno); return semVal1; } return 1; } static int semaphoreOp (int op, int semNum) { struct sembuf semaphore [] = {(unsigned short) semNum, (short) op, (short) SEM_UNDO}; if( semop (semid, semaphore, 1) == -1) { return -1; } return 1; } int main (void) { long loop, res; int lineNr (-1); int myError(0); res = init_semaphore (); if (res < 0) { printf ("\nretcode < 0 from init_semaphore\n"); semctl(semid, 1, IPC_RMID, 0); return res; } printSemaValue(__LINE__, "init_semaphore() was successful"); for (loop =0; myError==0; ++loop) { printf ("\nloop = %ld\n", loop); res = semaphoreOp (LOCK_SEMA, 1); lineNr =__LINE__ -1; if (res < 0) { int semVal0(0), semVal1(1); myError = errno; if (myError == EIDRM) { printf ("In Line %d: LOCK_SEMA, sem_num 1, was not successful;\nerrno = %d (=EIDRM, Identifier removed)\n\n", lineNr, myError); } else { printf ("In Line %d: LOCK_SEMA, sem_num 1, was not successful;\nerrno = %d\n\n", lineNr, myError); } break; } // sleep (1); res = semaphoreOp (UNLOCK_SEMA, 0); lineNr =__LINE__ -1; if (res < 0) { int semVal0(0), semVal1(1); myError = errno; if (myError == EIDRM) { printf ("In Line %d: UNLOCK_SEMA, sem_num 0, was not successful;\nerrno = %d (=EIDRM, Identifier removed)\n\n", lineNr, myError); } else { printf ("In Line %d: UNLOCK_SEMA, sem_num 0, was not successful;\nerrno = %d\n\n", lineNr, myError); } break; } printf ("\n"); } // for ... // semctl(semid, 0, IPC_RMID, 0); return 1; } -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1173797 http://bugzilla.opensuse.org/show_bug.cgi?id=1173797#c2 Bernhard Wiedemann <bwiedemann@suse.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bwiedemann@suse.com Component|Bugzilla |Development Version|unspecified |Leap 15.1 Assignee|bnc-team-screening@forge.pr |screening-team-bugs@suse.de |ovo.novell.com | Product|openSUSE.org |openSUSE Distribution QA Contact|novbugzilla-bugs@forge.prov |qa-bugs@suse.de |o.novell.com | --- Comment #2 from Bernhard Wiedemann <bwiedemann@suse.com> --- maybe you cause a resource leak? You can check with ipcs and cleanup with ipcrm -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1173797 http://bugzilla.opensuse.org/show_bug.cgi?id=1173797#c3 --- Comment #3 from Bernhard Wiedemann <bwiedemann@suse.com> --- The other hint is that 0x7FFF is the maximum you can store in a short, such as struct sembuf semaphore [] = {(unsigned short) semNum, (short) op, (short) SEM_UNDO}; so beyond that, you get negative values and those are likely invalid as input to those OS calls. -- You are receiving this mail because: You are on the CC list for the bug.
participants (1)
-
bugzilla_noreply@suse.com