projects
/
gapil.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Aggiunta di nuovi valori per si_code
[gapil.git]
/
sources
/
test_linkat.c
diff --git
a/sources/test_linkat.c
b/sources/test_linkat.c
index b43fa231821a3cc12d181002f348768d97c4edcd..fbc06dc0881963d11835ddc10bbf1e560eaa2795 100644
(file)
--- a/
sources/test_linkat.c
+++ b/
sources/test_linkat.c
@@
-19,7
+19,9
@@
/****************************************************************
*
* Program test_linkat.c:
/****************************************************************
*
* Program test_linkat.c:
- * Program to test use of linkat and O_TMPFILE and other combinations
+ * Program to test use of linkat with an O_TMPFILE or linking another file
+ * using AT_EMPTY_PATH or AT_SYMLINK_FOLLOW on /proc/self/fd/N
+ * giving the option to wait to remove source file
*
* Author: Simone Piccardi
* Oct. 2018
*
* Author: Simone Piccardi
* Oct. 2018
@@
-42,6
+44,7
@@
#include <sys/types.h>
#include <fcntl.h>
#include <sys/types.h>
#include <fcntl.h>
+
/* Help printing routine */
void usage(void);
/* Help printing routine */
void usage(void);
@@
-95,13
+98,15
@@
int main(int argc, char *argv[])
}
char *path, *dir, *file;
char pattern[] = "prova prova prova\n";
}
char *path, *dir, *file;
char pattern[] = "prova prova prova\n";
+ char outbuff[2048];
path = strdup(argv[optind]);
file = basename(argv[optind]);
dir = dirname(argv[optind]);
path = strdup(argv[optind]);
file = basename(argv[optind]);
dir = dirname(argv[optind]);
- printf("
Working on dir %s file: %s\n
with path: %s\n",
+ printf("
Destination on dir %s file: %s\n
with path: %s\n",
dir, file, path);
int fd, newfd;
if ( ! srcfile ) {
dir, file, path);
int fd, newfd;
if ( ! srcfile ) {
+ // temp file with O_TMPFILE
fd = open(dir, O_TMPFILE|O_RDWR,S_IRUSR|S_IWUSR);
if ( fd <= 0 )
perror("cannot open TMPFILE");
fd = open(dir, O_TMPFILE|O_RDWR,S_IRUSR|S_IWUSR);
if ( fd <= 0 )
perror("cannot open TMPFILE");
@@
-110,28
+115,32
@@
int main(int argc, char *argv[])
else
printf("saved %d chars on fd %d\n", i, fd);
} else {
else
printf("saved %d chars on fd %d\n", i, fd);
} else {
- printf("source is %s\n", srcfile);
+ // user provided source
+ printf("source file is %s\n", srcfile);
if ( (fd = open(srcfile, O_RDONLY)) < 0 ) {
perror("cannot open source");
exit(1);
}
if ( (fd = open(srcfile, O_RDONLY)) < 0 ) {
perror("cannot open source");
exit(1);
}
+ printf("waiting %d second to remove the file\n", wait);
+ sleep(wait);
}
newfd = open(dir, O_PATH|O_RDWR);
int err;
err = linkat(fd, "", newfd, file, AT_EMPTY_PATH);
if ( err < 0 ) {
}
newfd = open(dir, O_PATH|O_RDWR);
int err;
err = linkat(fd, "", newfd, file, AT_EMPTY_PATH);
if ( err < 0 ) {
- perror("error on creating TMPFILE");
- printf("cannot link fd %d on fd %d
,
%s with AT_EMPTY_PATH\n",
+ perror("error on creating TMPFILE
with AT_EMPTY_PATH
");
+ printf("cannot link fd %d on fd %d
/
%s with AT_EMPTY_PATH\n",
fd, newfd, file);
char fdpath[PATH_MAX];
snprintf(fdpath, PATH_MAX, "/proc/self/fd/%d", fd);
fd, newfd, file);
char fdpath[PATH_MAX];
snprintf(fdpath, PATH_MAX, "/proc/self/fd/%d", fd);
- printf("
fd
path %s\n", fdpath);
+ printf("
Attempt to use AT_SYMLINK_FOLLOW with
path %s\n", fdpath);
err = linkat(AT_FDCWD, fdpath, newfd, file, AT_SYMLINK_FOLLOW);
if ( err < 0 ) {
perror("still error creating TMPFILE");
err = linkat(AT_FDCWD, fdpath, newfd, file, AT_SYMLINK_FOLLOW);
if ( err < 0 ) {
perror("still error creating TMPFILE");
- sleep(wait);
exit(1);
exit(1);
- }
+ } else {
+ printf("Success, fd %d on fd %d/%s created\n", fd, newfd, file);
+ }
if ( fchmodat(newfd, file,S_IRUSR|S_IWUSR,0) < 0 )
perror("Cannot change permission to new file");
}
if ( fchmodat(newfd, file,S_IRUSR|S_IWUSR,0) < 0 )
perror("Cannot change permission to new file");
}
@@
-142,10
+151,13
@@
int main(int argc, char *argv[])
* routine to print usage info and exit
*/
void usage(void) {
* routine to print usage info and exit
*/
void usage(void) {
- printf("Program testlinkat : test fopen for a file \n");
+ printf("Program testlinkat : test linkat for a file \n");
+ printf("Create a link to a tempfile or a link to -f indicated file");
printf("Usage:\n");
printf("Usage:\n");
- printf(" test
fopen [-h] file mod
e \n");
+ printf(" test
linkat [-h] destfilepathnam
e \n");
printf(" -h print this help\n");
printf(" -h print this help\n");
+ printf(" -w [N] wait N seconds\n");
+ printf(" -f [file] use file as source\n");
exit(1);
}
exit(1);
}