Skip to content

Commit

Permalink
Allow easy chain of commands execution at start
Browse files Browse the repository at this point in the history
  • Loading branch information
elros34 committed Aug 23, 2018
1 parent 1094e47 commit 8769f81
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions main.cpp
Expand Up @@ -71,27 +71,18 @@ int main(int argc, char *argv[])
if(execCmd.isEmpty()) {
execCmd = settings->value("general/execCmd").toString();
}
if(execCmd.isEmpty()) {
// execute the user's default shell
passwd *pwdstruct = getpwuid(getuid());
execCmd = QString(pwdstruct->pw_shell);
execCmd.append(" --login");
}

delete settings; // don't need 'em here

QStringList execParts = execCmd.split(' ', QString::SkipEmptyParts);
if(execParts.length()==0)
exit(0);
char *ptrs[execParts.length()+1];
for(int i=0; i<execParts.length(); i++) {
ptrs[i] = new char[execParts.at(i).toLatin1().length()+1];
memcpy(ptrs[i], execParts.at(i).toLatin1().data(), execParts.at(i).toLatin1().length());
ptrs[i][execParts.at(i).toLatin1().length()] = 0;
passwd *pwdstruct = getpwuid(getuid());
char *shell = pwdstruct->pw_shell;
if (execCmd.isEmpty()) {
// execute the user's default shell
execl(shell, shell, "--login", (char*)NULL);
} else {
execl(shell, shell, "-c", qPrintable(execCmd), (char*)NULL);
}
ptrs[execParts.length()] = 0;

execvp(execParts.first().toLatin1(), ptrs);
exit(0);
}

Expand Down

0 comments on commit 8769f81

Please sign in to comment.