Linux-Development-Sys Digest #241, Volume #8     Sat, 28 Oct 00 23:13:09 EDT

Contents:
  Re: [Q] malloc() in signal handler (Nick Maclaren)
  DDD Debugger (Menni)
  Re: DDD Debugger (Philip Armstrong)
  Re: g++ compiler with templates (Philip Armstrong)
  Re: [Q] malloc() in signal handler (Philip Armstrong)
  Re: Genereting interrupt (The Ghost In The Machine)
  simple parallel port driver for LCD ("Michal K. Roszkowski")
  need to reload partition table ([EMAIL PROTECTED])
  Re: need to reload partition table ([EMAIL PROTECTED])
  Re: need to reload partition table ([EMAIL PROTECTED])
  set_blocksize: kernel error happening more ([EMAIL PROTECTED])
  kernel upgrade (Bo - Sun)
  Re: unexpected sorting order? (Ronald Cole)

----------------------------------------------------------------------------

From: [EMAIL PROTECTED] (Nick Maclaren)
Subject: Re: [Q] malloc() in signal handler
Date: 28 Oct 2000 18:28:04 GMT

In article <8tf1db$2th$[EMAIL PROTECTED]>,
Philip Armstrong <[EMAIL PROTECTED]> wrote:
>In article <8tee6s$a86$[EMAIL PROTECTED]>,
>Nick Maclaren <[EMAIL PROTECTED]> wrote:
>>No.  You can't do ANYTHING significant inside a signal handler safely.
>
>ouch.
>
>>That is what ISO C and POSIX say, and regrettably it corresponds with
>>the miserable state of most implementations.  GNU is one of the more
>>signal-friendly, but even it is not safe.  The techniques for making
>>it safe were well-known 25 years ago, but got forgotten when the
>>UNIX etc. revolution threw away the experience of previous decades.
>
>Yurk. A little reading reveals that you can't call *any* function
>safely in a signal handler. Which I guess makes sense. You get bitten
>by re-entrancy problems. eg If you get a signal when you're in the
>middle of a malloc() then calling malloc() in your signal handler is
>almost guaranteed to corrupt your heap.

Yes, but that problem is quite easy to code around!  As I say, I
have done it more than once.  It is very hard to avoid a storage
leak when that happens, but it is quite easy to avoid corruption.

The same thing applies to I/O.  It is easy to ensure that you
don't corrupt a file, if you design the primitives right, but it
is very hard to avoid disabling a file against further use.

The REALLY nasty problems occur with the data that is produced by
the compiler, and those are more-or-less insoluble without designing
a language that allows proper recover.  And you don't start from C
if you are going there.

>So would you have time to expand on how signals can be made safe? Or
>point to a suitable on line resource? Maybe this thread should shift
>to comp.arch...folowups set.

Unfortunately, I don't know of one.  I mean to write a book on
the greasy spanner approach to software engineering sometime,
but you know how things are.  This was traditionally passed on
by observation of code and from person to person.

If anyone is likely to tackle this seriously, in a language
system or language design, I am quite happy to be asked about
some of the techniques.  But the trouble is that they aren't
trivial to describe clearly and concisely.

This isn't primarily a hardware issue, but a software one.
I have removed comp.arch again, because I am sick and tired of
some of the lame-brain flamers on that group and no longer
subscribe to it.  Here is a VERY brief description of a couple
of techniques, that date from time immemorial:

    Every call that uses an object (say a FILE structure) starts
off by locking it and finishes by unlocking it.  Yes, EVERY call.
This doesn't need a system call, because the lock need be just
a store of a bit.  If the lock is already set, the object is
regarded as either in use or corrupted, and is not touched
further.

    Storage allocation can be done rather better by using a
simple compare-and-swap (or whatever).  You calculate the new top
of heap, and then set it atomically with checking that it has
not changed.  If not, you go round again.  Any decent architecture
has an atomic operation to do this with two pointers.

