how tail waits for file to appear again?

2023-02-16 Thread Maksim Rodin
Hello,
Sorry if I chose the wrong place to ask such a question.
I have been learning C for a couple of months and along with reading
"C Primer Plus" by Stephen Prata and doing some exercises from it I took
a hard (for me) task to replicate a tail program in its simplest form.
I was able to reproduce watching for new data and truncation of the
file using kqueue but I do not quite understand how the original tail
watches when the file appears again after deletion or renaming.
By reading the original tail sources downloaded from OpenBSD mirror I
see that this is done by calling tfreopen function which seems to use a
"for" loop to (continuously?) stat(2) the file name till stat(2) successfully
returns and it does not seem to load a CPU as a simple continuous "for"
loop would do.
Can someone explain how it is done?
May be there is a better way to watch for the file to appear correctly?
Is inserting a sleep(3) in a loop an appropriate way?

Below is the function how it is done in tail:
"""
#define AFILESINCR 8
static const struct timespec *
tfreopen(struct tailfile *tf) {
static struct tailfile  **reopen = NULL;
static intnfiles = 0, afiles = 0;
static const struct timespec  ts = {1, 0};

struct stat   sb;
struct tailfile **treopen, *ttf;
int   i;

if (tf && !(tf->fp == stdin) &&
((stat(tf->fname, ) != 0) || sb.st_ino != tf->sb.st_ino)) {
if (afiles < ++nfiles) {
afiles += AFILESINCR;
treopen = reallocarray(reopen, afiles, sizeof(*reopen));
if (treopen)
reopen = treopen;
else
afiles -= AFILESINCR;
}
if (nfiles <= afiles) {
for (i = 0; i < nfiles - 1; i++)
if (strcmp(reopen[i]->fname, tf->fname) == 0)
break;
if (i < nfiles - 1)
nfiles--;
else
reopen[nfiles-1] = tf;
} else {
warnx("Lost track of %s", tf->fname);
nfiles--;
}
}

for (i = 0; i < nfiles; i++) {
ttf = reopen[i];
if (stat(ttf->fname, ) == -1)
continue;
if (sb.st_ino != ttf->sb.st_ino) {
(void) memcpy(&(ttf->sb), , sizeof(ttf->sb));
ttf->fp = freopen(ttf->fname, "r", ttf->fp);
if (ttf->fp == NULL)
ierr(ttf->fname);
else {
warnx("%s has been replaced, reopening.",
ttf->fname);
tfqueue(ttf);
}
}
reopen[i] = reopen[--nfiles];
}

return nfiles ?  : NULL;
}
"""

-- 
Maksim Rodin



Re: tracker-miner-fs-3

2023-02-16 Thread Daniele Bonini


> tracker3-minerS depends on nautilus
> nautilus depends on file-roller
> file-roller depends on thunar-archive-plugin (omg.. optional)

Just to let you know that in the end I erased any of these
*optionals* in favour of xarchiver, maybe worse then file-roll
but.. saving on disk life..

-- Daniele Bonini
‎‎



Re: scp to an unwritable filesystem - err msg

2023-02-16 Thread Todd C . Miller
The problem is that the error message has to be transferred from
the remote end and there are a limited number of status messages.
These are defined by the (draft) RFC for the protocol.  OpenSSH
supports the following:

SSH_FX_OK0
SSH_FX_EOF   1
SSH_FX_NO_SUCH_FILE  2
SSH_FX_PERMISSION_DENIED 3
SSH_FX_FAILURE   4
SSH_FX_BAD_MESSAGE   5
SSH_FX_NO_CONNECTION 6
SSH_FX_CONNECTION_LOST   7
SSH_FX_OP_UNSUPPORTED8

It looks like there are more status codes defined by the draft
specification(s).  For example:

   SSH_FX_WRITE_PROTECT 12

But that is not currently supported by OpenSSH.  I don't know whether
there is interest in supporting other sftp v3 error codes in OpenSSH.

 - todd



Re: tracker-miner-fs-3

2023-02-16 Thread Mike Coddington
On Thu, Feb 16, 2023 at 05:06:05PM +0100, Daniele Bonini wrote:
> 
> Hello,
> Sorry if I'm reluctant to this piece of software: 
> 
> NAME
>   tracker-miner-fs-3 - Used to crawl the file system to mine data.
> 
> It is continuously accessing and browsing my disk..
> Any clue?
> Is it possible to safely disable it?
> Appreciated, thanks.

I ran 'pkg_info tracker3' which gave some good information about this
software. I hadn't heard of it before and you're right, it does sound
ominous based on the description you posted. It looks like that's part
of the GNOME desktop environment. If you're running GNOME, I'd advise
keeping it installed since it seems to do some sort of file indexing for
searching. If not, delete it. Personally, I prefer just running a window
manager and not a full-blown desktop environment, but that's me. Your
mileage may vary.

-- 
Put your Nose to the Grindstone!
-- Amalgamated Plastic Surgeons and Toolmakers, Ltd.



scp to an unwritable filesystem - err msg

2023-02-16 Thread Jan Stary
This is current/amd64 on a PC;
no dmesg as it's not HW related.

I have a filesystem on a remote machine, mounted ro.
When trying to copy onto that filesystem:

$ scp -r dir/ box:/fs/path/
Enter passphrase for key '/Users/hans/.ssh/id_ed25519': 
scp: stat remote: No such file or directory
scp: failed to upload directory dir/ to /fs/path/

After a bit of headscratching, I copied to box:/tmp instead
and then moved /tmp/dir to /fs/path on the remote machine,
realizing that it's mounted ro.

That makes me think that the 

scp: stat remote: No such file or directory

message is a bit misleading: /fs/path/dir cannot be created, as in

box$ mv: rename /tmp/dir to /fs/path/dir: Read-only file system

not that an intermediate path does not exist.
If I'm reading usr.bin/ssh/ right, it's the get_decode_stat()
calling fx2txt(), but the code is a bit over my head ...

Note that this happens when scp'ing a directory;
when scping a file onto the ro fs, the message is

scp: dest open "/fs/path/foo": Failure

Jan



Re: tracker-miner-fs-3

2023-02-16 Thread Daniele B.
Thanks David, thanks Mike.

In the meanwhile I also investigated a little bit..
By memory (my case) is the following, I'm with Thunar on XFCE (without gnome 
services):

tracker3-miner depends on nautilus
nautilus depends on file-roller
file-roller depends on thunar-archive-plugin (omg.. optional)

Indeed connecting everything something nasty to think about, this tracker..

What is your best advise?

-- Daniele Bonini



Re: tracker-miner-fs-3

2023-02-16 Thread David Anthony
I believe it’s part of Gnome - although very scary name…

Sent from my iPhone

> On Feb 16, 2023, at 11:09 AM, Daniele Bonini  wrote:
> 
> 
> Hello,
> Sorry if I'm reluctant to this piece of software: 
> 
> NAME
>  tracker-miner-fs-3 - Used to crawl the file system to mine data.
> SYNOPSIS
>  tracker-miner-fs-3
> DESCRIPTION
>  tracker-miner-fs-3 is not supposed to be run by the user since it is
>  started by its .desktop file when the user logs in. It can also be
>  started manually of course for debugging purposes. You can not run
>  more than one instance of this at the same time.
> SEE ALSO
>  tracker3-info(1)
> AUTHOR
>  The tracker develoeprs.
> 
> It is continuously accessing and browsing my disk..
> Any clue?
> Is it possible to safely disable it?
> Appreciated, thanks.
> 
> -- Daniele Bonini
> ‎‎
> 



tracker-miner-fs-3

2023-02-16 Thread Daniele Bonini


Hello,
Sorry if I'm reluctant to this piece of software: 

NAME
  tracker-miner-fs-3 - Used to crawl the file system to mine data.
SYNOPSIS
  tracker-miner-fs-3
DESCRIPTION
  tracker-miner-fs-3 is not supposed to be run by the user since it is
  started by its .desktop file when the user logs in. It can also be
  started manually of course for debugging purposes. You can not run
  more than one instance of this at the same time.
SEE ALSO
  tracker3-info(1)
AUTHOR
  The tracker develoeprs.

It is continuously accessing and browsing my disk..
Any clue?
Is it possible to safely disable it?
Appreciated, thanks.

-- Daniele Bonini
‎‎



Re: IPv6 chellange and OpenBSD

2023-02-16 Thread Daniele B.


> If you like the CLI don't forget OpenBSD Amsterdam plug>

Thanks also for this one, OpenBSD Amsterdam, not the first referral..
Indeed cudoz to you but I would say cudoz to Amsterdam..

PS: my daughter is sleeping, can't  me sorry for any unconviniance..



Re: IPv6 chellange and OpenBSD

2023-02-16 Thread Mischa

On 2023-02-16 11:09, Philipp Buehler wrote:

Am 16.02.2023 08:27 schrieb Daniele B.:

3) Can you advise about hosting providers in terms of managed VPS with
OpenBSD, in North America and Europe?


