avoiding CTRL-ALT-DEL by mistake

P

Pedro Graca

[ 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:ctrlaltdel:/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:ctrlaltdel:/sbin/shutdown -t1 -a -r now
ca:12345:ctrlaltdel:/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(WINDOW *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_win);
switch(c) {
case KEY_LEFT:
if (highlight==1) highlight=n_choices;
else --highlight;
break;
case KEY_RIGHT:
if (highlight==n_choices) highlight=1;
else ++highlight;
break;
case 10:
choice=highlight;
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(WINDOW *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_win, A_REVERSE);
mvwprintw(menu_win, y, x, "%s", choices);
wattroff(menu_win, A_REVERSE);
} else mvwprintw(menu_win, y, x, "%s", choices);
x+=12;
}
wrefresh(menu_win);
}
#v-
 
K

Kevin Goodsell

Pedro said:
[ 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.setup, please exclude comp.lang.c from your replies. Thank
you.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top