aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2021-01-16 08:26:17 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2021-01-16 08:36:54 +0000
commitfe258f23ef3612f8230c4ed82f1efa511cc0524f (patch)
treef364895c667e068e2c6f0bc98299aafe18cb981f /lib
parent2968dde3de6f6274517904add6a0a8e2e3f9662b (diff)
downloadsrc-fe258f23ef3612f8230c4ed82f1efa511cc0524f.tar.gz
src-fe258f23ef3612f8230c4ed82f1efa511cc0524f.zip
Save on getpid in setproctitle by supporting -1 as curproc.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/setproctitle.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c
index b975fd72b649..991af38565cd 100644
--- a/lib/libc/gen/setproctitle.c
+++ b/lib/libc/gen/setproctitle.c
@@ -184,8 +184,18 @@ setproctitle_fast(const char *fmt, ...)
oid[0] = CTL_KERN;
oid[1] = KERN_PROC;
oid[2] = KERN_PROC_ARGS;
- oid[3] = getpid();
- sysctl(oid, 4, 0, 0, "", 0);
+ oid[3] = -1;
+ if (sysctl(oid, 4, 0, 0, "", 0) != 0) {
+ /*
+ * Temporary compat for kernels which don't support
+ * passing -1.
+ */
+ oid[0] = CTL_KERN;
+ oid[1] = KERN_PROC;
+ oid[2] = KERN_PROC_ARGS;
+ oid[3] = getpid();
+ sysctl(oid, 4, 0, 0, "", 0);
+ }
fast_update = 1;
}
}
@@ -206,8 +216,18 @@ setproctitle(const char *fmt, ...)
oid[0] = CTL_KERN;
oid[1] = KERN_PROC;
oid[2] = KERN_PROC_ARGS;
- oid[3] = getpid();
- sysctl(oid, 4, 0, 0, buf, strlen(buf) + 1);
+ oid[3] = -1;
+ if (sysctl(oid, 4, 0, 0, buf, strlen(buf) + 1) != 0) {
+ /*
+ * Temporary compat for kernels which don't support
+ * passing -1.
+ */
+ oid[0] = CTL_KERN;
+ oid[1] = KERN_PROC;
+ oid[2] = KERN_PROC_ARGS;
+ oid[3] = getpid();
+ sysctl(oid, 4, 0, 0, buf, strlen(buf) + 1);
+ }
fast_update = 0;
}
}