HDTenEightyP/NetNews huggingface dataset:
From: qinyi@uk.ac.man.cs (Yi Qin (BCW PhD))
Newsgroups: comp.unix.programmer
Subject: Question of wait()
Date: 15 Apr 92 14:07:03 GMT
Organization: University of Manchester, UK

Hello.

The manual page of system call wait() (for SunOS4.1.1) says "_the wait()
delays its caller until a signal is received_ or one of  its  child
processes terminates or stops due to tracing." But I found this wait()
does not behave as said: upon receipt of a signal, it doesn't return
to the user mode of the process. It either exits in the normal way
when some unexpected signal is received, or executes the signal handler
when there is one installed for the received signal, and then resumes
wait(). IMHO, in the latter case at least, the process should continue
executs in the user mode after interrupted from wait(). The following
is a little test program is the source of my suspection and it's self-
explanatary. Please enlight me if you think I am still in the dark.

Thanks

Yi Qin
qinyi@cs.man.ac.uk
---------------------------

#include <stdio.h>
#include <errno.h>
#include <sys/wait.h>
#include <signal.h>

void sig_handler(sig, code, sigc, addr)  /* SIGINT handler */
int sig, code;
struct sigcontext *sigc;
char *addr;
{
    printf("sig_handler activated in process %d\n", getpid());
}

main()
{
    int status = 0;
    int pid;
    struct sigvec vec;

    vec.sv_handler = (void (*)())sig_handler;
    vec.sv_mask = 0;
    vec.sv_flags = 0;
    if (sigvec(SIGINT, &vec, 0) == -1) {  /* Install SIGINT handler */
        perror("sigvec");
        exit(2);
    }

    if ((pid = fork()) == 0) {  /* Here is the child's code. */
        printf("Child says: my pid is %d\n", getpid());
        for (;;) { }       /* The child goes into a dead loop */
    }
    else if (pid == -1) {  /* Error checking */
        perror("fork()");
        exit(2);
    }

    /* Here is the parent's code. */
    printf("Parent says: my pid is %d\n", getpid());
    printf("Before wait()\n");
    do {
        pid = wait(&status);      /* Only return when a child dies. */
        printf("wait() resumed\n");  /* Expected to be done but not
                                        done for any event except the
                                        death of child. This should be
                                        done if the manpage is right. */
    } while (pid == EINTR);

    printf("After wait(). Pid of dead child is %d\n", pid);

    /* In this program, the child always dies when the parent dies. */
}

------------------------------
Newsgroups: comp.unix.programmer
From: net@cs.tu-berlin.de (Oliver Laumann)
Subject: Re: Dynamic loading under MORE/bsd
Organization: Technical University of Berlin, Germany
Distribution: comp
Date: Thu, 9 Apr 1992 10:49:24 GMT

In article <1992Apr9.015729.2278@comp.vuw.ac.nz>
Ray.Nickson@comp.vuw.ac.nz (Ray Nickson) writes:
> main (int argc, char *argv[])
> {
>   char *codeptr = sbrk (0), *cp = codeptr;
>   [..]
>   
>   printf ("loading %s with entry %s at 0x%lx\n", 
>           argv[1], argv[2], (long)codeptr);
> [..]

I'm not sure if this solves your problem (I don't know anything about
MORE/bsd), but you certainly should't call sbrk(0) at that point in
your program.  There exist versions of stdio where the first call to
printf() in a program can cause a call to malloc(); in this case your
program's `break' gets altered between the sbrk(0) and the call to the
linker.

You should move the sbrk(0) to the line before the call to sprintf()
that assembles the arguments for /bin/ld.

In addition, your call to fopen() between the system() and the point
where you call sbrk() to actually allocate the memory for the file
to be loaded may again alter the `break'.  You should use open()
instead.

--
Oliver Laumann    net@tub.cs.tu-berlin.de  net@tub.UUCP  net@tub.BITNET
From: markd@phoenix.pub.uu.oz.au (Mark Delany)
Newsgroups: comp.unix.programmer
Subject: Re: Lost: an interesting hack
Date: 7 Apr 92 16:49:44 GMT
Organization: Phoenix ComSystem. Public UNIX Melbourne Australia.

In <1992Apr01.215845.7815@spike.insci.com> ross@insci.com (Ross Andrus) writes:


>Hello again

>  Once upon a time I saw an interesting hack which I now wish I'd paid more
>  attention to. If someone out there knows it (or wrote it in the first
>  place!) could you let me know where to find it (or send it to me)?

>  It goes (roughly) like this:  we want to save an `image' of a running 
>  process so that we can start it up again more or less exactly where it
>  left off. The general idea of the hack was to discover the extent of the 
>  data segment, write the whole mess to a file, and then later, in another 
>  process, read it all back in and pick up execution where it left off. 

A perennial post. 

The problem is not so much the program state, but the external state.
Which fd's, sockets, msg Q's, pipes, etc point to what and so on.

To envisage the nature of the problem, imagine your program is
half-way through a telnet session with "Joe random" computer system.
This state, must be stashed and re-established. No mean feat.

I am told that products are available that help in this area -
especially in the realm of supercomputing OS's - but there is hardly a
general solution available to the general problem in the Unix domain.

>  I remember reading this in the sources for one of the incarnations of
>  rogue, but I'm not sure I ever *ran* the program and tried it. Did 
>  this really work? Is it even vaguely portable? Is there a better way
>  to do this?

This is the most common solution. Application specific programs write
relevant state info to disk and detect it at startup. Hardly general,
perhaps portable.




-----------                                          --------------------------
Mark Delany                                          markd@phoenix.pub.uu.oz.au
From: rrybacki@ringer.cs.utsa.edu (Richard M. Rybacki)
Newsgroups: comp.unix.programmer
Subject: Re: non-blocking accept()
Date: 9 Apr 92 18:01:32 GMT
Organization: University of Texas at San Antonio

In article <1992Apr9.164413.17641@helios.physics.utoronto.ca> amid@bullet.ecf (AMID  Rudy) writes:
>'lo,
>
>  Can someone suggest to me exactly how to mark accept() non-blocking?  If
>I RTFM correctly, I have to set the file descriptor somehow.  I'm a novice
>Unix and C programmer so any help in this section is greatly appreciated.
>This is, btw, a socket programming project that I have to do in University.
>

#include <fcntl.h>
#include <errno.h>

.
.
.

fcntl(the_sock, F_SETFL, fcntl(the_sock, F_GETFL, 0) | O_NDELAY);

.
.
.

if ((new = accept(the_sock,...)) < 0)
	if (errno == EWOULDBLOCK)
		/* no queued connection attempts */
	else
		/* Not good if we are here */


-- 
Richard M. Rybacki                |     Happiness = Reality - Expectations
rrybacki@ringer.cs.utsa.edu       |     -- Click & Clack, The Tappet Brothers
From: pjunold@daimi.aau.dk (Peter Joachim Unold)
Newsgroups: comp.unix.programmer
Subject: a pipe problem
Summary: problems with pipes
Date: 13 Apr 92 00:55:06 GMT
Organization: DAIMI: Computer Science Department, Aarhus University, Denmark

I have a program that starts a process A which sends data to it's child B by
a pipe. Process A reads it's input from filedescriptor 0. However sometimes
I want Process B to send data to it's parrent A. It's important that this data
also should be be read from the same fd as used for stdin. Here's how it looks:

                *****      *****
keyboard--->----* A *----->* B * 
           |    *****      *****  
           |                 |
           ---------<---------

what I'm really trying to do is to make a pipe that looks like:

keyboard->--|
            ------->-----parent 
child---->--|

Is this possible at all? I've tried various variants of pipe, close and dup
without finding a solution. I hope someone can help me out of this one.

 - Peter Unold
Newsgroups: comp.unix.programmer
From: ihno@generics.ka.sub.org (Ihno Krumreich)
Subject: Re: Where is open file status is in UNIX
Organization: Generics GmbH
Date: Mon, 13 Apr 1992 20:02:15 GMT
Keywords: file status

In <1992Mar18.212152.7471@lambda.msfc.nasa.gov> mahmood@lambda.msfc.nasa.gov (Rafique Mahmood) writes:

