mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
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.
This commit is contained in:
parent
a237dcba17
commit
0f781a7252
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40679
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: bundle.c,v 1.37 1998/10/24 01:08:45 brian Exp $
|
||||
* $Id: bundle.c,v 1.38 1998/10/26 19:07:38 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -762,6 +762,8 @@ bundle_Create(const char *prefix, int type, const char **argv)
|
||||
|
||||
log_SetTun(bundle.unit);
|
||||
bundle.argv = argv;
|
||||
bundle.argv0 = argv[0];
|
||||
bundle.argv1 = argv[1];
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
@ -1200,6 +1202,7 @@ bundle_ShowStatus(struct cmdargs const *arg)
|
||||
int remaining;
|
||||
|
||||
prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle));
|
||||
prompt_Printf(arg->prompt, " Title: %s\n", arg->bundle->argv[0]);
|
||||
prompt_Printf(arg->prompt, " Device: %s\n", arg->bundle->dev.Name);
|
||||
prompt_Printf(arg->prompt, " Interface: %s @ %lubps\n",
|
||||
arg->bundle->iface->name, arg->bundle->ifSpeed);
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: bundle.h,v 1.16 1998/10/26 19:07:38 brian Exp $
|
||||
* $Id: bundle.h,v 1.17 1998/10/26 19:07:42 brian Exp $
|
||||
*/
|
||||
|
||||
#define PHASE_DEAD 0 /* Link is dead */
|
||||
@ -59,6 +59,8 @@ struct bundle {
|
||||
struct descriptor desc; /* really all our datalinks */
|
||||
int unit; /* The device/interface unit number */
|
||||
const char **argv; /* From main() */
|
||||
const char *argv0; /* Original */
|
||||
const char *argv1; /* Original */
|
||||
|
||||
struct {
|
||||
char Name[20]; /* The /dev/XXXX name */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $Id: ppp.8,v 1.130 1998/10/27 22:53:18 brian Exp $
|
||||
.\" $Id: ppp.8,v 1.131 1998/10/27 22:53:19 brian Exp $
|
||||
.Dd 20 September 1995
|
||||
.Os FreeBSD
|
||||
.Dt PPP 8
|
||||
@ -2389,6 +2389,10 @@ CHAP. Normally, this variable is assigned only in -direct mode. This value
|
||||
is available irrespective of whether utmp logging is enabled.
|
||||
.El
|
||||
.Pp
|
||||
These substitutions are also done by the
|
||||
.Dq set proctitle
|
||||
command.
|
||||
.Pp
|
||||
If you wish to pause
|
||||
.Nm
|
||||
while the command executes, use the
|
||||
@ -3319,6 +3323,17 @@ the maximum number of times specified by
|
||||
below. In
|
||||
.Fl background
|
||||
mode, each number is attempted at most once.
|
||||
.It set [proc]title Op Ar value
|
||||
The current process title as displayed by
|
||||
.Xr ps 1
|
||||
is changed according to
|
||||
.Ar value .
|
||||
If
|
||||
.Ar value
|
||||
is not specified, the original process title is restored. All the
|
||||
word replacements done by the shell commands (see the
|
||||
.Dq bg
|
||||
command above) are done here too.
|
||||
.It set reconnect Ar timeout ntries
|
||||
Should the line drop unexpectedly (due to loss of CD or LQR
|
||||
failure), a connection will be re-established after the given
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $Id: ppp.8,v 1.130 1998/10/27 22:53:18 brian Exp $
|
||||
.\" $Id: ppp.8,v 1.131 1998/10/27 22:53:19 brian Exp $
|
||||
.Dd 20 September 1995
|
||||
.Os FreeBSD
|
||||
.Dt PPP 8
|
||||
@ -2389,6 +2389,10 @@ CHAP. Normally, this variable is assigned only in -direct mode. This value
|
||||
is available irrespective of whether utmp logging is enabled.
|
||||
.El
|
||||
.Pp
|
||||
These substitutions are also done by the
|
||||
.Dq set proctitle
|
||||
command.
|
||||
.Pp
|
||||
If you wish to pause
|
||||
.Nm
|
||||
while the command executes, use the
|
||||
@ -3319,6 +3323,17 @@ the maximum number of times specified by
|
||||
below. In
|
||||
.Fl background
|
||||
mode, each number is attempted at most once.
|
||||
.It set [proc]title Op Ar value
|
||||
The current process title as displayed by
|
||||
.Xr ps 1
|
||||
is changed according to
|
||||
.Ar value .
|
||||
If
|
||||
.Ar value
|
||||
is not specified, the original process title is restored. All the
|
||||
word replacements done by the shell commands (see the
|
||||
.Dq bg
|
||||
command above) are done here too.
|
||||
.It set reconnect Ar timeout ntries
|
||||
Should the line drop unexpectedly (due to loss of CD or LQR
|
||||
failure), a connection will be re-established after the given
|
||||
|
Loading…
Reference in New Issue
Block a user