posix_openpt() - error - Cant access tty, job control turned off - c

I'm using a psuedo terminal, /bin/sh -i, by calling normal commands for posix_openpty() then fork(), in language C.
When I run from command line GUI terminal like this
$ ./MyTerminal
or
$ sudo ./MyTerminal
or as root like this
# ./MyTerminal
all works very good and as expected, no problems.
However, when I make a systemd service file like this, it works fine
[Service]
User=root
But when I try to get systemd to run it as normal user like this
[Service]
User=debian
THe first output for /bin/sh -i is
/bin/sh: 0: can't access tty; job control turned off $
And the terminal does not really work.
When I run /bin/bash, fork() w/posix_openpty() is returns me this, but the terminal generally works ok
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
Is such a weird prolem because when running outside of systemd everything works perfect. I see this problem in 1 other question but no clear solution. So what I have to change to make systemd run my file perfectly? Thanks for your help.

Related

log in adb shell "interactive mode" and "non-interactive mode"

I'm writing script to run iperf on linux device accessible via adb.
From a terminal, when I run the command: adb shell iperf -c ......
I get the log of the command 50 s after the command starting.
inconvenient: during 50 s you are not sure that iperf has started
I tried the logcat command (logcat --pid ...), It gives the same result.
From a terminal, when I enter adb session first and then I run the command: iperf -c .....
I get the log of the command in real time.
inconvenient: I'm not able to automate the procedure, because I have to start the adb session first
For the first use case: Is there a way to force "log flush" in order to get the log in real time?
For the second use case: Is there a way to send commands to already opened adb shell session?
Is there any other ways to launch iperf on device and get the log in real time?
The solution i found is the library pexpect that allow to interact with adb session.

catch console output from background process

I have a program running on armbian single board computer. The program starts with -b option during the startup of the system. I created this simple shell script
#!/bin/bash
#Myprog server start
sudo -b /home/myprog/myprog
This program is C written and it sometimes outputs some information with printf functions. But since it is started with -b option there's is noting in the console.
Now when I log in to the armbian via ssh with Putty I want to occasionally read the output of this program. Is it even possible?
Not exactly what you’re asking, but generally speaking it’s better practice to redirect output to a log file than to try to interactively look at the console output for a background app.
Something like:
sudo -b /home/prog/myprog >> /home/prog/log.txt 2>&1
Should do it.
Then view output with
tail -f /home/prog/log.txt
If it’s really important to you to run interactively without logs, I would suggest running it from within “screen” without backgrounding it.
screen
sudo /home/prog/myprog
Then ctrl-d to detach and let it run in background. screen -r to reattach.

Compile for Chromebook using Crouton

I currently have an Asus c300 chromebook. Since it doesn't have legacy boot, I'm using crouton to get a more standard command line environment. I was able to install gcc very easily in the chroot environment. It works very well under chroot.
Since the underlying hardware is the same, I thought the resulting executable should work for chromebook, without me being in the chroot environment. If true, I thought I could go into the chroot environment, compile whatever program I want/need, and exit back out to the regular environment and use it.
I tried it with a simple hello world program. When I tried to run the executable, I got the following error:
bash: ./a.out: Permission denied.
I tried to run it with sudo, and I get a similar error:
sudo: unable to execute ./a.out: Permission denied.
I even used su to login as root, and I still could not run the program (got the first error).
I thought su/sudo would override any kind of permission restriction. But, it's apparently not the case on the chromebook.
What am I missing? Is what I want to do possible?
EDIT: File permission was already set to 777.
You might simply have to change the permissions of the file or check the files ownership. umask determines weather or not a file that is created gets execute permissions by default. What does -ls -lat on the file reveal?
Also try running
chmod +x ./a.out
You can find more details of error with strace command
use:
strace ./a.out and check output.
I suppose you have different env (path and LD_library_path) under the chroot.

Editing .desktop file to run executable as root?

I have compiled a c program into an executable that I would now like to integrate into the applications menu in Debian 7.4 XFCE. In order to run the application under normal circumstances, I am required to type
sudo myprogram
Now I have created my .desktop file and placed it in /usr/share/applications
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=myprogram
Comment=configuration loader
Exec=sudo loader
Icon=/usr/share/icons/hicolor/48x48/apps/myprogram.png
Terminal=false
Categories=Development;IDE
The item is added to my applications menu as expected, and the icon shows up properly. The problem, however, is that double clicking the menu item to launch the application does nothing.
If I navigate to /usr/bin (where I have placed my executable) and type "sudo myprogram", the program launches as expected.
What can I do to fix this issue and get the program to launch from the menu? Perhaps /usr/bin is not the correct place to put it, or I have the incorrect Exec command. I greatly appreciate the help.
I ended up using (after installing gksu)
Exec = gksu myprogram
this launches a graphical sudo prompt, which is sufficient for my needs.
This is what the setuid bit in the permissions is for. It makes executables run with permissions of the file owner. This only works on actual executables, not on shell scripts!
sudo chmod u+s myprogram
sudo chown root myprogram
./myprogram # now runs as root
Please be careful when using this as it will always execute that program as root no matter who executes it. You can limit access by setting it to your usergroup and deny all execute.
chgrp "${USER}" myprogram # provided you have individual groups set up
chmod a-x myprogram # deny all execute
This approach does not need additional installation of packages.
Terminal=true opens a new terminal window which runs
sudo -i to ask for the password.
Then, using sh to run the program, the Terminal is closed and myprogram runs in the background because it has a & at the end.
[Desktop Entry]
Type=Application
Name=...
Exec=sudo -i sh -c "myprogram &"
Terminal=true
Request: Please report if it works under your OS.
Tested under:
Xubuntu
The pkexec solution from askubuntu:
Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY APP_COMMAND
Try adding this to .desktop
Path=/path/to/myprogram

Logging into Cygwin and executing commands using bat file in windows

I am using windows XP operating system and cygwin is installed in my C drive.
I need to login to cygwin directly to my directory path which contains a makefile and also a bash script called build.sh in the same directory. So i modified the original cygwin.bat file and added the line as shown below.
#echo off
C:
chdir C:\cygwin\bin
bash --login "/cygdrive/E/scheme_31july/build/build.sh"
When i double click on this bat file i could see my script executing but not on cygwin shell but on windows cmd shell as a result I get errors for "make" command like "No rule to make target" as make comes bundled with cygwin.
And when I explicitly login to cygwin using default cygwin.bat file and execute my script by giving following commands in cygwin shell the script executes without errors.
Basically I want to write a bat file so that I can keep it anywhere in my PC and instead of manually openeing the cygwin prompt and typing commands like:
$ cd /cygdrive/E/scheme_31july/build/
$ sh build.sh
it should happen automatically. I sit possible to do so.
Regards,
Harshit
No rule to make target sounds more like make being executed in the wrong directory. make itself seems to be available and running as intended.
Try this:
bash --login -c "cd /cygdrive/E/scheme_31july/build/ && sh build.sh"
This should start a --login session (which should give you access to all the settings and tools you'd expect in a cygwin prompt environment), then execute the given shell command, which is the cd and sh you asked for. You could also write those two lines to a separate script file, and pass the name of that to bash instead of the full path to build.sh.
You could also try to cd into C:\scheme_31july\build in the bat file and then execute bash from there. Not sure whether bash will try to change path upon entering the login session. You can try whether things work without the --login, both for this approach and the one above.
#echo off
C:
cd C:\scheme_31july\build
C:\cygwin\bin\bash.exe ./build.sh
I'm not sure whether you want the session to turn interactive after that or not. In the above case, bash will terminate after the script completed, and might even close the window. You might have to add a read into build.sh to avoid that. If you want bash to turn interactive after executing some command, you can try using the --rcfile option of bash to execute some commands and then turn interactive.

Resources