diff options
author | Ulrich Drepper <drepper@redhat.com> | 2009-06-15 22:58:21 -0700 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2009-06-15 22:58:21 -0700 |
commit | 837dea7cf54827d6e43d88a9463bcc10d30472d0 (patch) | |
tree | fa098ddd11b46e739965bd7c238da91383354e3c /login/programs | |
parent | 292e3abebff9f94ca47c1a725a691cb6ed6cff5f (diff) | |
download | glibc-837dea7cf54827d6e43d88a9463bcc10d30472d0.tar.gz |
Optimize pt_chown.
Don't call chown and chmod if not necessary.
Diffstat (limited to 'login/programs')
-rw-r--r-- | login/programs/pt_chown.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/login/programs/pt_chown.c b/login/programs/pt_chown.c index 485eddabc9..5167b29225 100644 --- a/login/programs/pt_chown.c +++ b/login/programs/pt_chown.c @@ -1,5 +1,5 @@ /* pt_chmod - helper program for `grantpt'. - Copyright (C) 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by C. Scott Ananian <cananian@alumni.princeton.edu>, 1998. @@ -119,12 +119,13 @@ do_pt_chown (void) /* Set the owner to the real user ID, and the group to that special group ID. */ - if (chown (pty, getuid (), gid) < 0) + if (st.st_gid != gid && chown (pty, getuid (), gid) < 0) return FAIL_EACCES; /* Set the permission mode to readable and writable by the owner, and writable by the group. */ - if (chmod (pty, S_IRUSR|S_IWUSR|S_IWGRP) < 0) + if ((st.st_mode & ACCESSPERMS) != (S_IRUSR|S_IWUSR|S_IWGRP) + && chmod (pty, S_IRUSR|S_IWUSR|S_IWGRP) < 0) return FAIL_EACCES; return 0; |