Commit e12fd8f9 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm/cwd00: avoid resolving an abs path

We may not have permissions for this.
Reported-by: 's avatarRuslan Kuprieiev <kupruser@gmail.com>
Cc: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8f71344c
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h> #include <string.h>
#include "zdtmtst.h" #include "zdtmtst.h"
...@@ -14,12 +16,14 @@ TEST_OPTION(dirname, string, "directory name", 1); ...@@ -14,12 +16,14 @@ TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char cwd0[256], cwd1[256], cwd2[256]; char cwd1[256], cwd2[256];
int fd;
test_init(argc, argv); test_init(argc, argv);
if (!getcwd(cwd0, sizeof(cwd0))) { fd = open(".", O_DIRECTORY | O_RDONLY);
err("can't get cwd: %m\n"); if (fd == -1) {
err("Unable to open the current dir");
exit(1); exit(1);
} }
...@@ -52,8 +56,8 @@ int main(int argc, char **argv) ...@@ -52,8 +56,8 @@ int main(int argc, char **argv)
pass(); pass();
cleanup: cleanup:
/* return to the initial dir before writing out results */ /* return to the initial dir before writing out results */
if (chdir(cwd0)) { if (fchdir(fd)) {
err("can't change directory to %s: %m\n", cwd0); err("can't restore cwd");
exit(1); exit(1);
} }
if (rmdir(dirname)) { if (rmdir(dirname)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment