mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-11 20:48:49 +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
|
// the warning being suppressed. In other words this unmatchedSuppression
|
||||||
// warnings are false positives.
|
// warnings are false positives.
|
||||||
unmatchedSuppression
|
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.
|
/// Set up the USER variable.
|
||||||
static void setup_user(bool force) {
|
static void setup_user(bool force) {
|
||||||
if (env_get_string(L"USER").missing_or_empty() || force) {
|
if (env_get_string(L"USER").missing_or_empty() || force) {
|
||||||
const struct passwd *pw = getpwuid(getuid());
|
struct passwd userinfo;
|
||||||
if (pw && pw->pw_name) {
|
struct passwd *result;
|
||||||
const wcstring uname = str2wcstring(pw->pw_name);
|
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);
|
env_set(L"USER", uname.c_str(), ENV_GLOBAL | ENV_EXPORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,8 +141,11 @@ static wcstring get_runtime_path() {
|
||||||
} else {
|
} else {
|
||||||
const char *uname = getenv("USER");
|
const char *uname = getenv("USER");
|
||||||
if (uname == NULL) {
|
if (uname == NULL) {
|
||||||
const struct passwd *pw = getpwuid(getuid());
|
struct passwd userinfo;
|
||||||
uname = pw->pw_name;
|
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
|
// /tmp/fish.user
|
||||||
|
@ -1381,10 +1384,6 @@ std::unique_ptr<universal_notifier_t> universal_notifier_t::new_notifier_for_str
|
||||||
case strategy_named_pipe: {
|
case strategy_named_pipe: {
|
||||||
return make_unique<universal_notifier_named_pipe_t>(test_path);
|
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
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_FLOCK
|
#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.
|
/// Danger! The semantics of flock and fcntl locking are very different.
|
||||||
/// Use with caution.
|
/// 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);
|
int flock(int fd, int op);
|
||||||
|
|
||||||
#define LOCK_SH 1 // Shared lock.
|
#define LOCK_SH 1 // Shared lock.
|
||||||
#define LOCK_EX 2 // Exclusive lock.
|
#define LOCK_EX 2 // Exclusive lock.
|
||||||
#define LOCK_UN 8 // Unlock.
|
#define LOCK_UN 8 // Unlock.
|
||||||
#define LOCK_NB 4 // Don't block when locking.
|
#define LOCK_NB 4 // Don't block when locking.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue