Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162348

Re: How can a daemon process open() the stdout of someone who signals it?

From John Forkosh <forkosh@panix.com>
Newsgroups comp.lang.c
Subject Re: How can a daemon process open() the stdout of someone who signals it?
Date 2021-08-12 03:11 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <sf23hf$jle$1@reader1.panix.com> (permalink)
References <sf0kp8$ki0$1@reader1.panix.com> <sf0r3g$ksq$1@dont-email.me>

Show all headers | View raw


Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
> John Forkosh wrote:
> 
>> Specifically, below's the little test program I wrote.
>> It works fine, but isn't programmed to do exactly what I want
>> because I can't figure out how to program that.
>> 
>> It runs as a daemon,
> 
> Just to be clear, comp.lang.c is not the correct forum to discuss
> daemons and system-specific development. You probably want
> one of the comp.os.unix or comp.os.linux groups for a comprehensive
> answer.

My bad if it's the wrong ng. That thought had occurred to me before
posting here, but it's obviously both a C-related and Unix-related
question, and I felt that (a)the C-related part dominated, and that
(b)C developers were more likely familiar with Unix than vice versa.

Anyway, thanks for the answer and suggestions. Definitely gives me
some possible approaches to pursue. I'd tried googling, looking
through my copy of Stevens, etc, but failed to find anything useful.
But your remarks are definitely leading to some useful googling,
filling in the details (although, like you say, it's still not
clear whether or not it can actually work as intended). Thanks again.

>> just sitting on a pause() until
>> it catches a signal, via  killall -SIGINT testdaemon
>> and then it just writes a dummy line with date/time and
>> #running processes to a log file. Just a "Hello, World" test.
>> 
>> But what I want is to write some stuff to the stdout
>> of the process that sent the signal to testdaemon.
> 
> In your daemon, you will want to
>  - establish which process signalled,
>  - establish which file the signalling process uses as stdout
>  - open that file (if possible), write your data, and then close it
> 
> You can get the PID of the signalling process from the
> siginfo_t si_pid value.
> 
> With the signaller's PID, you /may/ be able to obtain the path of the
> signaller's stdout file from the symlink named by /proc/<PID>/fd/1.
> Note that individual /proc files are usually read-protected so that
> only the relevant process's UID and GID can read them.
> 
> Once you retrieve the path of the signaller's stdout file, you can try
> to open it. It may not exist as a filesystem entity (it may be a pipe,
> for instance) or it may be write-protected, but if you can open it for
> write access (correction: /append/ access), you can write your data
> and close the file.
> 
>> Note that the testhandler() function has an
>> if(0)fprintf(stdout,etc).  So my question is,
>> what do I do to open()/fopen()/whatever the user's
>> (whoever sent testdaemon the sigint) stdout?
>> And then close it after the test handler completes,
>> just before the daemon goes back to pause().
>> 
>> So, for definiteness, here's the little testdaemon code,
> [code snipped]
> 
> HTH

-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How can a daemon process open() the stdout of someone who signals it? John Forkosh <forkosh@panix.com> - 2021-08-11 13:53 +0000
  Re: How can a daemon process open() the stdout of someone who signals it? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-11 15:41 +0000
    Re: How can a daemon process open() the stdout of someone who signals it? John Forkosh <forkosh@panix.com> - 2021-08-12 03:11 +0000
    Re: How can a daemon process open() the stdout of someone who signals it? Vir Campestris <vir.campestris@invalid.invalid> - 2021-08-13 21:30 +0100
      Re: How can a daemon process open() the stdout of someone who signals it? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-14 14:25 +0000
  Re: How can a daemon process open() the stdout of someone who signals it? Kaz Kylheku <563-365-8930@kylheku.com> - 2021-08-11 18:10 +0000
    Re: How can a daemon process open() the stdout of someone who signals it? John Forkosh <forkosh@panix.com> - 2021-08-12 03:17 +0000

csiph-web