473,763 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

avoiding CTRL-ALT-DEL by mistake

[ please answer in and set followup to "comp.os.linux. setup" ]

Well ... I've been using Windows for a long time before I switched to
Linux. I'm very used to type CTRL-ALT-DEL everytime I'm leaving my
computer or arriving to it. It's hapenned _twice_ (in the last six
months or so) for my Linux box.

I want to be able to reboot my machine with CTRL-ALT-DEL, but I don't
want to do it by mistake.

So, I noticed /etc/inittab has these lines

# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlal tdel:/sbin/shutdown -t1 -a -r now

and thought I'd change them to call another program. Looked around for
something that would allow me to choose what to do; couldn't find one,
so I did my own.
[ source at the bottom ]

Now /etc/inittab reads
# What to do when CTRL-ALT-DEL is pressed.
#ca:12345:ctrla ltdel:/sbin/shutdown -t1 -a -r now
ca:12345:ctrlal tdel:/sbin/my_shutdown

Before I test it (I really don't want to)
any thoughts? other ideas? advice?
[ comments to the code please post in and set followup to "comp.lang. c" ]

I'm very new to C, this is basically a copy of an example at
http://en.tldp.org/HOWTO/NCURSES-Programming-HOWTO/
#v+
#include <curses.h>
#include <unistd.h>

#define WIDTH 50
#define HEIGHT 6

int startx=0;
int starty=0;
char *choices[]={" Shutdown ", " Reboot ", " Cancel "};
int n_choices = sizeof(choices) / sizeof(char *);

void print_menu(WIND OW *menu_win, int highlight);

int main(void) {
WINDOW *menu_win;
int highlight=3;
int choice=0;
int c;

initscr();
clear();
noecho();
cbreak();
startx=(80 - WIDTH)/2;
starty=(24 - HEIGHT)/2;

menu_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(menu_win , TRUE);
print_menu(menu _win, highlight);
while(1) {
c=wgetch(menu_w in);
switch(c) {
case KEY_LEFT:
if (highlight==1) highlight=n_cho ices;
else --highlight;
break;
case KEY_RIGHT:
if (highlight==n_c hoices) highlight=1;
else ++highlight;
break;
case 10:
choice=highligh t;
break;
default:
refresh();
break;
}
print_menu(menu _win, highlight);
if (choice != 0) break; // exit the infinite loop
}
refresh();
endwin();
switch (choice) {
case 1: execl("/sbin/shutdown", "/sbin/shutdown", "-t1", "-a", "-h now", NULL); break;
case 2: execl("/sbin/shutdown", "/sbin/shutdown", "-t1", "-a", "-r now", NULL); break;
case 3: break;
}
return 0;
}

void print_menu(WIND OW *menu_win, int highlight) {
int x, y, i;

x = 2;
y = 4;
box(menu_win, 0, 0);
mvwprintw(menu_ win, 1, 1, "You pressed Ctrl+Alt+Del. What did you mean?");
for (i=0; i<n_choices; ++i) {
if (highlight == i+1) { // highlight the present choice
wattron(menu_wi n, A_REVERSE);
mvwprintw(menu_ win, y, x, "%s", choices[i]);
wattroff(menu_w in, A_REVERSE);
} else mvwprintw(menu_ win, y, x, "%s", choices[i]);
x+=12;
}
wrefresh(menu_w in);
}
#v-
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Nov 14 '05 #1
1 2637
Pedro Graca wrote:
[ please answer in and set followup to "comp.os.linux. setup" ]


Why did you even post this in comp.lang.c? Your question is not about
the C language, and your code uses practically no standard C, making
this whole thing way off topic in comp.lang.c.

comp.os.linux.s etup, please exclude comp.lang.c from your replies. Thank
you.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
14000
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to this socket just like you would enter things on the keyboard if you telneted to this server). In a normal telnet session you can enter some commands which take a long time to complete, and they run in the background and you get the command line...
10
23546
by: chirs | last post by:
I have a code to disable ctrl-v (paste) on the 2nd box. The problem is that when I type ctrl-v, the text shows, then disappear after I release ctrl-v. How can I make it not to show in the box. In VB, I can set keyascii=0 to kill the input. Is there a similar way to do it in JavaScript? Thanks a lot. <HTML><head></head><body> <form name="myForm"> Password: <input type="text"><br> Comfirm: <input type="text" name="myText"
13
9458
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to intercept the key so that I can do stuff on the server side to make the new window behave correctly? (We have a JSP-based webapp which stores state in the session. Now if two windows access (and modify!) the same session, then madness will result....
3
4973
by: Greg | last post by:
I want to be able to capture the user pressing Ctrl+S. I know that the IE browser has a key binding for Ctrl+S but is there any way that I can be notified of this key press anyway. I have found tons of examples of capturing keys in IE but *none* of them work for capturing Ctrl+S, Ctrl+F, Ctrl+P,etc or any key combination that has a binding in IE. Does anyone know how to do this?
12
13747
by: Wurm | last post by:
Hi all, Got a little problem with a lib that I'm working on. First of all, the problem is that the lib that I have makes connections to DirectSound, and has a host of custom built sound related functions. Now, in the lib is a 'destroy' function which when called will release all instances of DirectSound that I have created and if that is used, then great, no problem. The application that uses this lib is a console application running on...
3
7123
by: Glen Hong | last post by:
I have set up a hotkey using RegisterHotKey API function for Ctrl-Tab. Firstly, I can rap this when Ctrl-Tab is pressed however if I want to add an addition hotkey how can I distinguish between which hotkey was pressed? Secondly I am trying to replicate the Ctrl-Tab functionality you have in the DotNet IDE when you hold down the Ctrl key and then additional use the tab key you can cycle thru the MDI Children. I would like to gain the...
2
2878
by: crjunk | last post by:
I'm trying to write a piece of code that will programatically save a record automatically without me having to add a new ' Row.Item("ADD1") = txtAdd1.Text.Trim.ToUpper ' type command each time I add a new textbox. I've named all my textboxes in the following format txtAdd1 and I've named all my field in the SQL table the same way minus the txt at the beginning. This code scans the form for textboxes. If it finds a text box that is not...
2
8648
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some other subprocess modules) and how can i pass Ctrl-C to this program to terminate it in python? thanks
11
2259
by: Bookham Measures | last post by:
Hello As above, my Ctrl + Spacebar for intellisense is not working in VI 6.0. I have checked keyboard assignments and Ctrl + Space is listed for Edit -> CompleteWord. I added Ctrl + Shift + Space and that does work, but Ctrl + Space does not. I removed Ctrl + Space thinking re-adding it might help, but now the
21
7215
by: Zytan | last post by:
Instead of Ctrl+Y redoing what's stored in 'future history', it REPLACES that information (which will then be forever lost) with a new command: delete current line. This shortcut is so ridiculous I actually contemplated that I must have accidentally changed it to this myself, but I don't see how that could have possibly happened. Where can I / should I report this? It doesn't exist in Visual C# .NET, so it's not generic to VS .NET.
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.