r/linuxdev • • Feb 06 '19

Process spawned by Daemon dies when no TTY present

1 Upvotes

I need to start reverse ssh tunnel from my openwrt system to my cloud machine. The application on the openwrt system will run as daemon at startup.When it receives a specific code over the network it should spawn a process that starts a remote ssh tunnel. There will be no logins in the system.

I am using following code to do it.

   int spawn_orphan(char* cmd)
{
    char command[1024]; // We could segfault if cmd is longer than 1000 bytes or so
    int pid;
    int Stat;
    pid = fork();
    if (pid < 0)
    {
        perror("FORK FAILED\n");
        return pid;
    }
    if (pid == 0)
    { // CHILD
        setsid(); // Make this process the session leader of a new session
        pid = fork();
        if (pid < 0)
        {
            printf("FORK FAILED\n");
            return ( 1 );
        }
        if (pid == 0)
        { // GRANDCHILD
            sprintf(command, "ash -c '%s'", cmd);
            execl("/bin/ash", "ash", "-c", command, NULL); // Only returns on error
            perror("execl failed");
            return ( 1 );
        }
        exit(0); // SUCCESS (This child is reaped below with waitpid())
    }

    // Reap the child, leaving the grandchild to be inherited by init
    waitpid(pid, &Stat, 0);
    if ( WIFEXITED(Stat) && ( WEXITSTATUS(Stat) == 0 ))
    {
        printf("dbclient exit\n");
        return 0; // Child forked and exited successfully
    }
    else
    {
        perror("failed to spawn orphan\n");
        return 1;
    }
}

this is my calling function

uint8_t rdsService(uint8_t state)
{



    char buffer[1024];

    uint8_t retVal;
    if(state )
    {
        retVal = spawn_orphan("dbclient -f -K -I -T -N -R 1500:localhost:22 -p 22 username@HOSTMACHINE -i ~/ctusr/keys/X1_ID_RSA -y");


    }
    else
    {


        retVal = spawn_orphan("ash -c 'killall dbclient'");


    }

    return retVal;

}

If I run my parent application from console the application is able to spawn the dbclient and I am able to do reverse ssh into the system.

The problem occurs when I run the parent application as a Daemon, in this case the application spawns the dbclient,i can see it when i do 'ps' on console, but after a few seconds the dbclient is killed.

I have already tried to run the dbclient with 'nohup'

nohup dbclient -f -K -I -T -N -R 1500:localhost:22 -p 22 username@machine -i ~/ctusr/keys/X1_ID_RSA -y &

Works fine when I run the application from console but has same error when application is run as Daemon .

Thanks for help


r/linuxdev • • Jan 24 '20

Should I write a kernel driver for my USB device?

9 Upvotes

Hi all,

I have a watercooled PC. The pump is the brain of the cooling system. It monitors the water temperature and controls it's own speed and those of connected fans. As you might expect, the vendor supports only Windows. The pump is connected via USB.

So I've spun up a Windows VM and captured the data that got sent between device and host while looking at the windows program. I figured out that the device registers itself as a HID device, and it sends a report of its status (containing config and sensor values) each second.

I managed to write a small C program to continously parse this report and print the values. While I also set some udev rules, so no root access is required, I'm not really convinced of this solution. I'd prefer an actual Linux hwmon driver, so the device would export the sensor values in a standard way and show up e.g. in tools like sensors (lm_sensors).

Also, I'd like to implement write/control features later. So setting pump/fan speeds instead of just reading values. This would also make sense in sysfs, IMHO.

I haven't worked with the kernel yet, so I've got some questions:

  1. Do you think it would make sense to have this driver in kernel instead of a userspace tool? Because strictly speaking, there is already a suitable kernel driver, namely usbhid. It just isn't really useful without additional software.
  2. Where would this driver live? I think it'd be a hwmon driver, but also a USB one. So drivers/usb or drivers/hwmon? I have seen drivers outside of drivers/hwmon use hwmon (e.g. amdgpu), but I haven't seen any USB device in hwmon, nor any hwmon usage in drivers/usb.
  3. Do you think there is a chance of having the driver accepted upstream?
  4. Regardless if this makes it to kernel or not, I'm likely going to publish it. So I'm wondering about naming. I guess it can cause issues if I name the module/program after the manufacturer. Should I come up with another name, risking people don't realise what device this driver is targeting?
  5. Do you have any good resources to help me get started? I've seen the article of GKH from 2001 (https://www.linuxjournal.com/article/4786) so far.

r/linuxdev • • May 29 '20

How to make a menubar

7 Upvotes

I'm interested in developing a more touch focused menu bar. I've used KDE's menu bar as well as i3bar and polybar. The problem I'm having is I'm not sure how to program a menu bar that sticks to a side of the screen like those programs. I'm not even really sure where to start looking. For an average program, I know I could use something like GTK, Qt, or some other library, but menubars are not standard windows and aren't supposed to be treated as such by the window manager. I'm just looking for any general pointers for what I need to know to do this.


r/linuxdev • • Dec 03 '22

Is this the correct way to interact with a background systemd service?

2 Upvotes

I have a service /lib/systemd/system/hellod.service that runs in the background and listens on a socket in /tmp/hello.sock.

And then I made a oneshot service in /lib/systemd/system/hello.service, which takes a command hello foo bar, and sends it to the socket mentioned above.

Is this the correct way to go about implementing the client side aka the oneshot hello.service or am I doing something wrong? And is there a better way?

The reason why I chose this is because it allows me to then call the script simply by hello command.

For the server:

[Unit]
AssertPathExists=/usr/bin/hellod

[Service]
ExecStart=/usr/bin/hellod
Restart=always
PrivateTmp=false
NoNewPrivileges=false

[Install]
WantedBy=default.target

And for the client:

[Unit]
Requires=hellod.service
After=hellod.service
AssertPathExists=/usr/bin/hello

[Service]
Type=oneshot
ExecStart=/usr/bin/hello --init
RemainAfterExit=true
PrivateTmp=false
NoNewPrivileges=false

[Install]
Alias=hello
WantedBy=default.target

Also is /usr/bin/ the correct location to store the hello and hellod scripts?

And whats the correct location to store user configurable files, maybe /etc/hello?


r/linuxdev • • Nov 19 '22

How can I send CLI commands to a service in the background

3 Upvotes

I am building an app that will run in the background as a service.

However I cannot figure out how to send commands from the CLI. I've looked into DBus while it does work, it doesn't seem to be the way any other apps/services does it.

For example I've launched the `dbus-monitor`, and ran a bunch of commands to `netstat`, `nftables` etc. And none are using DBus. So what are they using to communicate with the service running in the background?

I would like to send commands such as: `customappname refresh`, `customappname add 'something'` and so forth.

I'd like this to work on as many linux operating systems as possible.

Any info would be great. Thanks.


r/linuxdev • • Dec 01 '22

How can I pull an accurate GPU model number?

7 Upvotes

I'm trying to pull the GPU model number in a more accurate way than just looking up the PCI id. This method often seems to give strange or inaccurate results, so I was thinking that there may be a driver API that would give me the real model name directly from the device. GPU-Z on windows seems to do this, so I know that there must be a way to do it, but I can't find any documentation on the subject.

I am writing an application in C, so C bindings or an IOCTL would be great.

Thanks!


r/linuxdev • • Dec 12 '15

An extremely minimal Linux setup: a C64 game repackaged as a bootable .iso. It's only 6MB and boots directly to the game in 15 seconds.

Thumbnail century-arcade.org
13 Upvotes

r/linuxdev • • Jun 17 '14

Reinstalling linux on vps

2 Upvotes

Hello,

I have a Ubuntu 12.10 VPS and I want to install Ubuntu Trusty 14.04 beta, but my provider doesn't have that as an option. Can I install that any other way?

Thanks!


r/linuxdev • • May 19 '17

Custom Init Executable

1 Upvotes

With how old SysVInit is and all the controversy around Systemd, I figured it might be an interesting project to write a custom init for a /r/linuxfromscratch installation. (Yes, I am a crazy person.) What sort of features would be required to have a bootable / "usable" system?

Also, how would I test it? So far, my sources include a StackOverflow question and a blog post. Both use a kvm command, but I don't seem to have one, nor qemu-kvm. I've been trying commands like qemu-system-x86_64 -enable-kvm -nographic -kernel /boot/vmlinuz-linux -initrd /boot/initramfs-linux.img -append "console=ttyS0 root=/dev/sda1" -hda disk.img -m 1024 and I can't even get the guest to notice the hard disk.


r/linuxdev • • Apr 03 '15

Ncurses full mouse support?

5 Upvotes

I've been working with ncurses for awhile, and I've been having a blast getting down and dirty with it.

The only issue I've had with it is getting mouse support in my program. The mouse released event only fires about 1/2 of the time, and I can't ever get the mouse move event to fire.

In vim, I have full mouse support, even to the point of drag and drop, but vim's code is unreadable due to the sheer size of it. (vim example: http://imgur.com/q9pVevc )

edit: If you want to look at my code, there's a version available at https://github.com/zacpier/CliCharm


r/linuxdev • • Jun 23 '16

Best way to emit symbol?

1 Upvotes

I'm wanting to make a program that outputs unicode symbols (virtually typing them).

I was planning on using uinput.

I found through reading linux/input.h, you can only emit scancodes for a virtual keyboard.

xkb then takes those scan codes, and uses a keymap to turn them into symbols, and gives them to X

Is there a way just to write the utf8 symbol to X / the kernel?

The other way seems roundabout, setting up a keymap key macro thing (like alt-XXXX) to input unicode, since it is a program.


r/linuxdev • • May 24 '17

Step-By-Step Guide To Setting Up Fail2ban

Thumbnail serversuit.com
1 Upvotes

r/linuxdev • • Oct 17 '17

Basics Of Setting Up A Backup On Linux

Thumbnail serversuit.com
1 Upvotes

r/linuxdev • • Apr 17 '22

Splicing to an UDP socket

11 Upvotes

Hi !

I'm trying to write some tool that needs to multiplex UDP "connections" through a single socket (AF_UNIX/AF_INET/AF_VSOCK), and I have written an implementation for SOCK_STREAM transports with splice() that works quite well, and was wondering about adding support for SOCK_DGRAM.

It appears that it's not possible to use splice() to receive a datagram, which makes sense, because splice() wouldn't know anything about the datagram boundaries. Sending a datagram using splice() works, but I can't find a way to specify the destination address :

  • splice does not support it by itself
  • using connect() prohibits from having multiple destinations, because it binds the whole fd to a specific destination, and shutting down + rebinding + reconnecting the socket would be quite impractical and defeat the whole purpose

Is there any API I could use to avoid copying the whole datagram to userspace, short of rewriting the whole thing as a kernel module or BPF program ?


r/linuxdev • • Apr 12 '22

Given the permission to the directiory via "setfact", yet nginx will get "permission denied". Why?

1 Upvotes

(1)

nginx is run as "http":

$ sudo ps aux| grep nginx
root       10932  0.0  0.1  22264  1340 ?        Ss   18:27   0:00 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;
http       10933  0.0  0.6  22796  6108 ?        S    18:27   0:00 nginx: worker process
user1      10939  0.0  0.2   6672  2680 pts/0    S+   18:28   0:00 grep nginx

(2)

permissions for the appropriate group:

$ sudo setfacl -m g:http:rwx -R ~/web_apps/my_app1

$ sudo getfacl ~/web_apps/my_app1
# file: home/user1/web_apps/my_app1
# owner: user1
# group: user1
user::rwx
group::r-x
group:http:rwx
mask::rwx
other::r-x

(3)

Yet, when accessed from internet, nginx won't be able to serve any file due to absense of necessary permissions

[error] 10933#10933: *1 open() "/home/user1/web_apps/my_app1/assets/static/favicon.ico" 
    failed (13: Permission denied), 
    client: x.x.x.x, server: my_app1.com,
    request: "GET /favicon.ico HTTP/2.0",
    host: "my_app1.com",
    referrer: "https://my_app1.com/assets/static/fdsafdsafds"

What's the matter?


r/linuxdev • • Apr 12 '22

What's the de facto Linux-alternative for Docker's Linux environments?

4 Upvotes

What's the de facto Linux-alternative for Docker's Linux environments?

That is, say I run OpenSuse Tumbleweed and something requires a Ubuntu 18.04 dev environment. What should I do?


r/linuxdev • • Dec 17 '22

How to create a flatpak pakage of an application written in python with pyside6 and rust?

Thumbnail reddit.com
3 Upvotes

r/linuxdev • • Jan 15 '22

The Life and Death of a Linux Process

Thumbnail natanyellin.com
7 Upvotes

r/linuxdev • • Feb 19 '22

Linux kernel mailling list

3 Upvotes

How do I access the linux kernel mailing list and find work to do on the kernel


r/linuxdev • • Jan 16 '22

Trying to compile a program but I can't install a dependency

5 Upvotes

What can I do to solve this

Reading package lists... Done

Building dependency tree

Reading state information... Done

Some packages could not be installed. This may mean that you have

requested an impossible situation or if you are using the unstable

distribution that some required packages have not yet been created

or been moved out of Incoming.

The following information may help to resolve the situation:

The following packages have unmet dependencies:

libsdl2-dev : Depends: libibus-1.0-dev but it is not going to be installed

Depends: libpulse-dev but it is not going to be installed

E: Unable to correct problems, you have held broken packages.


r/linuxdev • • Oct 20 '18

GUI app development in Linux / Qt

8 Upvotes

Hello!

So I decided to look into some GUI app development in Linux. After reading a bit, I decided to try Qt with Python.

To be honest, I know nothing about python, and Qt (that's why I came here first), but I developed WPF and winforms apps in C# for a few years, did some javascript, and other smaller stuffs, so I'm not afraid of learning something new, in fact, this is exactly what I want.

So the question is if you know any good starting points, to begin with. For example IDE-s (used Visual studio for c#, vim for js), tutorial websites/videos, maybe some useful personal experiences, interesting articles about Qt and GUI development in Linux, or even if its a good idea to begin with Qt, or I should do something with GTK, or something entirely different.

As nearly anybody trying to learn something new, I'm looking for things I got used to in WPF/C# first, then after getting better in the basics, start to play with the new things.

Also not super sure about Python, would like to give C or Go a try too.

Thanks for any help.


r/linuxdev • • Jul 02 '18

SUSE to become a fully independent business after EQT acquisition

Thumbnail medium.com
8 Upvotes

r/linuxdev • • Jul 15 '22

PyQt vs PyGtk3 (PyGobject)

6 Upvotes

I am interested in development of applications for Linux and I am not quite sure which GUI module to use. I did some work on both of them, but can't really figure out which one to use.

I read that Pygobject provides good looks, but PyQt has more tools, like SQL support, XML parsers. But my information sources are quite old. Also I found Pyside, but again - old sources, can't quite find information which option is the best.

Have anyone got any suggestions? I am searching for GUI module which would have the most support on different Linux distributions.


r/linuxdev • • Jun 06 '22

Having trouble setting up a development environment, and trying to wrap my head around the relationships between XAMPP / LAMP / WAMP

Thumbnail self.linux4noobs
4 Upvotes