mirror of
https://github.com/akuker/RASCSI.git
synced 2024-09-27 15:57:52 +00:00
Issue 319, detach all devices on SIGKILL/SIGTERM (#328)
* Removed size validation for MOs * rasctl -D detaches all devices * Detach all devices on Ctrl-C (KILL signal) * Added comment * Also detach all devices on SIGTERM
This commit is contained in:
parent
2cc9efc1a0
commit
84f40c7fe9
20
doc/rasctl.1
20
doc/rasctl.1
@ -8,26 +8,27 @@ rasctl \- Sends management commands to the rascsi process
|
|||||||
\fB\-m\fR |
|
\fB\-m\fR |
|
||||||
\fB\-s\fR |
|
\fB\-s\fR |
|
||||||
\fB\-v\fR |
|
\fB\-v\fR |
|
||||||
|
\fB\-D\fR |
|
||||||
\fB\-I\fR |
|
\fB\-I\fR |
|
||||||
\fB\-L\fR |
|
\fB\-L\fR |
|
||||||
\fB\-O\fR |
|
\fB\-O\fR |
|
||||||
\fB\-T\fR |
|
\fB\-T\fR |
|
||||||
\fB\-V\fR |
|
\fB\-V\fR |
|
||||||
|
[\fB\-C\fR \fIFILENAME:FILESIZE\fR]
|
||||||
[\fB\-E\fR \fIFILENAME\fR]
|
[\fB\-E\fR \fIFILENAME\fR]
|
||||||
[\fB\-F\fR \fIIMAGE_FOLDER\fR]
|
[\fB\-F\fR \fIIMAGE_FOLDER\fR]
|
||||||
[\fB\-C\fR \fIFILENAME:FILESIZE\fR]
|
|
||||||
[\fB\-x\fR \fICURRENT_NAME:NEW_NAME\fR]
|
|
||||||
[\fB\-R\fR \fICURRENT_NAME:NEW_NAME\fR]
|
[\fB\-R\fR \fICURRENT_NAME:NEW_NAME\fR]
|
||||||
[\fB\-g\fR \fILOG_LEVEL\fR]
|
|
||||||
[\fB\-h\fR \fIHOST\fR]
|
|
||||||
[\fB\-p\fR \fIPORT\fR]
|
|
||||||
[\fB\-r\fR \fIRESERVED_IDS\fR]
|
|
||||||
[\fB\-i\fR \fIID\fR
|
|
||||||
[\fB\-c\fR \fICMD\fR]
|
[\fB\-c\fR \fICMD\fR]
|
||||||
[\fB\-f\fR \fIFILE|PARAM\fR]
|
[\fB\-f\fR \fIFILE|PARAM\fR]
|
||||||
|
[\fB\-g\fR \fILOG_LEVEL\fR]
|
||||||
|
[\fB\-h\fR \fIHOST\fR]
|
||||||
|
[\fB\-i\fR \fIID\fR
|
||||||
[\fB\-n\fR \fINAME\fR]
|
[\fB\-n\fR \fINAME\fR]
|
||||||
|
[\fB\-p\fR \fIPORT\fR]
|
||||||
|
[\fB\-r\fR \fIRESERVED_IDS\fR]
|
||||||
[\fB\-t\fR \fITYPE\fR]
|
[\fB\-t\fR \fITYPE\fR]
|
||||||
[\fB\-u\fR \fIUNIT\fR]
|
[\fB\-u\fR \fIUNIT\fR]
|
||||||
|
[\fB\-x\fR \fICURRENT_NAME:NEW_NAME\fR]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B rasctl
|
.B rasctl
|
||||||
Sends commands to the rascsi process to make configuration adjustments at runtime or to check the status of the devices.
|
Sends commands to the rascsi process to make configuration adjustments at runtime or to check the status of the devices.
|
||||||
@ -43,6 +44,9 @@ Note: The command and type arguments are case insensitive. Only the first letter
|
|||||||
.BR \-C\fI " "\fIFILENAME:FILESIZE
|
.BR \-C\fI " "\fIFILENAME:FILESIZE
|
||||||
Create an image file in the default image folder with the specified name and size in bytes.
|
Create an image file in the default image folder with the specified name and size in bytes.
|
||||||
.TP
|
.TP
|
||||||
|
.BR \-D\fI
|
||||||
|
Detach all devices.
|
||||||
|
.TP
|
||||||
.BR \-E\fI " " \fIFILENAME
|
.BR \-E\fI " " \fIFILENAME
|
||||||
Display information on an image file.
|
Display information on an image file.
|
||||||
.TP
|
.TP
|
||||||
@ -94,7 +98,7 @@ Display the rascsi server version.
|
|||||||
.BR \-V\fI " " \fI
|
.BR \-V\fI " " \fI
|
||||||
Display the rasctl version.
|
Display the rasctl version.
|
||||||
.TP
|
.TP
|
||||||
.BR \-D\fI " "\fIFILENAME
|
.BR \-d\fI " "\fIFILENAME
|
||||||
Delete an image file in the default image folder.
|
Delete an image file in the default image folder.
|
||||||
.TP
|
.TP
|
||||||
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
|
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
|
||||||
|
@ -6,11 +6,11 @@ NAME
|
|||||||
rasctl - Sends management commands to the rascsi process
|
rasctl - Sends management commands to the rascsi process
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
rasctl -e | -l | -m | -s | -v | -I | -L | -O | -T | -V | [-E FILENAME]
|
rasctl -e | -l | -m | -s | -v | -D | -I | -L | -O | -T | -V | [-C FILE‐
|
||||||
[-F IMAGE_FOLDER] [-C FILENAME:FILESIZE] [-x CURRENT_NAME:NEW_NAME] [-R
|
NAME:FILESIZE] [-E FILENAME] [-F IMAGE_FOLDER] [-R CUR‐
|
||||||
CURRENT_NAME:NEW_NAME] [-g LOG_LEVEL] [-h HOST] [-p PORT] [-r RE‐
|
RENT_NAME:NEW_NAME] [-c CMD] [-f FILE|PARAM] [-g LOG_LEVEL] [-h HOST]
|
||||||
SERVED_IDS] [-i ID [-c CMD] [-f FILE|PARAM] [-n NAME] [-t TYPE] [-u
|
[-i ID [-n NAME] [-p PORT] [-r RESERVED_IDS] [-t TYPE] [-u UNIT] [-x
|
||||||
UNIT]
|
CURRENT_NAME:NEW_NAME]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
rasctl Sends commands to the rascsi process to make configuration ad‐
|
rasctl Sends commands to the rascsi process to make configuration ad‐
|
||||||
@ -28,6 +28,8 @@ OPTIONS
|
|||||||
Create an image file in the default image folder with the speci‐
|
Create an image file in the default image folder with the speci‐
|
||||||
fied name and size in bytes.
|
fied name and size in bytes.
|
||||||
|
|
||||||
|
-D Detach all devices.
|
||||||
|
|
||||||
-E FILENAME
|
-E FILENAME
|
||||||
Display information on an image file.
|
Display information on an image file.
|
||||||
|
|
||||||
@ -75,7 +77,7 @@ OPTIONS
|
|||||||
|
|
||||||
-V Display the rasctl version.
|
-V Display the rasctl version.
|
||||||
|
|
||||||
-D FILENAME
|
-d FILENAME
|
||||||
Delete an image file in the default image folder.
|
Delete an image file in the default image folder.
|
||||||
|
|
||||||
-x CURRENT_NAME:NEW_NAME
|
-x CURRENT_NAME:NEW_NAME
|
||||||
|
@ -63,12 +63,8 @@ void SCSIMO::Open(const Filepath& path)
|
|||||||
SetBlockCount(size >> GetSectorSizeShiftCount());
|
SetBlockCount(size >> GetSectorSizeShiftCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
// File size must be a multiple of the sector size
|
// Effective size must be a multiple of the sector size
|
||||||
if (size % GetSectorSizeInBytes()) {
|
size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes();
|
||||||
stringstream error;
|
|
||||||
error << "File size must be a multiple of " << GetSectorSizeInBytes() << " bytes but is " << size << " bytes";
|
|
||||||
throw io_exception(error.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
SetReadOnly(false);
|
SetReadOnly(false);
|
||||||
SetProtectable(true);
|
SetProtectable(true);
|
||||||
|
@ -1771,6 +1771,13 @@ static void *MonThread(void *param)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerminationHandler(int signum)
|
||||||
|
{
|
||||||
|
DetachAll();
|
||||||
|
|
||||||
|
exit(signum);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Main processing
|
// Main processing
|
||||||
@ -1833,6 +1840,14 @@ int main(int argc, char* argv[])
|
|||||||
return EPERM;
|
return EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Signal handler to detach all devices on a KILL or TERM signal
|
||||||
|
struct sigaction termination_handler;
|
||||||
|
termination_handler.sa_handler = TerminationHandler;
|
||||||
|
sigemptyset(&termination_handler.sa_mask);
|
||||||
|
termination_handler.sa_flags = 0;
|
||||||
|
sigaction(SIGINT, &termination_handler, NULL);
|
||||||
|
sigaction(SIGTERM, &termination_handler, NULL);
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ int main(int argc, char* argv[])
|
|||||||
cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl;
|
cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl;
|
||||||
cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-C FILE] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] ";
|
cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-C FILE] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] ";
|
||||||
cerr << "[-F IMAGE_FOLDER] [-L LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] ";
|
cerr << "[-F IMAGE_FOLDER] [-L LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] ";
|
||||||
cerr << "[-C FILENAME:FILESIZE] [-w FILENAME] [-R CURRENT_NAME:NEW_NAME] [-x CURRENT_NAME:NEW_NAME] ";
|
cerr << "[-C FILENAME:FILESIZE] [-d FILENAME] [-w FILENAME] [-R CURRENT_NAME:NEW_NAME] [-x CURRENT_NAME:NEW_NAME] ";
|
||||||
cerr << "[-e] [-E FILENAME] [-I] [-l] [-L] [-m] [-O] [-s] [-v] [-V] [-y]" << endl;
|
cerr << "[-e] [-E FILENAME] [-D] [-I] [-l] [-L] [-m] [-O] [-s] [-v] [-V] [-y]" << endl;
|
||||||
cerr << " where ID := {0-7}" << endl;
|
cerr << " where ID := {0-7}" << endl;
|
||||||
cerr << " UNIT := {0-31}, default is 0" << endl;
|
cerr << " UNIT := {0-31}, default is 0" << endl;
|
||||||
cerr << " CMD := {attach|detach|insert|eject|protect|unprotect|show}" << endl;
|
cerr << " CMD := {attach|detach|insert|eject|protect|unprotect|show}" << endl;
|
||||||
@ -135,7 +135,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "elmsvINOTVa:b:c:f:h:i:n:p:r:t:u:x:C:D:E:F:L:R:")) != -1) {
|
while ((opt = getopt(argc, argv, "elmsvDINOTVa:b:c:d:f:h:i:n:p:r:t:u:x:C:E:F:L:R:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'i': {
|
case 'i': {
|
||||||
int id;
|
int id;
|
||||||
@ -179,6 +179,15 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'D':
|
||||||
|
command.set_operation(DETACH_ALL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
command.set_operation(DELETE_IMAGE);
|
||||||
|
image_params = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'E':
|
case 'E':
|
||||||
command.set_operation(IMAGE_FILE_INFO);
|
command.set_operation(IMAGE_FILE_INFO);
|
||||||
filename = optarg;
|
filename = optarg;
|
||||||
@ -301,11 +310,6 @@ int main(int argc, char* argv[])
|
|||||||
case 'T':
|
case 'T':
|
||||||
command.set_operation(DEVICE_TYPES_INFO);
|
command.set_operation(DEVICE_TYPES_INFO);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
|
||||||
command.set_operation(DELETE_IMAGE);
|
|
||||||
image_params = optarg;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user