Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"If it ain't broke, don't fix it." -- Bert Lantz


devel / comp.arch.embedded / Re: Linux Embedded: how to get info from a running service

SubjectAuthor
* Linux Embedded: how to get info from a running servicepozz
`* Re: Linux Embedded: how to get info from a running serviceDavid Brown
 `* Re: Linux Embedded: how to get info from a running servicepozz
  +- Re: Linux Embedded: how to get info from a running serviceGrant Edwards
  `* Re: Linux Embedded: how to get info from a running serviceDavid Brown
   `* Re: Linux Embedded: how to get info from a running servicepozz
    `* Re: Linux Embedded: how to get info from a running serviceDavid Brown
     `* Re: Linux Embedded: how to get info from a running servicepozz
      `* Re: Linux Embedded: how to get info from a running serviceDavid Brown
       `- Re: Linux Embedded: how to get info from a running serviceGrant Edwards

1
Linux Embedded: how to get info from a running service

<uarnls$314pb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1629&group=comp.arch.embedded#1629

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Linux Embedded: how to get info from a running service
Date: Mon, 7 Aug 2023 23:28:25 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uarnls$314pb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Aug 2023 21:28:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f628bc304eb709f7cd6ddd790935095d";
logging-data="3183403"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jcZ1Qx+OFnOv5ES/5+yKDiYPPGnPmwJw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:T86pKw+JKKxhbcIakZZVNjxeEwA=
 by: pozz - Mon, 7 Aug 2023 21:28 UTC

I developed an application (in Python language) that is started by
systemd at startup and stay running forever (until the box is rebooted
or shutdown).

The user can get some info of the system by a web application, as a
typical router or NAS. The user points his web browser to the local IP
address of my Linux box and a graphical interface appears. This web
application is written in Python (WSGI) deployed on the box thanks to
nginx + gunicorn + Flask.

Now the question is: how to get infos from a running service such that
they can be shown on the web application?
The infos are specific of my application, they aren't standard. I'm in
control of the running service and WSGI application, so I can use
whatever solution is better.

Of course this is a typical IPC scenario: one process is WSGI and the
other is the running service.
I can use shared memory, message queues, named pipes, unix sockets,
Internet sockets, D-Bus and many other mechanisms.

Is there one that is better to use in my case? After some reading, maybe
D-Bus can be a good way. I understood systemd already uses D-Bus to
exchange infos about its services and units.
However its implementation is not straightforward as a unix socket with
custom messages.

What do you suggest?

PS: In the past I read only a few posts regarding Linux development,
even if it's for embedded devices. However I don't know how to ask
questions related to linux development, I noticed Usenet linux groups
are somewhat dead.

Re: Linux Embedded: how to get info from a running service

<uat5ap$3c0fm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1630&group=comp.arch.embedded#1630

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Tue, 8 Aug 2023 12:27:35 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <uat5ap$3c0fm$1@dont-email.me>
References: <uarnls$314pb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 8 Aug 2023 10:27:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="512f07d8c41584f35ecc4f03b0b34350";
logging-data="3539446"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CFdn5UuRXw3tJkgA6XQ4ZrqVWMP4wCs4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.6.1
Cancel-Lock: sha1:mZsBtRSjoKE14JqsBXJfbBOHIO4=
In-Reply-To: <uarnls$314pb$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Tue, 8 Aug 2023 10:27 UTC

On 07/08/2023 23:28, pozz wrote:
> I developed an application (in Python language) that is started by
> systemd at startup and stay running forever (until the box is rebooted
> or shutdown).
>
> The user can get some info of the system by a web application, as a
> typical router or NAS. The user points his web browser to the local IP
> address of my Linux box and a graphical interface appears. This web
> application is written in Python (WSGI) deployed on the box thanks to
> nginx + gunicorn + Flask.
>
> Now the question is: how to get infos from a running service such that
> they can be shown on the web application?
> The infos are specific of my application, they aren't standard. I'm in
> control of the running service and WSGI application, so I can use
> whatever solution is better.
>
> Of course this is a typical IPC scenario: one process is WSGI and the
> other is the running service.
> I can use shared memory, message queues, named pipes, unix sockets,
> Internet sockets, D-Bus and many other mechanisms.
>
> Is there one that is better to use in my case? After some reading, maybe
> D-Bus can be a good way. I understood systemd already uses D-Bus to
> exchange infos about its services and units.
> However its implementation is not straightforward as a unix socket with
> custom messages.
>
> What do you suggest?
>
> PS: In the past I read only a few posts regarding Linux development,
> even if it's for embedded devices. However I don't know how to ask
> questions related to linux development, I noticed Usenet linux groups
> are somewhat dead.

I don't know what kind of information you are needing, but an easy
option might be to have the python service regularly write out a json
format file with the current status or other information. The web app
can have Javascript that regularly reads that file and handles it on the
user's web browser. And if you want to go the other way, your Python
code can use "inotify" waits to see file writes from the web server.

Re: Linux Embedded: how to get info from a running service

<uate87$39nhe$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1631&group=comp.arch.embedded#1631

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Tue, 8 Aug 2023 14:59:52 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uate87$39nhe$1@dont-email.me>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 8 Aug 2023 12:59:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9625c302f4e9b40dffa87ae678ff2e5d";
logging-data="3464750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UdS/kWvan9OP+H6RMeSVn54url0+lTNE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:pDF/sH+VquHgRjNY/8I0SuWaBJw=
In-Reply-To: <uat5ap$3c0fm$1@dont-email.me>
 by: pozz - Tue, 8 Aug 2023 12:59 UTC

Il 08/08/2023 12:27, David Brown ha scritto:
> On 07/08/2023 23:28, pozz wrote:
[...]
>> What do you suggest?
>>
>> PS: In the past I read only a few posts regarding Linux development,
>> even if it's for embedded devices. However I don't know how to ask
>> questions related to linux development, I noticed Usenet linux groups
>> are somewhat dead.
>
> I don't know what kind of information you are needing, but an easy
> option might be to have the python service regularly write out a json
> format file with the current status or other information.  The web app
> can have Javascript that regularly reads that file and handles it on the
> user's web browser.  And if you want to go the other way, your Python
> code can use "inotify" waits to see file writes from the web server.

Sincerely I don't like your solution. First of all, you are writing
regularly on a normal file in the filesystem. Ok, maybe I can use a
tmpfs filesystem in RAM.

Another issue I see is synchronization. Without a sync mechanism, the
reader could read bad data, because the writer is writing to it.

Re: Linux Embedded: how to get info from a running service

<uatjj6$p6u$1@reader2.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1632&group=comp.arch.embedded#1632

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.localhost!not-for-mail
From: inva...@invalid.invalid (Grant Edwards)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Tue, 8 Aug 2023 14:31:02 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <uatjj6$p6u$1@reader2.panix.com>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me>
Injection-Date: Tue, 8 Aug 2023 14:31:02 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="localhost:::1";
logging-data="25822"; mail-complaints-to="abuse@panix.com"
User-Agent: slrn/1.0.3 (Linux)
 by: Grant Edwards - Tue, 8 Aug 2023 14:31 UTC

On 2023-08-08, pozz <pozzugno@gmail.com> wrote:

> Sincerely I don't like your solution. First of all, you are writing
> regularly on a normal file in the filesystem. Ok, maybe I can use a
> tmpfs filesystem in RAM.
>
> Another issue I see is synchronization. Without a sync mechanism, the
> reader could read bad data, because the writer is writing to it.

There is a trivial way to deal with that which has been used since
time immemorial on Unix:

Write to a temporary file, then close and reanme it. The open() and
rename() system calls are atomic with respect to each other. The task
calling open() will get either the old file or the new file, never
something "in between".

Re: Linux Embedded: how to get info from a running service

<uatjk9$3edog$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1633&group=comp.arch.embedded#1633

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Tue, 8 Aug 2023 16:31:36 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <uatjk9$3edog$1@dont-email.me>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 8 Aug 2023 14:31:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="512f07d8c41584f35ecc4f03b0b34350";
logging-data="3618576"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yGITbxlIPzhkxK867OKUMhFT/fFiRd4U="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.6.1
Cancel-Lock: sha1:HcxDaD+okI+NgnPh6523bysNOII=
In-Reply-To: <uate87$39nhe$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Tue, 8 Aug 2023 14:31 UTC