Note that these AUTOMATICALLY protect against corruption by
signal handlers, though you run the risk of losing the object
you were working on (in the first case) if a signal occurs and
the handler longjmps out OVER your code.  You lose nothing if it
sets a flag and returns.

But they require the heretical concepts of having an object
marked as corrupted in a way that cannot be reset by the program
and of permitting an object to be in a state that it cannot be
used.  Shock! Horror!  

I did this for the first full-function ISO C implementation for
MVS, and IBM used very similar techniques for the second (though
they tended to say 'Oh, shucks, it MIGHT work' rather than fail.
But I ignored some of the more demented aspects of the standard
(such as the fact that clearerr() ALWAYS succeeds).


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email:  [EMAIL PROTECTED]
Tel.:  +44 1223 334761    Fax:  +44 1223 334679

------------------------------

From: Menni <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.apps
Subject: DDD Debugger
Date: Sat, 28 Oct 2000 20:38:00 +0200

Hi alltogether!

When invoking the Data Display Debugger, I always get the error message
"DDD: No Debugger" (GDB could not be started). Trying to follow the
instructions of the help message does not lead to any change. 
On the bottom of the DDD-window a further message appears: "Running GDB
(pid <anynumber>, tty /dev/pts/4)..Exit 1."
What's going wrong there? How to start a debug session properly?

Thanks in advance!

Constant

------------------------------

From: [EMAIL PROTECTED] (Philip Armstrong)
Crossposted-To: comp.os.linux.development.apps
Subject: Re: DDD Debugger
Date: 28 Oct 2000 20:42:42 +0100

In article <[EMAIL PROTECTED]>, Menni  <[EMAIL PROTECTED]> wrote:
>When invoking the Data Display Debugger, I always get the error message
>"DDD: No Debugger" (GDB could not be started). Trying to follow the
>instructions of the help message does not lead to any change. 
>On the bottom of the DDD-window a further message appears: "Running GDB
>(pid <anynumber>, tty /dev/pts/4)..Exit 1."
>What's going wrong there? How to start a debug session properly?

It's telling you that it can't find gdb, which is the text mode
debugger that ddd sits on top of. (Actually I think ddd can use one of
several debuggers)

Have you installed gdb?

Phil

-- 
http://www.kantaka.co.uk/ .oOo. public key: http://www.kantaka.co.uk/gpg.txt


------------------------------

From: [EMAIL PROTECTED] (Philip Armstrong)
Subject: Re: g++ compiler with templates
Date: 28 Oct 2000 21:01:04 +0100

In article <[EMAIL PROTECTED]>,
Michael Kooiman <[EMAIL PROTECTED]> wrote:
>I'm writing a C++ text/based program on Caldera linux.
>I'm getting trouble when trying to compile the source code and having a
>general template function
>in it.
>
>The function is a friend of the class.
>Like:
>template<class Type>
>ostream& operator<<(ostream& stream, Array<T>& array)
>{
>    for (int i=0; i<array.getSize(); i++)
>     stream << array[i];        // ofcourse  overloaded the subscript
>operator in the Array class.
>return stream;
>}
>
>I get the message while compiling:
>Using template without type. .. and some more.
>Is there a special commandline option to turn on template support on of the
>compiler ?
>
>if anyone knows more, i'd appreciate some help here.

This is really a comp.lang.c++ question, but you probably want
something like:

#include <iostream>
template <class T> class Arr;
template <class T> ostream & operator<<(ostream &, Arr<T> &);

// Sample template class 
template <class T> class Arr
{
  int data;
  friend ostream & operator<< <T> (ostream & , Arr<T> &);
};

template <class T> ostream & operator<<(ostream &os, Arr<T> &array)
{
  os << data;
  return os;
}

I think you need to a) pre-declare the relevant class + friend
function and b) get the friend statement correctly specified for what
you want to do.

Have a read of /usr/doc/g++/FAQ.gz for some sample code.

Phil
-- 
http://www.kantaka.co.uk/ .oOo. public key: http://www.kantaka.co.uk/gpg.txt


------------------------------

From: [EMAIL PROTECTED] (Philip Armstrong)
Subject: Re: [Q] malloc() in signal handler
Date: 28 Oct 2000 21:17:26 +0100

In article <8tf5rk$3tj$[EMAIL PROTECTED]>,
Nick Maclaren <[EMAIL PROTECTED]> wrote:
>In article <8tf1db$2th$[EMAIL PROTECTED]>,
>Philip Armstrong <[EMAIL PROTECTED]> wrote:
>>In article <8tee6s$a86$[EMAIL PROTECTED]>,
>>Nick Maclaren <[EMAIL PROTECTED]> wrote:
>>Yurk. A little reading reveals that you can't call *any* function
>>safely in a signal handler. Which I guess makes sense. You get bitten
>>by re-entrancy problems. eg If you get a signal when you're in the
>>middle of a malloc() then calling malloc() in your signal handler is
>>almost guaranteed to corrupt your heap.
>
>Yes, but that problem is quite easy to code around!  As I say, I
>have done it more than once.  It is very hard to avoid a storage
>leak when that happens, but it is quite easy to avoid corruption.

Sure. Not having done any mind you; but I presume you set a bit
somewhere and have the main program loop check the bit regularly in
order to do the grunt work required by the signal occurence.

[snip]
>>So would you have time to expand on how signals can be made safe? Or
>>point to a suitable on line resource? Maybe this thread should shift
>>to comp.arch...folowups set.
>
>Unfortunately, I don't know of one.  I mean to write a book on
>the greasy spanner approach to software engineering sometime,
>but you know how things are.  This was traditionally passed on
>by observation of code and from person to person.

"greasy spanner approach" -- I like it.

[snip ideas of ways to handle this stuff]

>But they require the heretical concepts of having an object
>marked as corrupted in a way that cannot be reset by the program
>and of permitting an object to be in a state that it cannot be
>used.  Shock! Horror!  

Is c++ with exceptions sufficient? Assuming you write exception safe
code of course (which is a non-trivial exercise in itself. At least
the stl is {mostly} exception safe). I've a feeling that you might
still suffer from the resource leak problem, since most c++
implementations are still built on top of malloc() + involve calls to
C based libraries as well.

>I did this for the first full-function ISO C implementation for
>MVS, and IBM used very similar techniques for the second (though
>they tended to say 'Oh, shucks, it MIGHT work' rather than fail.
>But I ignored some of the more demented aspects of the standard
>(such as the fact that clearerr() ALWAYS succeeds).

Standards are like all rules; there for the obedience of fools and the
guidance of wise men as the saying goes. Of course you have to be
*really* sure which side of the line you fall if you're going to break
the standards!

cheers,

Phil




-- 
http://www.kantaka.co.uk/ .oOo. public key: http://www.kantaka.co.uk/gpg.txt


------------------------------

From: [EMAIL PROTECTED] (The Ghost In The Machine)
Subject: Re: Genereting interrupt
Date: Sat, 28 Oct 2000 20:27:24 GMT

In comp.os.linux.development.system, niko
<[EMAIL PROTECTED]>
 wrote
on Sat, 28 Oct 2000 14:39:05 GMT
<dyBK5.12810$[EMAIL PROTECTED]>:
>Hello All !
>I need generate some interrupts.

In what sense?

On Unix and Linux, there are signals (man signal); that's the closest thing
a user mode program can get.  (Interrupt is SIGINT.)  Signals can be
caught, except for SIGKILL and SIGSTOP.

Unix and Linux don't support x86 INT calls from within a usermode
program.  Doing so most likely will result in some sort of
kernel trap, which generates an illegal instruction signal (SIGILL).
Admittedly, I haven't tested this.

There's also the possibility that INT is used to implement the
user->system transition necessary on any Unix or Unix-like system.
I am ignorant on this particular issue, though.

(My main focus on Linux has been application-level development, with a
side thrust some years back into simple debugging of file system stuff
in affs, which never amounted to much but was interesting.
However, that level is far removed from the user, and not all that
near to the disk I/O, either; calls to read blocks are handled
through things like bread(), for example.)

If you want to do raw disk reads, you'll need root privileges anyway,
but you can use standard open()/fopen()/new ifstream calls (depending
on library and environment) on devices such as /dev/hda1 (for
the first partition of the first IDE drive) or /dev/sda (for
the entire disk of the first SCSI drive).  The only exception I know
about is the CD-ROM when attempting to read audio disks; that
requires an ioctl which I don't remember offhand; there are also
some issues with reading a tty or serial device, as it wants to
buffer a line by default.

One can even read memory using /proc/kcore or /proc/<pid>/mem,
privileges permitting.  Note that the seek point is the logical
address; a bad address will generate an I/O error of some sort,
most likely.  (See also /proc/<pid>/maps.)

Unix: the OS that was OO before there *was* an OO. :-)

>And I want to know are there any functions like MS$ geninterrupt(), int86(),
>.... etc

Maybe deep in the kernel; I'd have to look.  Usermode programs, no.

[.sigsnip]

-- 
[EMAIL PROTECTED] -- insert random misquote here

------------------------------

From: "Michal K. Roszkowski" <[EMAIL PROTECTED]>
Subject: simple parallel port driver for LCD
Date: Sat, 28 Oct 2000 17:23:12 -0700


Hi all,

i'm trying to write a driver for a LCD connected to my laptop via the
parallel port...
i've written user level code to control it which works fine...

due to how the thing is wired, the port has to be in standard mode which
is
set in the BIOS...

how ever when i load my driver module into the kernel, it seems to
switch
to bi-directional mode because my signals become inverted and the
LCD gets very confused...

when i unload the driver, the user lever program doesn't work anymore
because the signals are still inverted....
i need to reboot to set everything straight...

can anyone give me a hint to what the problem could be?

i'm using RedHat 6.2 with kernel 2.2.16-3
on an IBM thinkpad 570

thanks
michal



------------------------------

From: [EMAIL PROTECTED]
Subject: need to reload partition table
Date: Sun, 29 Oct 2000 00:38:55 -0000

I need to reload the partition table for a disk in which one of the
partitions is already mounted.  The one that is mounted will NOT be
changed, neither in it's sector position nor in its numbered order.
Trying to do so gets device busy now.  Clearly this is a whole device
busy indication, which shouldn't be applied in my situation.

I do need to get this done, so I'm looking at modifying the kernel.
But dilligence urges me to ask these questions first:

1.  Has anyone already done this?

2.  Any chance 2.4 has this?  I don't see it so far, OTOH, all this
    devfs has sure changed things and I'm not sure it just isn't so
    simple now that it would just work right.

3.  Any suggestions on the approach?

My thought is that instead of checking for the whole drive being busy,
read the partition table into a temporary location and look for the
partitions in the running table which are changed in any way in the new
one.  Check only the changed ones for busy and abort if so.

Alternatively, I could check for the partitions that are busy, and do
a check to see if they change or not.  If not, then make the change.

-- 
| Phil Howard - KA9WGN | My current websites: linuxhomepage.com, ham.org
| phil  (at)  ipal.net +----------------------------------------------------
| Dallas - Texas - USA | [EMAIL PROTECTED]

------------------------------

From: [EMAIL PROTECTED]
Subject: Re: need to reload partition table
Date: Sun, 29 Oct 2000 01:39:07 +0000

In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
wrote:

> I need to reload the partition table for a disk in which one of the
> partitions is already mounted.  The one that is mounted will NOT be changed,
> neither in it's sector position nor in its numbered order. Trying to do so
> gets device busy now.  Clearly this is a whole device busy indication, which
> shouldn't be applied in my situation.
> 

Which end of the flame thrower are you holding?.

> I do need to get this done, so I'm looking at modifying the kernel. But
> dilligence urges me to ask these questions first:
> 
> 1.  Has anyone already done this?
> 

Not that I knwo of!.

> 2.  Any chance 2.4 has this?  I don't see it so far, OTOH, all this
>     devfs has sure changed things and I'm not sure it just isn't so simple
>     now that it would just work right.
> 

2.4 won't change this.  devfs will present the partition device names, even
after changes.

> 3.  Any suggestions on the approach?
> 

While I understand that what you want would be ok,  what you want is
dangerous.  Accidental changes to the partition table with mounted partitions
could be problematic for whole machine.

A less intrusive way (kernel wise) would be to operate on the /dev/hdX device
directly. I think it's fdisk etc that does the checking, not sure though.

karl.

------------------------------

From: [EMAIL PROTECTED]
Subject: Re: need to reload partition table
Date: Sun, 29 Oct 2000 02:18:53 -0000

On Sun, 29 Oct 2000 01:39:07 +0000 [EMAIL PROTECTED] wrote:

|> I need to reload the partition table for a disk in which one of the
|> partitions is already mounted.  The one that is mounted will NOT be changed,
|> neither in it's sector position nor in its numbered order. Trying to do so
|> gets device busy now.  Clearly this is a whole device busy indication, which
|> shouldn't be applied in my situation.
|> 
|
| Which end of the flame thrower are you holding?.

Huh?


|> 2.  Any chance 2.4 has this?  I don't see it so far, OTOH, all this
|>     devfs has sure changed things and I'm not sure it just isn't so simple
|>     now that it would just work right.
|> 
|
| 2.4 won't change this.  devfs will present the partition device names, even
| after changes.

I take this to mean that the logic of loading the partition table is unrelated
to the devfs changes.  That could make sense (depending on the exact details
of the kernel architecture).


|> 3.  Any suggestions on the approach?
|> 

| While I understand that what you want would be ok,  what you want is
| dangerous.  Accidental changes to the partition table with mounted partitions
| could be problematic for whole machine.

It's just as dangerous now.  That's why it prevents the reloading.  The
problem is that it doesn't address the specific scope of what is actually
changed, and instead blocks the whole device.


| A less intrusive way (kernel wise) would be to operate on the /dev/hdX device
| directly. I think it's fdisk etc that does the checking, not sure though.

Sorry, but you are not all clear here.  What do you mean by "directly"?

The kernel is what checks for device busy when attempting to make partition
table change reloads.  This happens in the kernel when ioctl(fd,BLKRRPART,...)
is called on the device (fdisk does this call).  The kernel sees that some
partition is busy on the device and refuses to re-read the table.  There
is a reason for the concept, but it's just not implemented well (IMHO).

What I believe it should do is read the new table in from sector 0 (or from
wherever for other partitioning types), and perform a comparison between
the new table and the old table already in effect.  For each old partition
which is affected in any way by the difference, such as moving the partition,
or an overlap into that partition that wasn't there exactly that way before,
if that partition's associated device is busy, then refuse to make the new
partition table go into effect.  Alternatively, selectively refuse to make
changes which affect busy existing partitions, but apply changes which do
not cause any such effect.

BTW, I am using fdisk sometimes, and sfdisk at other times, to change the
partition tables.  They don't resist even when one of the partitions is
mounted, although I never actually make changes to the one that is mounted
(and in my case it has always been hda1).  Neither fdisk nor sfdisk is
serving my needs all that well and I am contemplating writing my own to
make my system building scripts work a lot smoother.

One thing I was hoping to see when devfs is implemented (it is now, so maybe
this feature can eventually be added) is to allow ANY block device to be
sliced up into partitions using ANY partitioning scheme, and add new devfs
names as this is done.  This would not only include every block device such
as floppies and network block devices, but even the very added partitions
themselves can be subdivided.  One use I have for this is a means to build
block device images in advance during system builds, resulting in a "ready
to dd" system image of any desired size.

-- 
| Phil Howard - KA9WGN | My current websites: linuxhomepage.com, ham.org
| phil  (at)  ipal.net +----------------------------------------------------
| Dallas - Texas - USA | [EMAIL PROTECTED]

------------------------------

From: [EMAIL PROTECTED]
Subject: set_blocksize: kernel error happening more
Date: Sun, 29 Oct 2000 02:30:17 -0000

This problem today is happening even more.  Now several partitions are
getting this error when I mount them right after mke2fs.

version info:

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
        Using EXT2FS Library version 1.18

mount: mount-2.10l

Linux vega-admin.ipal.net 2.2.17 #1 Tue Oct 17 18:16:54 CDT 2000 i686 unknown


A sample of the messages:

set_blocksize: b_count 1, dev ide0(3,2), block 64256, from c0143d32
set_blocksize: b_count 1, dev ide0(3,5), block 192704, from c0143d32
set_blocksize: b_count 1, dev ide0(3,6), block 128448, from c0143d32
set_blocksize: b_count 1, dev ide0(3,7), block 256960, from c0143d32
set_blocksize: b_count 1, dev ide0(3,8), block 256960, from c0143d32
set_blocksize: b_count 1, dev ide0(3,9), block 1156608, from c0143d32
set_blocksize: b_count 1, dev ide0(3,10), block 192704, from c0143d32
set_blocksize: b_count 1, dev ide0(3,4), block 42524032, from c0143d32


There are a LOT more messages coming out each time.  A log of the whole
thing, with a copy of the script I was running to do it all, is here:

http://phil.ipal.org/set_blocksize.txt (36335 bytes)

The thing is, there is no explanation in the kernel docs or source as to
what this message means or is trying to say.  It looks like debugging
info.

-- 
| Phil Howard - KA9WGN | My current websites: linuxhomepage.com, ham.org
| phil  (at)  ipal.net +----------------------------------------------------
| Dallas - Texas - USA | [EMAIL PROTECTED]

------------------------------

From: Bo - Sun <[EMAIL PROTECTED]>
Subject: kernel upgrade
Date: Sat, 28 Oct 2000 21:27:50 -0500

Hi, everyone:

I am new to linux, and now I need to upgrade my kernel from 2.2.14 to
2.2.16, would like to ask some questions:

where can I download the newer version of linux kernel?
What is the detailed procedures to upgrade it?

I appreriate your help.

Bo 




------------------------------

From: Ronald Cole <[EMAIL PROTECTED]>
Subject: Re: unexpected sorting order?
Date: 28 Oct 2000 19:07:30 -0800

Ronald Cole <[EMAIL PROTECTED]> writes:
> I've filed bug #19942 in Bugzilla.

A quick fix is to remove /etc/sysconfig/i18n.

-- 
Forte International, P.O. Box 1412, Ridgecrest, CA  93556-1412
Ronald Cole <[EMAIL PROTECTED]>      Phone: (760) 499-9142
President, CEO                             Fax: (760) 499-9152
My GPG fingerprint: C3AF 4BE9 BEA6 F1C2 B084  4A88 8851 E6C8 69E3 B00B

------------------------------


** FOR YOUR REFERENCE **

The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:

    Internet: [EMAIL PROTECTED]

You can send mail to the entire list (and comp.os.linux.development.system) via:

    Internet: [EMAIL PROTECTED]

Linux may be obtained via one of these FTP sites:
    ftp.funet.fi                                pub/Linux
    tsx-11.mit.edu                              pub/linux
    sunsite.unc.edu                             pub/Linux

End of Linux-Development-System Digest
******************************

Reply via email to