For some years now with https://transip.eu - spotless IPv6 and OpenBSD
included. The web/vnc console just works, too.


If you like the CLI don't forget OpenBSD 
Amsterdam


:)

Mischa



Re: IPv6 chellange and OpenBSD

2023-02-16 Thread Daniele B.


> For some years now with https://transip.eu - spotless IPv6 and OpenBSD
> included.

Thanks for this one, appreciated.
-- Daniele Bonini



Re: Mail from the command line

2023-02-16 Thread Andrew
Thanks Crystal for your reply and encouragement,
I'll explore all your suggestions and references when I have enough time.
Cheers,
Andrew

Le jeu. 16 févr. 2023 à 12:58, Crystal Kolipe 
a écrit :

> On Thu, Feb 16, 2023 at 12:27:37PM +0100, Andrew wrote:
> > *Do you know any recipe for using $ mail on the command line? Or a web
> link
> > that proposes one.*
> >
> > The man pages are great but they are meant for people with great
> technical
> > skills, which I am not.
>
> What exactly are you trying to set up?
>
> Local mail works out of the box on a default OpenBSD install, so I'm
> assuming
> that what you want to do is to send and receive mail to other internet
> hosts
> without using a desktop/gui client, I.E. using the traditional built-in
> mail
> functionality typical of a unix-like system.
>
> This isn't particularly difficult, but it does depend to a certain extent
> on
> the configuration of your ISP, and also exactly how you want the system to
> behave.  So it's not possible to give you a simple fixed list of steps to
> follow to 'make it work'.
>
> First up, the /usr/bin/mail utility in base is really a hard link to
> /usr/bin/mailx.
>
> This is a very simple command line mail tool, which you probably don't
> want to
> use as your mail email application because it's lacking many features.
>
> Other command line based mail programs are available in ports, such as
> mutt,
> which is widely used by openbsd developers.
>
> Then you need to set up smtpd to handle your inbound and outbound mail.
>
> For outbound mail, you _probably_ want to, (and need to), relay it via your
> ISP's 'smarthost', but we would need more information to know this for
> certain
> and to give specific advice on how to set it up.
>
> For inbound mail, you have several choices:
>
> * Run your own MX on a fixed IP broadband link.
> * Pick up your mail via POP3 or IMAP from within the mail user agent,
> (such as
>   mutt), and feed it in to your local mail spools that way.
> * Pick up your mail via POP3 or IMAP and feed it into the local mail
> system.
> * Run your own MX on your own server or VM somewhere, and relay it to your
>   own local, private MX.
> * Other options also exist.
>
> If you are new to this, then you probably want the second option.  Maybe
> the
> third.
>
> > And web pages are full of phoney tips which rarely work.
>
> Agreed.
>
> > I hope that this is the right place for asking such questions.
>
> Yes, it is.
>
> But we can't give you a step-by-step guide without a bit more information.
>


Re: Mail from the command line

2023-02-16 Thread Crystal Kolipe
On Thu, Feb 16, 2023 at 12:27:37PM +0100, Andrew wrote:
> *Do you know any recipe for using $ mail on the command line? Or a web link
> that proposes one.*
> 
> The man pages are great but they are meant for people with great technical
> skills, which I am not.

What exactly are you trying to set up?

Local mail works out of the box on a default OpenBSD install, so I'm assuming
that what you want to do is to send and receive mail to other internet hosts
without using a desktop/gui client, I.E. using the traditional built-in mail
functionality typical of a unix-like system.

This isn't particularly difficult, but it does depend to a certain extent on
the configuration of your ISP, and also exactly how you want the system to
behave.  So it's not possible to give you a simple fixed list of steps to
follow to 'make it work'.

First up, the /usr/bin/mail utility in base is really a hard link to
/usr/bin/mailx.

This is a very simple command line mail tool, which you probably don't want to
use as your mail email application because it's lacking many features.

Other command line based mail programs are available in ports, such as mutt,
which is widely used by openbsd developers.

Then you need to set up smtpd to handle your inbound and outbound mail.

For outbound mail, you _probably_ want to, (and need to), relay it via your
ISP's 'smarthost', but we would need more information to know this for certain
and to give specific advice on how to set it up.

For inbound mail, you have several choices:

* Run your own MX on a fixed IP broadband link.
* Pick up your mail via POP3 or IMAP from within the mail user agent, (such as
  mutt), and feed it in to your local mail spools that way.
* Pick up your mail via POP3 or IMAP and feed it into the local mail system.
* Run your own MX on your own server or VM somewhere, and relay it to your
  own local, private MX.
* Other options also exist.

If you are new to this, then you probably want the second option.  Maybe the
third.

> And web pages are full of phoney tips which rarely work.

Agreed.

> I hope that this is the right place for asking such questions.

Yes, it is.

But we can't give you a step-by-step guide without a bit more information.



Re: Mail from the command line

2023-02-16 Thread Peter N. M. Hansteen
On Thu, Feb 16, 2023 at 12:27:37PM +0100, Andrew wrote:
> 
> *Do you know any recipe for using $ mail on the command line? Or a web link
> that proposes one.*

typing "using mail from the command line" into a search engine yields quite a
few hits. This one https://phoenixnap.com/kb/linux-mail-command looks like
a fairly useful one once you skip the "how to install mailx on Linux" part.

- Peter

-- 
Peter N. M. Hansteen, member of the first RFC 1149 implementation team
https://bsdly.blogspot.com/ https://www.bsdly.net/ https://www.nuug.no/
"Remember to set the evil bit on all malicious network traffic"
delilah spamd[29949]: 85.152.224.147: disconnected after 42673 seconds.



Mail from the command line

2023-02-16 Thread Andrew
Hi Misc,
I'm so sorry guys if that question has been asked too often.

*Do you know any recipe for using $ mail on the command line? Or a web link
that proposes one.*

The man pages are great but they are meant for people with great technical
skills, which I am not.
And web pages are full of phoney tips which rarely work.

I hope that this is the right place for asking such questions.
Cheers,
Andrew


Re: IPv6 chellange and OpenBSD

2023-02-16 Thread Philipp Buehler

Am 16.02.2023 08:27 schrieb Daniele B.:

3) Can you advise about hosting providers in terms of managed VPS with
OpenBSD, in North America and Europe?


For some years now with https://transip.eu - spotless IPv6 and OpenBSD
included. The web/vnc console just works, too.

I think I had only one (maybe two) involvements with their support,
super quick and competent.

As of now they "only" offer 7.1, but sysupgrade is so easy...

HTH,
--
pb



Re: Ensuring data integrity

2023-02-16 Thread Crystal Kolipe
On Thu, Feb 16, 2023 at 01:48:49AM +0100, i...@tutanota.com wrote:
> If I setup a couple of drives in a RAID mirror on OpenBSD to serve as
> a NAS box, what is the best way to ensure data integrity?

This is a very broad question and the answer is always going to depend on
your specific use case.

However, in general, it's best to do this kind of thing at the application
level, or rather not to add excessive features at the filesystem or block
device level to try to ensure 'data integrity'.

This could be as simple as a script run from cron to check the hashes of files
which are not expected to change, or as complicated as modifying the
applications you are using to store ECC in their data files, or even write
multiple copies of the same data to different files on the disks, (and check
those as deemed to be required).

But the point is to do this _in the application_ or at least as a user-land
task, and not try to build a fancy 'one size fits all' solution to the
(perceived), problem with a complex combination of RAID arrays, funky
filesystems, and other trickery.

And the other key to ensuring data integrity over a long period of time is
to separate out data which is not expected to change, and archive it
separately.  Don't just create one massive RAID-5 dumping ground for
everything and keep adding data and disks to it in an unorganised fashion
until it breaks.



Re: OpenBSD, PHP lifecycle and PHP 8.1 broken compatibility

2023-02-16 Thread Daniele B.


> You can have multiple vm's with old versions.
> E.g. you can keep an openbsd 60 vm with PHP 5.5.37.

Reasoning about it.

I need to start saying..in respect of all who is reading..as many of you could 
work with OpenBSD and vms.

I already passed from that kind of environment and three problems pop up:
1) security: unfort. it seems far more easy to kill a virtual machine than .c
2) complexity
3) portability: although with appropriate "glue records" system become
 rendondant, resource usage overkilling, etc..

The only true positive thing is I see I can do backups by a copy and past of vm 
files but to an HD, in the true sense.

Is it something acceptable? Well some of you by guess can reply yes, we do it.
I personally endorsed the portability of OpenBSD and I'm stuck on that.

To eventually appear more..pointless in respect to my OpenBSD system:
a) we actually can't boot a vm by bios
b) hosting providers offer this online, with many virtual facilities
c) containers screw up any system delivery with easie: copy and past of 
docker-compose.yml and
    what I need is up and running in sec: all my infrastructure plus PHP[N] 
that I choose

Let's enrich all these matters that appear enough interesting..

Further more and..sorry for this one: are we all going to be on Internet with 
our own dev environments? hehe..
Now, yess, you can kill me..