Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Everything should be made as simple as possible, but not simpler. -- Albert Einstein


devel / comp.unix.programmer / Re: Advisory file locking

SubjectAuthor
* Advisory file lockingMuttley
`* Advisory file lockingScott Lurndal
 +- Advisory file lockingRichard Kettlewell
 +* Advisory file lockingMuttley
 |+- Advisory file lockingScott Lurndal
 |`* Advisory file lockingRainer Weikusat
 | +- Advisory file lockingMuttley
 | `- Advisory file lockingKenny McCormack
 `- Advisory file lockingWilliam Ahern

1
Advisory file locking

<th9kp1$jae$1@gioia.aioe.org>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2911&group=comp.unix.programmer#2911

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!aioe.org!BKzeqmo2UYxb4eR2zKm0zw.user.46.165.242.75.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Advisory file locking
Date: Sat, 1 Oct 2022 15:01:53 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <th9kp1$jae$1@gioia.aioe.org>
Injection-Info: gioia.aioe.org; logging-data="19790"; posting-host="BKzeqmo2UYxb4eR2zKm0zw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
 by: Muttley@dastardlyhq.com - Sat, 1 Oct 2022 15:01 UTC

If a process does flock() on a file then dies without unlocking it, does unix
clear that lock or is it left hanging? The man pages and google are silent on
this. Ditto whether LOCK_UN can block?

Also a related question - is there a command line tool that will show/remove
advisory locks and who owns them?

Re: Advisory file locking

<zq0_K.138031$479c.106764@fx48.iad>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2912&group=comp.unix.programmer#2912

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Advisory file locking
Newsgroups: comp.unix.programmer
References: <th9kp1$jae$1@gioia.aioe.org>
Lines: 22
Message-ID: <zq0_K.138031$479c.106764@fx48.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 01 Oct 2022 19:21:03 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 01 Oct 2022 19:21:03 GMT
X-Received-Bytes: 1440
 by: Scott Lurndal - Sat, 1 Oct 2022 19:21 UTC

Muttley@dastardlyhq.com writes:
>If a process does flock() on a file then dies without unlocking it, does unix
>clear that lock or is it left hanging? The man pages and google are silent on
>this. Ditto whether LOCK_UN can block?
>
>Also a related question - is there a command line tool that will show/remove
>advisory locks and who owns them?
>

"All locks associated with a file for a given process shall be removed
when a file descriptor for that file is closed by that process or the
process holding that file descriptor terminates. Locks are not inherited
by a child process."

https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html

(note: flock() is a bsd-ism and is not described by POSIX/SuS).

I'm not aware of any command to show the locks. I'm not aware of any
kernel/filesystem API that provides that visibility.

Re: Advisory file locking

<87fsg7chnn.fsf@LkoBDZeT.terraraq.uk>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2913&group=comp.unix.programmer#2913

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.niel.me!nntp.terraraq.uk!.POSTED.nntp.terraraq.uk!not-for-mail
From: invalid@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.unix.programmer
Subject: Re: Advisory file locking
Date: Sat, 01 Oct 2022 23:18:04 +0100
Organization: terraraq NNTP server
Message-ID: <87fsg7chnn.fsf@LkoBDZeT.terraraq.uk>
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: mantic.terraraq.uk; posting-host="nntp.terraraq.uk:2a00:1098:0:86:1000:3f:0:2";
logging-data="126388"; mail-complaints-to="usenet@mantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:Qn7tjj03km+qqLun/TpoQapUos4=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Sat, 1 Oct 2022 22:18 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Muttley@dastardlyhq.com writes:
>> If a process does flock() on a file then dies without unlocking it,
>> does unix clear that lock or is it left hanging? The man pages and
>> google are silent on this. Ditto whether LOCK_UN can block?
>>
>> Also a related question - is there a command line tool that will
>> show/remove advisory locks and who owns them?
>
>
> "All locks associated with a file for a given process shall be removed
> when a file descriptor for that file is closed by that process or the
> process holding that file descriptor terminates. Locks are not inherited
> by a child process."
>
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
>
> (note: flock() is a bsd-ism and is not described by POSIX/SuS).

AFAIK the rules are different for flock, which binds the lock to the
file descriptor (including all copies of it created by dup/fork). So I
think the answer to the original question “it depends” - if the file
descriptor is shared with another process then the lock may not be
released until all the processes with the same file descriptor
terminate.

--
https://www.greenend.org.uk/rjk/

Re: Advisory file locking

<thc6hi$ue5$1@gioia.aioe.org>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2914&group=comp.unix.programmer#2914

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!aioe.org!BKzeqmo2UYxb4eR2zKm0zw.user.46.165.242.75.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Advisory file locking
Date: Sun, 2 Oct 2022 14:17:22 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <thc6hi$ue5$1@gioia.aioe.org>
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad>
Injection-Info: gioia.aioe.org; logging-data="31173"; posting-host="BKzeqmo2UYxb4eR2zKm0zw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
 by: Muttley@dastardlyhq.com - Sun, 2 Oct 2022 14:17 UTC

