WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved]: why doesn't startx work from within a shell script?  (Read 5549 times)

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1360
Re: [Solved]: why doesn't startx work from within a shell script?
« Reply #30 on: November 16, 2022, 12:48:29 PM »
Hi GNUser
I had the same message showing up. I only did a brief search
on that, so short answer suggests consoles do not handle job
control and the message is just informational.
Thanks for confirming that you also get the message, and that you also favor that it is merely informational.

I had already edited my x-watchdog script, replacing startx with sudo openvt -c 1 -s login -f bruno and now I can launch it from ~/X.d/ along with all my other startup jobs, thanks to you. The script works exactly as intended. Once again, many thanks! :)

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1360
Re: [Solved]: why doesn't startx work from within a shell script?
« Reply #31 on: November 16, 2022, 12:53:30 PM »
P.S. This is the openvt command's help:

Code: [Select]
$ openvt --help
BusyBox v1.34.1 (2022-04-30 13:49:24 UTC) multi-call binary.

Usage: openvt [-c N] [-sw] [PROG ARGS]

Start PROG on a new virtual terminal

-c N Use specified VT
-s Switch to the VT
-w Wait for PROG to exit

One odd thing is that the -c 1 flag causes X to be restarted in tty2. If I change the flag to -c 2 then X is restarted in tty3. I don't quite understand this. Oh, well. It seems that starting/restarting X is fraught with unexpected things.

Offline mocore

  • Hero Member
  • *****
  • Posts: 509
  • ~.~
Re: [Solved]: why doesn't startx work from within a shell script?
« Reply #32 on: November 17, 2022, 05:26:24 AM »
ftr & out of curiocity ( https://busybox.busybox.narkive.com/Y0331j2s/new-applet-openvt )

 this is appears to be the latest the bb openvt source : https://git.busybox.net/busybox/tree/console-tools/openvt.c?h=1_35_stable

 this https://git.busybox.net/busybox/commit/?h=1_34_stable *should*
 match the version used in http://tinycorelinux.net/13.x/x86_64/release/src/busybox/  13.1 x86_64
 minus the patches  :P

 the function find_free_vtno appears to handle the '-c' case
which mentions ( though im not shore how relevent that may or may not be tbh =s )
Code: [Select]
// Not really needed, grep for DAEMON_ONLY_SANITIZE
https://git.busybox.net/busybox/tree/console-tools/openvt.c?h=1_35_stable#n156

also ... some intresting discution @ http://lists.busybox.net/pipermail/busybox/2009-December/071170.html
which mentions/quotes from "See docs/ctty.htm, "Getting a controlling tty":"  which i found an old copy of in this link http://bls.buu.ac.th/~s54326/08Dec16/busybox-1.19.3/docs/ctty.htm

also on this tangent iv found  https://landley.net/notes-2011.html#28-08-2011 - "(Did I mention I spent several weeks, some time back, setting everything up so that ctrl-c would exit an aboriginal linux native build? This involved getting a controlling TTY which /dev/console isn't, moving the shell off of PID 1 which has most signals blocked so it would ignore ctrl-c anyway, and then calling shutdown() to exit the emulator. It's sources/toys/oneit.c and sbin/init.sh setting it up, and together they make it look like I didn't do anything because it just works.)"

all though im not shore how relevnt all that may or many not be !



Offline GNUser

  • Hero Member
  • *****
  • Posts: 1360
Re: [Solved]: why doesn't startx work from within a shell script?
« Reply #33 on: December 06, 2022, 10:38:47 AM »
I found an alternative solution. Script can be named  RestartX  as before, with this in it:

Code: [Select]
#!/bin/sh
pkill Xorg
sleep 1
sudo setsid sh -c "exec login -f $(whoami) <>/dev/tty3 >&0 2>&1"
The script can be run from a terminal emulator running within X like so:
Code: [Select]
./RestartX &
This solution is based on this idea: https://unix.stackexchange.com/a/170075
« Last Edit: December 06, 2022, 10:40:22 AM by GNUser »

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1360
Re: [Solved]: why doesn't startx work from within a shell script?
« Reply #34 on: December 06, 2022, 11:54:10 AM »
Sorry to spam the thread, but I wanted to share that this slightly simpler version works just as well:

Code: [Select]
#!/bin/sh
pkill Xorg
sleep 1
sudo sh -c "login -f $(whoami) <>/dev/tty3 >&0" &
« Last Edit: December 06, 2022, 12:05:29 PM by GNUser »

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1360
Re: [Solved]: why doesn't startx work from within a shell script?
« Reply #35 on: February 28, 2023, 07:04:19 AM »
From first post in this thread:
On my media player, X crashes once in a while. I'm not sure why
A quick follow-up in case this information is helpful to someone: It turns out that all the crashes happen when watching a video in Brave (extension from repo) or Chrome (.deb -> homebrewed .tcz) in fullscreen mode. It doesn't happen every time, only once in a great while. Unfortunately, /var/log/Xorg.0.log shows nothing helpful, just a segfault. mpv in fullscreen mode, on the other hand, never causes a crash.

The media player is now running TCL14-alpha 64-bit rather than TCL13.1 64-bit. The TCL version makes no difference.

I don't think there is anything to be done about it. Just something to be aware of, I guess.