r/linuxdev • • May 10 '17

Application launcher, where to start?

3 Upvotes

Tried looking into some projects code but without succes finding what I need so I'm gonna ask here. How do application launchers and taskbars work?
How can I see which GUI applications are in the system and which are running (not talking about proceses, just opened visible GUI apps).


r/linuxdev • • Feb 23 '17

Logrotate for processes which never close log file descriptors

3 Upvotes

I was wondering what are my options when it comes to doing logrotate for processes which never close their file descriptors.

I am aware of the "restart the service" and copytruncate option. However, assuming that restarting the process is undesirable, the applications doesn't respond to SIGHUP, and copytruncate is not acceptable due to potential data loss, I'm not sure what options I have left.

One solution that came to mind is to have a named pipe already in place where the process is about to log to. Have another utility read from that pipe (copying to another log file) and have it react to the SIGHUP signal (from logrotate).

Now my question is, is there already a utiliy that I can use for this? If not, why? Is there something inherently wrong with this approach?

To test this out, I did 2 tests, one to confirm data loss with copy truncate, and one more to test my 'named pipe + uitility' approach:

Demonstrating copytruncate loss:

app.c

int main(int argc, char *argv[]) {
    FILE* f = fopen("log.txt", "a");
    int cnt = 0;
    for (int i = 0; i < 1000000; i++) {
	    for (int j = 0; j < 100; j++) {
            	fprintf(f, "Logging line %d\n", cnt);
	    	cnt++;
	    }
	    fflush(f);
    }
    fflush(f);
    fclose(f);
    printf("Wrote %d lines\n", cnt);
    return 0;
}

And an accompanying logrotate config:

$cat /etc/logrotate.d/logexp
/home/synepis/git/logexp/log.txt {
    size 20M
    create 700 synepis users 
    rotate 4
    copytruncate
}

Finally, I ran the application, during it's run I kicked off logrotate manually a few times via:

logrotate --force /etc/logrotate.d/logexp

App results:

./app
Wrote 100000000 lines

Log line count:

$ cat log.txt* | wc -l
69091700

Log utility approach:

I implemented a simple utility 'loghup' which creates a named pipe 'log.txt' and then simply reads of it to 'safe_log.txt'. Finally, it responds to SIGHUP by reopening the file (thus starting a new log rotation).

loghup.c

int sighup = 0;

void sig_handler(int signo) {
    if (signo == SIGHUP)
        sighup = 1;
}

void do_piping(char *input, char *output) {
    int fi = open(input, O_RDONLY);
    int fo = open(output, O_WRONLY | O_CREAT, 0644);
    
    size_t ret;
    char buff[4096];
    while((ret = read(fi, buff, 4096)) != 0) {
        if(ret == -1 && errno == EINTR) { // Retry later
            continue;
        } else if (ret == -1)  {
            break; // Error occured
        }
        
        write(fo, buff, ret);
    
        if (sighup) { // Reopen output log file on SIGHUP
            close(fo);
            fo = open(output, O_WRONLY | O_CREAT, 0644);
            sighup = 0;
        }
    }
    close(fo);
    close(fi);
}

int main(int argc, char *argv[]) {
    char *input_file = argv[1];
    char *output_file = argv[2];
    signal(SIGHUP, sig_handler); // Setup signal handler
    mkfifo(input_file, S_IRUSR | S_IWUSR);  // Create named pipe
    do_piping(input_file, output_file);
}

New logrotate config with SIGHUP:

 $cat /etc/logrotate.d/logexp 
 /home/synepis/git/logexp/safe_log.txt {
     size 20M
     create 700 synepis users 
     rotate 4
     postrotate
         /bin/kill -SIGHUP $(ps aux | grep "[l]oghup" | awk '{print $2}')
     endscript
 }

Then I ran:

 ./app
 ./loghup log.txt safe_log.txt

And forced logrotate a few times, finally:

 $ cat safe_log.txt* | wc -l
 100000000

r/linuxdev • • Sep 19 '16

Block Device Development Tutor?

3 Upvotes

Can someone refer me to an experienced Linux kernel developer who might be willing to teach me the finer details of implementing high performance Linux block devices?

I'm willing to pay a kernel dev to teach me over Skype, taking me through existing block device code such as: https://lwn.net/Articles/58720/ and linux/drivers/block/loop.c

I ultimately want to develop a block device that works somewhat like loop.c, but instead of the target being a filesystem image file, the target is a user mode process that manages the filesystem image (and can now provide instrumentation, encryption, etc). Does something like this already exist?

I am a decent C/C++ developer and Linux user with zero experience in kernel development.


r/linuxdev • • May 14 '16

Syncing aliases between Linux systems

3 Upvotes

As a student, or general Linux user, I find myself logging into multiple Linux systems. Over the years I have acquired useful aliases from professors, and some that I have personally added. I am thinking of creating some software, that could become a staple to the Linux environment, that would provide the syncing of aliases across multiple Linux systems.

It would, of course, deal with differing shell types, (csh, tcsh, bash, zsh, etc.), and would be able to convert between each type's own alias syntax.

More details on the features planned, are here on my github account: https://github.com/Proryanator/als

Some aliases can cut your use time in half, or even more. As much as some people find aliases to be a crutch for avoiding proper syntax, I disagree. I find myself typing the same combination of commands more often than not, so aliases are a must have for productivity.

I am curious, would this be something that other linux developers would find useful?

If there is something useful that already exists, please tell me! Or if as developers, this would be something you'd be interested in seeing get created, also good to hear! Any feedback is much appreciated!


r/linuxdev • • Jan 15 '16

[kernel] adding a controller to xpad.c?

3 Upvotes

So I have an old psx to usb controller that, while it works as a regular generic joystick device, I'd like to add to xpad.c in the linux kernel. I'm using Arch so I've been following the guide to compile specific modules. However, I cant seem to get it to work when I add it in the xpad module.

My USB device reports this info with lsusb.

I've tried adding the following line in my xpad.c file:

	{ 0x6666, 0x0667, "WiseGroup Smart Joy PSX, PS-PC Smart JoyPad", 0, DANCEPAD_MAP_CONFIG, XTYPE_XBOX },

which then looks like this. I then began gzipping and copying over the compiled module as per the guide. Yet the xpad module does not auto-load on reboot. dmesg and journalctl dont appear to throw any errors. modprobing xpad doesnt seem to map the joystick axis as buttons as I've requested it to do.

What am I doing wrong? I'm very new to building kernel modules. Have I named the usb device wrong is xpad.c?


r/linuxdev • • Dec 10 '15

syslog vs. rsyslog

3 Upvotes

Searching the internet for the difference between syslog and rsyslog gives quite a few results geared towards system admins, not for application developers. So, I'm coming to you people for help!

Setup: I am using Ubuntu 14.04 for my applications (building and running natively). When running this command:

ps -aux | grep syslog

I see these two processing running:

/usr/bin/pulseaudio --start --log-target=syslog
rsyslogd

Is my system using rsyslog instead of syslog? Can one/ should one run syslog and rsyslog at the same time? It still looks like my application logs are being written to /var/log/syslog.

From an application running on my system is an openlog(...) system call opening rsyslog instead of syslog? How do I know this?

As you can tell I'm kind of a noob so any extra info you can think of would be appreciated.


r/linuxdev • • Sep 07 '15

Pyvidia - Nvidia driver version detector for Linux

Thumbnail
github.com
3 Upvotes

r/linuxdev • • Apr 16 '15

Hi, r/linuxdev. I created a small program that allows a single terminal to display the contents of any other terminal's pwd.

3 Upvotes

If you work in the terminal and it looks interesting to you, give it a try and let me know of any comments/improvements

To install:

To use:

  • In one terminal run autols -s

  • In any other terminal that has the alias set up just use cd as you normally would

  • Run autols -e from any terminal to end

  • man autols available for reference

Edit 2: Version 2.1 available with the -p flag

Edit: Feel free to check out the source code here https://github.com/jacondel/autols It consists of two bash scripts (autocd & autols) and a man page


r/linuxdev • • Mar 26 '15

simulate accelerometer, gyroscope and gps.

3 Upvotes

Hi

I'm looking for a platform to simulate sensors ( with their errors and frequencies) : accelerometer, gyroscope, and GPS for Linux. and which give me the possibility to write my own scenarios.

any suggestions ?


r/linuxdev • • Mar 05 '15

Idea for a niche distro

3 Upvotes

Like many of you probably did, I grew up on MS-DOS. Dos didn't have a lot of the nice features we are used to. Expanded memory management, multiple processes, any sort of fault tolerance, a sane device manager, multiple users, security, and so on. But it was simple, and came with enough tools you could get stuff done.

With Linux, unless you were running a server, we never got a command line desktop OS. As soon as we got a working X11 server, that was that. Granted, you still had to go down to the command line to get things done, but that was done through a terminal window.

Another cool thing about DOS, in my mind, was that it was a viral OS. It had a SYS command that could be used to turn a floppy into a boot disk, and you could also run it from a boot disk against a hard drive.

Not only that, but DOS was also a batteries included OS. With Dos 5 and 6.22, it had...

  • a primitive scripting language (batch files)

  • a very usable text editor edit

  • qbasic - which was many people's first introduction to programming

  • a disk formatter and partitioner, among other utilities

Here are my thoughts on what a true desktop / laptop terminal based linux OS might look like.

  • viral at the source level - what does this mean? It means that with one master script you can grab the source, compile, and install/update the kernel, the system tools, and the userland. You should be able to do a complete install of this OS with just a single bash script. You should also be able to just update a single application with this tool as well.

  • an idea for distribution is that the disc iso itself could be the upgrade media. Meaning that either you supply a physical disc, or the OS grab an image from online, mounts it, and copies the necessary files from it to do the upgrade.

  • simple / custom init system. Not being a server and not being a full desktop means not having to bring in a lot of services.

  • minimal amount of kernel modules - i don't know what the minimum is, maybe have a custom kernel with a number of modules baked in.

  • use fbdev and fbset / or directfb + kms with open source drivers.

  • twin (or similar) instead of plain bash for the default environment. This could be heavily customized.

  • a suite of terminal based productivity software that comes with this OS. spread sheet, word processing, web browsing.

  • a software manual that comes with the software. Was thinking along the lines of a static wiki that can periodically be updated.

  • a control panel - maybe yast2? Something simple and n-curses based so very little fumbling around in bash will have to be done. Something to manage users, networks, printers, network file shares, etc. This could be combined with the master script.

  • python, or another simple language other than C.

Thoughts?


r/linuxdev • • Oct 01 '14

Question about readahead(2)

Thumbnail
reddit.com
3 Upvotes

r/linuxdev • • Sep 22 '14

Monitoring multiple TCP connections with select seems to be misbehaving.

3 Upvotes

I'm having difficulty monitoring multiple TCP connections in a non-blocking manner with select. I won't post code at first unless requested because there is really only one line in question and my code is in multiple files, some of which contain IP. I'm pretty sure the rest of it works fine.

I'm setting up a server and multiple clients which will communicate over TCP socket connections. My objective on the server side is to monitor the TCP socket for new connections as well as any established connections for new messages. I would like to do this in a non-blocking manner so I am using select to monitor the file descriptors. Anyway, after setting up the server with a non-blocking TCP connection I monitor the file descriptor with select. Then I run a client which attempts to connect to the server.

If my select line looks like this:

select((max_fd_num + 1), &readFDs, NULL, NULL, NULL)

it will block until it sees an incoming connection. I can then accept the connection correctly. That makes sense to me.

If, however, it looks like this:

struct timeval timeOutTime;
timeOutTime.tv_sec = 0;
timeOutTime.tv_usec = 0;
select((max_fd_num + 1), &readFDs, NULL, NULL, &timeOutTime)

and I have that select line in an infinite loop with some other stuff, it never returns anything other than 0. So i never see the connection. Since I don't want to block this would be the preferred method but it never seems to think that the connection is ready. The client seems to think that it connected correctly so it's very strange.

Help, please.

edit: I figured it out. Apparently I have to set up readFDs again before every time I call select. I guess select modifies this value when it's finished. The man pages aren't very clear on this. Thanks anyway.


r/linuxdev • • Sep 11 '14

A simple systemd opinion survey

Thumbnail
docs.google.com
3 Upvotes

r/linuxdev • • Jul 07 '14

Cant understand the "top" command.

3 Upvotes

Can someone please explain how to read the cpu load from the "top" command? It doesn't really make sense to me.

http://puu.sh/a0kCq/a517681017.png

Thanks!


r/linuxdev • • May 09 '14

Command line interface to daemon communication

3 Upvotes

I'm used to developing embedded applications with no operating system so I'm always writing my own drivers tailored to my specific application. I usually run a simple super loop program written in C with no wait states (Sending serial comm via DMA, delaying my main application layer with countdown timers in my own timer interrupts, etc.) I generally don't use things like printf and scanf for my serial input and output because I write my own drivers and sometimes compilers handle these in funny ways. Anyway, apparently these skills don't translate well to what I'm trying to do with some linux applications I'm writing…..

I am writing two linux applications with a shared memory space so I can communicate between the two processes. They are both in the same folder within my file structure. One of the applications, when run, enters a command line interface that I created. So I run ./MyCLI and that enters an infinite while loop application where I am allowing the user to input data with this.

scanf("%[\n]%*c", input); //wait for user input followed by enter

I take this input and stuff it in the shared memory space for the other application to process. Then I wait for the other process to return a result in a buffer and I print the result. Then I return to waiting for more user input.

That brings us to the second application…..

The second application runs as a daemon. (a child process with the standard input and output closed). The daemon takes the information from the first process in the shared memory, does some processing, and returns a result in the shared memory space.

This works great if you always want to get user input and have the daemon return a result when it's done processing However, I would like to send messages from the daemon periodically without the user entering anything. The problem in my program is that I'm sitting waiting in scanf for user input before I check to see if the daemon has any information to print.

So I guess my question is how do I get my first process to gather user input while also checking the shared memory space for daemon results/output.

Thanks in advance.

Also, All of the shared memory, setting up the daemon, and running applications, etc are set up correctly so I'm not worried about that. I'm not going to submit my whole code set because I want this to be a more high level discussion.

Edit: After quite a bit of research I found that POSIX message queues will fit my application perfectly. I do like the sockets idea, and I definitely see the benefit, but MQs will work for me just fine. Thanks to all the commenters.


r/linuxdev • • Apr 07 '14

Is there a course on text user interface design? /r/learnprogramming x-post

3 Upvotes

I am a Linux sysadmin, and I have been finding myself writing a bunch of scripts as of late. I want them usable to other people.

I am writing man page documents for them, but I want the tools easy to interpolate with other command line tools. Is there some kind of design or best practices book or course for this?


r/linuxdev • • Dec 12 '13

Ubiquity (KDE/Qt version) components? (x-post from /r/Linuxquestions)

Thumbnail
reddit.com
3 Upvotes

r/linuxdev • • Dec 11 '13

Information on respinning Ubuntu/Ubuntu derivatives?

3 Upvotes

I recall a resource on (I think) the Ubuntu Community Wiki that talked about using a Chrooted ISO as a basis for making an Ubuntu respin. Sadly I can't seem to find it. Is there any information on respinning Ubuntu or its derivatives with the Chrooted ISO method?

Edit: never mind, here's the tutorial.


r/linuxdev • • Oct 06 '12

Can we do dynamic linking for an LKM?

3 Upvotes

That is, can a driver try to import a symbol for another driver, and if the symbol doesn’t exist can the driver continue to load without resolving the import?


r/linuxdev • • Sep 14 '12

Looking for feedback / contributors for Sunfish -- a new Linux Userland based on Mono

Thumbnail
github.com
3 Upvotes

r/linuxdev • • Jun 26 '12

Excellent introduction to Linux Device Drivers

Thumbnail
linuxforu.com
3 Upvotes

r/linuxdev • • Mar 26 '12

This bug has bothered me for years

3 Upvotes

When I run ssh over terminal in linux it feels more laggy than on a textmode (getty/ctrl-alt-f1) console. Often I wait long seconds to see keypresses on screen, but if I hit a key (any key, say ctrl) they show up instantly.

I've had this problem across three different desktop/laptop systems spanning 9 years and multiple distributions. But I've never been able to search for it online. Has anybody else had this experience? Please tell me I'm not dreaming, somebody..

Given how long the issue has persisted, I think it's got something to do with how applications communicate with the X server. Any ideas on how one would go about debugging something like this?

Update: It turns out I was not on gnome-terminal but something called xfce4-terminal that looks exactly the same. After I switched to gnome-terminal I've stopped seeing the problem.


r/linuxdev • • Sep 30 '26

Motif X11 framework dev complete tutorial

Thumbnail
youtube.com
2 Upvotes

r/linuxdev • • Mar 28 '26

Detecting camera on/off events for Linux and controlling lights automatically with eBPF

Thumbnail shuhaowu.com
2 Upvotes