Fix ``set proctitle'' by using setproctitle().
This commit is contained in:
parent
0675e24de0
commit
cf0a39401d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53298
@ -39,6 +39,11 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef __OpenBSD__
|
||||
#include <util.h>
|
||||
#else
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -603,7 +608,7 @@ bundle_UnlockTun(struct bundle *bundle)
|
||||
}
|
||||
|
||||
struct bundle *
|
||||
bundle_Create(const char *prefix, int type, int unit, const char **argv)
|
||||
bundle_Create(const char *prefix, int type, int unit)
|
||||
{
|
||||
static struct bundle bundle; /* there can be only one */
|
||||
int enoentcount, err, minunit, maxunit;
|
||||
@ -673,9 +678,6 @@ bundle_Create(const char *prefix, int type, int unit, const char **argv)
|
||||
}
|
||||
|
||||
log_SetTun(bundle.unit);
|
||||
bundle.argv = argv;
|
||||
bundle.argv0 = argv[0];
|
||||
bundle.argv1 = argv[1];
|
||||
|
||||
ifname = strrchr(bundle.dev.Name, '/');
|
||||
if (ifname == NULL)
|
||||
@ -1097,7 +1099,6 @@ 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",
|
||||
arg->bundle->iface->name, arg->bundle->bandwidth);
|
||||
@ -1660,8 +1661,7 @@ bundle_setsid(struct bundle *bundle, int holdsession)
|
||||
*/
|
||||
waitpid(pid, &status, 0);
|
||||
/* Tweak our process arguments.... */
|
||||
bundle->argv[0] = "session owner";
|
||||
bundle->argv[1] = NULL;
|
||||
ID0setproctitle("session owner");
|
||||
/*
|
||||
* Hang around for a HUP. This should happen as soon as the
|
||||
* ppp that we passed our ctty descriptor to closes it.
|
||||
|
@ -63,9 +63,6 @@ struct iface;
|
||||
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 */
|
||||
@ -142,7 +139,7 @@ struct bundle {
|
||||
#define descriptor2bundle(d) \
|
||||
((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
|
||||
|
||||
extern struct bundle *bundle_Create(const char *, int, int, const char **);
|
||||
extern struct bundle *bundle_Create(const char *, int, int);
|
||||
extern void bundle_Destroy(struct bundle *);
|
||||
extern const char *bundle_PhaseName(struct bundle *);
|
||||
#define bundle_Phase(b) ((b)->phase)
|
||||
|
@ -33,6 +33,11 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef __OpenBSD__
|
||||
#include <util.h>
|
||||
#else
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -87,6 +92,7 @@
|
||||
#include "cbcp.h"
|
||||
#include "datalink.h"
|
||||
#include "iface.h"
|
||||
#include "id.h"
|
||||
|
||||
/* ``set'' values */
|
||||
#define VAR_AUTHKEY 0
|
||||
@ -2609,8 +2615,7 @@ SetProcTitle(struct cmdargs const *arg)
|
||||
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;
|
||||
ID0setproctitle(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2636,8 +2641,7 @@ SetProcTitle(struct cmdargs const *arg)
|
||||
}
|
||||
*ptr = '\0';
|
||||
|
||||
arg->bundle->argv[0] = title;
|
||||
arg->bundle->argv[1] = NULL;
|
||||
ID0setproctitle(title);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -269,6 +269,20 @@ ID0kill(pid_t pid, int sig)
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
ID0setproctitle(const char *title)
|
||||
{
|
||||
ID0set0();
|
||||
if (title == NULL) {
|
||||
setproctitle(NULL);
|
||||
log_Printf(LogID0, "setproctitle(NULL)\n");
|
||||
} else {
|
||||
setproctitle("%s", title);
|
||||
log_Printf(LogID0, "setproctitle(\"%%s\", \"%s\")\n", title);
|
||||
}
|
||||
ID0setuser();
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
int
|
||||
ID0kldload(const char *dev)
|
||||
|
@ -45,6 +45,7 @@ extern void ID0logout(const char *, int);
|
||||
extern int ID0bind_un(int, const struct sockaddr_un *);
|
||||
extern int ID0connect_un(int, const struct sockaddr_un *);
|
||||
extern int ID0kill(pid_t, int);
|
||||
extern void ID0setproctitle(const char *);
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
extern int ID0kldload(const char *);
|
||||
#endif
|
||||
|
@ -367,8 +367,7 @@ main(int argc, char **argv)
|
||||
if (!sw.quiet)
|
||||
prompt_Printf(prompt, "Working in %s mode\n", mode2Nam(sw.mode));
|
||||
|
||||
if ((bundle = bundle_Create(TUN_PREFIX, sw.mode, sw.unit,
|
||||
(const char **)argv)) == NULL)
|
||||
if ((bundle = bundle_Create(TUN_PREFIX, sw.mode, sw.unit)) == NULL)
|
||||
return EX_START;
|
||||
|
||||
/* NOTE: We may now have changed argv[1] via a ``set proctitle'' */
|
||||
@ -398,12 +397,11 @@ main(int argc, char **argv)
|
||||
|
||||
sig_signal(SIGUSR2, BringDownServer);
|
||||
|
||||
lastlabel = argc == 2 ? bundle->argv1 : argv[argc - 1];
|
||||
lastlabel = argv[argc - 1];
|
||||
for (arg = label; arg < argc; arg++) {
|
||||
/* In case we use LABEL or ``set enddisc label'' */
|
||||
bundle_SetLabel(bundle, lastlabel);
|
||||
system_Select(bundle, arg == 1 ? bundle->argv1 : argv[arg],
|
||||
CONFFILE, prompt, NULL);
|
||||
system_Select(bundle, argv[arg], CONFFILE, prompt, NULL);
|
||||
}
|
||||
|
||||
if (label < argc)
|
||||
|
Loading…
Reference in New Issue
Block a user