[prev in list] [next in list] [prev in thread] [next in thread] 

List:       glibc-bug
Subject:    sem_trywait on initial zeroed semaphore core dumps
From:       "Iseri, Jerry" <Jerry.Iseri () SpirentCom ! COM>
Date:       2002-11-28 0:16:58
[Download RAW message or body]



-----Original Message-----
From: Jerry.Iseri@talos4.Adtech-Inc.COM
[mailto:Jerry.Iseri@talos4.Adtech-Inc.COM]
Sent: Wednesday, November 20, 2002 3:39 PM
To: glibc-bug-reports-stable@gnu.org
Cc: Jerry.Iseri@SpirentCOM.com
Subject: sem_trywait on initial zeroed semaphore core dumps 


>Submitter-Id:	net
>Originator:	
>Organization:
 
>Confidential:	no
>Synopsis:	sem_trywait on zeroed semaphore core dumps
>Severity:	serious
>Priority:	medium
>Category:	libc
>Class:		sw-bug
>Release:	libc-2.2.4
>Environment:
	
Host type: i386-redhat-linux-gnu
System: Linux talos4 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
Architecture: i686

Addons: c_stubs glibc-compat linuxthreads
Build CFLAGS: -march=i386 -D__USE_STRING_INLINES -fstrict-aliasing
-freorder-blocks -DNDEBUG=1 -g -O3
Build CC: gcc
Compiler version: 2.96 20000731 (Red Hat Linux 7.2 2.96-108.1)
Kernel headers: 2.4.2-2
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio

>Description:
compile the following code using
g++ -DLinux -D_REENTRANT -o semaphore1 semaphore1.c -lrt -lpthread
This works on the following release (Red Hat Linux release 6.1 (Cartman)
Release:       libc-2.1.2
Environment:
                <machine, os, target, libraries (multiple lines)>
Host type: i386-redhat-linux-gnu
System: Linux swrhat4 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown
Architecture: i686

Addons: crypt glibc-compat linuxthreads
Build CFLAGS: -O3 -Wall -Winline -Wstrict-prototypes -Wwrite-strings -g
Build CC: egcs
Compiler version: egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
Kernel headers: 2.2.12-20
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio





>How-To-Repeat:
/*
 * File: semaphore1.c
 *
 *
 *
--------------------------------------------------------------------------
 *
 *
--------------------------------------------------------------------------
 *
 *	Pthreads-win32 - POSIX Threads Library for Win32
 *	Copyright(C) 1998 John E. Bossom
 *	Copyright(C) 1999,2002 Pthreads-win32 contributors
 *
 *	Contact Email: rpj@ise.canberra.edu.au
 *
 *	The current list of contributors is contained
 *	in the file CONTRIBUTORS included with the source
 *	code distribution. The list can also be seen at the
 *	following World Wide Web location:
 *	http://sources.redhat.com/pthreads-win32/contributors.html
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU Lesser General Public
 *	License along with this library in the file COPYING.LIB;
 *	if not, write to the Free Software Foundation, Inc.,
 *	59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 *
--------------------------------------------------------------------------
 *
 * Test Synopsis: Verify trywait() returns -1 and sets EAGAIN.
 * - 
 *
 * Test Method (Validation or Falsification):
 * - Validation
 *
 * Requirements Tested:
 * - 
 *
 * Features Tested:
 * - 
 *
 * Cases Tested:
 * - 
 *
 * Description:
 * - 
 *
 * Environment:
 * - 
 *
 * Input:
 * - None.
 *
 * Output:
 * - File name, Line number, and failed expression on failure.
 * - No output on success.
 *
 * Assumptions:
 * - 
 *
 * Pass Criteria:
 * - Process returns zero exit status.
 *
 * Fail Criteria:
 * - Process returns non-zero exit status.
 */

#include <unistd.h>
#if defined(SunOS)
#include <thread.h>
#endif
#include <pthread.h>
#include <sched.h>
#include <semaphore.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

void *
thr(void * arg)
{
  sem_t s;
  int result;

  assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);

  assert((result = sem_trywait(&s)) == -1);

  if ( result == -1 )
  {
    perror("thread: sem_trywait 1"); // No error
#if defined(LINUX)
    /*Is this a linux threads bug */
    printf("Linux errno = %d instead of Solaris/Win32 %d\n",errno,EAGAIN);
    //assert(errno == ESPIPE);
    /* works on RH Linux 6.1 */
    assert(errno == EAGAIN);
#else
    assert(errno == EAGAIN);
#endif
  }
  else
  {
    printf("thread: ok 1\n");
  }

  assert((result = sem_post(&s)) == 0);

  assert((result = sem_trywait(&s)) == 0);

  if ( result == -1 )
  {
    perror("thread: sem_trywait 2");
  }
  else
  {
    printf("thread: ok 2\n");
  }

  assert(sem_post(&s) == 0);

  return 0;
}


int
main()
{
  pthread_t t;
  sem_t s;
  int result;

  assert(pthread_create(&t, NULL, thr, NULL) == 0);
  assert(pthread_join(t, (void **)&result) == 0);
  assert(result == 0);

  assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);

  assert((result = sem_trywait(&s)) == -1);

  if ( result == -1 )
  {
    perror("main: sem_trywait 1"); // No error
#if defined(LINUX)
    /* a linux threads bug ??/ */
    printf("Linux errno = %d instead of Solaris/Win32 %d\n",errno,EAGAIN);
    //assert(errno == ESPIPE);
    /* works on RH Linux 6.1 */
    assert(errno == EAGAIN);
#else
    assert(errno == EAGAIN);
#endif
  }
  else
  {
    printf("main: ok 1\n");
  }

  assert((result = sem_post(&s)) == 0);

  assert((result = sem_trywait(&s)) == 0);

  if ( result == -1 )
  {
    perror("main: sem_trywait 2");
  }
  else
  {
    printf("main: ok 2\n");
  }

  assert(sem_post(&s) == 0);

  return 0;
}


>Fix:
	unknown


_______________________________________________
Bug-glibc mailing list
Bug-glibc@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-glibc
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic