misc: always check setenv(3) return value
Subsystems (3)
PATCH 1/3 misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.
--- include/env.h | 2 +- lib/pager.c | 3 ++- login-utils/login.c | 19 +++++++++++-------- login-utils/su-common.c | 2 +- login-utils/sulogin.c | 21 +++++++++++---------- sys-utils/hwclock.c | 5 +++-- sys-utils/rtcwake.c | 3 ++- term-utils/agetty.c | 4 +++- 8 files changed, 34 insertions(+), 25 deletions(-)
include/env.h +1 -1
@@ -9,7 +9,7 @@ extern char *safe_getenv(const char *arg);static inline void xsetenv (char const *name,char const *val,int overwrite) {if (setenv (name, val, overwrite) !=0 ) -err (EXIT_FAILURE ,"failed to set the %s environment variable" , name); +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ), name); }#endif /* UTIL_LINUX_ENV_H */
lib/pager.c +2 -1
@@ -138,7 +138,8 @@ static void pager_preexec(void)FD_SET (STDIN_FILENO , &in);select (1 , &in,NULL , &in,NULL ); -setenv ("LESS" ,"FRSX" ,0 ); +if (setenv ("LESS" ,"FRSX" ,0 ) !=0 ) +warn (_ ("failed to set the %s environment variable" ),"LESS" ); }static void wait_for_pager (void )
login-utils/login.c +11 -8
@@ -69,6 +69,7 @@#include "pathnames.h" #include "strutils.h" #include "nls.h" +#include "env.h" #include "xalloc.h" #include "all-io.h" #include "fileutils.h"
@@ -1040,27 +1041,29 @@ static void init_environ(struct login_context *cxt)memset (environ,0 ,sizeof (char *)); } -setenv ("HOME" , pwd->pw_dir,0 );/* legal to override */ -setenv ("USER" , pwd->pw_name,1 ); -setenv ("SHELL" , pwd->pw_shell,1 ); -setenv ("TERM" , termenv ? termenv :"dumb" ,1 ); +xsetenv ("HOME" , pwd->pw_dir,0 );/* legal to override */ +xsetenv ("USER" , pwd->pw_name,1 ); +xsetenv ("SHELL" , pwd->pw_shell,1 ); +xsetenv ("TERM" , termenv ? termenv :"dumb" ,1 );free (termenv);if (pwd->pw_uid) -logindefs_setenv ("PATH" ,"ENV_PATH" , _PATH_DEFPATH); +if (logindefs_setenv ("PATH" ,"ENV_PATH" , _PATH_DEFPATH) !=0 ) +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ),"PATH" );else if (logindefs_setenv ("PATH" ,"ENV_ROOTPATH" ,NULL ) !=0 ) -logindefs_setenv ("PATH" ,"ENV_SUPATH" , _PATH_DEFPATH_ROOT); +if (logindefs_setenv ("PATH" ,"ENV_SUPATH" , _PATH_DEFPATH_ROOT) !=0 ) +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ),"PATH" );/* mailx will give a funny error msg if you forget this one */ len =snprintf (tmp,sizeof (tmp),"%s/%s" , _PATH_MAILDIR, pwd->pw_name);if (len >0 && (size_t ) len <sizeof (tmp)) -setenv ("MAIL" , tmp,0 ); +xsetenv ("MAIL" , tmp,0 );/* LOGNAME is not documented in login(1) but HP-UX 6.5 does it. We'll * not allow modifying it. */ -setenv ("LOGNAME" , pwd->pw_name,1 ); +xsetenv ("LOGNAME" , pwd->pw_name,1 ); env =pam_getenvlist (cxt->pamh);for (i =0 ; env && env[i]; i++)
login-utils/su-common.c +1 -1
@@ -520,7 +520,7 @@ set_path(const struct passwd* pw) r =logindefs_setenv ("PATH" ,"ENV_SUPATH" , _PATH_DEFPATH_ROOT);if (r !=0 ) -err (EXIT_FAILURE ,_ ("failed to set PATH" )); +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ),"PATH" ); }/* Update `environ' for the new shell based on PW, with SHELL being
login-utils/sulogin.c +11 -10
@@ -56,6 +56,7 @@#include "c.h" #include "closestream.h" +#include "env.h" #include "nls.h" #include "pathnames.h" #ifdef USE_PLYMOUTH_SUPPORT
@@ -219,18 +220,18 @@ static void tcfinal(struct console *con)int fd;if ((con->flags &CON_SERIAL ) ==0 ) { -setenv ("TERM" ,"linux" ,1 ); +xsetenv ("TERM" ,"linux" ,1 );return ; }if (con->flags &CON_NOTTY ) { -setenv ("TERM" ,"dumb" ,1 ); +xsetenv ("TERM" ,"dumb" ,1 );return ; }#if defined (__s390__) || defined (__s390x__) -setenv ("TERM" ,"dumb" ,1 ); +xsetenv ("TERM" ,"dumb" ,1 );#else -setenv ("TERM" ,"vt102" ,1 ); +xsetenv ("TERM" ,"vt102" ,1 );#endif tio = &con->tio; fd = con->fd;
@@ -759,16 +760,16 @@ static void sushell(struct passwd *pwd)if (getcwd (home,sizeof (home)) ==NULL )strcpy (home,"/" ); -setenv ("HOME" , home,1 ); -setenv ("LOGNAME" ,"root" ,1 ); -setenv ("USER" ,"root" ,1 ); +xsetenv ("HOME" , home,1 ); +xsetenv ("LOGNAME" ,"root" ,1 ); +xsetenv ("USER" ,"root" ,1 );if (!profile) -setenv ("SHLVL" ,"0" ,1 ); +xsetenv ("SHLVL" ,"0" ,1 );/* * Try to execute a shell. */ -setenv ("SHELL" , su_shell,1 ); +xsetenv ("SHELL" , su_shell,1 );unmask_signal (SIGINT , &saved_sigint);unmask_signal (SIGTSTP , &saved_sigtstp);unmask_signal (SIGQUIT , &saved_sigquit);
@@ -793,7 +794,7 @@ static void sushell(struct passwd *pwd)execl (su_shell, shell,NULL );warn (_ ("failed to execute %s" ), su_shell); -setenv ("SHELL" ,"/bin/sh" ,1 ); +xsetenv ("SHELL" ,"/bin/sh" ,1 );execl ("/bin/sh" , profile ?"-sh" :"sh" ,NULL );warn (_ ("failed to execute %s" ),"/bin/sh" ); }
sys-utils/hwclock.c +3 -2
@@ -81,6 +81,7 @@#include "strutils.h" #include "hwclock.h" #include "timeutils.h" +#include "env.h" #ifdef HAVE_LIBAUDIT #include <libaudit.h>
@@ -399,7 +400,7 @@ mktime_tz(struct tm tm, const bool universal, zone =getenv ("TZ" );/* remember original time zone */ if (universal) {/* Set timezone to UTC */ -setenv ("TZ" ,"" , TRUE); +xsetenv ("TZ" ,"" , TRUE);/* * Note: tzset() gets called implicitly by the time code, * but only the first time. When changing the environment
@@ -434,7 +435,7 @@ mktime_tz(struct tm tm, const bool universal, }/* now put back the original zone. */ if (zone) -setenv ("TZ" , zone, TRUE); +xsetenv ("TZ" , zone, TRUE);else unsetenv ("TZ" );tzset ();
sys-utils/rtcwake.c +2 -1
@@ -34,6 +34,7 @@#include "c.h" #include "closestream.h" +#include "env.h" #include "nls.h" #include "optutils.h" #include "pathnames.h"
@@ -157,7 +158,7 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)* with the system clock (which always uses UTC). */ if (ctl->clock_mode ==CM_UTC ) -setenv ("TZ" ,"UTC" ,1 ); +xsetenv ("TZ" ,"UTC" ,1 );tzset ();/* Read rtc and system clocks "at the same time", or as * precisely (+/- a second) as we can read them.
term-utils/agetty.c +3 -1
@@ -45,6 +45,7 @@#include "widechar.h" #include "ttyutils.h" #include "color-names.h" +#include "env.h" #ifdef USE_PLYMOUTH_SUPPORT # include "plymouth-ctrl.h"
@@ -1155,7 +1156,8 @@ static void open_tty(char *tty, struct termios *tp, struct options *op) op->term =DEFAULT_STERM ; } -setenv ("TERM" , op->term,1 ); +if (setenv ("TERM" , op->term,1 ) !=0 ) +log_err (_ ("failed to set the %s environment variable" ),"TERM" ); }/* Initialize termios settings. */
Signature · 1 line
2.9.3
PATCH 2/3 kill: remove pid command-name to option alias
Removal was promised to happen at March 2014 and the time has to get rid of this unexpected feature.
Reference: c5b057b3422504a671ee588fa66574ae876521f1
--- Documentation/deprecated.txt | 5 ----- misc-utils/kill.1 | 5 ----- misc-utils/kill.c | 4 ---- 3 files changed, 14 deletions(-)
Documentation/deprecated.txt +0 -5
@@ -34,11 +34,6 @@ why: does not provide control on output data formatting. The recommended solut -------------------------- -what: "pid" as binary name for "kill --pid" -why: too ugly, too obscure - --------------------------- - What: mkfs Why: use filesystem specific mkfs.<type>.
misc-utils/kill.1 +0 -5
@@ -91,11 +91,6 @@ uid as the present process. \fB\-p\fR, \fB\-\-pid\fR Only print the process id (pid) of the named processes, do not send any signals. -.IP -The \fB\-\-pid\fR option is automatically enabled when the \fBkill\fR command -is invoked with the name of -.BR pid . -This functionality is deprecated, and will be removed in March 2016. .TP \fB\-\-verbose\fR Print pid(s) that will be signaled with kill along with the signal.
misc-utils/kill.c +0 -4
@@ -472,10 +472,6 @@ int main(int argc, char **argv)textdomain (PACKAGE );atexit (close_stdout); - ctl.do_pid = (!strcmp (program_invocation_short_name,"pid" ));/* Yecch */ -if (ctl.do_pid)/* FIXME: remove in March 2016. */ -warnx (_ ("use of 'kill --pid' option as command name is deprecated" )); - argv =parse_arguments (argc, argv, &ctl);/* The rest of the arguments should be process ids and names. */
Signature · 1 line
2.9.3
Re: [PATCH 2/3] kill: remove pid command-name to option alias
Quoted 2 lines · Sami Kerola
Removal was promised to happen at March 2014 and the time has to get rid of this unexpected feature.
s/at March/in March/
s/2014/2016/
s/time has/time has come/
Benno
Signature · 1 line
http://www.fastmail.com - Email service worth paying for. Try it for free
Re: [PATCH 2/3] kill: remove pid command-name to option alias
Quoted 7 lines · Benno Schulenberg
Quoted 2 lines · Sami Kerola
Removal was promised to happen at March 2014 and the time has to get rid of this unexpected feature.
s/at March/in March/
s/2014/2016/
s/time has/time has come/
Thanks Benno fixed in 'misc' branch.
https://github.com/kerolasa/lelux-utiliteetit/commit/0be3ad70ad85cce75be6fffb87fa81e62bd4b105
Signature · 2 lines
Sami Kerola http://www.iki.fi/kerolasa/
PATCH 3/3 pg: stop building the command by default
In reply to Sami KerolaThe pg command is marked deprecated in POSIX since 1997, and this project has thought the same since Feb 2013. Time has come to stop shipping this binary by default.
Reference: 956e582874d3a28434018bf12057c745f74821de
--- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +2 -2
@@ -1804,8 +1804,8 @@ AM_CONDITIONAL([BUILD_MORE], [test "x$build_more" = xyes]) AC_ARG_ENABLE([pg], - AS_HELP_STRING([--disable-pg], [do not build pg]), - [], [UL_DEFAULT_ENABLE([pg], [check])] + AS_HELP_STRING([--enable-pg], [build pg]), + [], [UL_DEFAULT_ENABLE([pg], [no])] ) UL_BUILD_INIT([pg]) UL_REQUIRES_HAVE([pg], [ncursesw, ncurses], [ncurses or ncursesw library])
Signature · 1 line
2.9.3
Karel Zak
maintainerQuoted 9 lines · Sami Kerola
include/env.h | 2 +- lib/pager.c | 3 ++- login-utils/login.c | 19 +++++++++++-------- login-utils/su-common.c | 2 +- login-utils/sulogin.c | 21 +++++++++++---------- sys-utils/hwclock.c | 5 +++-- sys-utils/rtcwake.c | 3 ++- term-utils/agetty.c | 4 +++- 8 files changed, 34 insertions(+), 25 deletions(-)
All "misc" branch merged. Thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerinclude/env.h extern char *safe_getenv(const char *arg); · line 13
Quoted 7 lines · Sami Kerola
include/env.h +1
-1@@ -9,7 +9,7 @@ extern char *safe_getenv(const char *arg);static inline void xsetenv (char const *name,char const *val,int overwrite) {if (setenv (name, val, overwrite) !=0 ) -err (EXIT_FAILURE ,"failed to set the %s environment variable" , name); +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ), name); }
no nls.h included
In file included from lib/env.c:22:0:./include/env.h: In function ‘xsetenv’:./include/env.h:12:21: warning: implicit declaration of function ‘_’ [-Wimplicit-function-declaration] ./include/env.h:12:3: warning: nested extern declaration of ‘_’ [-Wnested-externs] ./include/env.h:12:21: warning: passing argument 2 of ‘err’ makes pointer from integer without a cast [-Wint-conversion]
login-utils/login.c static void init_environ(struct login_context *cxt) · line 1056
Quoted 9 lines
login-utils/login.c +4
-2if (pwd->pw_uid) -logindefs_setenv ("PATH" ,"ENV_PATH" , _PATH_DEFPATH); +if (logindefs_setenv ("PATH" ,"ENV_PATH" , _PATH_DEFPATH) !=0 ) +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ),"PATH" );else if (logindefs_setenv ("PATH" ,"ENV_ROOTPATH" ,NULL ) !=0 ) -logindefs_setenv ("PATH" ,"ENV_SUPATH" , _PATH_DEFPATH_ROOT); +if (logindefs_setenv ("PATH" ,"ENV_SUPATH" , _PATH_DEFPATH_ROOT) !=0 ) +err (EXIT_FAILURE ,_ ("failed to set the %s environment variable" ),"PATH" );
What about to use { } ?
login-utils/login.c: In function ‘init_environ’:
login-utils/login.c:1050:5: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses]
Fixed.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com