On 08/08/2023 14:59, pozz wrote:
> Il 08/08/2023 12:27, David Brown ha scritto:
>> On 07/08/2023 23:28, pozz wrote:
> [...]
>>> What do you suggest?
>>>
>>> PS: In the past I read only a few posts regarding Linux development,
>>> even if it's for embedded devices. However I don't know how to ask
>>> questions related to linux development, I noticed Usenet linux groups
>>> are somewhat dead.
>>
>> I don't know what kind of information you are needing, but an easy
>> option might be to have the python service regularly write out a json
>> format file with the current status or other information.  The web app
>> can have Javascript that regularly reads that file and handles it on
>> the user's web browser.  And if you want to go the other way, your
>> Python code can use "inotify" waits to see file writes from the web
>> server.
>
> Sincerely I don't like your solution. First of all, you are writing
> regularly on a normal file in the filesystem. Ok, maybe I can use a
> tmpfs filesystem in RAM.
>

That would be the normal choice, yes.

> Another issue I see is synchronization. Without a sync mechanism, the
> reader could read bad data, because the writer is writing to it.
>

You typically handle this by writing to "status.tmp", then renaming
(moving) it to "status.json", or whatever names you are using. Renaming
a file like this is guaranteed atomic on Linux - anything attempting to
open a handle to "status.json" will either get the old file (which is
kept alive while the file descriptor is open) or the new file. This is
not the first situation in which people wanted to avoid reading
half-written files!

Re: Linux Embedded: how to get info from a running service

<uatm5a$39nhe$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1634&group=comp.arch.embedded#1634

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Tue, 8 Aug 2023 17:14:51 +0200
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <uatm5a$39nhe$2@dont-email.me>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me> <uatjk9$3edog$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 8 Aug 2023 15:14:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9625c302f4e9b40dffa87ae678ff2e5d";
logging-data="3464750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//H+bPoCn/T6GUd+j+o1EeeA6nLlPOvXQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:h6waaFl+/4p4CHr9qNSFWI7t5MI=
In-Reply-To: <uatjk9$3edog$1@dont-email.me>
 by: pozz - Tue, 8 Aug 2023 15:14 UTC

Il 08/08/2023 16:31, David Brown ha scritto:
> On 08/08/2023 14:59, pozz wrote:
>> Il 08/08/2023 12:27, David Brown ha scritto:
>>> On 07/08/2023 23:28, pozz wrote:
>> [...]
>>>> What do you suggest?
>>>>
>>>> PS: In the past I read only a few posts regarding Linux development,
>>>> even if it's for embedded devices. However I don't know how to ask
>>>> questions related to linux development, I noticed Usenet linux
>>>> groups are somewhat dead.
>>>
>>> I don't know what kind of information you are needing, but an easy
>>> option might be to have the python service regularly write out a json
>>> format file with the current status or other information.  The web
>>> app can have Javascript that regularly reads that file and handles it
>>> on the user's web browser.  And if you want to go the other way, your
>>> Python code can use "inotify" waits to see file writes from the web
>>> server.
>>
>> Sincerely I don't like your solution. First of all, you are writing
>> regularly on a normal file in the filesystem. Ok, maybe I can use a
>> tmpfs filesystem in RAM.
>>
>
> That would be the normal choice, yes.
>
>> Another issue I see is synchronization. Without a sync mechanism, the
>> reader could read bad data, because the writer is writing to it.
>>
>
> You typically handle this by writing to "status.tmp", then renaming
> (moving) it to "status.json", or whatever names you are using.  Renaming
> a file like this is guaranteed atomic on Linux - anything attempting to
> open a handle to "status.json" will either get the old file (which is
> kept alive while the file descriptor is open) or the new file.  This is
> not the first situation in which people wanted to avoid reading
> half-written files!

Good thing to know.

Just to better understand what happens. If reader opens status.json just
before the writer rename status.tmp to status.json, we will have a
process (the reader) that reads from the old version of "status.json"
instead of the new version that is really on the filesystem?

Consider that the reader could keep open the old status.json for a long
time. Does the OS guarantee that old data (maybe 1GB) can be read even
if a new file with new data is available?

Re: Linux Embedded: how to get info from a running service

<uats09$3fprh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1635&group=comp.arch.embedded#1635

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Tue, 8 Aug 2023 18:54:33 +0200
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uats09$3fprh$1@dont-email.me>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me> <uatjk9$3edog$1@dont-email.me>
<uatm5a$39nhe$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 8 Aug 2023 16:54:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="512f07d8c41584f35ecc4f03b0b34350";
logging-data="3663729"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jMFfCbbs4cfGQWNGWNnoaK/E/vtmXLfA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.6.1
Cancel-Lock: sha1:u5rAPYhha8JSQiXtav3g8fQv/BM=
Content-Language: en-GB
In-Reply-To: <uatm5a$39nhe$2@dont-email.me>
 by: David Brown - Tue, 8 Aug 2023 16:54 UTC

On 08/08/2023 17:14, pozz wrote:
> Il 08/08/2023 16:31, David Brown ha scritto:
>> On 08/08/2023 14:59, pozz wrote:
>>> Il 08/08/2023 12:27, David Brown ha scritto:
>>>> On 07/08/2023 23:28, pozz wrote:
>>> [...]
>>>>> What do you suggest?
>>>>>
>>>>> PS: In the past I read only a few posts regarding Linux
>>>>> development, even if it's for embedded devices. However I don't
>>>>> know how to ask questions related to linux development, I noticed
>>>>> Usenet linux groups are somewhat dead.
>>>>
>>>> I don't know what kind of information you are needing, but an easy
>>>> option might be to have the python service regularly write out a
>>>> json format file with the current status or other information.  The
>>>> web app can have Javascript that regularly reads that file and
>>>> handles it on the user's web browser.  And if you want to go the
>>>> other way, your Python code can use "inotify" waits to see file
>>>> writes from the web server.
>>>
>>> Sincerely I don't like your solution. First of all, you are writing
>>> regularly on a normal file in the filesystem. Ok, maybe I can use a
>>> tmpfs filesystem in RAM.
>>>
>>
>> That would be the normal choice, yes.
>>
>>> Another issue I see is synchronization. Without a sync mechanism, the
>>> reader could read bad data, because the writer is writing to it.
>>>
>>
>> You typically handle this by writing to "status.tmp", then renaming
>> (moving) it to "status.json", or whatever names you are using.
>> Renaming a file like this is guaranteed atomic on Linux - anything
>> attempting to open a handle to "status.json" will either get the old
>> file (which is kept alive while the file descriptor is open) or the
>> new file.  This is not the first situation in which people wanted to
>> avoid reading half-written files!
>
> Good thing to know.
>
> Just to better understand what happens. If reader opens status.json just
> before the writer rename status.tmp to status.json, we will have a
> process (the reader) that reads from the old version of "status.json"
> instead of the new version that is really on the filesystem?
>

Yes, exactly.

A file in Linux exists independently from filenames. There can be many
things pointing to a file, and the file exists until there are no more
pointers. Usually these "pointers" are directory entries, but they can
also be open file descriptors (which are actually visible as pseudofiles
in the /proc filesystem).

So when you open the "status.json" file, you get that file, and it stays
in existence at least until the file is closed. The new "status.tmp" is
a different file. The rename just makes a new pointer to the new file,
and erases the old pointer to the old file.

> Consider that the reader could keep open the old status.json for a long
> time. Does the OS guarantee that old data (maybe 1GB) can be read even
> if a new file with new data is available?
>

Yes, as long as you hold the file descriptor open.

Re: Linux Embedded: how to get info from a running service

<uavf4f$3qf61$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1636&group=comp.arch.embedded#1636

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Wed, 9 Aug 2023 09:27:12 +0200
Organization: A noiseless patient Spider
Lines: 103
Message-ID: <uavf4f$3qf61$1@dont-email.me>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me> <uatjk9$3edog$1@dont-email.me>
<uatm5a$39nhe$2@dont-email.me> <uats09$3fprh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 9 Aug 2023 07:27:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="368db1383f9289de66d1ec3aac6c21a9";
logging-data="4013249"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Fl8t0gbUpN6QHV4VmQZSZeo070X4YIn0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:+Vd7Jsq5ajqBjiXSgfWXU5u+UjI=
In-Reply-To: <uats09$3fprh$1@dont-email.me>
 by: pozz - Wed, 9 Aug 2023 07:27 UTC

Il 08/08/2023 18:54, David Brown ha scritto:
> On 08/08/2023 17:14, pozz wrote:
>> Il 08/08/2023 16:31, David Brown ha scritto:
>>> On 08/08/2023 14:59, pozz wrote:
>>>> Il 08/08/2023 12:27, David Brown ha scritto:
>>>>> On 07/08/2023 23:28, pozz wrote:
>>>> [...]
>>>>>> What do you suggest?
>>>>>>
>>>>>> PS: In the past I read only a few posts regarding Linux
>>>>>> development, even if it's for embedded devices. However I don't
>>>>>> know how to ask questions related to linux development, I noticed
>>>>>> Usenet linux groups are somewhat dead.
>>>>>
>>>>> I don't know what kind of information you are needing, but an easy
>>>>> option might be to have the python service regularly write out a
>>>>> json format file with the current status or other information.  The
>>>>> web app can have Javascript that regularly reads that file and
>>>>> handles it on the user's web browser.  And if you want to go the
>>>>> other way, your Python code can use "inotify" waits to see file
>>>>> writes from the web server.
>>>>
>>>> Sincerely I don't like your solution. First of all, you are writing
>>>> regularly on a normal file in the filesystem. Ok, maybe I can use a
>>>> tmpfs filesystem in RAM.
>>>>
>>>
>>> That would be the normal choice, yes.
>>>
>>>> Another issue I see is synchronization. Without a sync mechanism,
>>>> the reader could read bad data, because the writer is writing to it.
>>>>
>>>
>>> You typically handle this by writing to "status.tmp", then renaming
>>> (moving) it to "status.json", or whatever names you are using.
>>> Renaming a file like this is guaranteed atomic on Linux - anything
>>> attempting to open a handle to "status.json" will either get the old
>>> file (which is kept alive while the file descriptor is open) or the
>>> new file.  This is not the first situation in which people wanted to
>>> avoid reading half-written files!
>>
>> Good thing to know.
>>
>> Just to better understand what happens. If reader opens status.json
>> just before the writer rename status.tmp to status.json, we will have
>> a process (the reader) that reads from the old version of
>> "status.json" instead of the new version that is really on the
>> filesystem?
>>
>
> Yes, exactly.
>
> A file in Linux exists independently from filenames.  There can be many
> things pointing to a file, and the file exists until there are no more
> pointers.  Usually these "pointers" are directory entries, but they can
> also be open file descriptors (which are actually visible as pseudofiles
> in the /proc filesystem).

Is this behaviour the same for whatever filesystem (ext2, fat, ...)?

What I don't understand is what exactly happens under the hood.

Consider the following sequences:
- process W (writer) write version A to status.tmp
- process W rename status.tmp to status.json
- process W write version B to status.tmp
- process R (reader) open file status.json (version A)
- process W rename status.tmp to status.json
[Now all new open operations on status.json will get new version of data]
[process W could write/rename status.tmp/json 1000 times]
- after one hour (just to say), process R starts reading from the file

From what I understand, process R will get the full contents of version
A (even if it restarts reading changing file position many times). The
OS takes care of data A, because this "ghost file"[1] is in use.

Most probably, if the file size is small, the OS copy its contents in a
cache in RAM when process R open the file, so process R will read from
RAM and this explains why it will get the original version A content.

Anyway, in general the file could be any size, maybe 1GB. So I assume at
least some parts of version A data still remains in the HDD, even when
process W write/rename a new version.
Until process R doesn't close the file, version A data are phisically on
the HDD, consuming part of its memory. Is it correct?

[1] Ghost because it can't be read by any other process.

> So when you open the "status.json" file, you get that file, and it stays
> in existence at least until the file is closed.  The new "status.tmp" is
> a different file.  The rename just makes a new pointer to the new file,
> and erases the old pointer to the old file.
>
>> Consider that the reader could keep open the old status.json for a
>> long time. Does the OS guarantee that old data (maybe 1GB) can be read
>> even if a new file with new data is available?
>>
>
> Yes, as long as you hold the file descriptor open.
>

Re: Linux Embedded: how to get info from a running service

<uavipa$3s6gi$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1637&group=comp.arch.embedded#1637

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED.87.79-160-51.customer.lyse.net!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Wed, 9 Aug 2023 10:29:30 +0200
Organization: A noiseless patient Spider
Message-ID: <uavipa$3s6gi$1@dont-email.me>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me> <uatjk9$3edog$1@dont-email.me>
<uatm5a$39nhe$2@dont-email.me> <uats09$3fprh$1@dont-email.me>
<uavf4f$3qf61$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 9 Aug 2023 08:29:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="87.79-160-51.customer.lyse.net:79.160.51.87";
logging-data="4069906"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.6.1
In-Reply-To: <uavf4f$3qf61$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 9 Aug 2023 08:29 UTC

On 09/08/2023 09:27, pozz wrote:
> Il 08/08/2023 18:54, David Brown ha scritto:
>> On 08/08/2023 17:14, pozz wrote:
>>> Il 08/08/2023 16:31, David Brown ha scritto:
>>>> On 08/08/2023 14:59, pozz wrote:
>>>>> Il 08/08/2023 12:27, David Brown ha scritto:
>>>>>> On 07/08/2023 23:28, pozz wrote:
>>>>> [...]
>>>>>>> What do you suggest?
>>>>>>>
>>>>>>> PS: In the past I read only a few posts regarding Linux
>>>>>>> development, even if it's for embedded devices. However I don't
>>>>>>> know how to ask questions related to linux development, I noticed
>>>>>>> Usenet linux groups are somewhat dead.
>>>>>>
>>>>>> I don't know what kind of information you are needing, but an easy
>>>>>> option might be to have the python service regularly write out a
>>>>>> json format file with the current status or other information.
>>>>>> The web app can have Javascript that regularly reads that file and
>>>>>> handles it on the user's web browser.  And if you want to go the
>>>>>> other way, your Python code can use "inotify" waits to see file
>>>>>> writes from the web server.
>>>>>
>>>>> Sincerely I don't like your solution. First of all, you are writing
>>>>> regularly on a normal file in the filesystem. Ok, maybe I can use a
>>>>> tmpfs filesystem in RAM.
>>>>>
>>>>
>>>> That would be the normal choice, yes.
>>>>
>>>>> Another issue I see is synchronization. Without a sync mechanism,
>>>>> the reader could read bad data, because the writer is writing to it.
>>>>>
>>>>
>>>> You typically handle this by writing to "status.tmp", then renaming
>>>> (moving) it to "status.json", or whatever names you are using.
>>>> Renaming a file like this is guaranteed atomic on Linux - anything
>>>> attempting to open a handle to "status.json" will either get the old
>>>> file (which is kept alive while the file descriptor is open) or the
>>>> new file.  This is not the first situation in which people wanted to
>>>> avoid reading half-written files!
>>>
>>> Good thing to know.
>>>
>>> Just to better understand what happens. If reader opens status.json
>>> just before the writer rename status.tmp to status.json, we will have
>>> a process (the reader) that reads from the old version of
>>> "status.json" instead of the new version that is really on the
>>> filesystem?
>>>
>>
>> Yes, exactly.
>>
>> A file in Linux exists independently from filenames.  There can be
>> many things pointing to a file, and the file exists until there are no
>> more pointers.  Usually these "pointers" are directory entries, but
>> they can also be open file descriptors (which are actually visible as
>> pseudofiles in the /proc filesystem).
>
> Is this behaviour the same for whatever filesystem (ext2, fat, ...)?
>

Yes (as far as I understand it), though some filesystems (like fat)
don't support multiple directory links to the same file. All *nix
suitable filesystems do, because hard links are a key feature. (In
use-cases like yours, you would - as you suggested - put the file on a
tmpfs mount.)

> What I don't understand is what exactly happens under the hood.
>
> Consider the following sequences:
> - process W (writer) write version A to status.tmp
> - process W rename status.tmp to status.json
> - process W write version B to status.tmp
> - process R (reader) open file status.json (version A)
> - process W rename status.tmp to status.json
> [Now all new open operations on status.json will get new version of data]
> [process W could write/rename status.tmp/json 1000 times]
> - after one hour (just to say), process R starts reading from the file
>

