Date: Wed, 16 Jun 1999 17:49:12 +0200 (CEST) From: dirk.meyer@dinoex.sub.org To: FreeBSD-gnats-submit@freebsd.org Subject: kern/12247: userlevel program let kernel hang Message-ID: <199906161549.RAA00552@home.dinoex.sub.org>
next in thread | raw e-mail | index | archive | help
>Number: 12247 >Category: kern >Synopsis: userlevel program let kernel hang >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jun 16 09:20:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Dirk Meyer >Release: FreeBSD 3.2-RELEASE i386 >Organization: privat >Environment: FreeBSD 3.2-RELEASE i386 FreeBSD 2.2.8-RELEASE i386 KERNEL.GENERIC and my custom KERNELS /usr/bin/gdb >Description: while debugging a userlevel program The user can hang the system, no other processes seem to work. >How-To-Repeat: (sync all data first) extract this shar file, create the executable with "gmake" and run the script "hangme.sh" Send a signal <CTRL>+<C> to the debugger # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # hangme # hangme/hangme.c # hangme/hangme.sh # hangme/GNUmakefile # echo c - hangme mkdir -p hangme > /dev/null 2>&1 echo x - hangme/hangme.c sed 's/^X//' >hangme/hangme.c << 'END-of-hangme/hangme.c' X/****************************************************************** X* HANGME.C X******************************************************************/ X X/****************************************************************** X* X* This Programm should test a problem with locking X* X* Copyright (c) 1992,1993,1994,1995,1996,1997,1998,1999 X* by Dirk Meyer, All rights reserved. X* Im Grund 4, 34317 Habichtswald, Germany X* Email: dirk.meyer@dinoex.sub.org X* X******************************************************************/ X X#include <stdio.h> X#include <stdlib.h> X#include <string.h> X X#include <unistd.h> X#include <fcntl.h> X#include <signal.h> X#include <errno.h> X X/****************************************************************** X******************************************************************/ X Xtypedef int lockhandle_t; X Xconst char *const *Argv; X Xpid_t Session_gpid; X Xconst char *Logfile = "logfile"; X Xvolatile int Hang_up; X X/****************************************************************** X******************************************************************/ X Xvoid lock_handle( lockhandle_t handle, const char *datei ) X{ X int st; X X if ( datei == NULL ) X return; X X /* CONSTANTCONDITION */ X while ( 1 ) { X st = flock( handle, LOCK_EX | LOCK_NB ); X if ( st == 0 ) X break; X if ( errno == EWOULDBLOCK ) { X printf( "blocked by <%s>\n", datei ); X break; X }; X fprintf( stderr, X "lock <%s> returns %d: %s", datei, st, X strerror( errno ) ); X if ( errno == ENOLCK ) { X sleep( 20 ); X continue; X }; X return; X }; X /* CONSTANTCONDITION */ X while ( 1 ) { X st = flock( handle, LOCK_EX ); X if ( st == 0 ) X break; X fprintf( stderr, X "lock <%s> returns %d: %s", datei, st, X strerror( errno ) ); X if ( errno == ENOLCK ) { X sleep( 20 ); X continue; X }; X return; X } X} X X/****************************************************************** X******************************************************************/ X XFILE *file_open( const char *datei, const char *mode ) X{ X FILE *handle; X X if ( datei == NULL ) X return ( NULL ); X X handle = fopen( datei, mode ); X if ( handle == NULL ) X fprintf( stderr, X "Fatal: Datei '%s' nicht verfuegbar", datei ); X if ( mode[ 0 ] != 'r' ) X lock_handle( fileno( handle ), datei ); X return ( handle ); X} X Xvoid file_close( FILE *handle ) X{ X int status; X X status = fclose( handle ); X if ( status != 0 ) { X fprintf( stderr, X "Fatal: Fehler %d beim Schliessen der Datei", X status ); X } X} X X/****************************************************************** X******************************************************************/ X X#ifdef __FreeBSD__ X#undef SIG_DFL X#define SIG_DFL (void (*)(int))0 X#undef SIG_IGN X#define SIG_IGN (void (*)(int))1 X#endif X Xvoid my_appl_exit( void ); Xvoid my_appl_exit( void ) X{ X signal( SIGHUP, SIG_DFL ); X signal( SIGQUIT, SIG_DFL ); X} X Xvoid onquit( int test ); X/* ARGSUSED */ Xvoid onquit( int test ) X{ X fprintf( stderr, "QUIT-Signal\n" ); X signal( SIGQUIT, onquit ); X X signal( SIGHUP, SIG_IGN ); X signal( SIGTERM, SIG_IGN ); X if ( Session_gpid > 1 ) X (void)kill( -Session_gpid, SIGHUP ); X if ( Session_gpid > 1 ) X (void)kill( -Session_gpid, SIGTERM ); X my_appl_exit(); X execv( Argv[ 0 ], (char *const *)Argv ); X} X Xvoid onhangup( int test ); X/* ARGSUSED */ Xvoid onhangup( int test ) X{ X FILE *flog; X X fprintf( stderr, "HANGUP-Signal\n" ); X if ( Hang_up == 0 ) { X signal( SIGHUP, SIG_IGN ); X if ( Session_gpid > 1 ) { X (void)kill( -Session_gpid, SIGHUP ); X } X }; X Hang_up = 1; X signal( SIGHUP, onhangup ); X X /* deadlock */ X flog = file_open( Logfile, "ab" ); X file_close( flog ); X} X Xvoid my_appl_init( void ); Xvoid my_appl_init( void ) X{ X#ifdef __FreeBSD__ X int error; X#endif X X atexit( my_appl_exit ); X#ifdef __FreeBSD__ X error = setpgid( 0, getppid() ); X if ( error < 0 ) { X fprintf( stderr, X "!!! Fehler %d in " X "'setpgid( ppid=%ld )' :%s", X error, (long)getppid(), X strerror( errno ) ); X }; X Session_gpid = setsid(); X if ( Session_gpid < (pid_t)0 ) { X fprintf( stderr, X "!!! Fehler %d in " X "'setsid()' :%s", error, X strerror( errno ) ); X }; X#else X Session_gpid = 0; X#endif X signal( SIGHUP, onhangup ); X signal( SIGQUIT, onquit ); X} X Xvoid main( int argc, const char *const *argv ); Xvoid main( int argc, const char *const *argv ) X{ X FILE *flog; X X Hang_up = 0; X Argv = argv; X my_appl_init(); X flog = file_open( Logfile, "ab" ); X fputs( "main\n", flog ); X while ( Hang_up == 0 ) X ; X file_close( flog ); X exit( 0 ); X} X X/****************************************************************** X* END OF FILE HANGUP.C X******************************************************************/ END-of-hangme/hangme.c echo x - hangme/hangme.sh sed 's/^X//' >hangme/hangme.sh << 'END-of-hangme/hangme.sh' X#!/bin/sh X# X# (c) 1994-99, Dirk Meyer, Im Grund 4, 34317 Habichtswald X# Xnpid="$$" X./hangme & Xsleep 1 Xnpid=`expr ${npid} + 1` Xecho "${npid}" Xkillall -1 hangme Xsleep 1 Xgdb ./hangme "${npid}" << 'EOF' Xq XEOF Xgdb ./hangme "${npid}" << 'EOF' Xq XEOF Xkillall -9 hangme X# X# eof END-of-hangme/hangme.sh echo x - hangme/GNUmakefile sed 's/^X//' >hangme/GNUmakefile << 'END-of-hangme/GNUmakefile' X XCPPFLAGS+= -Wall XCFLAGS+= -g XLDLAGS+= -g X Xall: hangme X END-of-hangme/GNUmakefile exit >Fix: none found >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199906161549.RAA00552>