Use the thread-safe getpwuid_r() instead of getpwuid().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24751 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <libroot_private.h>
|
||||||
|
|
||||||
/* use pwents to find home */
|
/* use pwents to find home */
|
||||||
#define USE_PWENTS
|
#define USE_PWENTS
|
||||||
@@ -187,7 +188,7 @@ find_directory(directory_which which, dev_t device, bool createIt,
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (which) {
|
switch (which) {
|
||||||
/* Per volume directories */
|
/* Per volume directories */
|
||||||
case B_DESKTOP_DIRECTORY:
|
case B_DESKTOP_DIRECTORY:
|
||||||
@@ -279,6 +280,10 @@ find_directory(directory_which which, dev_t device, bool createIt,
|
|||||||
err = B_OK;
|
err = B_OK;
|
||||||
if (template) {
|
if (template) {
|
||||||
if (!strncmp(template, "$h", 2)) {
|
if (!strncmp(template, "$h", 2)) {
|
||||||
|
struct passwd pwBuffer;
|
||||||
|
char pwStringBuffer[MAX_PASSWD_BUFFER_SIZE];
|
||||||
|
struct passwd *pw;
|
||||||
|
|
||||||
if (bootDevice > -1 && device != bootDevice) {
|
if (bootDevice > -1 && device != bootDevice) {
|
||||||
int l = pathLength - strlen(buffer);
|
int l = pathLength - strlen(buffer);
|
||||||
if (l > 5)
|
if (l > 5)
|
||||||
@@ -286,11 +291,10 @@ find_directory(directory_which which, dev_t device, bool createIt,
|
|||||||
} else {
|
} else {
|
||||||
#ifndef _KERNEL_MODE
|
#ifndef _KERNEL_MODE
|
||||||
#ifdef USE_PWENTS
|
#ifdef USE_PWENTS
|
||||||
struct passwd *pw;
|
if (getpwuid_r(geteuid(), &pwBuffer, pwStringBuffer,
|
||||||
// WARNING getpwuid() might not be threadsafe...
|
sizeof(pwStringBuffer), &pw) == 0) {
|
||||||
pw = getpwuid(getuid());
|
|
||||||
if (pw)
|
|
||||||
home = pw->pw_dir;
|
home = pw->pw_dir;
|
||||||
|
}
|
||||||
#endif // USE_PWENTS
|
#endif // USE_PWENTS
|
||||||
if (!home) {
|
if (!home) {
|
||||||
/* use env var */
|
/* use env var */
|
||||||
|
|||||||
Reference in New Issue
Block a user