Spawn a shell if no command is specified.

Instead of requiring the user to always specifying a command to launch,
default to spawning a shell (/bin/sh) if no command has been specified.
master
Damien Goutte-Gattat 2 months ago
parent 01362fa150
commit 25ce49ce6d
Signed by: damien
GPG Key ID: 6F7F0F91D138FC7B

@ -88,8 +88,10 @@ parseCommandLine(InhibitAction *action)
"(defaults to \"%1\").").arg(action->reason), "reason");
parser.addOption(reasonOption);
parser.addPositionalArgument("command", "The command to run",
"command...");
parser.addPositionalArgument("command",
QString("The command to run "
"(defaults to \"%1\")").arg(action->command),
"[command...]");
if ( ! parser.parse(QCoreApplication::arguments()) )
die(1, parser.errorText());
@ -107,12 +109,10 @@ parseCommandLine(InhibitAction *action)
action->reason = parser.value(reasonOption);
QStringList args = parser.positionalArguments();
if ( args.size() > 1 ) {
if ( args.size() > 0 ) {
action->command = args.at(0);
action->arguments = args.mid(1);
}
else
die(1, "No command to run");
}
int
@ -121,7 +121,8 @@ main(int argc, char **argv)
QCoreApplication app(argc, argv);
app.setApplicationName("pm-inhibit");
app.setApplicationVersion(VERSION);
InhibitAction action = { "pm-inhibit", "Per user request." };
InhibitAction action = { "pm-inhibit", "Per user request.", "/bin/sh",
QStringList() };
parseCommandLine(&action);
@ -130,6 +131,8 @@ main(int argc, char **argv)
die(1, "Cannot inhibit power management features");
QProcess process;
process.setInputChannelMode(QProcess::ForwardedInputChannel);
process.setProcessChannelMode(QProcess::ForwardedChannels);
process.start(action.command, action.arguments);
process.waitForFinished(-1);

Loading…
Cancel
Save