summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/command.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1998-10-27 22:53:22 +0000
committerbrian <brian@FreeBSD.org>1998-10-27 22:53:22 +0000
commit4e483e71e2e95ad274f3a88b0cc7cdf1d5290bc5 (patch)
tree1fee5c906f35334ee2892371474e20579f6e1608 /usr.sbin/ppp/command.c
parent2b23dbce042044ec20c571600164b14b7d6d6543 (diff)
downloadFreeBSD-src-4e483e71e2e95ad274f3a88b0cc7cdf1d5290bc5.zip
FreeBSD-src-4e483e71e2e95ad274f3a88b0cc7cdf1d5290bc5.tar.gz
Add ``set proctitle'' for changing argv[0]. All substitutions
are done in the same way as command execution. For example, ``set proctitle USER INTERFACE PROCESSID'' would be useful in a -direct profile for identifying who's connected.
Diffstat (limited to 'usr.sbin/ppp/command.c')
-rw-r--r--usr.sbin/ppp/command.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index a45ab3c..3e20df7 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.172 1998/10/26 19:07:42 brian Exp $
+ * $Id: command.c,v 1.173 1998/10/27 22:53:19 brian Exp $
*
*/
#include <sys/types.h>
@@ -134,7 +134,7 @@
#define NEG_DNS 50
const char Version[] = "2.0";
-const char VersionDate[] = "$Date: 1998/10/26 19:07:42 $";
+const char VersionDate[] = "$Date: 1998/10/27 22:53:19 $";
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
@@ -152,6 +152,7 @@ static int RunListCommand(struct cmdargs const *);
static int IfaceAddCommand(struct cmdargs const *);
static int IfaceDeleteCommand(struct cmdargs const *);
static int IfaceClearCommand(struct cmdargs const *);
+static int SetProcTitle(struct cmdargs const *);
#ifndef NOALIAS
static int AliasEnable(struct cmdargs const *);
static int AliasOption(struct cmdargs const *);
@@ -1776,6 +1777,8 @@ static struct cmdtab const SetCommands[] = {
"modem parity", "set parity [odd|even|none]"},
{"phone", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "telephone number(s)",
"set phone phone1[:phone2[...]]", (const void *)VAR_PHONE},
+ {"proctitle", "title", SetProcTitle, LOCAL_AUTH,
+ "Process title", "set proctitle [value]"},
{"reconnect", NULL, datalink_SetReconnect, LOCAL_AUTH | LOCAL_CX,
"Reconnect timeout", "set reconnect value ntries"},
{"recvpipe", NULL, SetVariable, LOCAL_AUTH,
@@ -2417,3 +2420,44 @@ IfaceClearCommand(struct cmdargs const *arg)
return 0;
}
+
+static int
+SetProcTitle(struct cmdargs const *arg)
+{
+ static char title[LINE_LEN];
+ char *argv[MAXARGS], *ptr;
+ int len, remaining, f, argc = arg->argc - arg->argn;
+
+ if (arg->argc == arg->argn) {
+ arg->bundle->argv[0] = arg->bundle->argv0;
+ arg->bundle->argv[1] = arg->bundle->argv1;
+ return 0;
+ }
+
+ if (argc >= sizeof argv / sizeof argv[0]) {
+ argc = sizeof argv / sizeof argv[0] - 1;
+ log_Printf(LogWARN, "Truncating proc title to %d args\n", argc);
+ }
+ expand(argv, argc, arg->argv + arg->argn, arg->bundle);
+
+ ptr = title;
+ remaining = sizeof title - 1;
+ for (f = 0; f < argc && remaining; f++) {
+ if (f) {
+ *ptr++ = ' ';
+ remaining--;
+ }
+ len = strlen(argv[f]);
+ if (len > remaining)
+ len = remaining;
+ memcpy(ptr, argv[f], len);
+ remaining -= len;
+ ptr += len;
+ }
+ *ptr = '\0';
+
+ arg->bundle->argv[0] = title;
+ arg->bundle->argv[1] = NULL;
+
+ return 0;
+}
OpenPOWER on IntegriCloud