setproctitle-0.3.2/000075500000000000000000000000001153555421400142405ustar00rootroot00000000000000setproctitle-0.3.2/.gitignore000064400000000000000000000000121153555421400162210ustar00rootroot00000000000000*.o *.so* setproctitle-0.3.2/LICENSE000064400000000000000000000002601153555421400152430ustar00rootroot00000000000000setproctitle.3 is under the 3-clause BSD-style license as specified within the file itself. The rest of the files in this package are under GNU Lesser General Public License. setproctitle-0.3.2/Makefile000064400000000000000000000042111153555421400156760ustar00rootroot00000000000000# # Copyright (C) 2001-2006 Dmitry V. Levin # # Makefile for the setproctitle project. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # PROJECT = setproctitle VERSION = $(shell sed '/^Version: */!d;s///;q' setproctitle.spec) MAJOR = 0 SHLIB_NAME = lib$(PROJECT).so SONAME = $(SHLIB_NAME).$(MAJOR) SHLIB = $(SHLIB_NAME).$(VERSION) MAP = $(PROJECT).map TARGETS = $(SHLIB) $(SONAME) $(SHLIB_NAME) INSTALL = install libdir = /usr/lib includedir = /usr/include mandir = /usr/share/man man3dir = $(mandir)/man3 DESTDIR = WARNINGS = -W -Wall -Waggregate-return -Wcast-align -Wconversion \ -Wdisabled-optimization -Wmissing-declarations \ -Wmissing-format-attribute -Wmissing-noreturn \ -Wmissing-prototypes -Wpointer-arith -Wredundant-decls \ -Wshadow -Wstrict-prototypes -Wwrite-strings CPPFLAGS = -std=gnu99 $(WARNINGS) -D_GNU_SOURCE CFLAGS = $(RPM_OPT_FLAGS) -fPIC LDFLAGS = -shared -nostartfiles -Wl,-soname,$(SONAME),--version-script,$(MAP),-z,defs,-z,now,-stats all: $(TARGETS) $(SONAME) $(SHLIB_NAME): $(SHLIB) ln -sf $< $@ $(SHLIB): $(PROJECT).o $(MAP) $(LINK.o) $< $(OUTPUT_OPTION) $(PROJECT).o: $(PROJECT).c setproctitle.h install: $(INSTALL) -pD -m755 $(SHLIB) $(DESTDIR)$(libdir)/$(SHLIB) $(INSTALL) -pD -m644 $(PROJECT).3 $(DESTDIR)$(man3dir)/$(PROJECT).3 $(INSTALL) -pD -m644 $(PROJECT).h $(DESTDIR)$(includedir)/$(PROJECT).h ln -s $(SHLIB) $(DESTDIR)$(libdir)/$(SONAME) ln -s $(SHLIB) $(DESTDIR)$(libdir)/$(SHLIB_NAME) clean: $(RM) $(TARGETS) core *.o *~ setproctitle-0.3.2/setproctitle.3000064400000000000000000000067771153555421400170660ustar00rootroot00000000000000.\" Copyright (c) 2004-2007 Dmitry V. Levin. .\" All rights reserved. .\" Copyright (c) 1994, 1995 Christopher G. Demetriou .\" All rights reserved. .\" .\" This manual page was originally developed for the NetBSD Project by .\" Christopher G. Demetriou. .\" .\" 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. 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 March 20, 2007 .Dt SETPROCTITLE 3 .Os .Sh NAME .Nm setproctitle .Nd set process title .Sh SYNOPSIS .In setproctitle.h .Ft int .Fn setproctitle "const char *fmt" "..." .Sh DESCRIPTION The .Fn setproctitle function sets the invoking process's title. The process title is set to the last component of the program name, followed by a colon, a single space, and the formatted string specified by .Fa fmt . If .Fa fmt is .Dv NULL , the colon and formatted string are omitted. .Sh EXAMPLES Set the process title to the program name, with no further information: .Bd -literal -offset indent setproctitle(0); .Ed .Pp Set the process title to the program name, an informational string, and the process ID: .Bd -literal -offset indent setproctitle("foo! (%d)", getpid()); .Ed .Sh SEE ALSO .Xr ps 1 , .Xr w 1 , .Xr printf 3 .Sh HISTORY The .Fn setproctitle function first appeared in .Nx 0.9a . The .Fn setproctitle library first appeared in .Os ALT GNU/Linux . .Sh AUTHORS The .Nm library was written for the ALT GNU/Linux by Dmitry V. Levin. .br This manual page was written for the NetBSD Project by Christopher G. Demetriou. .Sh CAVEATS It is important never to pass a string with user-supplied data as a format without using .Ql %s . An attacker can put format specifiers in the string to mangle the stack, leading to a possible security hole. This holds true even if the string has been built .Dq by hand using a function like .Fn snprintf , as the resulting string may still contain user-supplied conversion specifiers for later interpolation by .Fn setproctitle . .Pp Always be sure to use the proper secure idiom: .Bd -literal -offset indent setproctitle("%s", string); .Ed .Pp The .Fn setproctitle function clobbers the argv (array of argument strings passed to the process). If this data is going to be used after first .Fn setproctitle invocation, it should be saved in another memory location. setproctitle-0.3.2/setproctitle.c000064400000000000000000000067041153555421400171340ustar00rootroot00000000000000 /* Copyright (C) 2004-2006 Dmitry V. Levin The setproctitle library interface. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "setproctitle.h" extern int _init(int argc, char *argv[], char *envp[]); static char *title_buffer = 0; static size_t title_buffer_size = 0; static char *title_progname, *title_progname_full; int setproctitle(const char *fmt, ...) { if (!title_buffer || !title_buffer_size) { errno = ENOMEM; return -1; } memset(title_buffer, '\0', title_buffer_size); ssize_t written; if (fmt) { ssize_t written2; va_list ap; written = snprintf(title_buffer, title_buffer_size, "%s: ", title_progname); if (written < 0 || (size_t) written >= title_buffer_size) return -1; va_start(ap, fmt); written2 = vsnprintf(title_buffer + written, title_buffer_size - written, fmt, ap); va_end(ap); if (written2 < 0 || (size_t) written2 >= title_buffer_size - written) return -1; } else { written = snprintf(title_buffer, title_buffer_size, "%s", title_progname); if (written < 0 || (size_t) written >= title_buffer_size) return -1; } written = strlen(title_buffer); memset(title_buffer + written, '\0', title_buffer_size - written); return 0; } /* It has to be _init function, because __attribute__((constructor)) functions gets called without arguments. */ int _init(int argc, char *argv[], char *envp[]) { char *begin_of_buffer = 0, *end_of_buffer = 0; int i; for (i = 0; i < argc; ++i) { if (!begin_of_buffer) begin_of_buffer = argv[i]; if (!end_of_buffer || end_of_buffer + 1 == argv[i]) end_of_buffer = argv[i] + strlen(argv[i]); } for (i = 0; envp[i]; ++i) { if (!begin_of_buffer) begin_of_buffer = envp[i]; if (!end_of_buffer || end_of_buffer + 1 == envp[i]) end_of_buffer = envp[i] + strlen(envp[i]); } if (!end_of_buffer) return 0; char **new_environ = malloc((i + 1) * sizeof(envp[0])); if (!new_environ) return 0; for (i = 0; envp[i]; ++i) if (!(new_environ[i] = strdup(envp[i]))) goto cleanup_enomem; new_environ[i] = 0; if (program_invocation_name) { title_progname_full = strdup(program_invocation_name); if (!title_progname_full) goto cleanup_enomem; char *p = strrchr(title_progname_full, '/'); if (p) title_progname = p + 1; else title_progname = title_progname_full; program_invocation_name = title_progname_full; program_invocation_short_name = title_progname; } environ = new_environ; title_buffer = begin_of_buffer; title_buffer_size = end_of_buffer - begin_of_buffer; return 0; cleanup_enomem: for (--i; i >= 0; --i) free(new_environ[i]); free(new_environ); return 0; } setproctitle-0.3.2/setproctitle.h000064400000000000000000000020641153555421400171340ustar00rootroot00000000000000/* Copyright (C) 2004-2008 Dmitry V. Levin The setproctitle library interface. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef SETPROCTITLE_H_ #define SETPROCTITLE_H_ #ifdef __cplusplus extern "C" { #endif extern int setproctitle (const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2))); #ifdef __cplusplus } #endif #endif /* SETPROCTITLE_H_ */ setproctitle-0.3.2/setproctitle.map000064400000000000000000000000511153555421400174540ustar00rootroot00000000000000{ global: setproctitle; local: *; }; setproctitle-0.3.2/setproctitle.spec000064400000000000000000000040231153555421400176340ustar00rootroot00000000000000Name: setproctitle Version: 0.3.2 Release: alt3 Summary: A setproctitle implementation License: LGPL/BSD-style Group: System/Libraries Source: %name-%version.tar %description This library provides setproctitle function for setting the invoking process's title. %package devel Summary: Development environment for setproctitle Group: Development/C Requires: %name = %version-%release %description devel This package contains development files required to build setproctitle-based software. %prep %setup %build %make_build %install %makeinstall_std libdir=%_libdir %files %_libdir/*.so.* %doc LICENSE %files devel %_libdir/*.so %_includedir/* %_man3dir/* %changelog * Wed Mar 09 2011 Dmitry V. Levin 0.3.2-alt3 - Rebuilt for debuginfo. * Thu Nov 04 2010 Dmitry V. Levin 0.3.2-alt2 - Rebuilt for soname set-versions. * Sun Dec 14 2008 Dmitry V. Levin 0.3.2-alt1 - setproctitle.h: Added extern "C" wrapper. - Removed obsolete %%post_ldconfig/%%postun_ldconfig calls. * Wed Mar 21 2007 Dmitry V. Levin 0.3.1-alt1 - setproctitle.3: + Noted that setproctitle() clobbers argv[]. + Updated authorship and license information. - Packaged LICENSE file, updated License tag. * Sun Sep 03 2006 Dmitry V. Levin 0.3-alt1 - setproctitle: Clear the _whole_ title buffer every time. - Linked the library with -Wl,-z,defs. * Sat Apr 29 2006 Dmitry V. Levin 0.2-alt1 - Build with _GNU_SOURCE defined, replaced deprecated __progname and __progname_full symbols with program_invocation_short_name and program_invocation_name. - Enabled almost all diagnostics supported by gcc and fixed all issues found by gcc-3.4.5-alt2. - Changed linking to use gcc instead of ld. - Linked the library with -Wl,-z,now. - Updated FSF postal address. * Tue May 03 2005 Dmitry V. Levin 0.1-alt2 - Pass libdir to "make install" for better mutlilib support (#6764). * Sun Jun 06 2004 Dmitry V. Levin 0.1-alt1 - Initial revision.