<commit_before>#!/usr/bin/env python3

from configparser import SafeConfigParser
import glob
import json
import os
import psutil
import re


def lightdm_checker():
    lightdm_re = re.compile(r'\blightdm\b')
    running_lightdm = any(p for p in psutil.process_iter()
                          if lightdm_re.search(p.exe()))
    if not running_lightdm:
        return None
    if not os.path.exists('/usr/share/lightdm/guest-session'):
        return None
    if not os.path.exists('/usr/share/lightdm/lightdm.conf.d'):
        return None
    status = None
    for conf_file in glob.glob('/usr/share/lightdm/lightdm.conf.d/*.conf'):
        parser = SafeConfigParser()
        parser.read(conf_file)
        if not parser.has_section('Seat:*'):
            continue
        if not parser.has_option('Seat:*', 'allow-guest'):
            continue
        if parser.getboolean('Seat:*', 'allow-guest'):
            return True
        status = False
    return status


checkers = (lightdm_checker,)

for checker in checkers:
    results = checker()
    if results is not None:
        break

if results is None:
    results = 'unknown'
<commit_msg>Assume non-root xinit and Xorg means no guest session<commit_after>#!/usr/bin/env python3

from configparser import SafeConfigParser
import glob
import json
import os
import psutil
import re


def xinit_checker():
    xinit = Xorg = None
    for p in psutil.process_iter():
        if p.exe().endswith('/xinit'):
            xinit = p
        elif p.exe().endswith('/Xorg'):
            Xorg = p
    if xinit and Xorg and Xorg.ppid() == xinit.pid and \
       xinit.uids().real and Xorg.uids().real:  # Shouldn't be running as root
        return False

    return None


def lightdm_checker():
    lightdm_re = re.compile(r'\blightdm\b')
    running_lightdm = any(p for p in psutil.process_iter()
                          if lightdm_re.search(p.exe()))
    if not running_lightdm:
        return None
    if not os.path.exists('/usr/share/lightdm/guest-session'):
        return None
    if not os.path.exists('/usr/share/lightdm/lightdm.conf.d'):
        return None
    status = None
    for conf_file in glob.glob('/usr/share/lightdm/lightdm.conf.d/*.conf'):
        parser = SafeConfigParser()
        parser.read(conf_file)
        if not parser.has_section('Seat:*'):
            continue
        if not parser.has_option('Seat:*', 'allow-guest'):
            continue
        if parser.getboolean('Seat:*', 'allow-guest'):
            return True
        status = False
    return status


# Make sure xinit_checker is last. Just because somebody is running xinit
# doesn't mean that they aren't _also_ running a display manager that has a
# guest session, so xinit_checker should only be used as a last resort.
checkers = (lightdm_checker, xinit_checker)

for checker in checkers:
    results = checker()
    if results is not None:
        break

if results is None:
    results = 'unknown'

{'fraction_non_alphanumeric': 0.10444218379111564, 'fraction_numerical': 0.0006781959986436081, 'mean_word_length': 2.4911242603550297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4204335', 'n_tokens_mistral': 917, 'n_tokens_neox': 897, 'n_words': 262}