Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: add homedir() #1791

Merged
merged 1 commit into from
Jun 6, 2015
Merged

os: add homedir() #1791

merged 1 commit into from
Jun 6, 2015

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented May 25, 2015

Do not land this yet.

This PR adds os.homedir(), which calls libuv's uv_os_homedir() to retrieve the current user's home directory. This is an alternative to #1670. This PR currently consists of two commits. 6887116 is the libuv update, which has not landed in io.js yet. This commit should be removed once a proper update is in place. e7e5992 is the io.js update.

@silverwind silverwind added os Issues and PRs related to the os subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels May 25, 2015
char buf[MAX_PATH];
#else
char buf[PATH_MAX];
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node.h defines PATH_MAX on Windows so the #ifdef is probably not necessary here.

@Fishrock123 Fishrock123 mentioned this pull request May 25, 2015
} else if (!common.isWindows && process.env.HOME) {
assert.equal(home, process.env.HOME);
delete process.env.HOME;
assert.equal(home, os.homedir());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is a good assumption. I'd just check that it still returns something, possibly something that looks like a path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Updated.

@bnoordhuis
Copy link
Member

LGTM. You should probably run the CI before landing this.

@cjihrig
Copy link
Contributor Author

cjihrig commented May 25, 2015

I will once libuv is updated and I can remove the floating patch.

@rvagg
Copy link
Member

rvagg commented May 25, 2015

lgtm, the duplication in test-os.js seems unnecessary but I guess it's consistent with what's in there

@Fishrock123 Fishrock123 added the libuv Issues and PRs related to the libuv dependency or the uv binding. label May 26, 2015
@Fishrock123
Copy link
Contributor

Libuv 1.6.0 has landed. 👍

return -EIO;

uid = getuid();
buf = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, buf would be NULL only.

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 4, 2015

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 4, 2015

@rvagg the CI is still running, but I'm seeing some strange failures. Unable to compile on SmartOS, out of memory errors on FreeBSD, and too many files open on CentOS. Anything odd going on with the build?

@rvagg
Copy link
Member

rvagg commented Jun 4, 2015

@cjihrig eeek, not that I'm aware of, @jbergstroem has been tinkering on CentOS5 but not the others.

@jbergstroem
Copy link
Member

I'll have a look.

@jbergstroem
Copy link
Member

Affected os:es seems to hit file-max

freebsd: kern.maxfiles limit exceeded by uid 1003, please see tuning(7).
centos5: VFS: file-max limit 334442 reached

Jenkins has <100 file descriptors open which leads me to believe that ccache might try to. I can't say I've seen it previously, but I'll keep digging.

@jbergstroem
Copy link
Member

Looking at cat /proc/sys/fs/file-nr (or equivalents) at different machines; can't say I see it grow even close to limits while compiling.

@jbergstroem
Copy link
Member

(for reference, the run I'm measuring is here: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/767/)

@jbergstroem
Copy link
Member

So yeah, I'm unable to reproduce what happened at that specific run. Jenkins.

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 4, 2015

Added limits.h in https://github.com/cjihrig/io.js/commit/69c1c33348ac1803615c73e42bf7dfef3155a4a7#diff-2b7b259d26f297c87b7d71512e33ccecR14 to get the compile working on SmartOS. The CentOS failure seemed to be flakey. FreeBSD is still throwing ENOMEM. @bnoordhuis any clue why this might be happening (other than the obvious answer that the process is out of memory)?

Updated CI run: https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/769/

@bnoordhuis
Copy link
Member

I speculate it's because of this. :-)

(IIRC, I pointed that out in the review, that sysconf() can return < 0, but I'm not 100% sure. At any rate, bufsize is a size_t so the -1 wraps around and becomes SIZE_MAX.)

(EDIT: That may have been another PR, come to think of it.)

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 4, 2015

@bnoordhuis you did mention that. The data type for bufsize not being switched from size_t to long was my bad (I did add the check for bufsize <= 0, but didn't change the data type). Assuming that this is the problem, I'm curious why this didn't cause a problem with the libuv CI. And, do you think we should ditch the sysconf() call and use something else as the starting point for malloc()?

EDIT: this has a good example that calls sysconf() and falls back to a different value if it fails, although they also use a size_t to hold the return value :-)

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 4, 2015

@bnoordhuis you were right, so I added a37072b as a floating patch on libuv, and the CI is much happier now. Let me know how you want this handled in libuv.

@bnoordhuis
Copy link
Member

@cjihrig Left a comment. Can you file that as a libuv PR? We'll do a patch release for that.

@jbergstroem
Copy link
Member

Ah, should've tested the branch while searching for issues; I just assumed it was lingering processes or similar.

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 5, 2015

@bnoordhuis if I update the floating patch here, is this OK to land?

EDIT: Removed the floating patch since the libuv update PR was opened.

saghul added a commit to saghul/node that referenced this pull request Jun 5, 2015
@saghul
Copy link
Member

saghul commented Jun 5, 2015

@cjihrig FYI: #1905

bnoordhuis pushed a commit that referenced this pull request Jun 5, 2015
PR-URL: #1905
Refs: #1791
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 5, 2015

@Fishrock123
Copy link
Contributor

os.homedir() calls libuv's uv_os_homedir() to retrieve the current
user's home directory.

PR-URL: #1791
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
@cjihrig cjihrig merged commit 6e78e5f into nodejs:master Jun 6, 2015
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 6, 2015

It would help if I rebased the branch to include the libuv 1.6.1 update.

https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/775/ is all green.

Landed in 6e78e5f.

@cjihrig cjihrig deleted the homedir branch June 6, 2015 04:45
@rvagg rvagg mentioned this pull request Jun 11, 2015
rvagg added a commit that referenced this pull request Jun 13, 2015
Notable Changes:

* libuv: Upgraded to 1.6.0 and 1.6.1, see full ChangeLog for details.
  (Saúl Ibarra Corretgé) #1905 #1889. Highlights include:
  - Fix TTY becoming blocked on OS X
  - Fix UDP send callbacks to not to be synchronous
  - Add uv_os_homedir() (exposed as os.homedir(), see below)
* npm: See full release notes for details. (Kat Marchán) #1899. Highlight:
  - Use GIT_SSH_COMMAND (available as of Git 2.3)
* openssl:
  - Upgrade to 1.0.2b and 1.0.2c, introduces DHE man-in-the-middle protection
    (Logjam) and fixes malformed ECParameters causing infinite loop
    (CVE-2015-1788). See the security advisory for full details.
    (Shigeki Ohtsu) #1950 #1958
  - Support FIPS mode of OpenSSL, see README for instructions.
    (Fedor Indutny) #1890
* os: Add os.homedir() method. (Colin Ihrig) #1791
* smalloc: Deprecate whole module. (Vladimir Kurchatkin) #1822
* Add new collaborators:
  - Alex Kocharin (@rlidwka)
  - Christopher Monsanto (@monsanto)
  - Ali Ijaz Sheikh (@ofrobots)
  - Oleg Elifantiev (@Olegas)
  - Domenic Denicola (@domenic)
  - Rich Trott (@Trott)
@sindresorhus
Copy link

I made a polyfill for anyone wanting to use this while still supporting older node/io versions:
https://github.com/sindresorhus/os-homedir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants