Re: Detect Linux Runlevel

2016-12-08 Thread Marko Rauhamaa
Tim Chase : > Interesting. I read up on os.open() and os.read() > https://docs.python.org/2/library/os.html#os.read > but didn't notice anything there clarifying that it was unbuffered > compared to the __builtins__.open() and fp.read() functions. > > Could you point me to resources where I can

Re: Detect Linux Runlevel

2016-12-08 Thread Tim Chase
On 2016-12-07 07:30, Marko Rauhamaa wrote: > Tim Chase : > > On 2016-12-07 00:29, Marko Rauhamaa wrote: > >> A word a warning: your code doesn't lock /var/run/utmp before > >> access, which is a race condition. The file may be updated at any > >> time, and ordinary file reads may yield corrupted re

Re: Detect Linux Runlevel

2016-12-07 Thread Marko Rauhamaa
Grant Edwards : > There are a few things in Unix that are fundamentally broken and > really just can't be used for the things they are intended for (serial > ports come to mind). > > However, that doesn't seem to prevent them from having been used > sucessfully that way way for 40 years. ;) Sigh.

Re: Detect Linux Runlevel

2016-12-07 Thread Grant Edwards
On 2016-12-07, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Whereas if it were mandatory locking, enforced by the OS, it >> wouldn't be a problem? > > The point is, the utmp scheme seems to be fundamentally broken. You > can't use a regular file for this kind of communication. There are a few t

Re: Detect Linux Runlevel

2016-12-07 Thread Marko Rauhamaa
Steven D'Aprano : > Whereas if it were mandatory locking, enforced by the OS, it wouldn't > be a problem? The point is, the utmp scheme seems to be fundamentally broken. You can't use a regular file for this kind of communication. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: Detect Linux Runlevel

2016-12-07 Thread Steven D'Aprano
On Wednesday 07 December 2016 18:08, Marko Rauhamaa wrote: >This is a problem with advisory locking. The fact that anyone can >create an exclusive lock on a file they can only read! Is this >behavior appropriate? > >https://www.redhat.com/archives/linux-security/1996-Novembe >

Re: Detect Linux Runlevel

2016-12-06 Thread Marko Rauhamaa
Michael Torrie : > On 12/06/2016 03:29 PM, Marko Rauhamaa wrote: >> Another thing is that, as stated before, the runlevel business is >> legacy. It is still supported by systemd-update-utmp, but for how >> long is anybody's guess. > > System V compatibility is still important to Linux, and as long

Re: Detect Linux Runlevel

2016-12-06 Thread Marko Rauhamaa
Tim Chase : > On 2016-12-07 00:29, Marko Rauhamaa wrote: >> A word a warning: your code doesn't lock /var/run/utmp before >> access, which is a race condition. The file may be updated at any >> time, and ordinary file reads may yield corrupted records. > > Since the code is reading in record-sized

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-06 21:27, Wildman via Python-list wrote: > On Tue, 06 Dec 2016 13:06:35 -0600, Tim Chase wrote: > I forgot to mention that I want to include your name in the > final script as a contributor, if that is ok. No issues here. > You will get a cut of the royalties. Lets see, how much is >

Re: Detect Linux Runlevel

2016-12-06 Thread Wildman via Python-list
On Tue, 06 Dec 2016 13:06:35 -0600, Tim Chase wrote: > I forgot to mention that I want to include your name in the final script as a contributor, if that is ok. You will get a cut of the royalties. Lets see, how much is 20% of $0.00? Well, I'll let my account work that out as soon as she gets

Re: Detect Linux Runlevel

2016-12-06 Thread Wildman via Python-list
On Tue, 06 Dec 2016 09:45:05 -0700, Michael Torrie wrote: > I appreciate your measured response to what could be seen as an > inflammatory post. It was inflammatory and I considered a different response but after the knee jerking, I give it some thought and decided otherwise. The simple fact is

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-07 00:29, Marko Rauhamaa wrote: > Tim Chase : > > > This works based on my poking at it in both Py2 and Py3: > > Great info, Tim. > > A word a warning: your code doesn't lock /var/run/utmp before > access, which is a race condition. The file may be updated at any > time, and ordinary

Re: Detect Linux Runlevel