On Sat, 01 Oct 2022 19:21:03 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
>Muttley@dastardlyhq.com writes:
>>If a process does flock() on a file then dies without unlocking it, does unix
>>clear that lock or is it left hanging? The man pages and google are silent on
>>this. Ditto whether LOCK_UN can block?
>>
>>Also a related question - is there a command line tool that will show/remove
>>advisory locks and who owns them?
>>
>
>
> "All locks associated with a file for a given process shall be removed
> when a file descriptor for that file is closed by that process or the
> process holding that file descriptor terminates. Locks are not inherited
> by a child process."
>
>https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
>
>(note: flock() is a bsd-ism and is not described by POSIX/SuS).

Didn't know, though its available on Linux and MacOS so clearly is fairly
widespread.

>I'm not aware of any command to show the locks. I'm not aware of any
>kernel/filesystem API that provides that visibility.

Pity. Some rainy day I'll have to trawl /proc on linux and see if anything
looks like a list of file locks for a process.

Re: Advisory file locking

<VLh_K.66065$JZK5.62423@fx03.iad>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2915&group=comp.unix.programmer#2915

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx03.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Advisory file locking
Newsgroups: comp.unix.programmer
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad> <thc6hi$ue5$1@gioia.aioe.org>
Lines: 40
Message-ID: <VLh_K.66065$JZK5.62423@fx03.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 02 Oct 2022 15:04:21 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 02 Oct 2022 15:04:21 GMT
X-Received-Bytes: 2293
 by: Scott Lurndal - Sun, 2 Oct 2022 15:04 UTC

Muttley@dastardlyhq.com writes:
>On Sat, 01 Oct 2022 19:21:03 GMT
>scott@slp53.sl.home (Scott Lurndal) wrote:
>>Muttley@dastardlyhq.com writes:
>>>If a process does flock() on a file then dies without unlocking it, does unix
>>>clear that lock or is it left hanging? The man pages and google are silent on
>>>this. Ditto whether LOCK_UN can block?
>>>
>>>Also a related question - is there a command line tool that will show/remove
>>>advisory locks and who owns them?
>>>
>>
>>
>> "All locks associated with a file for a given process shall be removed
>> when a file descriptor for that file is closed by that process or the
>> process holding that file descriptor terminates. Locks are not inherited
>> by a child process."
>>
>>https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
>>
>>(note: flock() is a bsd-ism and is not described by POSIX/SuS).
>
>Didn't know, though its available on Linux and MacOS so clearly is fairly
>widespread.

Given OS/x is derived from BSD, that's not unexpected. SVR4 added support
for a bunch of BSD interfaces back in the day as well for portability
reasons, likewise linux.

From the BSD man page:

NOTES
Locks are on files, not file descriptors. That is, file descriptors du-
plicated through dup(2) or fork(2) do not result in multiple instances of
a lock, but rather multiple references to a single lock. If a process
holding a lock on a file forks and the child explicitly unlocks the file,
the parent will lose its lock.

As Richard points out, this implies that the lock persists until the last
reference to the inode is released.

Re: Advisory file locking

<87o7utgc1d.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2916&group=comp.unix.programmer#2916

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Advisory file locking
Date: Sun, 02 Oct 2022 22:18:06 +0100
Lines: 14
Message-ID: <87o7utgc1d.fsf@doppelsaurus.mobileactivedefense.com>
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad>
<thc6hi$ue5$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Bn0PVuNGIGObPdwxx45bAwli+fml7x8VxQGpjRQo/Q3PZwGWw=
Cancel-Lock: sha1:dqnXTcjF5wqXK2qgmF/wvIGZ/IA= sha1:lKBuDkPbSvXjWpDrz3nFhepZuYk=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Sun, 2 Oct 2022 21:18 UTC

Muttley@dastardlyhq.com writes:
> On Sat, 01 Oct 2022 19:21:03 GMT
> scott@slp53.sl.home (Scott Lurndal) wrote:

[...]

>>I'm not aware of any command to show the locks. I'm not aware of any
>>kernel/filesystem API that provides that visibility.
>
> Pity. Some rainy day I'll have to trawl /proc on linux and see if anything
> looks like a list of file locks for a process.

The (virtual) file /proc/locks lists all currently held file locks. The
pid of the process holding the lock is in the fifth column.

Re: Advisory file locking

<the4jn$je9$1@gioia.aioe.org>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2917&group=comp.unix.programmer#2917

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!aioe.org!BKzeqmo2UYxb4eR2zKm0zw.user.46.165.242.75.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Advisory file locking
Date: Mon, 3 Oct 2022 07:56:40 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <the4jn$je9$1@gioia.aioe.org>
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad>
<thc6hi$ue5$1@gioia.aioe.org>
<87o7utgc1d.fsf@doppelsaurus.mobileactivedefense.com>
Injection-Info: gioia.aioe.org; logging-data="19913"; posting-host="BKzeqmo2UYxb4eR2zKm0zw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
 by: Muttley@dastardlyhq.com - Mon, 3 Oct 2022 07:56 UTC

On Sun, 02 Oct 2022 22:18:06 +0100
Rainer Weikusat <rweikusat@talktalk.net> wrote:
>Muttley@dastardlyhq.com writes:
>> On Sat, 01 Oct 2022 19:21:03 GMT
>> scott@slp53.sl.home (Scott Lurndal) wrote:
>
>[...]
>
>>>I'm not aware of any command to show the locks. I'm not aware of any
>>>kernel/filesystem API that provides that visibility.
>>
>> Pity. Some rainy day I'll have to trawl /proc on linux and see if anything
>> looks like a list of file locks for a process.
>
>The (virtual) file /proc/locks lists all currently held file locks. The
>pid of the process holding the lock is in the fifth column.

Thanks.

Re: Advisory file locking

<thei5s$2935a$1@news.xmission.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2918&group=comp.unix.programmer#2918

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Advisory file locking
Date: Mon, 3 Oct 2022 11:48:12 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <thei5s$2935a$1@news.xmission.com>
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad> <thc6hi$ue5$1@gioia.aioe.org> <87o7utgc1d.fsf@doppelsaurus.mobileactivedefense.com>
Injection-Date: Mon, 3 Oct 2022 11:48:12 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2395306"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 3 Oct 2022 11:48 UTC

In article <87o7utgc1d.fsf@doppelsaurus.mobileactivedefense.com>,
Rainer Weikusat <rweikusat@talktalk.net> wrote:
>Muttley@dastardlyhq.com writes:
>> On Sat, 01 Oct 2022 19:21:03 GMT
>> scott@slp53.sl.home (Scott Lurndal) wrote:
>
>[...]
>
>>>I'm not aware of any command to show the locks. I'm not aware of any
>>>kernel/filesystem API that provides that visibility.
>>
>> Pity. Some rainy day I'll have to trawl /proc on linux and see if anything
>> looks like a list of file locks for a process.
>
>The (virtual) file /proc/locks lists all currently held file locks. The
>pid of the process holding the lock is in the fifth column.

There is also a "lslocks" command to list out the data in that file for you.

However, I could not get "lslocks" to show me the full pathname of the
file; it always truncates it. However, the following "find" hack does the
trick (assuming you know, from the "lslocks" output, the inode number and
which filesystem the file is on - e.g., /):

find $fs -xdev -inum $inum -ls 2>/dev/null

(Of course, you could also get the device and inum info directly from
/proc/locks as well)

--
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy of the church so decides."

- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -

Re: Advisory file locking

<2ncs0j-uch.ln1@wilbur.25thandClement.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2919&group=comp.unix.programmer#2919

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 04 Oct 2022 01:00:02 +0000
Message-ID: <2ncs0j-uch.ln1@wilbur.25thandClement.com>
From: william@25thandClement.com (William Ahern)
Subject: Re: Advisory file locking
Newsgroups: comp.unix.programmer
References: <th9kp1$jae$1@gioia.aioe.org> <zq0_K.138031$479c.106764@fx48.iad>
User-Agent: tin/2.4.4-20191224 ("Millburn") (OpenBSD/7.1 (amd64))
Date: Mon, 3 Oct 2022 17:52:18 -0700
Lines: 29
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-SwYvNWIKi5ounQmnRDjCBwPCKCbRBiIvz/mZORdXisxoE9TAqQ3DK34JBDu+AwvS6pCASN187o9VWgG!QoAPKYv7t9KsWbrUENP/leTNO18wdT1rPQpDR9QXreiUmV1gU2uF0REisnAY0GLgbw==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: William Ahern - Tue, 4 Oct 2022 00:52 UTC

Scott Lurndal <scott@slp53.sl.home> wrote:
> Muttley@dastardlyhq.com writes:
>>If a process does flock() on a file then dies without unlocking it, does unix
>>clear that lock or is it left hanging? The man pages and google are silent on
>>this. Ditto whether LOCK_UN can block?
>>
>>Also a related question - is there a command line tool that will show/remove
>>advisory locks and who owns them?
>>
>
>
> "All locks associated with a file for a given process shall be removed
> when a file descriptor for that file is closed by that process or the
> process holding that file descriptor terminates. Locks are not inherited
> by a child process."
>
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
>
> (note: flock() is a bsd-ism and is not described by POSIX/SuS).
>

FWIW, there's an open proposal to add a flock-like mechanism: File-private
POSIX locks. https://www.austingroupbugs.net/view.php?id=768 (See also
https://lwn.net/Articles/586904/)

Rather than simply standardizing the BSD routine, it mirrors the fcntl
interface with F_OFD_GETLK, F_FD_SETLK, etc, including support for range
locks. It was merged into Linux (kernel, glibc, and musl libc) awhile ago,
but doesn't seem to have been adopted anywhere else, AFAICT.


devel / comp.unix.programmer / Re: Advisory file locking

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor