Fix ``set proctitle'' by using setproctitle().

This commit is contained in:
Brian Somers 1999-11-17 21:12:35 +00:00
parent 0675e24de0
commit cf0a39401d
6 changed files with 34 additions and 20 deletions

View File

@ -39,6 +39,11 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef __OpenBSD__
#include <util.h>
#else
#include <libutil.h>
#endif
#include <paths.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -603,7 +608,7 @@ bundle_UnlockTun(struct bundle *bundle)
} }
struct 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 */ static struct bundle bundle; /* there can be only one */
int enoentcount, err, minunit, maxunit; 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); log_SetTun(bundle.unit);
bundle.argv = argv;
bundle.argv0 = argv[0];
bundle.argv1 = argv[1];
ifname = strrchr(bundle.dev.Name, '/'); ifname = strrchr(bundle.dev.Name, '/');
if (ifname == NULL) if (ifname == NULL)
@ -1097,7 +1099,6 @@ bundle_ShowStatus(struct cmdargs const *arg)
int remaining; int remaining;
prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle)); 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, " Device: %s\n", arg->bundle->dev.Name);
prompt_Printf(arg->prompt, " Interface: %s @ %lubps", prompt_Printf(arg->prompt, " Interface: %s @ %lubps",
arg->bundle->iface->name, arg->bundle->bandwidth); arg->bundle->iface->name, arg->bundle->bandwidth);
@ -1660,8 +1661,7 @@ bundle_setsid(struct bundle *bundle, int holdsession)
*/ */
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
/* Tweak our process arguments.... */ /* Tweak our process arguments.... */
bundle->argv[0] = "session owner"; ID0setproctitle("session owner");
bundle->argv[1] = NULL;
/* /*
* Hang around for a HUP. This should happen as soon as the * Hang around for a HUP. This should happen as soon as the
* ppp that we passed our ctty descriptor to closes it. * ppp that we passed our ctty descriptor to closes it.

View File

@ -63,9 +63,6 @@ struct iface;
struct bundle { struct bundle {
struct descriptor desc; /* really all our datalinks */ struct descriptor desc; /* really all our datalinks */
int unit; /* The device/interface unit number */ int unit; /* The device/interface unit number */
const char **argv; /* From main() */
const char *argv0; /* Original */
const char *argv1; /* Original */
struct { struct {
char Name[20]; /* The /dev/XXXX name */ char Name[20]; /* The /dev/XXXX name */
@ -142,7 +139,7 @@ struct bundle {
#define descriptor2bundle(d) \ #define descriptor2bundle(d) \
((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) ((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 void bundle_Destroy(struct bundle *);
extern const char *bundle_PhaseName(struct bundle *); extern const char *bundle_PhaseName(struct bundle *);
#define bundle_Phase(b) ((b)->phase) #define bundle_Phase(b) ((b)->phase)

View File

@ -33,6 +33,11 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef __OpenBSD__
#include <util.h>
#else
#include <libutil.h>
#endif
#include <paths.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -87,6 +92,7 @@
#include "cbcp.h" #include "cbcp.h"
#include "datalink.h" #include "datalink.h"
#include "iface.h" #include "iface.h"
#include "id.h"
/* ``set'' values */ /* ``set'' values */
#define VAR_AUTHKEY 0 #define VAR_AUTHKEY 0
@ -2609,8 +2615,7 @@ SetProcTitle(struct cmdargs const *arg)
int len, remaining, f, argc = arg->argc - arg->argn; int len, remaining, f, argc = arg->argc - arg->argn;
if (arg->argc == arg->argn) { if (arg->argc == arg->argn) {
arg->bundle->argv[0] = arg->bundle->argv0; ID0setproctitle(NULL);
arg->bundle->argv[1] = arg->bundle->argv1;
return 0; return 0;
} }
@ -2636,8 +2641,7 @@ SetProcTitle(struct cmdargs const *arg)
} }
*ptr = '\0'; *ptr = '\0';
arg->bundle->argv[0] = title; ID0setproctitle(title);
arg->bundle->argv[1] = NULL;
return 0; return 0;
} }

View File

@ -269,6 +269,20 @@ ID0kill(pid_t pid, int sig)
return result; 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) #if defined(__FreeBSD__) && !defined(NOKLDLOAD)
int int
ID0kldload(const char *dev) ID0kldload(const char *dev)

View File

@ -45,6 +45,7 @@ extern void ID0logout(const char *, int);
extern int ID0bind_un(int, const struct sockaddr_un *); extern int ID0bind_un(int, const struct sockaddr_un *);
extern int ID0connect_un(int, const struct sockaddr_un *); extern int ID0connect_un(int, const struct sockaddr_un *);
extern int ID0kill(pid_t, int); extern int ID0kill(pid_t, int);
extern void ID0setproctitle(const char *);
#if defined(__FreeBSD__) && !defined(NOKLDLOAD) #if defined(__FreeBSD__) && !defined(NOKLDLOAD)
extern int ID0kldload(const char *); extern int ID0kldload(const char *);
#endif #endif

View File

@ -367,8 +367,7 @@ main(int argc, char **argv)
if (!sw.quiet) if (!sw.quiet)
prompt_Printf(prompt, "Working in %s mode\n", mode2Nam(sw.mode)); prompt_Printf(prompt, "Working in %s mode\n", mode2Nam(sw.mode));
if ((bundle = bundle_Create(TUN_PREFIX, sw.mode, sw.unit, if ((bundle = bundle_Create(TUN_PREFIX, sw.mode, sw.unit)) == NULL)
(const char **)argv)) == NULL)
return EX_START; return EX_START;
/* NOTE: We may now have changed argv[1] via a ``set proctitle'' */ /* 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); sig_signal(SIGUSR2, BringDownServer);
lastlabel = argc == 2 ? bundle->argv1 : argv[argc - 1]; lastlabel = argv[argc - 1];
for (arg = label; arg < argc; arg++) { for (arg = label; arg < argc; arg++) {
/* In case we use LABEL or ``set enddisc label'' */ /* In case we use LABEL or ``set enddisc label'' */
bundle_SetLabel(bundle, lastlabel); bundle_SetLabel(bundle, lastlabel);
system_Select(bundle, arg == 1 ? bundle->argv1 : argv[arg], system_Select(bundle, argv[arg], CONFFILE, prompt, NULL);
CONFFILE, prompt, NULL);
} }
if (label < argc) if (label < argc)