2016-12-06 Thread Michael Torrie
On 12/06/2016 03:29 PM, Marko Rauhamaa wrote: > Another thing is that, as stated before, the runlevel business is > legacy. It is still supported by systemd-update-utmp, but for how long > is anybody's guess. System V compatibility is still important to Linux, and as long as it is, something resem

Re: Detect Linux Runlevel

2016-12-06 Thread Marko Rauhamaa
Tim Chase : > This works based on my poking at it in both Py2 and Py3: Great info, Tim. A word a warning: your code doesn't lock /var/run/utmp before access, which is a race condition. The file may be updated at any time, and ordinary file reads may yield corrupted records. The library function

Re: Detect Linux Runlevel

2016-12-06 Thread Wildman via Python-list
On Tue, 06 Dec 2016 13:06:35 -0600, Tim Chase wrote: > On 2016-12-06 12:10, Wildman via Python-list wrote: >> If I had tried this in the beginning, it would have >> save you a lot of work. >> >> Since both versions of the code works, which one do >> you recommend? Or does it matter? > > Heh, I'

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-06 12:10, Wildman via Python-list wrote: > If I had tried this in the beginning, it would have > save you a lot of work. > > Since both versions of the code works, which one do > you recommend? Or does it matter? Heh, I'm not sure it matters much. The code I provided should be expand

Re: Detect Linux Runlevel

2016-12-06 Thread Wildman via Python-list
On Mon, 05 Dec 2016 16:08:57 -0600, Tim Chase wrote: > On 2016-12-05 14:58, Wildman via Python-list wrote: >> I there a way to detect what the Linux runlevel is from >> within a Python program? I would like to be able to do >> it without the use of an external program such as 'who' >> or 'runleve

Re: Detect Linux Runlevel

2016-12-06 Thread Michael Torrie
On 12/06/2016 09:18 AM, Wildman via Python-list wrote: > It is sad that you consider learning something new to > be worthless. I used the term "worthlessware" in an > economical sense, meaning it has little or no commercial > value. However, from a learning standpoint I consider > it to be pricel

Re: Detect Linux Runlevel

2016-12-06 Thread Michael Torrie
On 12/06/2016 06:51 AM, Tim Chase wrote: > Based on the OP's description, this is a small part of a much larger > program. And I would personally rather maintain a large Python > code-base than a large Bash code-base. Absolutely. Especially when you consider inxi is 12,000 lines of bash code in

Re: Detect Linux Runlevel

2016-12-06 Thread Wildman via Python-list
On Tue, 06 Dec 2016 01:14:35 +0100, Bernd Nawothnig wrote: > On 2016-12-05, Wildman wrote: >> And I am trying to write it without using external programs, where >> possible. > > That is not the Unix way. Yes, but it is my way. >> I am a hobby programmer and I've been trying to learn python >> f

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-06 01:14, Bernd Nawothnig wrote: > > I am a hobby programmer and I've been trying to learn python > > for a few months now. The program is 'worthlessware' but it > > is a 'learning experience' for me. > > It looks for me like a worthless learning experience. Eh, one person's "wort

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-05 23:00, Wildman via Python-list wrote: > On Mon, 05 Dec 2016 21:42:52 -0600, Tim Chase wrote: > > This works based on my poking at it in both Py2 and Py3: > > That works perfectly. I owe you a big thanks. That was a > lot of work and time on your part. I really appreciate it. It w

Re: Detect Linux Runlevel

2016-12-05 Thread Marko Rauhamaa
Michael Torrie : > On 12/05/2016 04:37 PM, Marko Rauhamaa wrote: >> Unfortunately, I am not wholly impressed by the end result. Mogadishu >> has been replaced by Pyongyang. Some age-old Unix principles have been >> abandoned without clear justification. For example, I was appalled to >> find out t

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 21:42:52 -0600, Tim Chase wrote: > On 2016-12-05 18:26, Wildman via Python-list wrote: >> On Mon, 05 Dec 2016 16:08:57 -0600, Tim Chase wrote: >> >> > On 2016-12-05 14:58, Wildman via Python-list wrote: >> >> I there a way to detect what the Linux runlevel is from >> >> within

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 20:46:22 -0700, Michael Torrie wrote: > On 12/05/2016 08:27 PM, Wildman via Python-list wrote: >> On Mon, 05 Dec 2016 18:25:58 -0700, Michael Torrie wrote: >> >>> I think Python is a good choice for such a utility, but I agree it is >>> much better to rely on these external ut

Re: Detect Linux Runlevel

2016-12-05 Thread Michael Torrie
On 12/05/2016 08:27 PM, Wildman via Python-list wrote: > On Mon, 05 Dec 2016 18:25:58 -0700, Michael Torrie wrote: > >> I think Python is a good choice for such a utility, but I agree it is >> much better to rely on these external utilities as children to do the >> platform-dependent work, rather

Re: Detect Linux Runlevel

2016-12-05 Thread Tim Chase
On 2016-12-05 18:26, Wildman via Python-list wrote: > On Mon, 05 Dec 2016 16:08:57 -0600, Tim Chase wrote: > > > On 2016-12-05 14:58, Wildman via Python-list wrote: > >> I there a way to detect what the Linux runlevel is from > >> within a Python program? I would like to be able to do > >> it wit

Re: Detect Linux Runlevel

2016-12-05 Thread Michael Torrie
On 12/05/2016 07:48 PM, Steve D'Aprano wrote: > On Tue, 6 Dec 2016 11:08 am, Michael Torrie wrote about systemd: > >> I have yet to see any evidence of this Pyonguang situation. > > Let me guess... you're running a single-user Linux box? No I've done it on servers that weren't single-user (mail

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 18:25:58 -0700, Michael Torrie wrote: > I think Python is a good choice for such a utility, but I agree it is > much better to rely on these external utilities as children to do the > platform-dependent work, rather than try to re-implement everything in > Python. A long time

Re: Detect Linux Runlevel

2016-12-05 Thread Nathan Ernst
OT, but I'm curious, do they explain *why* it's wrong and give an alternative, or just outright deride it as "the wrong way". I ask because I've read similar complaints about the community around systemd, but as it rarely affects me personally, I've never bothered to care. On Mon, Dec 5, 2016 at 8

Re: Detect Linux Runlevel

2016-12-05 Thread Steve D'Aprano
On Tue, 6 Dec 2016 11:08 am, Michael Torrie wrote about systemd: > I have yet to see any evidence of this Pyonguang situation. Let me guess... you're running a single-user Linux box? Fortunately, I've managed to avoid needing to personally interact with systemd at all. But over the last year or

Re: Detect Linux Runlevel

2016-12-05 Thread Michael Torrie
On 12/05/2016 05:14 PM, Bernd Nawothnig wrote: > On 2016-12-05, Wildman wrote: >> And I am trying to write it without using external programs, where >> possible. > > That is not the Unix way. > >> I am a hobby programmer and I've been trying to learn python >> for a few months now. The program i

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 16:08:57 -0600, Tim Chase wrote: > On 2016-12-05 14:58, Wildman via Python-list wrote: >> I there a way to detect what the Linux runlevel is from >> within a Python program? I would like to be able to do >> it without the use of an external program such as 'who' >> or 'runleve

Re: Detect Linux Runlevel

2016-12-05 Thread Bernd Nawothnig
On 2016-12-05, Wildman wrote: > And I am trying to write it without using external programs, where > possible. That is not the Unix way. > I am a hobby programmer and I've been trying to learn python > for a few months now. The program is 'worthlessware' but it > is a 'learning experience' for m

Re: Detect Linux Runlevel

2016-12-05 Thread Michael Torrie
On 12/05/2016 04:37 PM, Marko Rauhamaa wrote: > Unfortunately, I am not wholly impressed by the end result. Mogadishu > has been replaced by Pyongyang. Some age-old Unix principles have been > abandoned without clear justification. For example, I was appalled to > find out that a systemd unit can b

Re: Detect Linux Runlevel

2016-12-05 Thread Marko Rauhamaa
Michael Torrie : > On 12/05/2016 03:29 PM, Marko Rauhamaa wrote: >> In fact, systemd is not an init system for Linux. Linux is the kernel of >> the systemd operating system. Systemd is the >> >> One Ring to rule them all, One Ring to find them, >>One Ring to bring them all and in the da

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 15:39:24 -0700, Michael Torrie wrote: > On 12/05/2016 03:34 PM, Wildman via Python-list wrote: >> Too bad I don't speak C. I am an amateur programmer and most or all >> my experience has been with assembly and various flavors of BASIC, >> including VB and PowerBASIC. I did lo

Re: Detect Linux Runlevel

2016-12-05 Thread Lew Pitcher
On Monday December 5 2016 17:24, in comp.lang.python, "Chris Angelico" wrote: > On Tue, Dec 6, 2016 at 8:38 AM, Lew Pitcher > wrote: >> The OP asked for the runlevel, not the systemd target. > > Runlevels don't exist in systemd. And systemd targets don't exist in > Upstart. The question "what r

Re: Detect Linux Runlevel

2016-12-05 Thread Michael Torrie
On 12/05/2016 03:29 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Dec 6, 2016 at 8:38 AM, Lew Pitcher >> wrote: >>> The OP asked for the runlevel, not the systemd target. >> >> Runlevels don't exist in systemd. And systemd targets don't exist in >> Upstart. The question "what runlevel

Re: Detect Linux Runlevel

2016-12-05 Thread Michael Torrie
On 12/05/2016 03:34 PM, Wildman via Python-list wrote: > Too bad I don't speak C. I am an amateur programmer and most or all > my experience has been with assembly and various flavors of BASIC, > including VB and PowerBASIC. I did look over the code but I guess > I'm just a rebel without a clue.

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 23:59:48 +0200, Marko Rauhamaa wrote: > Wildman : >> Thanks but I knew about systemctl. As I already said my goal is to do >> it without the use of an external program. > > Inspect: > >https://github.com/systemd/systemd/blob/master/src/systemctl/systemctl.c> > > In p

Re: Detect Linux Runlevel

2016-12-05 Thread Marko Rauhamaa
Chris Angelico : > On Tue, Dec 6, 2016 at 8:38 AM, Lew Pitcher > wrote: >> The OP asked for the runlevel, not the systemd target. > > Runlevels don't exist in systemd. And systemd targets don't exist in > Upstart. The question "what runlevel are we in" does not make sense > unless you're using an

Re: Detect Linux Runlevel

2016-12-05 Thread Tim Chase
On 2016-12-05 14:58, Wildman via Python-list wrote: > I there a way to detect what the Linux runlevel is from > within a Python program? I would like to be able to do > it without the use of an external program such as 'who' > or 'runlevel'. You can use something like https://gist.github.com/lik

Re: Detect Linux Runlevel

2016-12-05 Thread Chris Angelico
On Tue, Dec 6, 2016 at 8:38 AM, Lew Pitcher wrote: > The OP asked for the runlevel, not the systemd target. Runlevels don't exist in systemd. And systemd targets don't exist in Upstart. The question "what runlevel are we in" does not make sense unless you're using an init system that works on the

Re: Detect Linux Runlevel

2016-12-05 Thread Marko Rauhamaa
Wildman : > Thanks but I knew about systemctl. As I already said my goal is to do > it without the use of an external program. Inspect: https://github.com/systemd/systemd/blob/master/src/systemctl/systemctl.c> In particular: get_state_one_unit() Then, proceed to: https://dbus.freedes

Re: Detect Linux Runlevel

2016-12-05 Thread Lew Pitcher
On Monday December 5 2016 16:25, in comp.lang.python, "DFS" wrote: > On 12/05/2016 03:58 PM, Wildman wrote: >> I there a way to detect what the Linux runlevel is from >> within a Python program? I would like to be able to do >> it without the use of an external program such as 'who' >> or 'runle

Re: Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
On Mon, 05 Dec 2016 16:25:56 -0500, DFS wrote: > On 12/05/2016 03:58 PM, Wildman wrote: >> I there a way to detect what the Linux runlevel is from >> within a Python program? I would like to be able to do >> it without the use of an external program such as 'who' >> or 'runlevel'. > > > Why not

Detect Linux Runlevel

2016-12-05 Thread Wildman via Python-list
I there a way to detect what the Linux runlevel is from within a Python program? I would like to be able to do it without the use of an external program such as 'who' or 'runlevel'. -- GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/py