Fix compiler warnings on some platforms and provide a better method

of defeating gcc's warn_unused_result attribute.
This commit is contained in:
Todd C. Miller
2012-03-29 10:33:40 -04:00
parent 8393ec0501
commit aecb5206e2
11 changed files with 117 additions and 99 deletions

View File

@@ -67,6 +67,8 @@ rpl_getenv(const char *name)
return val;
}
typedef char * (*sudo_fn_getenv_t)(const char *);
char *
getenv(const char *name)
{
@@ -79,9 +81,9 @@ getenv(const char *name)
return NULL;
default: {
#if defined(HAVE_DLOPEN) && defined(RTLD_NEXT)
char * (*fn)(const char *);
sudo_fn_getenv_t fn;
fn = dlsym(RTLD_NEXT, "getenv");
fn = (sudo_fn_getenv_t)dlsym(RTLD_NEXT, "getenv");
if (fn != NULL)
return fn(name);
#endif /* HAVE_DLOPEN && RTLD_NEXT */
@@ -132,6 +134,8 @@ rpl_putenv(PUTENV_CONST char *string)
return 0;
}
typedef int (*sudo_fn_putenv_t)(PUTENV_CONST char *);
int
putenv(PUTENV_CONST char *string)
{
@@ -142,9 +146,9 @@ putenv(PUTENV_CONST char *string)
return -1;
default: {
#if defined(HAVE_DLOPEN) && defined(RTLD_NEXT)
int (*fn)(PUTENV_CONST char *);
sudo_fn_putenv_t fn;
fn = dlsym(RTLD_NEXT, "putenv");
fn = (sudo_fn_putenv_t)dlsym(RTLD_NEXT, "putenv");
if (fn != NULL)
return fn(string);
#endif /* HAVE_DLOPEN && RTLD_NEXT */
@@ -195,6 +199,8 @@ rpl_setenv(const char *var, const char *val, int overwrite)
return rpl_putenv(envstr);
}
typedef int (*sudo_fn_setenv_t)(const char *, const char *, int);
int
setenv(const char *var, const char *val, int overwrite)
{
@@ -205,9 +211,9 @@ setenv(const char *var, const char *val, int overwrite)
return -1;
default: {
#if defined(HAVE_SETENV) && defined(HAVE_DLOPEN) && defined(RTLD_NEXT)
int (*fn)(const char *, const char *, int);
sudo_fn_setenv_t fn;
fn = dlsym(RTLD_NEXT, "setenv");
fn = (sudo_fn_setenv_t)dlsym(RTLD_NEXT, "setenv");
if (fn != NULL)
return fn(var, val, overwrite);
#endif /* HAVE_SETENV && HAVE_DLOPEN && RTLD_NEXT */
@@ -252,6 +258,12 @@ rpl_unsetenv(const char *var)
#endif
}
#ifdef UNSETENV_VOID
typedef void (*sudo_fn_unsetenv_t)(const char *);
#else
typedef int (*sudo_fn_unsetenv_t)(const char *);
#endif
#ifdef UNSETENV_VOID
void
unsetenv(const char *var)
@@ -263,9 +275,9 @@ unsetenv(const char *var)
return -1;
default: {
#if defined(HAVE_UNSETENV) && defined(HAVE_DLOPEN) && defined(RTLD_NEXT)
void (*fn)(const char *);
sudo_fn_unsetenv_t fn;
fn = dlsym(RTLD_NEXT, "unsetenv");
fn = (sudo_fn_unsetenv_t)dlsym(RTLD_NEXT, "unsetenv");
if (fn != NULL)
fn(var);
else
@@ -285,9 +297,9 @@ unsetenv(const char *var)
return -1;
default: {
#if defined(HAVE_UNSETENV) && defined(HAVE_DLOPEN) && defined(RTLD_NEXT)
int (*fn)(const char *);
sudo_fn_unsetenv_t fn;
fn = dlsym(RTLD_NEXT, "unsetenv");
fn = (sudo_fn_unsetenv_t)dlsym(RTLD_NEXT, "unsetenv");
if (fn != NULL)
return fn(var);
#endif /* HAVE_UNSETENV && HAVE_DLOPEN && RTLD_NEXT */

View File

@@ -604,8 +604,7 @@ handler(int s)
* The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice.
*/
if (write(signal_pipe[1], &signo, sizeof(signo)) == -1)
/* shut up glibc */;
ignore_result(write(signal_pipe[1], &signo, sizeof(signo)));
}
#ifdef SA_SIGINFO
@@ -626,8 +625,7 @@ handler_nofwd(int s, siginfo_t *info, void *context)
* The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice.
*/
if (write(signal_pipe[1], &signo, sizeof(signo)) == -1)
/* shut up glibc */;
ignore_result(write(signal_pipe[1], &signo, sizeof(signo)));
}
}
#endif /* SA_SIGINFO */

View File

@@ -695,11 +695,9 @@ pty_close(struct command_status *cstat)
io_fds[SFD_USERTTY] : STDOUT_FILENO;
if (write(n, reason, strlen(reason)) != -1) {
if (WCOREDUMP(cstat->val)) {
if (write(n, " (core dumped)", 14) == -1)
/* shut up glibc */;
ignore_result(write(n, " (core dumped)", 14));
}
if (write(n, "\n", 1) == -1)
/* shut up glibc */;
ignore_result(write(n, "\n", 1));
}
}
}
@@ -961,8 +959,7 @@ exec_monitor(struct command_details *details, int backchannel)
exec_pty(details, &errpipe[1]);
cstat.type = CMD_ERRNO;
cstat.val = errno;
if (write(errpipe[1], &cstat, sizeof(cstat)) == -1)
/* shut up glibc */;
ignore_result(write(errpipe[1], &cstat, sizeof(cstat)));
_exit(1);
}
close(errpipe[1]);

View File

@@ -298,8 +298,7 @@ getln(int fd, char *buf, size_t bufsiz, int feedback)
}
continue;
}
if (write(fd, "*", 1) == -1)
/* shut up glibc */;
ignore_result(write(fd, "*", 1));
}
*cp++ = c;
}