Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Fixed bug in bstg_fdstore_get2 with opening directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirk Russell committed Dec 31, 2015
1 parent 0729b97 commit 51f1d3b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/funcs/list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ special/move.c
src/chown/fchown.c
src/chmod/fchmod0770.c
src/chmod/fchmod07770.c
src/chdir/chdir.c
src/chdir/fchdir.c
24 changes: 24 additions & 0 deletions src/funcs/src/chdir/chdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

int cwdfd;

if ((cwdfd = open(".", O_RDONLY)) > 0) {
chdir(bstg_pathstore_get());
fchdir(cwdfd);
close(cwdfd);
}

__RCSID("$Id$");
24 changes: 24 additions & 0 deletions src/funcs/src/chdir/fchdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

int cwdfd;

if ((cwdfd = open(".", O_RDONLY)) > 0) {
fchdir(bstg_fdstore_get(ps));
fchdir(cwdfd);
close(cwdfd);
}

__RCSID("$Id$");
10 changes: 10 additions & 0 deletions src/lib/bstg.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@
#include <bsd/stdlib.h>
#endif

#ifdef __QNXNTO__
#ifndef O_NOACCESS
#define O_NOACCESS O_ACCMODE
#endif
#endif

#ifndef O_NOACCESS
#define O_NOACCESS O_RDONLY
#endif

#endif
17 changes: 12 additions & 5 deletions src/lib/fdstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,25 @@ bstg_fdstore_set(bstg_fdstore_t *ps, int fd)
int
bstg_fdstore_get2(bstg_fdstore_t *ps, int flags)
{
int fd;
int fd, x;
static int omodes[4] = { O_RDWR, O_WRONLY, O_RDONLY, O_NOACCESS };
enum { number_of_modes = sizeof(omodes)/sizeof(omodes[0]) } ;

if ((fd = bstg_fdstore_getraw(ps)) > 0) {
return fd;
}

/*
* There are no valid fds in the set.
* Give it one more try to create a valid fd.
* There are no valid fds in the set. Try to create a valid fd.
*/
return bstg_fdstore_set(ps, open(bstg_pathstore_get(),
O_RDWR | O_NONBLOCK | O_NOCTTY | flags, 0777));
for (x = 0; x < number_of_modes; x++) {
if ((fd = open(bstg_pathstore_get(),
omodes[x] | O_NONBLOCK | O_NOCTTY | flags, 0777)) > 0) {
return bstg_fdstore_set(ps, fd);
}
}

return -1;
}


Expand Down

0 comments on commit 51f1d3b

Please sign in to comment.