mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
lint: replace getpwuid()
with getpwuid_r()
This commit is contained in:
parent
a92a7cbb9c
commit
f10e4f88b6
4 changed files with 12 additions and 17 deletions
|
@ -8,6 +8,3 @@ varFuncNullUB
|
|||
// the warning being suppressed. In other words this unmatchedSuppression
|
||||
// warnings are false positives.
|
||||
unmatchedSuppression
|
||||
|
||||
flockSemanticsWarning:src/env_universal_common.cpp
|
||||
flockSemanticsWarning:src/history.cpp
|
||||
|
|
|
@ -702,9 +702,12 @@ wcstring env_get_pwd_slash(void) {
|
|||
/// Set up the USER variable.
|
||||
static void setup_user(bool force) {
|
||||
if (env_get_string(L"USER").missing_or_empty() || force) {
|
||||
const struct passwd *pw = getpwuid(getuid());
|
||||
if (pw && pw->pw_name) {
|
||||
const wcstring uname = str2wcstring(pw->pw_name);
|
||||
struct passwd userinfo;
|
||||
struct passwd *result;
|
||||
char buf[8192];
|
||||
int retval = getpwuid_r(getuid(), &userinfo, buf, sizeof(buf), &result);
|
||||
if (!retval && result) {
|
||||
const wcstring uname = str2wcstring(userinfo.pw_name);
|
||||
env_set(L"USER", uname.c_str(), ENV_GLOBAL | ENV_EXPORT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,8 +141,11 @@ static wcstring get_runtime_path() {
|
|||
} else {
|
||||
const char *uname = getenv("USER");
|
||||
if (uname == NULL) {
|
||||
const struct passwd *pw = getpwuid(getuid());
|
||||
uname = pw->pw_name;
|
||||
struct passwd userinfo;
|
||||
struct passwd *result;
|
||||
char buf[8192];
|
||||
int retval = getpwuid_r(getuid(), &userinfo, buf, sizeof(buf), &result);
|
||||
if (!retval && result) uname = userinfo.pw_name;
|
||||
}
|
||||
|
||||
// /tmp/fish.user
|
||||
|
@ -1381,10 +1384,6 @@ std::unique_ptr<universal_notifier_t> universal_notifier_t::new_notifier_for_str
|
|||
case strategy_named_pipe: {
|
||||
return make_unique<universal_notifier_named_pipe_t>(test_path);
|
||||
}
|
||||
default: {
|
||||
debug(0, "Unsupported universal notifier strategy %d\n", strat);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,19 +176,15 @@ int killpg(int pgr, int sig);
|
|||
#endif
|
||||
|
||||
#ifndef HAVE_FLOCK
|
||||
/// Fallback implementation of flock in terms of fcntl
|
||||
/// Fallback implementation of flock in terms of fcntl.
|
||||
/// Danger! The semantics of flock and fcntl locking are very different.
|
||||
/// Use with caution.
|
||||
// Ignore the cppcheck warning as this is the implementation that it is
|
||||
// warning about!
|
||||
// cppcheck-suppress flockSemanticsWarning
|
||||
int flock(int fd, int op);
|
||||
|
||||
#define LOCK_SH 1 // Shared lock.
|
||||
#define LOCK_EX 2 // Exclusive lock.
|
||||
#define LOCK_UN 8 // Unlock.
|
||||
#define LOCK_NB 4 // Don't block when locking.
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue