summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-08-18 20:15:10 +0000
committerbrian <brian@FreeBSD.org>1997-08-18 20:15:10 +0000
commit0aabeac27664d50b8dfd12654c1b1eb7f65bdb29 (patch)
treedc18a51d61d6cea6e2441053ee7c98ae42bcc198 /usr.sbin/ppp
parent63c7a9d9e03147630260a4e5eb238fc487329917 (diff)
downloadFreeBSD-src-0aabeac27664d50b8dfd12654c1b1eb7f65bdb29.zip
FreeBSD-src-0aabeac27664d50b8dfd12654c1b1eb7f65bdb29.tar.gz
Introduce the "bg" command. It's pretty
much the same as "shell", but it's in the background.
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/command.c52
-rw-r--r--usr.sbin/ppp/ppp.834
-rw-r--r--usr.sbin/ppp/ppp.8.m434
3 files changed, 90 insertions, 30 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 223a326..21b26bc 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: command.c,v 1.67 1997/07/14 01:41:26 brian Exp $
+ * $Id: command.c,v 1.68 1997/08/17 20:45:45 brian Exp $
*
*/
#include <sys/types.h>
@@ -73,7 +73,9 @@ int randinit;
static int ShowCommand(), TerminalCommand(), QuitCommand();
static int CloseCommand(), DialCommand(), DownCommand();
static int SetCommand(), AddCommand(), DeleteCommand();
-static int ShellCommand();
+static int BgShellCommand(struct cmdtab *, int, char **);
+static int FgShellCommand(struct cmdtab *, int, char **);
+static int ShellCommand(struct cmdtab *, int, char **, int);
static int
HelpCommand(list, argc, argv, plist)
@@ -183,10 +185,21 @@ char **argv;
}
static int
-ShellCommand(cmdlist, argc, argv)
-struct cmdtab *cmdlist;
-int argc;
-char **argv;
+BgShellCommand(struct cmdtab *cmdlist, int argc, char **argv)
+{
+ if (argc == 0)
+ return -1;
+ return ShellCommand(cmdlist, argc, argv, 1);
+}
+
+static int
+FgShellCommand(struct cmdtab *cmdlist, int argc, char **argv)
+{
+ return ShellCommand(cmdlist, argc, argv, 0);
+}
+
+static int
+ShellCommand(struct cmdtab *cmdlist, int argc, char **argv, int bg)
{
const char *shell;
pid_t shpid;
@@ -210,11 +223,16 @@ char **argv;
}
#endif
- if(argc == 0 && !(mode & MODE_INTER)) {
- LogPrintf(LogWARN, "Can only start an interactive shell in"
- " interactive mode\n");
- return 1;
- }
+ if(argc == 0)
+ if (!(mode & MODE_INTER)) {
+ LogPrintf(LogWARN, "Can only start an interactive shell in"
+ " interactive mode\n");
+ return 1;
+ } else if (bg) {
+ LogPrintf(LogWARN, "Can only start an interactive shell in"
+ " the foreground mode\n");
+ return 1;
+ }
if((shell = getenv("SHELL")) == 0)
shell = _PATH_BSHELL;
@@ -266,6 +284,14 @@ char **argv;
argv[i] = strdup(IfDevName);
else if (strcasecmp(argv[i], "MYADDR") == 0)
argv[i] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
+ if (bg) {
+ pid_t p;
+ p = getpid();
+ if (daemon(1,1) == -1) {
+ LogPrintf(LogERROR, "%d: daemon: %s", p, strerror(errno));
+ exit(1);
+ }
+ }
(void)execvp(argv[0], argv);
}
else
@@ -292,6 +318,8 @@ struct cmdtab const Commands[] = {
"accept option request", "accept option .."},
{ "add", NULL, AddCommand, LOCAL_AUTH,
"add route", "add dest mask gateway"},
+ { "bg", "!bg", BgShellCommand, LOCAL_AUTH,
+ "Run a command in the background", "[!]bg command"},
{ "close", NULL, CloseCommand, LOCAL_AUTH,
"Close connection", "close"},
{ "delete", NULL, DeleteCommand, LOCAL_AUTH,
@@ -314,7 +342,7 @@ struct cmdtab const Commands[] = {
"Save settings", "save"},
{ "set", "setup", SetCommand, LOCAL_AUTH,
"Set parameters", "set[up] var value"},
- { "shell", "!", ShellCommand, LOCAL_AUTH,
+ { "shell", "!", FgShellCommand, LOCAL_AUTH,
"Run a subshell", "shell|! [sh command]"},
{ "show", NULL, ShowCommand, LOCAL_AUTH,
"Show status and statictics", "show var"},
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index 0dccd7b..b9195d3 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -1,4 +1,4 @@
-.\" $Id: ppp.8,v 1.48 1997/08/17 20:45:48 brian Exp $
+.\" $Id: ppp.8,v 1.49 1997/08/17 22:45:25 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@@ -1434,6 +1434,19 @@ is the next hop gateway to get to the given
.Dq dest
machine/network.
+.It [!]bg command
+The given command is executed in the background.
+Any of the pseudo arguments
+.Dv HISADDR ,
+.Dv INTERFACE
+and
+.Dv MYADDR
+will be replaced with the appropriate values. If you wish to pause
+.Nm
+while the command executes, use the
+.Dv shell
+command instead.
+
.It close
Close the current connection (but don't quit).
@@ -1727,19 +1740,22 @@ This command gives a summary of available set commands.
.El
.It shell|! [command]
-Execute a shell according to the value of the
-.Dv SHELL
-environment variable. If
+If
.Dq command
-is specified, it is executed without a parent shell. Note, it's possible
-to use the
+is not specified a shell is invoked according to the
+.Dv SHELL
+environment variable. Otherwise, the given command is executed.
+Any of the pseudo arguments
.Dv HISADDR ,
.Dv INTERFACE
and
.Dv MYADDR
-symbols here. Also note that if you use the ! character, you must have
-a space between it and
-.Dq command .
+will be replaced with the appropriate values. Use of the ! character
+requires a following space as with any other commands. You should note
+that this command is executed in the foreground - ppp will not continue
+running until this process has exited. Use the
+.Dv bg
+command if you wish processing to happen in the background.
.It show var
This command allows the user to examine the following:
diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4
index 0dccd7b..b9195d3 100644
--- a/usr.sbin/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp.8.m4
@@ -1,4 +1,4 @@
-.\" $Id: ppp.8,v 1.48 1997/08/17 20:45:48 brian Exp $
+.\" $Id: ppp.8,v 1.49 1997/08/17 22:45:25 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@@ -1434,6 +1434,19 @@ is the next hop gateway to get to the given
.Dq dest
machine/network.
+.It [!]bg command
+The given command is executed in the background.
+Any of the pseudo arguments
+.Dv HISADDR ,
+.Dv INTERFACE
+and
+.Dv MYADDR
+will be replaced with the appropriate values. If you wish to pause
+.Nm
+while the command executes, use the
+.Dv shell
+command instead.
+
.It close
Close the current connection (but don't quit).
@@ -1727,19 +1740,22 @@ This command gives a summary of available set commands.
.El
.It shell|! [command]
-Execute a shell according to the value of the
-.Dv SHELL
-environment variable. If
+If
.Dq command
-is specified, it is executed without a parent shell. Note, it's possible
-to use the
+is not specified a shell is invoked according to the
+.Dv SHELL
+environment variable. Otherwise, the given command is executed.
+Any of the pseudo arguments
.Dv HISADDR ,
.Dv INTERFACE
and
.Dv MYADDR
-symbols here. Also note that if you use the ! character, you must have
-a space between it and
-.Dq command .
+will be replaced with the appropriate values. Use of the ! character
+requires a following space as with any other commands. You should note
+that this command is executed in the foreground - ppp will not continue
+running until this process has exited. Use the
+.Dv bg
+command if you wish processing to happen in the background.
.It show var
This command allows the user to examine the following:
OpenPOWER on IntegriCloud