LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   where is the config or code behind the desktop "suspend" button? (http://www.linuxquestions.org/questions/linux-desktop-74/where-is-the-config-or-code-behind-the-desktop-suspend-button-4175469977/)

SaintDanBert 07-17-2013 03:14 PM

where is the config or code behind the desktop "suspend" button?
 
I'm running Mint-12 with Cinnamon. When I open the SysMenu from my tray, I see a button for Shutdown and friends. When I select that button, I get a dialog with more buttons:
  • Suspend
  • Hibernate
  • Restart
  • Shutdown
  • Cancel
If I select one of these buttons (except Cancel) stuff happens and programs run. I want to understand what is really going on.

Does the tray item run a program that draws the dialog?
Which program and where can I find it? I may want to "decorate" that dialog to suit my own tastes.

Does the dialog launch programs or scripts in response to each button?
If so, which programs and where do I find them?

Does the dialog throw an event which upstart uses
to match with a job to accomplish the requested actions?
NOTE -- Ubuntu and Mint rely on Upstart, running as pid=1 with the name 'init' for all sorts of things including system startup and system shutdown.
Are we really required to read the code for our Desktop Environment -- in my case Cinnamon -- to get answers to these questions?
I have not found any documentation anywhere. (I suspect I have not looked in the right places.)

Merci d'avance,
~~~ 0;-Dan

frankbell 07-17-2013 07:18 PM

This article does not go into the details of the code, but it might be a good start:

http://www.advogato.org/article/913.html

If you do

Code:

apropos acpi
in a terminal, it will list man pages relevant to ACPI (Advanced Configuration and Power Interface) that will also help.

Shadow_7 07-17-2013 08:56 PM

Normally the acpid daemon handles events. In debian the scripts for the events are located at /etc/acpi/events/. YMMV

SaintDanBert 07-18-2013 11:11 AM

Thanks to shadow_7 and frankbell for their replies and references.

Let's take shutdown as an example.
  • I can use the 'shutdown' command from the shell
  • I can use the 'telinit' command from the shell
  • I can somehow throw a 'runlevel' event
  • I can use power management features
All of these will cause all processes to stop and power to get turned off. At the core, they might all result in the exact same things happening. (I have not read the code for the 'shutdown' command.)

From the desktop, with my mouse, I click twice:
  1. SysMenu item in the tray
  2. Shutdown button in the resulting dialog box
Somewhere in the code for the dialog box, I'd expect to find something like:
Code:

//
// this is pseudo-code, not an actual code fragment
//
switch ( myButton ) {
...
case ( isShutdown( myButton ) ) {
    causeShutdown( );
}
...
}

My original post sought to learn what actually happens in the 'causeShutdown( )' function. It could use 'system( )' to run the shutdown command in a shell. That's pretty ugly so I suspect that other things happen. What happens?

Merci d'avance,
~~~ 0;-Dan

Shadow_7 07-19-2013 04:04 PM

In debian the power button event, as in you push the button for power on the computer. It triggers a script /etc/acpi/powerbtn-acpi-support.sh. Which checks for other scripts to run, but ultimately issues the following command.

# shutdown -h -P now "Power button pressed"

I normally just enter a "shutdown -h now" as root when I shutdown. It's easy enough and I normally have a root shell open, even on the desktop. But I like knowing what my computer is doing and normally take a minimalist approach. If I'm not using it, it's not running. With cpu and net meters in the task bar, so I know when things are not as I wish them at a glance.

SaintDanBert 07-24-2013 04:24 PM

Quote:

Originally Posted by Shadow_7 (Post 4993470)
In debian the power button event, as in you push the button for power on the computer. It triggers a script /etc/acpi/powerbtn-acpi-support.sh. Which checks for other scripts to run, ...

Since I run Linux Mint (Ubuntu derived which is Debian derived) I suspect that the desktop code simply "throws the ACPI event" same as the power button. Thus the same crank turns regardless of how one gets there. Part of my information quest seeks to simply confirm what happens.

I know?!? I know !! Read the code for my desktop environment,
... and we wonder why few but thoroughbred geeks use Linux.
(Well, maybe we don't wonder after all.)

Heavy sigh,
~~~ 8d;-/ Dan

SaintDanBert 07-24-2013 04:28 PM

Quote:

Originally Posted by Shadow_7 (Post 4992273)
Normally the acpid daemon handles events. In debian the scripts for the events are located at /etc/acpi/events/. YMMV

I use Linux Mint.
Code:

.....It is derived from Ubuntu.
.......... It is derived from Debian.

On my Mint workstation, I find
  • scripts -- in /etc/acpi
  • 'upstart' jobs -- in /etc/acpi/events
NOTE -- I think that I used the term jobs correctly for the various stanzas that tell 'upstart' (running as PID=1, "init" process) what to do when various events happen.

Shadow_7 07-25-2013 01:45 PM

At least there is code to reference to actually know "for sure" what likely happens. If we take the time to audit the code. In most other OSes, in apple you trust, in microsoft you trust, in the NSA you trust. I say likely because even CPUs have bugs that do unintended things, throw in some questionable ram and underpowered circuitry and it's a tech lottery.

SaintDanBert 07-25-2013 08:22 PM

Quote:

Originally Posted by Shadow_7 (Post 4996680)
At least there is code to reference to actually know "for sure" what likely happens. If we take the time to audit the code. In most other OSes, in apple you trust, in microsoft you trust, in the NSA you trust. I say likely because even CPUs have bugs that do unintended things, throw in some questionable ram and underpowered circuitry and it's a tech lottery.

"We should not marvel that modern computer software has [defects]. Rather we should find awe in the fact that they work at all."

I heard this in a keynote speech years ago. I cannot remember who said it. They were talking about the test-ability of software systems and showed how even trivial, event-driven, GUI based applications can count the test cases with large enough numbers to be effectively infinite. The speaker went on to say that it was no wonder so many software publishers were letting their end-users do most of the testing in the manner of open source projects.

~~~ 8d;-Dan

jdackle 07-27-2013 09:19 AM

NOTE: I will be talking about terminal commands below, I expect the actual calls from the GUI to be made using the corresponding library functions, as you suggested in one of your posts.

To my best understanding, the command "/sbin/shutdown" will use init (the deprecated(?) "-n" option bypasses init for the shutdown - see "man shutdown").
/etc/init.d - all (most?) service scripts for all runlevels
/etc/rc0.d - scripts to be run at runlevel 0 (halt/poweroff)
/etc/rc5.d - the usual full-desktop running level
/etc/rc6.d - reboot

/sbin/halt, /sbin/poweroff and /sbin/reboot seem to be respectivelly equivalent to "shutdown -h -H -t now", "shutdown -h -P -t now" and "shutdown -r" (they are binary files though, not just wrapper-scripts)


For suspending and hibernating, "pm-suspend" and "pm-hibernate" might be used (though there are definitelly other options). Check "man pm-is-supported" to check whether those abilities are available on your system.

Not sure this is the kind of information you were looking for but... there it goes.

SaintDanBert 07-27-2013 01:49 PM

Quote:

Originally Posted by jdackle (Post 4997860)
...
Not sure this is the kind of information you were looking for but... there it goes.

Thanks for this.
  • ANY information about the parts is useful to this thread.
  • (grin)With your favorite distribution, your features may vary.
  • Your description of [/b]/etc/init.d/...[/b] sounds like it is based on the SystemV-init technology. Many distros have moved to either systemd or upstart which are reactive event driven. That said, I know with Mint-* (derived from Ubuntu) they use upstart which somehow honors any SystemV-init parts available. Apparently this enables install and use of packages which require system start processing but have not made the switch to an event driven process.
As I said before, ANY information about how all of this works is valuable. Gentle reader, please add your tuppence to the pile.

~~~ 0;-Dan

jdackle 07-27-2013 05:35 PM

That was a gentle post of yours, Dan! *grin*

Yes, last I checked about all that was several years ago (I'll hardly ever get the need, professionally, to go any deeper than database structuring, no need to touch the OS). And yes, by that time, the SystemV-init technology was rather "current".
When the upstart "thing" came up - or maybe just when I took notice of it (I think about the time I switched from Mandrake/Mandriva to Ubuntu) - I noticed it still used the init system, so gave it no more thought... Now I'm realising the init scripts are rather "legacy support". :D

SaintDanBert 07-28-2013 03:36 PM

Quote:

Originally Posted by jdackle (Post 4998098)
That was a gentle post of yours, Dan! *grin*

Are you saying that I was critical ... but nicely?
I did not intend "criticism" but clarification.
ASIDE -- I find that many technical people function at the level of "unconscious competence" -- we don't know what we know. They can look at a pile of technical details and pluck out answers. When asked, they are hard pressed to tell anyone "how did you know/do that?"

There is a similar concept called "conscious competence." In other words, we know what we know. Similarly they know the boundaries of their knowledge and carefully wander those realms. These folks make the best teachers and explainers.

In this case, the '/etc/init.d/*' reference by itself spoke volumes to me because I've spent decades in that world. I also know that the same folder tree does double duty in the world of 'upstart'. Someone new to either set of features might get confused so I wrote a clarification.
Quote:

Originally Posted by jdackle (Post 4998098)
...
When the upstart "thing" came up - or maybe just when I took notice of it (I think about the time I switched from Mandrake/Mandriva to Ubuntu) - I noticed it still used the init system, so gave it no more thought... Now I'm realising the init scripts are rather "legacy support". :D

I know that Ubuntu 08.04 used 'upstart' with a heavy reliance on legacy SystemV-init because I ran that edition. I believe that earlier Ubuntu editions also used 'upstart' to some degree.

Cordialement,
~~~ 0;-Dan

jdackle 07-29-2013 10:16 AM

Quote:

Originally Posted by SaintDanBert (Post 4998494)
Are you saying that I was critical ... but nicely?
I did not intend "criticism" but clarification.

No, I didn't think you were critical. It's just that your clarification showed me how off the mark my post was. And the way you showed me that was even nicer than a critical but gentle post. :cool:
Quote:

ASIDE -- I find that many technical people function at the level of "unconscious competence" -- we don't know what we know. They can look at a pile of technical details and pluck out answers. When asked, they are hard pressed to tell anyone "how did you know/do that?"

There is a similar concept called "conscious competence." In other words, we know what we know. Similarly they know the boundaries of their knowledge and carefully wander those realms. These folks make the best teachers and explainers.

Well, my degree is in Sociology and that aside of yurs is a good point. However, sometimes I myself just have trouble giving a quick and simple answer to how I did something relativelly complex (or which requires some previous "basic" background the receiver of my answer might or not have - in terms of human conscience and behaviour, "basic background" is a very very very variable thing). And what I just said doesn't at all invalidate the role of "unconscious competence", it's just another angle sprung off the subject. :D

Quote:

Originally Posted by SaintDanBert (Post 4998494)
I know that Ubuntu 08.04 used 'upstart' with a heavy reliance on legacy SystemV-init because I ran that edition. I believe that earlier Ubuntu editions also used 'upstart' to some degree.

Yep, 2008 was about the time I made the switch. Checks!

Quote:

Originally Posted by SaintDanBert (Post 4998494)
Cordialement,
~~~ 0;-Dan

Salutations cordiales,
Jean-D. Ackle

SaintDanBert 07-29-2013 10:38 PM

Quote:

Originally Posted by jdackle (Post 4998925)
... sometimes I myself just have trouble giving a quick and simple answer to how I did something relatively complex (or which requires some previous "basic" background the receiver of my answer might or not have - in terms of human conscience and behaviour, "basic background" is a very very very variable thing)...

Have you ever asked a yes or no question and gotten a dissertation in reply? Decades ago, I did that. My dear, good, friend and boss stopped the dissertation saying, "Answer yes or no, pause, then offer a brief sentence or two to explain why you chose your answer." Another time, he encouraged me to ask if they want or need an explanation beyond yes or no. This approach demands that you take 90 seconds to think before saying something (unless you like to shoot from the hip.)

Even complex information starts with something simple, "Can I do XYZ?"
An affirmative leads folks to the next logical steps, "How do I do XYZ?" and "How will it take?" Often, simple knowledge that a solution exists is enough to inform a person to research. All they need is the location of the first brick on the path* to the solution. ==My== next step usually takes the form of Socratic questions, "Have you tried ...?" and "Have you thought about ...?"

Cheers,
~~~ 0;-Dan

__________
* "path" -- I recently stopped saying "yellow brick road" because too few folks recognized the reference. Sigh, the grey hair is catching up with me.


All times are GMT -5. The time now is 10:46 PM.