Search code examples
pythonubuntuchromiumpopen

Ubuntu / Python : Can't launch Chromium from SubProccess.Popen


Basicaly, i've plugged an Arduino to communicate with my computer and the goal is to open Chromium when i'm clicking a button. When clicked, the arduino will send a string on the serial communication and the computer will get this string thanks to a Python script.

This script will then launch Chromium using Popen(['chromium-brower'])

I've been able to do all that without any problem, excepted for the Chromium that won't launch. The syntaxe is correct, but the terminal return a weird error that I don't understand.

sudo python serialtest.py start [0825/084720:ERROR:nss_util.cc(96)] Failed to create /home/dlslabo/.pki/nssdb directory. [0825/084721:FATAL:chrome_main_delegate.cc(386)] Check failed: process_type.empty(). Unable to get the user data directory for process type: zygote #0 0x7f1a233095fe base::debug::StackTrace::StackTrace() #1 0x7f1a23325f8e logging::LogMessage::~LogMessage() #2 0x7f1a2f3a11f5 #3 0x7f1a2aa8f224 #4 0x7f1a2aa8d80d content::ContentMain() #5 0x7f1a2f3a065a #6 0x7f1a17a25a40 __libc_start_main #7 0x7f1a2f3a0519

Here is my python program :

#!/usr/bin/env python

import serial
from subprocess import Popen

ser = serial.Serial('/dev/ttyACM0', 9600)

while 1 :
   line = ser.readline().strip()
   print line
   if line == "start":
      p = Popen(["chromium-browser"])

I tried with others app as Popen(["gedit"]) and Popen(["firefox"]) and it worked fine. From what I read on the internet, this could be because i'm executing the script as super user. But I don't know why this would cause a problem.


Solution

  • Running a browser (or any other program that isn't for system administration) as the root user is a bad idea for security.

    It looks like you're using root because you need access to a particular device node. In that case, you can make a non-root user the owner of the device. The easiest way to do this is via udev rules. Create a file named /etc/udev/rules.d/99-tty-acm.rules with the following content:

    KERNEL=="ttyACM0", OWNER="mynonrootuser", MODE=0660
    

    If more users might need access, create a group for them, say ttyacm, and set GROUP="ttyacm" and MODE=0660. More about writing udev rules here.