shithub: riscv

Download patch

ref: 19166f2cf32725b1907c8032ae224282a1fa3f8f
parent: 311e3b51c6b1bde2f58968453de56a5ca2a6dbb4
author: cinap_lenrek <[email protected]>
date: Wed Sep 26 10:56:23 EDT 2018

libc: add procsetname()

--- a/sys/include/libc.h
+++ b/sys/include/libc.h
@@ -489,6 +489,9 @@
 extern	int	rwakeupall(Rendez*);
 extern	void**	privalloc(void);
 
+extern void	procsetname(char*, ...);
+#pragma varargck argpos procsetname 1
+
 /*
  *  network dialing
  */
--- a/sys/src/cmd/aux/listen.c
+++ b/sys/src/cmd/aux/listen.c
@@ -53,31 +53,6 @@
 		" [-a addr] [proto]");
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-static void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 void
 main(int argc, char *argv[])
 {
--- a/sys/src/cmd/cpu.c
+++ b/sys/src/cmd/cpu.c
@@ -116,31 +116,6 @@
 	return strdup(lp+1);
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 void
 main(int argc, char **argv)
 {
--- a/sys/src/cmd/cwfs/portfns.h
+++ b/sys/src/cmd/cwfs/portfns.h
@@ -142,7 +142,6 @@
 void	prdate(void);
 void	preread(Device*, Off);
 int	prime(vlong);
-void	procsetname(char *fmt, ...);
 void	putbuf(Iobuf*);
 Off	qidpathgen(Device*);
 void*	querychanger(Device *);
--- a/sys/src/cmd/cwfs/proc.c
+++ b/sys/src/cmd/cwfs/proc.c
@@ -1,31 +1,6 @@
 #include "all.h"
 #include "io.h"
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 void
 newproc(void (*f)(void *), void *arg, char *text)
 {
--- a/sys/src/cmd/exportfs/exportsrv.c
+++ b/sys/src/cmd/exportfs/exportsrv.c
@@ -437,31 +437,6 @@
 	putsbuf(t);
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 void
 slave(Fsrpc *f)
 {
--- a/sys/src/cmd/import.c
+++ b/sys/src/cmd/import.c
@@ -37,31 +37,6 @@
 
 static void	mksecret(char *, uchar *);
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 void
 post(char *name, char *envname, int srvfd)
 {
--- a/sys/src/cmd/ip/6in4.c
+++ b/sys/src/cmd/ip/6in4.c
@@ -285,31 +285,6 @@
 }
 
 /*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
-/*
  * encapsulate v6 packets from the packet interface in v4 ones
  * and send them into the tunnel.
  */
--- a/sys/src/cmd/ip/ayiya.c
+++ b/sys/src/cmd/ip/ayiya.c
@@ -466,31 +466,6 @@
 	exits(0);
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 static int alarmed;
 
 static void
--- a/sys/src/cmd/ip/ipconfig/ipconfig.h
+++ b/sys/src/cmd/ip/ipconfig/ipconfig.h
@@ -121,7 +121,6 @@
 void	removedefroute(uchar*, uchar*, uchar*, uchar*);
 
 long	jitter(void);
-void	procsetname(char *fmt, ...);
 void	catch(void*, char*);
 int	countaddrs(uchar *a, int len);
 void	addaddrs(uchar *to, int nto, uchar *from, int nfrom);
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -801,31 +801,6 @@
 	noted(NDFLT);
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 /* return pseudo-random integer in range low...(hi-1) */
 ulong
 randint(ulong low, ulong hi)
--- a/sys/src/cmd/ip/tinc.c
+++ b/sys/src/cmd/ip/tinc.c
@@ -175,15 +175,12 @@
 void	delsubnet(Snet*);
 void	netrecalc(void);
 
-void	procsetname(char *fmt, ...);
 int	consend(Conn *c, char *fmt, ...);
+#pragma varargck argpos consend 2
 void	routepkt(Host *s, uchar *p, int n);
 void	needkey(Host *from);
 void	clearkey(Host *from);
 
-#pragma varargck argpos procsetname 1
-#pragma varargck argpos consend 2
-
 void*
 emalloc(ulong len)
 {
@@ -209,23 +206,6 @@
 		sysfatal("strdup: %r");
 	setmalloctag(s, getcallerpc(&s));
 	return s;
-}
-
-void
-procsetname(char *fmt, ...)
-{
-	int fd, n;
-	char buf[128];
-	va_list arg;
-
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) < 0)
-		return;
-	va_start(arg, fmt);
-	n = vsnprint(buf, sizeof buf, fmt, arg);
-	va_end(arg);
-	write(fd, buf, n+1);
-	close(fd);
 }
 
 char*
--- a/sys/src/cmd/ndb/cs.c
+++ b/sys/src/cmd/ndb/cs.c
@@ -201,31 +201,6 @@
 	exits("usage");
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
 void
 main(int argc, char *argv[])
 {
--- a/sys/src/cmd/ndb/dn.c
+++ b/sys/src/cmd/ndb/dn.c
@@ -1467,31 +1467,6 @@
 }
 
 /*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-	int fd;
-	char *cmdname;
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	cmdname = vsmprint(fmt, arg);
-	va_end(arg);
-	if (cmdname == nil)
-		return;
-	snprint(buf, sizeof buf, "#p/%d/args", getpid());
-	if((fd = open(buf, OWRITE)) >= 0){
-		write(fd, cmdname, strlen(cmdname)+1);
-		close(fd);
-	}
-	free(cmdname);
-}
-
-/*
  *  create a slave process to handle a request to avoid one request blocking
  *  another
  */
--- a/sys/src/cmd/ndb/dns.h
+++ b/sys/src/cmd/ndb/dns.h
@@ -508,7 +508,6 @@
 RR*	getdnsservers(int);
 void	logreply(int, uchar*, DNSmsg*);
 void	logsend(int, int, uchar*, char*, char*, int);
-void	procsetname(char *fmt, ...);
 
 /* dnresolve.c */
 RR*	dnresolve(char*, int, int, Request*, RR**, int, int, int, int*);
--- a/sys/src/libc/9sys/mkfile
+++ b/sys/src/libc/9sys/mkfile
@@ -31,6 +31,7 @@
 	nulldir.$O\
 	postnote.$O\
 	privalloc.$O\
+	procsetname.$O\
 	pushssl.$O\
 	pushtls.$O\
 	putenv.$O\
--- /dev/null
+++ b/sys/src/libc/9sys/procsetname.c
@@ -1,0 +1,19 @@
+#include <u.h>
+#include <libc.h>
+
+void
+procsetname(char *fmt, ...)
+{
+	int fd, n;
+	char buf[128];
+	va_list arg;
+
+	snprint(buf, sizeof buf, "#p/%lud/args", (ulong)getpid());
+	if((fd = open(buf, OWRITE)) < 0)
+		return;
+	va_start(arg, fmt);
+	n = vsnprint(buf, sizeof buf, fmt, arg);
+	va_end(arg);
+	write(fd, buf, n+1);
+	close(fd);
+}