diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 19 | ||||
-rw-r--r-- | lib/libc/gen/getprogname.3 | 96 | ||||
-rw-r--r-- | lib/libc/gen/getprogname.c | 26 | ||||
-rw-r--r-- | lib/libc/gen/setproctitle.3 | 5 | ||||
-rw-r--r-- | lib/libc/gen/setprogname.c | 33 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 |
6 files changed, 169 insertions, 12 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index fb2f7eb8f9a..e3c040e576a 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.60 2013/05/31 18:41:25 tedu Exp $ +# $OpenBSD: Makefile.inc,v 1.61 2013/05/31 20:59:23 ajacoutot Exp $ # gen sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen @@ -11,14 +11,14 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c \ fstab.c ftok.c fts.c ftw.c getbsize.c getcap.c getcwd.c \ getdomainname.c getgrent.c getgrouplist.c gethostname.c \ getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \ - getpwent.c getttyent.c getusershell.c glob.c initgroups.c \ - isatty.c isctype.c isfdtype.c isfinite.c isinf.c isnan.c \ - isnormal.c signbit.c lockf.c login_cap.c nice.c \ + getprogname.c getpwent.c getttyent.c getusershell.c glob.c \ + initgroups.c isatty.c isctype.c isfdtype.c isfinite.c isinf.c \ + isnan.c isnormal.c signbit.c lockf.c login_cap.c nice.c \ nlist.c nftw.c opendir.c pause.c popen.c posix_spawn.c psignal.c \ pw_dup.c pwcache.c raise.c readdir.c readdir_r.c readpassphrase.c \ - rewinddir.c scandir.c \ - seekdir.c setdomainname.c sethostname.c setjmperr.c setmode.c \ - setproctitle.c shm_open.c siginterrupt.c siglist.c signal.c signame.c \ + rewinddir.c scandir.c seekdir.c setdomainname.c sethostname.c \ + setprogname.c setjmperr.c setmode.c setproctitle.c shm_open.c \ + siginterrupt.c siglist.c signal.c signame.c \ sigsetops.c sleep.c statvfs.c strtofflags.c sysconf.c sysctl.c \ syslog.c syslog_r.c telldir.c time.c times.c timezone.c \ tolower_.c ttyname.c \ @@ -41,8 +41,8 @@ MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 confstr.3 \ exec.3 fabs.3 fnmatch.3 fpclassify.3 fpgetmask.3 frexp.3 ftok.3 fts.3 \ ftw.3 getbsize.3 getcap.3 getcwd.3 getdomainname.3 getdiskbyname.3 \ getfsent.3 getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ - getmntinfo.3 getnetgrent.3 getpagesize.3 getpass.3 getpwent.3 \ - getpwnam.3 \ + getmntinfo.3 getnetgrent.3 getpagesize.3 getpass.3 getprogname.3 \ + getpwent.3 getpwnam.3 \ getttyent.3 getusershell.3 glob.3 initgroups.3 isalnum.3 isalpha.3 \ isascii.3 isblank.3 iscntrl.3 isdigit.3 isfdtype.3 isgraph.3 \ isgreater.3 islower.3 isprint.3 ispunct.3 isspace.3 isupper.3 \ @@ -104,6 +104,7 @@ MLINKS+=getgrent.3 endgrent.3 getgrent.3 setgroupent.3 getgrent.3 getgrgid.3 \ MLINKS+=gethostname.3 sethostname.3 MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \ getnetgrent.3 setnetgrent.3 +MLINKS+=getprogname.3 setprogname.3 MLINKS+=getpwent.3 endpwent.3 getpwent.3 setpwent.3 MLINKS+=getpwnam.3 getpwuid.3 getpwnam.3 getpwnam_r.3 getpwnam.3 getpwuid_r.3 \ getpwnam.3 setpassent.3 diff --git a/lib/libc/gen/getprogname.3 b/lib/libc/gen/getprogname.3 new file mode 100644 index 00000000000..b3d8e4c38e2 --- /dev/null +++ b/lib/libc/gen/getprogname.3 @@ -0,0 +1,96 @@ +.\" $OpenBSD: getprogname.3,v 1.1 2013/05/31 20:59:23 ajacoutot Exp $ +.\" +.\" Copyright (c) 2001 Christopher G. Demetriou +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed for the +.\" NetBSD Project. See http://www.NetBSD.org/ for +.\" information about NetBSD. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd $Mdocdate: May 31 2013 $ +.Dt GETPROGNAME 3 +.Os +.Sh NAME +.Nm getprogname , +.Nm setprogname +.Nd get/set the name of the current program +.Sh SYNOPSIS +.In stdlib.h +.Ft const char * +.Fn getprogname "void" +.Ft void +.Fn setprogname "const char *name" +.Sh DESCRIPTION +These utility functions get and set the current program's name +as used by various error-reporting functions. +.Pp +.Fn getprogname +returns the name of the current program. +This function is typically useful when generating error messages +or other diagnostic output. +If the program name has not been set, +.Fn getprogname +will return +.Dv NULL . +.Pp +The +.Fn setprogname +function sets the name of the program to be the last component of the +.Fa progname +argument. +Since a pointer to the given string is kept as the program name, +it should not be modified for the rest of the program's lifetime. +.Pp +In +.Ox , +the name of the program is set by the start-up code that is run before +.Fn main ; +thus, +running +.Fn setprogname +is not necessary. +Programs that desire maximum portability should still call it; +on another operating system, +these functions may be implemented in a portability library. +Calling +.Fn setprogname +allows the aforementioned library to learn the program name without +modifications to the start-up code. +.Sh SEE ALSO +.Xr err 3 , +.Xr setproctitle 3 +.Sh HISTORY +The +.Nm getprogname +and +.Nm setprogname +function calls appeared in +.Ox 5.4 . +.Sh CAVEAT +The string returned by +.Fn getprogname +is supplied by the invoking process and should not be trusted by +setuid or setgid programs. diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c new file mode 100644 index 00000000000..a6d51037a09 --- /dev/null +++ b/lib/libc/gen/getprogname.c @@ -0,0 +1,26 @@ +/* $OpenBSD: getprogname.c,v 1.1 2013/05/31 20:59:23 ajacoutot Exp $ */ +/* + * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> + +extern const char *__progname; + +const char * +getprogname(void) +{ + return (__progname); +} diff --git a/lib/libc/gen/setproctitle.3 b/lib/libc/gen/setproctitle.3 index 21256315c44..9886210857b 100644 --- a/lib/libc/gen/setproctitle.3 +++ b/lib/libc/gen/setproctitle.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: setproctitle.3,v 1.16 2007/05/31 19:19:28 jmc Exp $ +.\" $OpenBSD: setproctitle.3,v 1.17 2013/05/31 20:59:23 ajacoutot Exp $ .\" .\" Copyright (c) 1994, 1995 Christopher G. Demetriou .\" All rights reserved. @@ -29,7 +29,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: May 31 2013 $ .Dt SETPROCTITLE 3 .Os .Sh NAME @@ -67,6 +67,7 @@ setproctitle("foo! (%d)", getpid()); .Sh SEE ALSO .Xr ps 1 , .Xr w 1 , +.Xr getprogname 3 , .Xr printf 3 .Sh HISTORY The diff --git a/lib/libc/gen/setprogname.c b/lib/libc/gen/setprogname.c new file mode 100644 index 00000000000..c8625f0498a --- /dev/null +++ b/lib/libc/gen/setprogname.c @@ -0,0 +1,33 @@ +/* $OpenBSD: setprogname.c,v 1.1 2013/05/31 20:59:24 ajacoutot Exp $ */ +/* + * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> +#include <string.h> + +extern const char *__progname; + +void +setprogname(const char *progname) +{ + const char *tmpn; + + tmpn = strrchr(progname, '/'); + if (tmpn == NULL) + __progname = progname; + else + tmpn + 1; +} diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index edd6b3c711a..3f763170cb9 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ major=68 -minor=2 +minor=3 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then librthread/shlib_version also be updated. |