Questions tagged [fcntl]

fcntl refers to a function that provides control over the open file referenced by a file descriptor

fcntl refers to a function that provides control over the open file referenced by a file descriptor.

234 questions
2
votes
1 answer

F_SEAL_SEAL undeclared, even when headers are included

I'm trying to use file sealing on Linux. Here's an example C program. #define _GNU_SOURCE #include #include int main(void) { (void)F_SEAL_SEAL; } You can build it using gcc -Wall -o ./linux_file_sealing…
Tom Seddon
  • 2,648
  • 1
  • 19
  • 28
2
votes
2 answers

Why fcntl() flag values are defined in Octal format & how this function works for blocking/non-blocking sockets?

// "fcntl-linux.h" (with few lines skipped): /* open/fcntl. */ #define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_APPEND 02000 #define O_NONBLOCK 04000 #define O_SYNC …
iammilind
  • 68,093
  • 33
  • 169
  • 336
2
votes
0 answers

Python retrieve and configure remote network interface using socket.socket

I am trying to configure network interfaces on remote machines using python. The surrounding context is that I have a service that provisions VM instances and is required to create appropriate network interfaces on the VM host for the instance to…
Da Kr
  • 41
  • 4
2
votes
1 answer

C alternative to fputs()/fgets() with open()

I'm learning about kernel modules communicating with user level programs and originally was opening a file with FILE *pFile = fopen(...) and writing to it with char *str = malloc(10); fputs(str, pFile); However now I need to use functionality in…
Austin
  • 6,921
  • 12
  • 73
  • 138
2
votes
1 answer

why glibc fcntl is implemented as this?

all;I'm looking the glibc source code now;i have a question is this: int fcntl(int fd, int cmd, ...) { va_list ap; va_start(ap, cmd); void* arg = va_arg(ap, void*); va_end(ap); return __fcntl64(fd, cmd, arg); } why this…
qwertimg
  • 23
  • 3
2
votes
1 answer

What happen when I lock file located on remote storage via fcntl?

I just wonder. I have two processes on two different servers. Those processes write information to the same file and use locking via fcntl for synchronization. What happen if one of processes will be aborted and it owned file lock? How NFS server…
user275402
  • 175
  • 1
  • 1
  • 6
2
votes
1 answer

fcntl F_GETLK always return true

i'm trying to make a single instance daemon using a lock file but fcntl() doesn't seem to work as expected... int creat_lock_file (char * pid_fn) { struct flock pid_lck = {F_WRLCK, SEEK_SET, 0, 0, 0 }; /* Open/Create pid file */ …
2
votes
1 answer

strerror(errno) return "Invalid argument" when call read() & write()

I try to access a file in android by native method, but i got "Invalid argument" after call read or write function. The data_ptr is align to 512 bytes and it is declared as byte array in java. JNIEXPORT jint…
Hsin-Hsiang
  • 411
  • 1
  • 3
  • 13
2
votes
3 answers

what's the purpose of fcntl with parameter F_DUPFD

I traced an oracle process, and find it first open a file /etc/netconfig as file handle 11, and then duplicate it as 256 by calling fcntl with parameter F_DUPFD, and then close the original file handle 11. Later it read using file handle 256. So…
Daniel
  • 621
  • 3
  • 9
  • 18
2
votes
2 answers

C++ Strings in Read Function from fcntl.h

In my basic Linux Programming course at college, we use fcntl.h and unistd.h Using C++ strings, I get the following: statusOfFunction = write(fileDescriptor, input.c_str(), input.length()); This line works. I get a file created, with the contents…
2
votes
1 answer

file lock in unix system using c and fcntl

I'm trying to learn programming c in unix. So I read through Beejs Guide and tried to learn more about file locking. So I just took some Code example from him and tried to read out if the file is locked or not but every time I do, I get errno 22…
user1550036
  • 211
  • 1
  • 3
  • 9
2
votes
0 answers

Implementing dup and dup2 using fcntl

I'm implementing dup and dup2 using fcntl, that what I have coded : int dup(int oldfd) { return fcntl(oldfd, F_DUPFD, STDERR_FILENO); } int dup2(int oldfd, int newfd) { if(oldfd == newfd) return oldfd; if(fcntl(oldfd, F_GETFD)…
KarimS
  • 3,812
  • 9
  • 41
  • 64
2
votes
1 answer

In what way is fcntl.lockf() locking a file?

I'm currently attempting to lock a file via python so other processes cannot even read it. So far i was testing behavior of fcntl.lockf() via python interpreter: >>> file = open("/path/to/file", "w") >>> fcntl.lockf(file.fileno(), fcntl.LOCK_EX |…
1
vote
0 answers

Using open() from fcnt.h - do not create file if already exists

I am writing a c file where the user runs it from the terminal (centos) and it gets on argument in argv, argv[1] = "FileName.txt". The code supposes to print the file's content only if the file does exist. I am only allowed to use for…
eladgl
  • 69
  • 8
1
vote
1 answer

How to check if stdin is closed?

I am writing a program which currently gets continuous input from stdin and does something with it until stdin is closed. fgets(buffer, BUFFERSIZE, stdin); while(fcntl(fileno(stdin), F_GETFD) != -1 || errno != EBADF){ /* some code */ …