>I like to know where UNIX system keeps the status of a file, which
>is currently opened or not. I looked at the stat.h file , which contain
>many info. but not about open status.

>I will appreciate if anyone please let me know.

This information is kept in the kernel, not on the disk. 

Ihno
-- 
Ihno Krumreich     | Phone (49) 721 38 70 94
Generics Gmbh      | email: ihno@generics.ka.sub.org
Breite Strasse 24  | FAX   (49) 721 38 56 22
D-W7500 Karlsruhe  |
From: wescott@grok67.ColumbiaSC.NCR.COM (Mike Wescott)
Newsgroups: comp.unix.programmer
Subject: Re: How to write the ANSI C time functions
Date: 15 Apr 92 17:05:02 GMT
Organization: "NCR Corp, Columbia, SC"

In article <12441@auspex-gw.auspex.com>, guy@Auspex.COM (Guy Harris) writes:
|> Wrongo.  "time()" returns something that is best thought of as *atomic*
|> time - i.e., it is supposed to return a value that, at 12:00 UTC,
|> January 1, 1970, was 0, and that has gone up by one every time an atomic
|> clock would have advanced by one second.

Hmmm. Didn't you really mean to say 00:00 UTC, Jan 1, 1970?

-- 
	-Mike Wescott
	 mike.wescott@ColumbiaSC.NCR.COM
Newsgroups: comp.unix.programmer
From: franl@centerline.com (Fran Litterio)
Subject: Re: indirect goto
Organization: CenterLine Software, Inc.
Date: Wed, 8 Apr 1992 19:46:09 GMT

In article <1992Apr7.015758.15792@descartes.waterloo.edu> amichail@descartes.waterloo.edu (Amir Michail) writes:

> I need to make a indirect goto in C depending upon a value of a 
> variable.  The only way I can think of doing it as follows:
> 
> l1:
> << code >>
> l2:
> << code >.
> l3:
> << code >>
> 
> now, suppose I want to jump to l1, l2 or l3 depending on whether
> the variable d = 0 or 1 or 2 respectively.  I could try
> 
> switch(d){
> case 1 : goto l1;
> case 2 : goto l2;
> case 3 : goto l3;
> }
> 
> The only problem is, d could have many values in my program,
> perhaps 10000 or so.
> Is there any other way I could do this?

Use an array of pointers to functions, each of which contains one of
the above "<< code >>" blocks.  Then instead of the above switch
construct, do this:

	array_of_ptrs_to_functions[d]();
--
franl@centerline.com   || Fran Litterio                               
uunet!centerline!franl || CenterLine Software R&D                     
617-498-3255           || 10 Fawcett St, Cambridge, MA, USA 02138-1110
From: hurtta@cs.Helsinki.FI (Kari E. Hurtta)
Newsgroups: comp.unix.programmer
Subject: Re: recursively moving to directories
Date: 15 Apr 92 17:44:38 GMT
	<1992Apr14.061241.17386@cbr.dwr.csiro.au>
Organization: Department of Computer Science, University of Helsinki, Finland

In article <1992Apr14.061241.17386@cbr.dwr.csiro.au> marcus@cbr.dwr.csiro.au (Marcus Schnell) wrote:
> Thanks to all who helped with this problem. The answer (or one of them
> anyway) was:
>    
>     find . -exec chown <new-user> {} \;

Or:
     find . -exec chown <new-user> \{\} \;

You probably need quote {} characters - depending your shell.

- K E H
From: pen@lysator.liu.se (Peter Eriksson)
Newsgroups: comp.unix.programmer
Subject: Re: logging outgoing telnet sessions to catch 'hackers'
Date: 8 Apr 92 23:24:33 GMT
Organization: Lysator Computer Club, Linkoping University, Sweden

l1ngo@copper.denver.colorado.edu (Swift) writes:

>We're running Dynix on a Sequent S81 and are considering methods of
>logging outgoing telnet sessions. We can log which sites connect to
>ours (by putting tcp_wrapper between inetd and the server daemons), but
>we're trying to determine the best way to log users connections
>to other hosts. Frequently, another site might report incidences of
>possible hacking from our site and we'd like to know who's doing it.

>Some options I've considered:
>0. Modifying the kernel. Not possible without the source.
>1. Modifying telnet to log sessions. This can be easily circumvented by
> getting the source and recompiling though.
>2. Monitoring output from 'netstat' and 'who'. This seems 'kludgy.'
>3. Peeking into the kernel. I have very little experience with this and
> am not sure what method to use. I have heard of mmap(), but the manual
> pages are insufficient. Does anyone have an example or a reference?

Perhaps you should check out my "pauthd" package or Dan Bernsteins
"authd" package. Although it won't log outgoing connections it will
allow the other site to find out the name of the user originating
the connection so that they can log that information to be used
later to trace crackers. The same daemon can be used to make it
somewhat more difficult for people to create faked emails and things
like that.

Pauth is available from 'ftp.lysator.liu.se' in the 'pub/daemons'
directory. 

>Thanks in advance,
>Lin

/Peter
--
Peter Eriksson                                              pen@lysator.liu.se
Lysator Academic Computer Society                 ...!uunet!lysator.liu.se!pen
University of Linkoping, Sweden                               Support the LPF!
From: Frank@mindlink.bc.ca (Frank I. Reiter)
Newsgroups: comp.unix.programmer
Subject: Re: Which pipe sent SIGPIPE w/o trying to write to it??
Date: 10 Apr 92 21:03:22 GMT
Organization: MIND LINK! - British Columbia, Canada
Distribution: world

> Kartik Subbarao writes:
> 
> >Here's the situation:  I've got several pipes to several different processes
> >and I receive a SIGPIPE.
> 
> >I don't want to try to write anything to each of
> >these pipes as some of the processes are running tools and such and I don't
> >want anything I send interpreted by them.  Is there a way to do this??
> 
> I don't know what you mean when you say "I don't want to try to write
> anything to each of these pipes". The only way SIGPIPE gets generated is
> when you write on a pipe with no one to read it. Since you get SIGPIPE, you
> must already be writing something to that pipe yourself.

I believe the initial poster wants his SIGPIPE handler to find out which pipe
was broken in order to decide what to do about it.  I am facing the same
situation where a process A talks with a process B through a socket.  Sometimes
process A is running on a terminal, other times it is running on a pipe (when
someone telnets to it for example.)

A SIGPIPE from the socket to process B means that process B has quit or died
and A should keep going.  A SIGPIPE from stdout means the user has gone away
and we want to treat it as a SIGHUP.

Unless someone has a better idea I will have to try printing a nul to stdout to
see if that causes ANOTHER signal just to find out which pipe caused the
problem.

I'd love to hear that better idea!

Frank.
--
___________________________________________________________________
Frank I. Reiter                Internet: Frank@mindlink.bc.ca
MIND LINK! Communications Corp. Surrey, British Columbia, Canada
Newsgroups: comp.unix.programmer
From: samborn@sunrise.com (Kevin Samborn)
Subject: Detecting a dead client with ONC RPC/XDR
Keywords: RPC/XDR, dead clients, sockets, TCP/IP
Organization: Sunrise Software International, Newport, RI
Date: Tue, 14 Apr 1992 14:30:58 GMT


In a simple RPC application, I would like the server to detect the
death of its clients.

Ideally, I would like RPC to give me a "callback" when one of the
children dies, however, after reading the source to RPC 4.0, it
appears there is no current mechanism for this...

Does anyone know how to achieve this behavior?

thanks,
kevin samborn

--
kevin samborn
samborn@sunrise.com     
...!uunet!ezx!samborn
From: l1ngo@copper.denver.colorado.edu (Swift)
Newsgroups: comp.unix.programmer
Subject: Re: logging outgoing telnet sessions to catch 'hackers' (summary)
Date: 13 Apr 92 21:00:44 GMT
Organization: University of Colorado at Denver

In article <11347@mindlink.bc.ca> Frank@mindlink.bc.ca (Frank I. Reiter) writes:
>> Rob J. Nauta writes:
>> 
>> I'm not sure about the ethical side of this. This is an invasion of
>> privacy, which should be dealt with carefully. Logging and examining
>> all telnet sessions is like opening and reading all incoming mail,
>> letters and taping all phonecalls.
>
>You may be assuming too much.  Perhaps he only wants to log the fact that a
>connection was made, not the entire session.  That was the impression I got.

Let me clarify this. I only intended to log which hosts a user connects to.
Usually, this is all that's needed to find a hacker (at the very least, it
narrows down the list of "suspects").

The consensus of the responses seems to be to go ahead and modify telnet
to log the hosts that each user connects to as it is very simple to do.
The assumptions were that most hackers probably won't bother to recompile
telnet (or are too lazy to), and it certainly can't hurt us.

There are also a few packages out there (tcp_wrapper, authd, and pauthd)
which aid in making system more secure.

I'd like to thank everyone who emailed me. I found all your suggestions
very helpful!

As for the privacy issue a poster brought up, it really doesn't apply in
my case, but there was a similar talk on comp.unix.admin about email privacy. 
Interestingly enough, a large fraction of sysadmins condoned and engaged in
the reading of other people's email. It seems unethical by many (myself
included), but I'm unsure of the legalities.

Lin
----------------------------------------------------------------------------
l1ngo@copper.denver.colorado.edu  -- Computational Math Network Sysadmin
          University of Colorado at Denver:  "Searchless AI!"
     "First, assume a spherical camel..." -- Robots on Your Doorstep
Newsgroups: comp.unix.programmer
From: allbery@NCoast.ORG (Brandon S. Allbery KF8NH)
Subject: Re: sleep and alarm
Reply-To: allbery@ncoast.org (Brandon S. Allbery KF8NH)
Organization: North Coast Public Access *NIX, Cleveland, OH
Date: Sat, 11 Apr 1992 20:31:30 GMT
Followup-To: comp.unix.programmer

As quoted from <1992Apr8.130101.2113@descartes.waterloo.edu> by bbobak@descartes.waterloo.edu (Brad Bobak):
+---------------
|  Hi all. I have a question about sleep and alarm that I was wondering if you
| could answer for me. In the man pages, sleep sez:
| 
|                                                     ...The actual
|      suspension time may be an arbitrary amount longer because of
|      other activity in the system.
| 
|  Was wondering if this is true for alarm also?
+---------------

Yes.  sleep() is implemented in terms of alarm() (or setitimer(), an extension
of alarm()).

The problem is that delivery of a signal causes a process to be scheduled; it
does NOT cause the process to immediately resume execution.  Moreover, other
higher-priority kernel processes (interrupts delivered to device drivers, say)
will take priority over user process scheduling.  The result is that a process
may actually resume execution due to a signal some time after the signal is
delivered.  Usually the delay is less than one second, but on a heavily loaded
system it may be longer.

This is not, BTW, a BSD-signals vs. System-V-signals issue; this is a real-time
issue.  A real-time UNIX would presumably provide a means for a process to
gain immediate control when certain signals (certainly including alarm() or
setitimer(), the latter being more appropriate for real-time programs) were
received, unless the "real-time" aspect were limited to device drivers as
opposed to user processes.

++Brandon
-- 
Brandon S. Allbery, KF8NH [44.70.4.88]        allbery@NCoast.ORG
Senior Programmer, Telotech, Inc. (if I may call myself that...)
Xref: sparky comp.unix.programmer:2399 comp.unix.shell:2079
From: krs@uts.amdahl.com (Kris Stephens [Hail Eris!])
Newsgroups: comp.unix.programmer,comp.unix.shell
Subject: Re: Which which returns status
Date: 15 Apr 92 17:10:38 GMT
Organization: Amdahl Corporation, Sunnyvale CA

In article <1992Apr15.145759.11381@spectrum.xerox.com> leisner.henr801c@xerox.com writes:
>The which command on my Sun (SunOS 4.1.1B) doesn't return status.
>
>I want to do something like:
>	if(command exists)
>		then execute command
>	else 	
>		execute simpler command.
>
>I don't want to code path names in my file -- I'd rather do a which command
>which I can test...
>
>Anything out there to do this (it will be relatively simple to hack up the which command...)
>
>BTW -- since which sources the .cshrc file (which is strange since I thought the
>-f option negates this), setting the path in the .cshrc file does unexpected 
>things.

Well, you didn't say which shell you're using, but the following should
work for both sh and ksh:

	if `type command | grep -v 'not found' > /dev/null`
	then
		:	# run command
	else
		:	# run alternative command
	fi

In my ksh, by the way, 'type' is an alias for 'whence -v'.  The reason for
the grep is that (some?) Bourne shell type builtins don't necessarily return
false (1) for command-not-found.

...Kris
-- 
Kristopher Stephens, | (408-746-6047) | krs@uts.amdahl.com | KC6DFS
Amdahl Corporation   |                |                    |
     [The opinions expressed above are mine, solely, and do not    ]
     [necessarily reflect the opinions or policies of Amdahl Corp. ]
Newsgroups: comp.unix.programmer
From: Shikhar Bajaj <bajaj@thumper.bellcore.com>
Subject: Re: Input within a time frame
Organization: Bellcore
Date: Fri, 17 Apr 92 17:37:18 GMT



>Does anyone know how I would be able to get a character
>of input within a certain time limit (say 3 seconds?).

You can use the select() command.  This command is used for Asynchronous
I/O multiplexing.  So, for a 3 second delay on stdin, you would something like

main()
{
  ...
fd_set ready;
struct timeval time_out;

FD_ZERO(&ready)
FD_SET(stdin, &ready)

time_out.tv_sec = 3;
time_out.tv_usec = 0;

if (select(stdin + 1, &ready,  0, 0, &time_out) < 0)
	<error message>

if (FD_ISSET(stdin, &ready))
	getchar(c);

....
}

disclaimer:  This code is off the cuff so it comes with no guaranties.


Shikhar Bajaj
Bell Communications Research
445 South Street
Morristown, NJ 07962-1910
MRE 2Q-178
(201) 829-4541
bajaj@faline.bellcore.com
From: bengtl@maths.lth.se (Bengt Larsson)
Newsgroups: comp.unix.programmer
Subject: Re: Scripting in general
Date: 15 Apr 92 23:02:33 GMT
Organization: Lund Institute of Technology, Sweden

In article <1992Apr14.174048.3475@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
>From the keyboard of bengtl@maths.lth.se (Bengt Larsson):
>:With such a language you could possibly implement quite a lot of things
>:as scripts, in a safe way. Perl is a little too much... Perl IMO.
>
>What precisely do you mean?  Larry's thinking about perl5, and constructive
>input might have a chance of altering whatever is bothering you here.

I don't think it's possible to change Perl like I would want and be
in any way backwards-compatible. I can try to be specific, but it will
look like a lot of whining. If you don't want to see it hit "n" now:



Opinions about Perl. Personal such. No offense intended.

Obscure syntax. Strange constructs for interpolating variables in regexps,
filename globbing etc. No structured types. Lots of interesting cases
where parantheses are needed or not. Confusing scalar/vector contexts.
Integer/floating/string ambiguity.

"A word that doesn't have any other interpretation in the grammar is
treated as if it had single quotes around it". I'm not quite sure
what it means, but it looks strange.

Returning structures like from "stat" as plain arrays is ugly.

The syntax for file names in "open" does not appeal to me, even though
it's Unixy. "fopen" and "popen" is more like it.

Sed-like s/ tr/ and y/ is ugly, or at least obscure.

Lots of cute predefined names. But I suppose Larry will make aliases for 
that.

It's not enough like C for my taste. Obviously it's much a question of
taste. 

I sure like the no-builtin limits, consistent regexp syntax (except
var interpolation. Using eval is an egrerious hack. In the language I
referred to you compile a regexp with "var = regexp(string)"). Packages
is a good thing. Nice debugger. Good support. Good portability.

I'm not a regular user of Perl, as you may guess. I make do with shell
+ awk/sed/sort etc. 

If you are going to make a new scripting language anyway, why make
it as unreadable as shell scripts? There is no point.

Bengt L.
-- 
Bengt Larsson - bengtl@maths.lth.se