Yes.

It's easy to try all this from two Python interactive sessions. It's
hard to test race conditions of doing things quickly, but waiting an
hour should be easy to simulate :-)

> From what I understand, process R will get the full contents of version
> A (even if it restarts reading changing file position many times). The
> OS takes care of data A, because this "ghost file"[1] is in use.
>

Yes. Just don't close the file descriptor between accesses. (You can
duplicate the file descriptor, close the first one, and carry on using
the duplicate to access the old file.)

> Most probably, if the file size is small, the OS copy its contents in a
> cache in RAM when process R open the file, so process R will read from
> RAM and this explains why it will get the original version A content.
>

It is all just like normal files. But since version A is marked for
immediate deletion upon closure, the OS knows it never needs to survive
a reboot. So if the data was not written out to disk, but was still in
the write cache, then it will never be written out to the disk unless
the system is desperate for memory.

This is similar to the trick for temporary files. Create a new file for
writing. Open a read/write handle to the file. Then delete the file.
You can use the handle (and duplicates of it) to access the file, pass
on the handle to child processes, etc., but the OS knows it does not
need to actually write anything to the disk. (Windows has special API
calls to get a similar effect for immediately deletable files.)

> Anyway, in general the file could be any size, maybe 1GB. So I assume at
> least some parts of version A data still remains in the HDD, even when
> process W write/rename a new version.
> Until process R doesn't close the file, version A data are phisically on
> the HDD, consuming part of its memory. Is it correct?
>

Yes. You have understood perfectly.

> [1] Ghost because it can't be read by any other process.
>

It can, through a duplicate file descriptor. In practice this is
commonly done by child processes - when you fork(), the child gets a
copy of all the open file descriptors.

>
>
>> So when you open the "status.json" file, you get that file, and it
>> stays in existence at least until the file is closed.  The new
>> "status.tmp" is a different file.  The rename just makes a new pointer
>> to the new file, and erases the old pointer to the old file.
>>
>>> Consider that the reader could keep open the old status.json for a
>>> long time. Does the OS guarantee that old data (maybe 1GB) can be
>>> read even if a new file with new data is available?
>>>
>>
>> Yes, as long as you hold the file descriptor open.
>>
>

Re: Linux Embedded: how to get info from a running service

<ub02mb$16r$1@reader2.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1638&group=comp.arch.embedded#1638

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.localhost!not-for-mail
From: inva...@invalid.invalid (Grant Edwards)
Newsgroups: comp.arch.embedded
Subject: Re: Linux Embedded: how to get info from a running service
Date: Wed, 9 Aug 2023 13:00:59 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <ub02mb$16r$1@reader2.panix.com>
References: <uarnls$314pb$1@dont-email.me> <uat5ap$3c0fm$1@dont-email.me>
<uate87$39nhe$1@dont-email.me> <uatjk9$3edog$1@dont-email.me>
<uatm5a$39nhe$2@dont-email.me> <uats09$3fprh$1@dont-email.me>
<uavf4f$3qf61$1@dont-email.me> <uavipa$3s6gi$1@dont-email.me>
Injection-Date: Wed, 9 Aug 2023 13:00:59 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="localhost:::1";
logging-data="1243"; mail-complaints-to="abuse@panix.com"
User-Agent: slrn/1.0.3 (Linux)
 by: Grant Edwards - Wed, 9 Aug 2023 13:00 UTC

On 2023-08-09, David Brown <david.brown@hesbynett.no> wrote:
> On 09/08/2023 09:27, pozz wrote:

>> [1] Ghost because it can't be read by any other process.
>>
>
> It can, through a duplicate file descriptor. In practice this is
> commonly done by child processes - when you fork(), the child gets a
> copy of all the open file descriptors.

You can also pass filedescriptors to non-related processes via
Unix-domain sockets.

https://copyconstruct.medium.com/file-descriptor-transfer-over-unix-domain-sockets-dcbbf5b3b6ec

https://www.sobyte.net/post/2022-01/pass-fd-over-domain-socket/

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor