Questions tagged [c]
C is a general-purpose computer programming language used for operating systems, games and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.
880 questions
1
vote
1
answer
39
views
Do I need to define an absolute path to be able to compile the DRM / Panfrost subtree code of JSM on the RockPro64 / Khadas Edge-V / RK3399?
I'm trying to compile the drm-subtree of JSM because I want to enable the panfrost driver on the RockPro64 / KHADAS EDGE-V / RK3399. The code is here:
https://github.com/jsm222/drm-subtree
He improved ...
2
votes
1
answer
155
views
Bash exception handling with a stack trace and cleanup code - how to implement?
When using the set -e flag in Bash, then it's difficult to get user-friendly error messages (a stack trace) and it's difficult to add cleanup code that executes before your script exits with an error ...
0
votes
1
answer
148
views
In one process, any way to know whether there exists any other same program is running? [duplicate]
So I am designing a feature to redirect log file if there are multiple processes of this very program are running.
I guess this requires me to somehow get to know whether there exists yet unfinished ...
1
vote
1
answer
124
views
If fprinting to stderr fails, which error code should a C program return? [closed]
Assume the following C snippet showing a piece of error handling:
#include <sysexits.h>
#include <stdio.h>
…
int main(int argc, char argv*[]) {
int retval=0;
…
if(3!=argc) { /* wrong ...
26
votes
3
answers
2k
views
Why does gmtime() give days 1-31, but months 0-11?
The 'gmtime()' standard library function returns a struct that has days numbered 1-31, but months numbered 0-11.
Why is that? Presumably there is some historic reason?
7
votes
1
answer
546
views
Syscalls required by glibc calls
Are there any lists compiled that provide a list of linux system calls used per function in a standard glibc build?
For example, free() requires mmap, munmap, mprotect, prlimit64, and brk.
If ...
2
votes
2
answers
131
views
Sudo doesn't work in my C wrapper
I’m trying to write a C wrapper to run a bash process. The goal of this wrapper is to apply a seccomp policy to restrict certain syscalls.
Here is the code:
#define _GNU_SOURCE
#include <stdio.h>...
0
votes
0
answers
107
views
Panfrost kernel driver on FreeBSD for rk3566?
We are two FreeBSD lovers and a stubborn system administrators.
We are trying to project a phone based on FreeBSD for several months.
Emanuel Vadot and Jesper Schmitz Mouridsen have enabled the ...
0
votes
2
answers
124
views
when opening a FIFO for reading+writing, and blocking - how to tell if other side opened for reading or writing?
If I open a fifo for reading+writing in blocking mode:
fd = open("foo", "O_RDWR");
Then it blocks until someone on the other end opens it for either reading or writing. But how do ...
0
votes
0
answers
65
views
Window move bound to display area
Trying to move a window by grip-able button. On 2 other window managers, and no manager it works fine. Windows move anywhere you want pass display edge bounds. On GNOME Shell and Mutter(Gala) the ...
0
votes
1
answer
66
views
Failed to register hook to tracepoint of signal_generate in Linux?
I am testing FTRACE in Linux VM (ubuntu 24.04) the kernel is Linux VirtualBox 6.11.0-26-generic.
I wrote a kernel module to register a hook (probe) to kernel tracepoint of signal_generate, here is the ...
0
votes
2
answers
87
views
Do race conditions occur during pathname resolution with constant string absolute path literals?
According to The Open Group Base Specifications Issue 8, on the rationale of the open() and openat() functions:
The purpose of the openat() function is to enable opening files in directories other ...
0
votes
1
answer
84
views
flock not working between forks on the same fd
I am working on a process that forks several times. To debug it, I am using a debug file for which I open a fd and which stays the same for all child forks. Then I have a function print_debug, that ...
0
votes
0
answers
61
views
Why does there appear to be a discrepancy when trying to programmatically access files associated with different tasks in Linux from kernel space?
As a way to better understand Linux kernel structures, interacting with and pulling information from these (and also getting more experience coding in C), I've been building simple kernel modules to ...
0
votes
0
answers
40
views
How many environments are stored in the stack? [duplicate]
When I used the getenv() function to get the address of USER, I got 0x7ffceae5e923 but when randomly checking the address using gdb, the $USER variable was stored at 0x7ffffffffe90e [ I started a ...
2
votes
1
answer
53
views
Why PAM modules are restricted from accessing keys on root keyring?
I'm writing a special PAM module that is supposed to authenticate user with a password stored in kernel keyring.
The key is added by running the following command as root:
keyctl add user some-key 123 ...
0
votes
0
answers
35
views
How does printf() actually work? [duplicate]
When I execute the c file
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("before the system call. I am too excited!\n");
system("ps");
...
0
votes
1
answer
68
views
how does Visual Studio Code resolve includes & macros for autocomplete & build?
If using only the C/++ Extension from Microsoft in Visual Studio Code, then how does preprocessing of includes & macros for autocomplete work? Many include headers (such as sys/statvfs.h), depend ...
2
votes
0
answers
60
views
Wrong attributes bitmask in READDIR requests on NFSv4.1
I'm struggling the following problem.
I have an NFS v4.1 mount, where I have a directory with a couple of thousands files. I'm trying to list their names and types. Even with a minimal example program ...
6
votes
1
answer
1k
views
Changing all strcpy to strscpy
I am learning about Linux kernel development. I have cloned into the stable branch of Linux. I watched a tutorial from Greg KH on youtube that explains you can use the checkpatch.pl script to find ...
0
votes
0
answers
96
views
Does a systemd service send org.freedesktop.DBus.Properties.PropertiesChanged signal at boot-up?
I have 2 systemd services.
a.service
b.service
b depends on a but I don't want to explicitly mention the dependency in b.service file.
Instead I am waiting on the
org.freedesktop.DBus.Properties....
0
votes
1
answer
147
views
Use libnm or popen(nmcli) to configure network programmatically?
We have a system where we need the user to be able to permanently change the network settings from the interface (via our C code), that used to be achieved by generating a new dhcpcd.conf file and ...
0
votes
0
answers
33
views
Hit noise when playing part of wave file with ALSA PCM interface
I am working a WAVE file playing with ALSA PCM interface in Linux, and I heard noise when I played the file quickly and partially.
Here is my playing function.
static int playback_function(uint8_t *...
0
votes
1
answer
31
views
Cannot see "file,line,func" fields in the journal
I am trying to use sd_journal_print_with_location() function.
#include <systemd/sd-journal.h>
int main() {
sd_journal_print_with_location(LOG_INFO, "CODE_FILE=tst_file.c", "...
2
votes
1
answer
310
views
Automatic flush of stream when reading input
I read in Advanced Programming in Unix Environment this:
Line buffering comes with two caveats. First, the size of the buffer
that the standard I/O library uses to collect each line is fixed, so
I/O ...
0
votes
0
answers
115
views
Send UDP data from one NIC and receive on another NIC on same machine
I have multiple NIC's on my Ubuntu machine.
$ ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 ...
0
votes
1
answer
645
views
Get output into journal in a C written service
I have a small service written in C on Debian.
This service automatically starts with Linux and does some file operations and other things as expected.
The service prints some informational messages ...
0
votes
0
answers
1k
views
There is no file linux/init.h
I'm trying to write my own pci-device driver on an Ubuntu system.
The example I found says that I need:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/pci.h>
I'm ...
0
votes
1
answer
46
views
Is mmap holding a reference to the OFD specified by POSIX, or a Linux extension, and where is it documented?
I am using Open File Description (OFD) owned locks on Linux (fcntl with command F_OFD_SETLK). After locking a file, I memory mapped it, and closed the file descriptor. Another process tried to lock ...
0
votes
1
answer
252
views
setuid not working with C code and system() call [duplicate]
I have NICE-DCV installed in RHEL-8.10 and as root doing a dcv list-sessions shows all sessions on the system. But if a user does dcv list-sessions then the output from that is only their session ...
0
votes
1
answer
175
views
Implement UDP packets filtering in C
I have a question on how to setup the filtering as described in the following scenario:
I see that systemd-resolved listens on port 53 and sends all the DNS requests to the real DNS resolvers.
I am ...
3
votes
2
answers
310
views
shell script to match a function in a file and replace it with another function in another file
I have files that contains multiple functions like below.
file1.c:
static void function1()
{
code
}
...
static void functionX()
{
code
}
...
static void lastFunction()
{
code
}
file2.c:
...
1
vote
0
answers
158
views
Arch Linux version & headers package don't line up
I'm trying to write a kernel module in C on ArchLinux. Installing the linux-headers package gives me the version 6.10.5-arch1-1 but running uname -r returns 6.10.5-arch2-1
How can I install the ones ...
1
vote
0
answers
235
views
Waking Qemu From Suspend With USB Device
I am doing research with Linux Power Management interactions with USB devices. Which is why I would like to be able to wake a qemu vm from suspend with a passed through USB device. I have been able to ...
1
vote
1
answer
174
views
Gedit Bracket match is out of range
Gedit matches brackets like { with } and tells us where the matching opening/closing bracket is. If it is more than 10000 characters, it says "Bracket match is out of range" instead. How ...
3
votes
2
answers
228
views
Is it possible for SIGALRM to be delivered after setitimer() disables the timer?
I have some code like this that has failed once on CI and once locally, though I cannot reproduce it reliably. The code is like this:
#include <stddef.h>
#include <signal.h>
#include <...
3
votes
2
answers
2k
views
Why is off_t signed?
On my journey to create a 16 EiB sized file,
I encountered the following issue:
POSIX defines files to have their size represented using type off_t,
and that "blkcnt_t and off_t shall be signed ...
9
votes
1
answer
2k
views
Does mtrace() still work in modern distros?
tldr: Does mtrace still work or am I just doing it wrong?
I was attempting to use mtrace and have been unable to get it to write data to a file. I followed the instructions in man 3 mtrace:
t_mtrace.c:...
1
vote
0
answers
135
views
File descriptors get corrupted when program runs in background
I have written a program for an embedded Linux system(petalinux). It runs fine when started from the terminal or TCF debugger.
However, I want it to run when the system starts, so I use the start-stop-...
1
vote
1
answer
659
views
Where do i trace NVME IO within the Linux driver?
I want to write a small Linux driver extension. More specific: I want to write all the communication between the host and a M.2-nvme-ssd into a userspace file. The nvme driver is pretty big though and ...
0
votes
0
answers
33
views
Does bash explicitly allow commands like passwd, su, etc., to run in setuid while disabling other custom binaries? [duplicate]
I know that /bin/bash has certain built-in protections that prevent the abuse of the Set-UID mechanism. So if I create a custom binary and execute it, it won't run with SUID 0 (refer the below image). ...
0
votes
0
answers
270
views
How to keep a shell alive after it gets started from inside a program?
I was not sure where to ask this question, since it is a mix of both programming and Linux, but hopefully this is the right place. I have written a simple program, which I'm buffer overflowing. I have ...
1
vote
0
answers
132
views
What safety CFLAGS does the Linux kernel use?
I have seen it said that the Linux kernel is built with -fwrapv to define signed integer overflow as wraparound, potentially sacrificing a tiny bit of performance in return for preventing the ...
0
votes
1
answer
414
views
Help with Makefile for C program
I'm trying to generate a new library that includes another one I have created previously.
In my current folder I have my source files inside a src folder and my headers inside an include folder.
This ...
38
votes
3
answers
7k
views
Single '#' in old C files
I started studying old C code (Unix v6) and I'm wondering what is the purpose of a single # in the beginning of the .c file. For example from https://github.com/lsahn-gh/unix-v6/blob/master/sys%2Fken%...
9
votes
5
answers
2k
views
Print all C comments to a separate text file
I would like to print all my C comments to a separate text file.
Using awk, sed, grep, or bash
output all multi-line C comments between /* ... */ (inclusive)
output lines with // comments
Optional: ...
0
votes
1
answer
194
views
compile error with tiny http server c code gcc debian
My distro is MX Linux (Debian)
GCC was already installed with distro.
I am trying to compile some open source code from Nir Lictman.
His Minimalist C web server code compiles in his YouTube video.
...
0
votes
3
answers
602
views
Making changes to the shared library
Suppose we have a C program that uses the shared library.
If you make changes to a shared library and rebuild it, all programs using that library will automatically receive those changes the next time ...
0
votes
0
answers
174
views
How do I identify the connected USB device?
If I write the rules, for example, in this form:
ACTION=="remove", GOTO="serial_end"
SUBSYSTEM!="tty", GOTO="serial_end"
KERNEL=="ttyUSB[0-9]*", RUN+=...
1
vote
1
answer
535
views
Reboot command doesn't invoke reboot system call?
OS is Debian.
As per my question here:
Is there a way to determine what process is rebooting a server?
I wrote a kernel module to intercept the reboot syscall via modifying the syscall table.
...