Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
Shut down X on exit?
#1
I set up a FreeBSD htpc which runs kodi at boot via a login script.  There is no desktop environment installed.  When I try to exit kodi the display just locks up and the X-Server stays running.  Is there a way to make the kodi exit function shut down the X-server or do I always have to kill it manually?
Reply
#2
Would you want also to shut down/reboot the machine or just shut down X? I assume you'd want shut down/reboot, not just shutting down the X and staring at console..

Problem is, by default vanilla FreeBSD's user has no rights for shutting down machine or overriding apps that run under higher privileges (X needs root privileges, unless you are using OpenBSD). It's basic security. Yeah, you can close the KODI app, but it would not naturally do a thing when you'd be trying to shut down X through KODI app, unless you take up special efforts..

I've used sysutils/upower package, combined with security/doas

You can achieve this way shutting down/rebooting from Kodi, even if user has no special privileges

Examples:
Following would give unprivileged user kodi basic ability to shut down/reboot the machine
#pkg install doas
#nano /usr/local/etc/doas.conf 
Content of the file: Assuming KODI is being ran using unprivileged user kodi which also belongs into video group.
Quote:permit persist :video #kodi user has to belong this group, or it does not have hw acceleration for graphics
permit nopass kodi as root cmd reboot 
permit nopass kodi as root cmd shutdown 

You can extend it by adding following into /boot/loader.conf  (ability to shut down/reboot by using plain keyboard, assuming keyboard in question has shut down button)
Quote:kern.vt.kbd_reboot=1
kern.vt.kbd_poweroff=1

Allowing shutdown/reboot by KODI menu option. First login as root ,then
#pkg install upower
#touch /usr/local/etc/polkit-1/localauthority/50-local.d/custom-actions.pkla


Open this file using again your favorite text editor. Add following (assuming KODI would run on unprivileged user named kodi)
Quote:[Actions for KODI users] 
Identity=kodi:kodi 
Action=org.freedesktop.upower.* 
ResultAny=yes 
ResultInactive=yes 
ResultActive=yes 
What did you mean by "login script"? I am curious. I've been using Slim login manager so far, which would autologin user kodi and autostart application kodi through .xinitrc file. Pretty simple as well and login manager itself is not visible during process. Maybe your method would be even simpler.
Reply
#3
X needs root?  How is it that I can xinit kodi from my .zshrc file then?  So the way I'm doing it is I followed https://forums.freebsd.org/threads/22304/#post-125992 to set up an auto-login at boot.  I modified his suggestion slightly.  I added a new ttyv9 instead of using ttyv1 like he did.  Then I added the following to the account's .zshrc (his new default shell):
Code:
XPID=`pgrep xinit`
if [ $XPID ] ; then
  echo "Kodi is already running." ;
else ;
  echo "Kodi not running.  Starting it now.  Enjoy the show!" ;
  xinit kodi & ;
fi
The weird thing is that after editing my /etc/passwd to change my shell to zsh it was still loading my old shell.  Maybe it needs a reboot or something.  So I had to run chsh manually.  But it works great.  

And no, I do not want to shut the machine down as it also serves as a media ftp server for other kodi instances running in the house.  I don't even really care much about shutting kodi itself down now that I think about it.  I guess I can just leave it running since it shouldn't be wasting too much electricity anyway when the display is off.  I was more thinking about what if it crashes then I would have to ssh in and kill it.  But this should be rare enough that it's not a big deal.  Plus I would have to ssh in to restart it anyway.  I was working on this box for like 7 hours last night and my head wasn't thinking clearly.  Thank you for the detailed reply though.

But I got everything working now the way i want.  I'm a recovering Linux user and I'm just trying FreeBSD for the first time.  I think it's just awesome.  I love it.  BTW I hope you succeed in getting kodi 18 compiled for us few BSD guys out here.
Reply
#4
About X, I'd have to check it. Haven't really tried to keep myself up to date there.

Yeah, Kodi 18 compiles now fine on FreeBSD 11.1, on both STABLE and RELEASE versions, you can use official Kodi 18 repo for it. Thanks to Rechi, who helped in making my PR's acceptable.

Only one caveat: use -DENABLE_ALSA=OFF flag. Kodi would be using OpenBSD's sndio and it works as well. There is a 'linuxism' in one of the ALSA cpp files FreeBSD has no clue what to do with. It's easier to simply not use ALSA.
Reply
#5
(2017-11-18, 16:30)aht0 Wrote: Google claims my knowledge base to be out-of-date about X. Used to be so.. Learn something daily

Yeah, Kodi 18 compiles fine on FreeBSD at the moment. Rechi assisted me with making PR's acceptable.

do git clone, then cd into xbmc folder, do mkdir build, cd into it and do cmake .. -DENABLE_ALSA=OFF , then gmake . All this you can do using plain user.

It should compile to the end just fine 'as is'. It's going to use SNDIO for sound.
Some of the packages (like devel/fmtlib) you'd have to compile from ports, because quarterly binary packages do not seem to offer fmtlib package, for the rest binaries work.

Then ascend yourself to root , give command gmake install and that's all there is to it.

Btw, did you encountered any issues with non-existing HDMI Audio (probable with Radeon graphics, because by default one variable in radeon driver's source files is '0' and would have to be changed to '1' and driver/kernel has to be recompiled)?
 I am using an AMD APU and it was just horrible using its onboard HDMI, not just on FreeBSD but on Linux also, just slow drivers and it was unwatchable.  Yes on FreeBSD audio also did not work, but it did on Linux.  I switched to a Radeon 5450 I had lying around and it was even worse.  Then I switched to an sm912 android box and just used the PC as a file server.  Andriod was much better but passthrough audio did not work and it's bloated crap frankly and crashes too often.  Finally last week I bought an nvidia 1030 seeing they had proper driver support and everything is perfect.   Everything just works.  I am now officially on team nvidia.  It took me a while to get X configured properly (I'm no Unix expert), but once I did everything worked flawlessly.  Video playback is now smooth and looks great.  I can passthrough lossless audio.  It was $68 shipped from Jet.com, more than I would have liked to spend, but not too bad in the scheme of things, cheaper than the android box was and for me it's a better option than trying to troubleshoot drivers.  It has HDMI 2.0a so it'll do 4k HDR so I should be future proof for a long while, at least until the OEMs decide to switch the HDR standard and screw over all the early adopters (3d all over again).  I'm still using an old 1080p projector for now.  I don't like being an early adopter anymore.

I hope 18 makes its way to the binary packages eventually.  I'm not very experienced with compiling from source.  I've been spoiled by install scripts for too long, and I grew up in the age of interpreted languages.  I'll probably give it a shot when it's officially released and stable, but I like having my pkg manager keep things up to date for me.  It's just tedious having to rebuild every update, having to look up the whole process, but this is the OS I chose I guess.  For now I'm still running 17.3 since that's the version pkg grabs.
Reply
#6
Building 18 on dual-core Pentium (over-clocked G3258 in my case) takes about 20min. It be probably "time for a cup of coffee" on machines with more cores.

I've been using (off and on) Radeon HD6450. Works just fine, after you have your added your kodi user in video group and have modified certain variable in radeon driver. Without kodi user being in video, KODI would only be able to use software rendering without any hardware acceleration. Which means horrible performance. 

What you'd have to do for getting past both issues:
1)for Kodi user, type in following orders as root:
#pw groupmod video -g 44 
#pw groupmod video -m kodi


2) for Radeon
open /usr/src/sys/dev/drm2/radeon/radeon_drv.c in text editor (assuming you installed FreeBSD with sources)
Find 

int radeon_audio = 0 

change it to

int radeon_audio = 1

save, rebuild the kernel (directions in FreeBSD Handbook, pretty simple), reboot. Radeon HDMI audio should work now, unless default output device is wrong (which it tends to be if you have other sound devices present in the system).

If it happens that you still have no sound and it's being transmitted from wrong output do:

#cat /dev/sndstat

you should see something like
Quote:pcm0: <ATI R6xx (HDMI)> (play) 
pcm1: <Realtek ALC269 (Right Analog)> (play/rec) default 
pcm2: <Realtek ALC269 (Internal Analog)> (play/rec) 
No devices installed from userspace. 
Now do

#sysctl -a | grep hw.snd.default_unit 

it should give you response something like

hw.snd.default_unit: x         (x meaning digit aligning with pcmx

Change it in "live" using sysctl 

#sysctl hw.snd.default_unit=0 
hw.snd.default_unit: x -> 0 


For permanent change, simply write it into /etc/sysctl.conf 

I was writing it for next possible FreeBSD user running into trouble with both problems. So the forum search would return it if searched.

Nvidia's card should yeah work 'as is', unless it's again 'wrong default audio device' problem. With Intel iGPU it's pretty much the same (with ones supported by FreeBSD, there are bunch which arent supported yet), with some boards you'd have to enable HDMI audio from bios, before it becomes visible in OS.

I am glad you have gotten it working for yourself. For most people it's generally "shrug, I'll use some Linux.."
Reply
#7
Well I was previously running Arch Linux and one day it decided to just stop booting after some update gone wrong.  Around that time I was learning more about the GPL and decided to consciously avoid using any GPL licensed software if possible (kodi has no equal), but especially for OS more so than individual programs.  So pretty much I shrugged and said "I'll use some BSD."

I really do like FreeBSD much better though, from the terminal at least.  I like the way things are organized.  I like the package management system, very "apt" like, although I wish the software was a little more up to date.  I don't know if driver support is good enough to use it as my Laptop OS.  I'd like to try though, but for now there's still some software that's Linux only (or Mac/Windows but they don't count) and I don't know how good that compatibility layer is.  Unfortunately my desktop has to stay Windows probably forever to play games.  I don't think I'll be buying another console again, and I don't see game devs moving to make anything for us, even though Sony and Nintendo built their consoles around BSD.  Mac too.  It's a damn shame.
Reply
#8
I just realized if you don't run
Code:
disown
after starting kodi from .zshrc, then kodi will close when you exit your terminal session.  It doesn't affect the autologin on my tty9, but I just had to restart kodi after it crashed by loggging in manually via ssh.
Reply
#9
If you used Arch Linux, you might be interested in PacBSD. It differs from vanilla Freebsd by PacMan and optional OpenRC init.
https://pacbsd.org/

Linux ABI is a lottery. Linux kernel and system calls supported are at 2.6.xx level. Software might work splendidly over Linux ABI or it might not work at all.
Reply
#10
Yeah I like playing around with the unity game engine, and I doubt that will run well in FreeBSD.  It sometimes doesn't even run well in Linux.  But I'm considering dual booting FreeBSD and Windows (currently have Arch/Windows but never use Windows) and just using Unity in windows, especially now that MS added a Linux compatibility layer, limited as it is.  Is that desperation in the air?  Yes there is cygwin but it's kind of a burden to use.  I think I'll play around with this over thanksgiving break because I need to reinstall windows anyway.

I liked Arch because the hardware support was the best I found and software was always bleeding edge, BUT I absolutely hated pacman/yaourt.   Any time I wanted to do anything out of the ordinary I had to look up how to do it.  It's just not intuitive at all.  I much preferred ubuntu's apt system which pkg is very similar to, so I'm liking freebsd much better there.
Reply
#11
what's the partitioning scheme and FreeBSD main file system you are using/planning to be using?

FreeBSD+Windows dual boot could be rather annoying to get working.
For example:
(MBR+BIOS) scheme and FreeBSD installed using UFS2 root - works OTB. Don't even have to specify Windows anywhere, as long as you install Windows first and FreeBSD later.
(GPT+BIOS boot) + UFS2 - doable, with GRUB2 for example. Or even use GRUB2 from some Linux.
(MBR+BIOS)+ZFS = does not work at all AFAIK. MBR boot sector is too small to fit FreeBSD's ZFS boot code.
(GPT+BIOS)+ZFS = not sure, normal GRUB2 does not boot ZFS. PC-BSD/TrueOS had GRUB2 port, which still exists in sysutils/grub2-pcbsd. Most likely you will not get it working.
(GPT+UEFI)+ZFS = rEFInd is the only choice I know of, capable of booting such combo/FreeBSD.

Perhaps advance warning would save you days of frustration. Good luck with it.
Reply
#12
Luckily for me I have two separate hdds so I don't have to worry about setting up a bootloader for both.  I can just pick the boot device when I power on.

Well I think I'm giving up already.  Just getting WiFi to work so that I could install a desktop was too much for me.  I think my card might not even be supported.  Looks like I'm stuck with Linux AND Windows for the forseeable future.
Reply
#13
Dirty fix. If you have Android smartphone, connect it into WiFi, attach USB cable to it and connect it to your FreeBSD machine. Then share the connection (USB-modem). It should create USB-Ethernet connection. Check what device name assigned to it and call dhclient on it on command line. Should work like charm.

You can then mess with WiFi later, especially if you are unlucky to have WiFi card needing external firmware. I recommend getting Atheros AR9462, AR9580, AR9280 or something from Intel (perhaps 5100). All are 802.11abgn cards and fully supported. And cheaply available in eBay.
Reply
#14
So I'm trying to build kodi from source and I don't see a stable or release branch.  I'm just grabbing the master.  I hope it's not too buggy.
Reply
#15
You need to get root privileges.
>portsnap fetch
>portsnap extract
>cd /usr/ports/multimedia/kodi
>make config
>make
>make install
>make clean

This works for 17.x Krypton in FreeBSD Ports Collection
'>' meaning shell prompt

If you want 18.x 'Leia'. Download it from Kodi master repo. Then
>cd xmbc
>mkdir build
>cd build
>cmake .. -DENABLE_ALSA=OFF
>gmake

Go to root user
>su
>gmake install

Sorry for late reply. I've been abroad in hospital and thus 'busy & AFK'
Reply

Logout Mark Read Team Forum Stats Members Help
Shut down X on exit?0