1
0

Implemented quiet option for cmd_spawn (closes #12)

This commit is contained in:
Patrick Gaskin
2020-05-07 15:31:26 -04:00
parent b323a54758
commit e5a3635117
2 changed files with 11 additions and 2 deletions

View File

@@ -58,6 +58,7 @@
# shutdown
# reboot
# cmd_spawn - the command line to pass to /bin/sh -c (started in /)
# It can be prefixed with "quiet:" to prevent the toast with the process PID from being displayed.
# cmd_output - the timeout in milliseconds (0 < t < 10000), a colon, then the command line to pass to /bin/sh -c (started in /)
#
# chain:<action>:<arg>

View File

@@ -347,19 +347,27 @@ NM_ACTION_(power) {
NM_ACTION_(cmd_spawn) {
#define NM_ERR_RET nullptr
char *tmp = strdup(arg);
char *cmd = tmp;
bool quiet = false;
if (!strncmp(tmp, "quiet:", 6)) {
cmd += 6;
quiet = true;
}
QProcess proc;
uint64_t pid;
bool ok = proc.startDetached(
QStringLiteral("/bin/sh"),
QStringList(std::initializer_list<QString>{
QStringLiteral("-c"),
QString::fromUtf8(arg),
QString::fromUtf8(cmd),
}),
QStringLiteral("/"),
(qint64*)(&pid)
);
free(tmp);
NM_ASSERT(ok, "could not start process");
NM_RETURN_OK(nm_action_result_toast("Successfully started process with PID %lu.", (unsigned long)(pid)));
NM_RETURN_OK(quiet ? nm_action_result_silent() : nm_action_result_toast("Successfully started process with PID %lu.", (unsigned long)(pid)));
#undef NM_ERR_RET
}