Ported over to our own private API - it's now functional under the Haiku kernel.

Improved argument parsing code - you no longer have to specify each option separately.
Improved time parsing for the "-d" option: it's now possible to add a unit to the
time value ("m" or "s"), and you don't have to add a space anymore (ie. -d5 will
work, too).
Cleaned up the source file to better match our style guide, and look better overall.

Also added a comment about the usefulness of some of the options here - I think
we should remove the alert stuff again; one requester (in Roster) is really enough
for my taste.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10234 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-11-25 18:04:08 +00:00
parent 216b269cbc
commit a5cceb23c2
+283 -219
View File
@@ -1,10 +1,9 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// //
// Copyright (c) 2002, OpenBeOS // Copyright (c) 2002, Haiku
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
// //
// This software is part of the Haiku distribution and is covered
// by the MIT license.
// //
// File: shutdown.cpp // File: shutdown.cpp
// Author: Francois Revol ([email protected]) // Author: Francois Revol ([email protected])
@@ -22,25 +21,31 @@
// tried 3 hours to find it. // tried 3 hours to find it.
// Some code from Shard's Archiver from BeBits (was BSD/MIT too :). // Some code from Shard's Archiver from BeBits (was BSD/MIT too :).
// //
// Compile with: LDFLAGS="-lbe" make
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// ToDo: I think we should remove the shutdown alert again - we already have one
// in the roster, and that should really be enough.
// Also, I don't quite see a lot of sense in the delayed shutdown, either -- axeld.
#include <syscalls.h>
#include <OS.h>
#include <Application.h> #include <Application.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Button.h> #include <Button.h>
#include <Messenger.h> #include <Messenger.h>
#include <Mime.h> #include <Mime.h>
#include <OS.h> #include <String.h>
#include <StringView.h>
#include <View.h>
#include <Window.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <String.h>
#include <StringView.h>
#include <unistd.h> #include <unistd.h>
#include <View.h> #include <ctype.h>
#include <Window.h>
// timer should be handled better (with system_time()) // timer should be handled better (with system_time())
#define PULSE_RATE 100000 #define PULSE_RATE 100000
@@ -50,118 +55,117 @@
#define B_SYSTEM_SHUTDOWN 0x12d #define B_SYSTEM_SHUTDOWN 0x12d
#define B_SYSTEM_REBOOT 0x12e #define B_SYSTEM_REBOOT 0x12e
const char *roster_sig = "application/x-vnd.Be-ROST"; static const char *kRosterSignature = "application/x-vnd.Be-ROST";
extern "C" void _kshutdown_(long arg);
#define SHUTDOWN_HALT 0
#define SHUTDOWN_REBOOT 1
// globals // globals
const char kIconBits[] = { const char kIconBits[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x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f, 0x3f, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
}; };
const char kElectronBits[] = { const char kElectronBits[] = {
0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff, 0x00, 0x25, 0x24, 0x26, 0x00, 0xff, 0xff, 0xff, 0x00, 0x25, 0x24, 0x26, 0x00, 0xff, 0xff,
0x00, 0x25, 0x21, 0x21, 0x22, 0x26, 0x00, 0xff, 0x00, 0x25, 0x21, 0x21, 0x22, 0x26, 0x00, 0xff,
0x00, 0x21, 0x3f, 0x22, 0x22, 0x25, 0x00, 0xff, 0x00, 0x21, 0x3f, 0x22, 0x22, 0x25, 0x00, 0xff,
0x00, 0x25, 0x22, 0x22, 0x24, 0x24, 0x00, 0xff, 0x00, 0x25, 0x22, 0x22, 0x24, 0x24, 0x00, 0xff,
0xff, 0x00, 0x23, 0x23, 0x25, 0x00, 0xff, 0xff, 0xff, 0x00, 0x23, 0x23, 0x25, 0x00, 0xff, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
}; };
#define EL_POS_COUNT 17 #define EL_POS_COUNT 17
static const int electron1_table[][2] = { static const int electron1_table[][2] = {
{3, 8}, {7, 8}, {12, 8}, {17, 10}, {3, 8}, {7, 8}, {12, 8}, {17, 10},
{22, 12}, {26, 16}, {28, 20}, {28, 24}, {22, 12}, {26, 16}, {28, 20}, {28, 24},
{26, 26}, {22, 27}, {18, 26}, {14, 25}, {26, 26}, {22, 27}, {18, 26}, {14, 25},
{10, 24}, {5, 22}, {3, 18}, {1, 14}, {10, 24}, {5, 22}, {3, 18}, {1, 14},
{1, 10}, {-1, -1} }; {1, 10}, {-1, -1}
};
static const int electron2_table[][2] = { static const int electron2_table[][2] = {
{23, 18}, {21, 22}, {18, 25}, {14, 27}, {23, 18}, {21, 22}, {18, 25}, {14, 27},
{10, 27}, {5, 26}, {0, 25}, {1, 18}, {10, 27}, {5, 26}, {0, 25}, {1, 18},
{4, 15}, {8, 12}, {12, 10}, {16, 8}, {4, 15}, {8, 12}, {12, 10}, {16, 8},
{20, 8}, {24, 9}, {28, 11}, {27, 13}, {20, 8}, {24, 9}, {28, 11}, {27, 13},
{25, 15}, {-1, -1} }; {25, 15}, {-1, -1}
};
unsigned long time_to_sleep = 0; // -d
int reboot = 0; // -r
class SView : public BView uint32 gTimeToSleep = 0;
{ bool gReboot = false;
class SView : public BView {
public: public:
SView(BRect frame); SView(BRect frame);
~SView(); ~SView();
void Draw(BRect updateRect); void Draw(BRect updateRect);
void Pulse(); void Pulse();
BButton *fButton; BButton *fButton;
BString *fTitleStr; BString *fTitleStr;
@@ -169,39 +173,42 @@ class SView : public BView
BBitmap *fIcon; BBitmap *fIcon;
BBitmap *fElectron; BBitmap *fElectron;
int fElectronPos; int fElectronPos;
int fPulseDivider; int fPulseDivider;
int32 fWidth; int32 fWidth;
int32 fHeight; int32 fHeight;
int32 fLeftMargin; int32 fLeftMargin;
static const int32 fTopMargin = 8;
unsigned long fTimeLeft; unsigned long fTimeLeft;
static const int32 fTopMargin = 8;
}; };
class ShutdownWindow : public BWindow class ShutdownWindow : public BWindow {
{
public: public:
ShutdownWindow(thread_id id); ShutdownWindow(thread_id id);
~ShutdownWindow(); ~ShutdownWindow();
void MessageReceived(BMessage *msg);
bool QuitRequested(); void MessageReceived(BMessage *msg);
bool QuitRequested();
private: private:
SView *fView; SView *fView;
thread_id fShutdownThread; thread_id fShutdownThread;
}; };
class ShutdownApp : public BApplication class ShutdownApp : public BApplication {
{
public: public:
ShutdownApp(thread_id id); ShutdownApp(thread_id id);
~ShutdownApp(); ~ShutdownApp();
private: private:
ShutdownWindow *fWindow; ShutdownWindow *fWindow;
}; };
SView::SView(BRect frame) SView::SView(BRect frame)
:BView(frame, "SView", B_FOLLOW_LEFT_RIGHT, B_PULSE_NEEDED | B_WILL_DRAW), :BView(frame, "SView", B_FOLLOW_LEFT_RIGHT, B_PULSE_NEEDED | B_WILL_DRAW),
fButton(NULL), fButton(NULL),
@@ -214,7 +221,7 @@ SView::SView(BRect frame)
fWidth(0), fWidth(0),
fHeight(0), fHeight(0),
fLeftMargin(B_LARGE_ICON + 8), fLeftMargin(B_LARGE_ICON + 8),
fTimeLeft(time_to_sleep) fTimeLeft(gTimeToSleep)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLowColor(ViewColor()); SetLowColor(ViewColor());
@@ -224,10 +231,11 @@ SView::SView(BRect frame)
fElectron = new BBitmap(BRect(0, 0, 7, 7), B_CMAP8); fElectron = new BBitmap(BRect(0, 0, 7, 7), B_CMAP8);
fElectron->SetBits(kElectronBits, 8*8, 0, B_CMAP8); fElectron->SetBits(kElectronBits, 8*8, 0, B_CMAP8);
fTitleStr = new BString; fTitleStr = new BString;
if (reboot) if (gReboot)
*fTitleStr << "Rebooting in " << (int32)fTimeLeft << " seconds !"; *fTitleStr << "Rebooting in " << (int32)fTimeLeft << " seconds !";
else else
*fTitleStr << "Shutting down in " << (int32)fTimeLeft << " seconds !"; *fTitleStr << "Shutting down in " << (int32)fTimeLeft << " seconds !";
fTitle = new BStringView(BRect(55, 10, 260, 35), "", fTitleStr->String()); fTitle = new BStringView(BRect(55, 10, 260, 35), "", fTitleStr->String());
fButton = new BButton(BRect(159, 42, 259, 66), "quit", "Cancel", new BMessage('_QRQ')); fButton = new BButton(BRect(159, 42, 259, 66), "quit", "Cancel", new BMessage('_QRQ'));
fButton->MakeDefault(true); fButton->MakeDefault(true);
@@ -235,18 +243,15 @@ SView::SView(BRect frame)
AddChild(fButton); AddChild(fButton);
} }
SView::~SView() SView::~SView()
{ {
if (fButton != NULL) delete fButton;
delete fButton; delete fTitle;
delete fIcon;
if (fTitle != NULL)
delete fTitle;
if (fIcon != NULL)
delete fIcon;
} }
void void
SView::Pulse() SView::Pulse()
{ {
@@ -255,7 +260,7 @@ SView::Pulse()
fPulseDivider = PULSE_MODULO; fPulseDivider = PULSE_MODULO;
fTimeLeft--; fTimeLeft--;
fTitleStr->SetTo(""); fTitleStr->SetTo("");
if (reboot) if (gReboot)
*fTitleStr << "Rebooting in " << (int32)fTimeLeft << " seconds !"; *fTitleStr << "Rebooting in " << (int32)fTimeLeft << " seconds !";
else else
*fTitleStr << "Shutting down in " << (int32)fTimeLeft << " seconds !"; *fTitleStr << "Shutting down in " << (int32)fTimeLeft << " seconds !";
@@ -266,6 +271,7 @@ SView::Pulse()
Invalidate(); Invalidate();
} }
void void
SView::Draw(BRect updateRect) SView::Draw(BRect updateRect)
{ {
@@ -275,23 +281,24 @@ SView::Draw(BRect updateRect)
// SetHighColor(tint_color(ViewColor(), B_HIGHLIGHT_BACKGROUND_TINT)); // SetHighColor(tint_color(ViewColor(), B_HIGHLIGHT_BACKGROUND_TINT));
SetHighColor(0xB8, 0xB8, 0xB8); // same color as the registrar shutdown dialog SetHighColor(0xB8, 0xB8, 0xB8); // same color as the registrar shutdown dialog
FillRect(BRect(0, 0, B_LARGE_ICON, bounds.bottom)); FillRect(BRect(0, 0, B_LARGE_ICON, bounds.bottom));
if(fIcon != NULL) if (fIcon != NULL)
{
DrawBitmap(fIcon, BPoint((B_LARGE_ICON / 2), fTopMargin)); DrawBitmap(fIcon, BPoint((B_LARGE_ICON / 2), fTopMargin));
}
if(fIcon != NULL) if (fIcon != NULL) {
{
DrawBitmap(fElectron, BPoint((B_LARGE_ICON / 2) + electron1_table[fElectronPos][0], fTopMargin + electron1_table[fElectronPos][1])); DrawBitmap(fElectron, BPoint((B_LARGE_ICON / 2) + electron1_table[fElectronPos][0], fTopMargin + electron1_table[fElectronPos][1]));
DrawBitmap(fElectron, BPoint((B_LARGE_ICON / 2) + electron2_table[fElectronPos][0], fTopMargin + electron2_table[fElectronPos][1])); DrawBitmap(fElectron, BPoint((B_LARGE_ICON / 2) + electron2_table[fElectronPos][0], fTopMargin + electron2_table[fElectronPos][1]));
} }
if (Window()) if (Window())
Window()->Flush(); Window()->Flush();
} }
ShutdownWindow::ShutdownWindow(thread_id id) ShutdownWindow::ShutdownWindow(thread_id id)
:BWindow(BRect( 139, 81, 407, 156), "Shutdown Status", B_TITLED_WINDOW_LOOK, : BWindow(BRect( 139, 81, 407, 156), "Shutdown Status", B_TITLED_WINDOW_LOOK,
B_NORMAL_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS), B_NORMAL_WINDOW_FEEL,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS),
fView(NULL) fView(NULL)
{ {
fShutdownThread = id; fShutdownThread = id;
@@ -300,6 +307,7 @@ ShutdownWindow::ShutdownWindow(thread_id id)
AddChild(fView); AddChild(fView);
} }
ShutdownWindow::~ShutdownWindow() ShutdownWindow::~ShutdownWindow()
{ {
fView->LockLooper(); fView->LockLooper();
@@ -307,17 +315,18 @@ ShutdownWindow::~ShutdownWindow()
delete fView; delete fView;
} }
void void
ShutdownWindow::MessageReceived(BMessage *msg) ShutdownWindow::MessageReceived(BMessage *msg)
{ {
switch(msg->what) switch (msg->what) {
{
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
} }
} }
bool bool
ShutdownWindow::QuitRequested() ShutdownWindow::QuitRequested()
{ {
@@ -326,19 +335,23 @@ ShutdownWindow::QuitRequested()
return true; return true;
} }
ShutdownApp::ShutdownApp(thread_id id) ShutdownApp::ShutdownApp(thread_id id)
:BApplication("application/x-vnd.ShutDown-app") : BApplication("application/x-vnd.ShutDown-app")
{ {
fWindow = new ShutdownWindow(id); fWindow = new ShutdownWindow(id);
fWindow->SetWorkspaces(0xFFFFFFFF); fWindow->SetWorkspaces(0xFFFFFFFF);
fWindow->Show(); fWindow->Show();
} }
ShutdownApp::~ShutdownApp() ShutdownApp::~ShutdownApp()
{ {
} }
int32 app_thread(void *arg)
int32
app_thread(void *arg)
{ {
thread_id tid = (thread_id) arg; thread_id tid = (thread_id) arg;
(new ShutdownApp(tid))->Run(); (new ShutdownApp(tid))->Run();
@@ -346,116 +359,167 @@ int32 app_thread(void *arg)
return B_OK; return B_OK;
} }
/***************************/
// #pragma mark -
// we get here when shutdown is cancelled. // we get here when shutdown is cancelled.
// then sleep() returns // then sleep() returns
void handle_usr1(int sig)
void
handle_usr1(int sig)
{ {
while (0); while (0);
} }
int main(int argc, char **argv)
bool
parseTime(char *arg, char *argv, int32 *_i)
{ {
int i; char *unit;
int quick = 0; // -q
int alert = 0; // -a
BMessenger msgr(roster_sig);
for (i = 1; i < argc; i++) { if (isdigit(arg[0])) {
if (!strcmp(argv[i], "-q")) gTimeToSleep = strtoul(arg, &unit, 10);
quick = 1; } else if (argv && isdigit(argv[0])) {
else if (!strcmp(argv[i], "-r")) (*_i)++;
reboot = 1; gTimeToSleep = strtoul(argv, &unit, 10);
else if (!strcmp(argv[i], "-c")) { } else
team_info ti; return false;
thread_info thi;
int32 team_cookie = 0;
int32 thread_cookie = 0;
team_id myteam;
get_thread_info(find_thread(NULL), &thi); if (unit[0] == '\0' || !strcmp(unit, "s"))
myteam = thi.team; return true;
while (get_next_team_info(&team_cookie, &ti) == B_OK) { if (!strcmp(unit, "m")) {
if (strstr(ti.args, "shutdown") != NULL && (ti.team != myteam)) { gTimeToSleep *= 60;
thread_cookie = 0; return true;
while (get_next_thread_info(ti.team, &thread_cookie, &thi) == B_OK) {
if (!strcmp(thi.name, "shutdown")) {
kill(thi.thread, SIGUSR1);
}
}
}
}
exit (0);
} else if (!strcmp(argv[i], "-a")) {
alert = 1;
} else if (!strcmp(argv[i], "-d") && (i+1 < argc)) {
i++;
time_to_sleep = strtol(argv[i], &argv[i], 10);
} else {
fprintf(stderr,
"usage: %s [-r] [-q] [-c] [-a] [-d time]
-r reboot,
-q quick shutdown (don't broadcast apps),
-c cancel a running shutdown,
-a alerts user while waiting,
-d delay shutdown by <time> seconds.
", argv[0]);
exit (1);
}
} }
if (time_to_sleep > 0) { return false;
unsigned int left; }
thread_id BApp_thread = -1;
void
usage(const char *arg0)
{
const char *program = strrchr(arg0, '/');
if (program == NULL)
program = arg0;
else
program++;
fprintf(stderr, "usage: %s [-rqca] [-d time]\n"
"\t-r reboot,\n"
"\t-q quick shutdown (don't broadcast apps),\n"
"\t-c cancel a running shutdown,\n"
"\t-a alerts user while waiting,\n"
"\t-d delay shutdown by <time> seconds.\n", program);
exit(1);
}
int
main(int argc, char **argv)
{
bool quick = false;
bool alert = false;
for (int32 i = 1; i < argc; i++) {
char *arg = argv[i];
if (arg[0] == '-') {
if (!isalpha(arg[1]))
usage(argv[0]);
while (arg && isalpha((++arg)[0])) {
switch (arg[0]) {
case 'q':
quick = true;
break;
case 'r':
gReboot = true;
break;
case 'c':
{
// find all running shutdown command and signal its shutdown thread
thread_info threadInfo;
get_thread_info(find_thread(NULL), &threadInfo);
team_id thisTeam = threadInfo.team;
int32 team_cookie = 0;
team_info teamInfo;
while (get_next_team_info(&team_cookie, &teamInfo) == B_OK) {
if (strstr(teamInfo.args, "shutdown") != NULL && teamInfo.team != thisTeam) {
int32 thread_cookie = 0;
while (get_next_thread_info(teamInfo.team, &thread_cookie, &threadInfo) == B_OK) {
if (!strcmp(threadInfo.name, "shutdown"))
kill(threadInfo.thread, SIGUSR1);
}
}
}
exit(0);
break;
}
case 'a':
alert = true;
break;
case 'd':
if (parseTime(arg + 1, argv[i + 1], &i)) {
arg = NULL;
break;
}
// supposed to fall through
default:
usage(argv[0]);
}
}
} else
usage(argv[0]);
}
if (gTimeToSleep > 0) {
thread_id appThread = -1;
int32 left;
signal(SIGUSR1, handle_usr1); signal(SIGUSR1, handle_usr1);
if (alert) { if (alert) {
// BApplication::Run() blocks // BApplication::Run() blocks
BApp_thread = spawn_thread(app_thread, "BApplication", B_NORMAL_PRIORITY, (void *)find_thread(NULL)); appThread = spawn_thread(app_thread, "ShutdownApp", B_NORMAL_PRIORITY, (void *)find_thread(NULL));
resume_thread(BApp_thread); resume_thread(appThread);
} } else
printf("Delaying %s by %lu seconds...\n", gReboot ? "reboot" : "shutdown", gTimeToSleep);
left = sleep(gTimeToSleep);
left = sleep((unsigned int)time_to_sleep);
if (alert) { if (alert) {
status_t err;
// be_app->LockLooper();
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
// be_app->UnlockLooper();
status_t err;
wait_for_thread(BApp_thread, &err); wait_for_thread(appThread, &err);
snooze(100000); snooze(100000);
} }
if (left > 0) { if (left > 0) {
fprintf(stderr, "Shutdown cancelled.\n"); fprintf(stderr, "Shutdown cancelled.\n");
exit (0); exit(0);
} }
} }
if (quick) { if (quick) {
if (reboot) _kern_shutdown(gReboot);
_kshutdown_(SHUTDOWN_REBOOT);
else
_kshutdown_(SHUTDOWN_HALT);
fprintf(stderr, "Shutdown failed!\n"); fprintf(stderr, "Shutdown failed!\n");
return 2; return 2;
} else { } else {
status_t err = 1; BMessenger messenger(kRosterSignature);
if (reboot) status_t err = messenger.SendMessage(gReboot ? B_SYSTEM_REBOOT : B_SYSTEM_SHUTDOWN);
err = msgr.SendMessage(B_SYSTEM_REBOOT);
else
err = msgr.SendMessage(B_SYSTEM_SHUTDOWN);
if (err != B_OK) { if (err != B_OK) {
fprintf(stderr, "Failed to send message to roster server: %s\n", strerror(err)); fprintf(stderr, "Failed to send message to roster server: %s\n", strerror(err));
exit (2); exit(2);
} }
} }
return 0; return 0;
} }