From cf0a39401da73d01cdbce0a037d078e3b6bc9f42 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Wed, 17 Nov 1999 21:12:35 +0000 Subject: [PATCH] Fix ``set proctitle'' by using setproctitle(). --- usr.sbin/ppp/bundle.c | 14 +++++++------- usr.sbin/ppp/bundle.h | 5 +---- usr.sbin/ppp/command.c | 12 ++++++++---- usr.sbin/ppp/id.c | 14 ++++++++++++++ usr.sbin/ppp/id.h | 1 + usr.sbin/ppp/main.c | 8 +++----- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index dcc07f267603..18a0ff185f32 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -39,6 +39,11 @@ #include #include +#ifdef __OpenBSD__ +#include +#else +#include +#endif #include #include #include @@ -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. diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h index b2e59cee14c1..a56860b4c714 100644 --- a/usr.sbin/ppp/bundle.h +++ b/usr.sbin/ppp/bundle.h @@ -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) diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 47a83e0b2935..4096597217c4 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -33,6 +33,11 @@ #include #include #include +#ifdef __OpenBSD__ +#include +#else +#include +#endif #include #include #include @@ -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; } diff --git a/usr.sbin/ppp/id.c b/usr.sbin/ppp/id.c index 06aad0294177..0d15c92d96e5 100644 --- a/usr.sbin/ppp/id.c +++ b/usr.sbin/ppp/id.c @@ -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) diff --git a/usr.sbin/ppp/id.h b/usr.sbin/ppp/id.h index 3254f6437580..57344cfae51c 100644 --- a/usr.sbin/ppp/id.h +++ b/usr.sbin/ppp/id.h @@ -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 diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index cbe0f5586cd6..a108f937a383 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -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)