/dev/stderr in systemd service

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I'm writing a service which should start LTE connection.



But the utility I'm using to connect (sakis3g) is writing to /dev/stderr, which is not available in systemd and the log is full of



Cannot create /dev/stderr: No such device or address


Is there some way to work around it?



Changing the utility script/binary is unfortunately not an option.



EDIT: Here is the service:



[Unit]
Description=LTE
After=syslog.target network-online.target
Before=openvpn-client@client
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/mav/LTE/
ExecStartPre=/sbin/ip link set wwan0 down
ExecStart=/opt/mav/LTE/sakis3g connect -g --sudo
ExecStop=/opt/mav/LTE/sakis3g disconnect --sudo

[Install]
WantedBy=multi-user.target


And it works in this state. But when I start sakis3g with -g flag for more verbose debug output, then the stderr errors appear.







share|improve this question






















  • You should provide more information about your .service file.
    – Valentin B
    Oct 30 '17 at 10:41














up vote
4
down vote

favorite












I'm writing a service which should start LTE connection.



But the utility I'm using to connect (sakis3g) is writing to /dev/stderr, which is not available in systemd and the log is full of



Cannot create /dev/stderr: No such device or address


Is there some way to work around it?



Changing the utility script/binary is unfortunately not an option.



EDIT: Here is the service:



[Unit]
Description=LTE
After=syslog.target network-online.target
Before=openvpn-client@client
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/mav/LTE/
ExecStartPre=/sbin/ip link set wwan0 down
ExecStart=/opt/mav/LTE/sakis3g connect -g --sudo
ExecStop=/opt/mav/LTE/sakis3g disconnect --sudo

[Install]
WantedBy=multi-user.target


And it works in this state. But when I start sakis3g with -g flag for more verbose debug output, then the stderr errors appear.







share|improve this question






















  • You should provide more information about your .service file.
    – Valentin B
    Oct 30 '17 at 10:41












up vote
4
down vote

favorite









up vote
4
down vote

favorite











I'm writing a service which should start LTE connection.



But the utility I'm using to connect (sakis3g) is writing to /dev/stderr, which is not available in systemd and the log is full of



Cannot create /dev/stderr: No such device or address


Is there some way to work around it?



Changing the utility script/binary is unfortunately not an option.



EDIT: Here is the service:



[Unit]
Description=LTE
After=syslog.target network-online.target
Before=openvpn-client@client
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/mav/LTE/
ExecStartPre=/sbin/ip link set wwan0 down
ExecStart=/opt/mav/LTE/sakis3g connect -g --sudo
ExecStop=/opt/mav/LTE/sakis3g disconnect --sudo

[Install]
WantedBy=multi-user.target


And it works in this state. But when I start sakis3g with -g flag for more verbose debug output, then the stderr errors appear.







share|improve this question














I'm writing a service which should start LTE connection.



But the utility I'm using to connect (sakis3g) is writing to /dev/stderr, which is not available in systemd and the log is full of



Cannot create /dev/stderr: No such device or address


Is there some way to work around it?



Changing the utility script/binary is unfortunately not an option.



EDIT: Here is the service:



[Unit]
Description=LTE
After=syslog.target network-online.target
Before=openvpn-client@client
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/mav/LTE/
ExecStartPre=/sbin/ip link set wwan0 down
ExecStart=/opt/mav/LTE/sakis3g connect -g --sudo
ExecStop=/opt/mav/LTE/sakis3g disconnect --sudo

[Install]
WantedBy=multi-user.target


And it works in this state. But when I start sakis3g with -g flag for more verbose debug output, then the stderr errors appear.









share|improve this question













share|improve this question




share|improve this question








edited Oct 30 '17 at 11:46

























asked Oct 30 '17 at 9:11









Pitel

24128




24128











  • You should provide more information about your .service file.
    – Valentin B
    Oct 30 '17 at 10:41
















  • You should provide more information about your .service file.
    – Valentin B
    Oct 30 '17 at 10:41















You should provide more information about your .service file.
– Valentin B
Oct 30 '17 at 10:41




You should provide more information about your .service file.
– Valentin B
Oct 30 '17 at 10:41










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










If there was no stderr, you wouldn't see the error.



Here, the error is about not being able to open the /dev/stderr file, which on Linux is a symlink to the actual file that is open on the fd 2 (while on other systems, opening /dev/stderr is like doing a dup(2)).



The problem here is likely that fd 2 is open on a socket (inet TCP, Unix stream or other) and you can't open() a socket file.



If you run:



sudo lsof -aU +E -d 2


On a system using systemd you'll notice that fd 2 of most services is a unix domain stream socket to systemd-journald.



As a work around, you may be able to start it as:



bash -o pipefail -c ' cat >&2 3>&-; 3>&1'


That is make stderr a pipe (to cat) instead of a socket, cat forwarding what it receives on the pipe to the original stderr (the socket), and make sure we preserve the exit status of the command with the pipefail option.



In any case, the source of that sakis3g is available and that sakis3g init file is a bash script, that happen to do:



echo text >> /dev/stderr


instead of:



echo test >&2


It's even got a few > /dev/stderr instead of >> /dev/stderr which is even more wrong. It has no tee -a /dev/stderr | other cmd which would have been a legitimate use of /dev/stderr and would also not work with stderr on a socket, so it's easily fixable.



You may want to let them know of the problem by raising an issue at https://github.com/Trixarian/sakis3g-source/issues






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401372%2fdev-stderr-in-systemd-service%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    If there was no stderr, you wouldn't see the error.



    Here, the error is about not being able to open the /dev/stderr file, which on Linux is a symlink to the actual file that is open on the fd 2 (while on other systems, opening /dev/stderr is like doing a dup(2)).



    The problem here is likely that fd 2 is open on a socket (inet TCP, Unix stream or other) and you can't open() a socket file.



    If you run:



    sudo lsof -aU +E -d 2


    On a system using systemd you'll notice that fd 2 of most services is a unix domain stream socket to systemd-journald.



    As a work around, you may be able to start it as:



    bash -o pipefail -c ' cat >&2 3>&-; 3>&1'


    That is make stderr a pipe (to cat) instead of a socket, cat forwarding what it receives on the pipe to the original stderr (the socket), and make sure we preserve the exit status of the command with the pipefail option.



    In any case, the source of that sakis3g is available and that sakis3g init file is a bash script, that happen to do:



    echo text >> /dev/stderr


    instead of:



    echo test >&2


    It's even got a few > /dev/stderr instead of >> /dev/stderr which is even more wrong. It has no tee -a /dev/stderr | other cmd which would have been a legitimate use of /dev/stderr and would also not work with stderr on a socket, so it's easily fixable.



    You may want to let them know of the problem by raising an issue at https://github.com/Trixarian/sakis3g-source/issues






    share|improve this answer


























      up vote
      4
      down vote



      accepted










      If there was no stderr, you wouldn't see the error.



      Here, the error is about not being able to open the /dev/stderr file, which on Linux is a symlink to the actual file that is open on the fd 2 (while on other systems, opening /dev/stderr is like doing a dup(2)).



      The problem here is likely that fd 2 is open on a socket (inet TCP, Unix stream or other) and you can't open() a socket file.



      If you run:



      sudo lsof -aU +E -d 2


      On a system using systemd you'll notice that fd 2 of most services is a unix domain stream socket to systemd-journald.



      As a work around, you may be able to start it as:



      bash -o pipefail -c ' cat >&2 3>&-; 3>&1'


      That is make stderr a pipe (to cat) instead of a socket, cat forwarding what it receives on the pipe to the original stderr (the socket), and make sure we preserve the exit status of the command with the pipefail option.



      In any case, the source of that sakis3g is available and that sakis3g init file is a bash script, that happen to do:



      echo text >> /dev/stderr


      instead of:



      echo test >&2


      It's even got a few > /dev/stderr instead of >> /dev/stderr which is even more wrong. It has no tee -a /dev/stderr | other cmd which would have been a legitimate use of /dev/stderr and would also not work with stderr on a socket, so it's easily fixable.



      You may want to let them know of the problem by raising an issue at https://github.com/Trixarian/sakis3g-source/issues






      share|improve this answer
























        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        If there was no stderr, you wouldn't see the error.



        Here, the error is about not being able to open the /dev/stderr file, which on Linux is a symlink to the actual file that is open on the fd 2 (while on other systems, opening /dev/stderr is like doing a dup(2)).



        The problem here is likely that fd 2 is open on a socket (inet TCP, Unix stream or other) and you can't open() a socket file.



        If you run:



        sudo lsof -aU +E -d 2


        On a system using systemd you'll notice that fd 2 of most services is a unix domain stream socket to systemd-journald.



        As a work around, you may be able to start it as:



        bash -o pipefail -c ' cat >&2 3>&-; 3>&1'


        That is make stderr a pipe (to cat) instead of a socket, cat forwarding what it receives on the pipe to the original stderr (the socket), and make sure we preserve the exit status of the command with the pipefail option.



        In any case, the source of that sakis3g is available and that sakis3g init file is a bash script, that happen to do:



        echo text >> /dev/stderr


        instead of:



        echo test >&2


        It's even got a few > /dev/stderr instead of >> /dev/stderr which is even more wrong. It has no tee -a /dev/stderr | other cmd which would have been a legitimate use of /dev/stderr and would also not work with stderr on a socket, so it's easily fixable.



        You may want to let them know of the problem by raising an issue at https://github.com/Trixarian/sakis3g-source/issues






        share|improve this answer














        If there was no stderr, you wouldn't see the error.



        Here, the error is about not being able to open the /dev/stderr file, which on Linux is a symlink to the actual file that is open on the fd 2 (while on other systems, opening /dev/stderr is like doing a dup(2)).



        The problem here is likely that fd 2 is open on a socket (inet TCP, Unix stream or other) and you can't open() a socket file.



        If you run:



        sudo lsof -aU +E -d 2


        On a system using systemd you'll notice that fd 2 of most services is a unix domain stream socket to systemd-journald.



        As a work around, you may be able to start it as:



        bash -o pipefail -c ' cat >&2 3>&-; 3>&1'


        That is make stderr a pipe (to cat) instead of a socket, cat forwarding what it receives on the pipe to the original stderr (the socket), and make sure we preserve the exit status of the command with the pipefail option.



        In any case, the source of that sakis3g is available and that sakis3g init file is a bash script, that happen to do:



        echo text >> /dev/stderr


        instead of:



        echo test >&2


        It's even got a few > /dev/stderr instead of >> /dev/stderr which is even more wrong. It has no tee -a /dev/stderr | other cmd which would have been a legitimate use of /dev/stderr and would also not work with stderr on a socket, so it's easily fixable.



        You may want to let them know of the problem by raising an issue at https://github.com/Trixarian/sakis3g-source/issues







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 30 '17 at 12:40

























        answered Oct 30 '17 at 12:26









        Stéphane Chazelas

        283k53521855




        283k53521855



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401372%2fdev-stderr-in-systemd-service%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            The Forum (Inglewood, California)

            Palaiologos