<commit_before>/*******************************************************************************
 * Copyright (c) 2011, 2016 Eurotech and/or its affiliates
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Eurotech
 *******************************************************************************/
package org.eclipse.kura.linux.net.wifi;

import java.io.File;

import org.eclipse.kura.KuraException;
import org.eclipse.kura.core.linux.util.LinuxProcessUtil;
import org.eclipse.kura.linux.net.util.KuraConstants;
import org.eclipse.kura.linux.net.util.LinuxNetworkUtil;
import org.eclipse.kura.net.wifi.WifiMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WpaSupplicantManager {

    private static Logger s_logger = LoggerFactory.getLogger(WpaSupplicantManager.class);

    private static final String OS_VERSION = System.getProperty("kura.os.version");
    private static final File TEMP_CONFIG_FILE = new File("/tmp/wpa_supplicant.conf");

    private static String m_driver = null;

    private static boolean s_isIntelEdison = false;

    static {
        StringBuilder sb = new StringBuilder(KuraConstants.Intel_Edison.getImageName());
        sb.append('_').append(KuraConstants.Intel_Edison.getImageVersion()).append('_')
                .append(KuraConstants.Intel_Edison.getTargetName());
        if (OS_VERSION.equals(sb.toString())) {
            s_isIntelEdison = true;
        }
    }

    public static void start(String interfaceName, final WifiMode mode, String driver) throws KuraException {
        start(interfaceName, mode, driver, new File(getWpaSupplicantConfigFilename(interfaceName)));
    }

    public static void startTemp(String interfaceName, final WifiMode mode, String driver) throws KuraException {
        start(interfaceName, mode, driver, TEMP_CONFIG_FILE);
    }

    private static synchronized void start(String interfaceName, final WifiMode mode, String driver, File configFile)
            throws KuraException {
        s_logger.debug("enable WPA Supplicant");

        try {
            if (WpaSupplicantManager.isRunning(interfaceName)) {
                stop(interfaceName);
            }

            String drv = WpaSupplicant.getDriver(interfaceName);
            if (drv != null) {
                if (s_isIntelEdison) {
                    m_driver = driver;
                } else {
                    m_driver = drv;
                }
            } else {
                m_driver = driver;
            }

            // start wpa_supplicant
            String wpaSupplicantCommand = formSupplicantStartCommand(interfaceName, configFile);
            s_logger.info("starting wpa_supplicant for the {} interface -> {}", interfaceName, wpaSupplicantCommand);
            int stat = LinuxProcessUtil.start(wpaSupplicantCommand);
            if (stat != 0) {
                s_logger.error("failed to start wpa_supplicant for the {} interface for unknown reason - errorCode={}",
                        interfaceName, stat);
                throw KuraException.internalError("failed to start hostapd for unknown reason");
            }
        } catch (Exception e) {
            s_logger.error("Exception while enabling WPA Supplicant!", e);
            throw KuraException.internalError(e);
        }
    }
<commit_msg>Modified WpaSupplicantManager.java start method<commit_after>/*******************************************************************************
 * Copyright (c) 2011, 2016 Eurotech and/or its affiliates
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Eurotech
 *******************************************************************************/
package org.eclipse.kura.linux.net.wifi;

import java.io.File;

import org.eclipse.kura.KuraException;
import org.eclipse.kura.core.linux.util.LinuxProcessUtil;
import org.eclipse.kura.linux.net.util.KuraConstants;
import org.eclipse.kura.linux.net.util.LinuxNetworkUtil;
import org.eclipse.kura.net.wifi.WifiMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WpaSupplicantManager {

    private static Logger s_logger = LoggerFactory.getLogger(WpaSupplicantManager.class);

    private static final String OS_VERSION = System.getProperty("kura.os.version");
    private static final File TEMP_CONFIG_FILE = new File("/tmp/wpa_supplicant.conf");

    private static String m_driver = null;

    private static boolean s_isIntelEdison = false;

    static {
        StringBuilder sb = new StringBuilder(KuraConstants.Intel_Edison.getImageName());
        sb.append('_').append(KuraConstants.Intel_Edison.getImageVersion()).append('_')
                .append(KuraConstants.Intel_Edison.getTargetName());
        if (OS_VERSION.equals(sb.toString())) {
            s_isIntelEdison = true;
        }
    }

    public static void start(String interfaceName, final WifiMode mode, String driver) throws KuraException {
        start(interfaceName, mode, driver, new File(getWpaSupplicantConfigFilename(interfaceName)));
    }

    public static void startTemp(String interfaceName, final WifiMode mode, String driver) throws KuraException {
        start(interfaceName, mode, driver, TEMP_CONFIG_FILE);
    }

    private static synchronized void start(String interfaceName, final WifiMode mode, String driver, File configFile)
            throws KuraException {
        s_logger.debug("enable WPA Supplicant");

        try {
            if (WpaSupplicantManager.isRunning(interfaceName)) {
                stop(interfaceName);
            }

            String drv = WpaSupplicant.getDriver(interfaceName);
            if (drv != null) {
                if (s_isIntelEdison) {
                    m_driver = driver;
                } else {
                    m_driver = drv;
                }
            } else {
                m_driver = driver;
            }

            // start wpa_supplicant
            String wpaSupplicantCommand = formSupplicantStartCommand(interfaceName, configFile);
            s_logger.info("starting wpa_supplicant for the {} interface -> {}", interfaceName, wpaSupplicantCommand);
            int stat = LinuxProcessUtil.start(wpaSupplicantCommand);
            if (stat != 0 && stat != 255) {
                s_logger.error("failed to start wpa_supplicant for the {} interface for unknown reason - errorCode={}",
                        interfaceName, stat);
                throw KuraException.internalError("failed to start hostapd for unknown reason");
            }
        } catch (Exception e) {
            s_logger.error("Exception while enabling WPA Supplicant!", e);
            throw KuraException.internalError(e);
        }
    }

{'fraction_non_alphanumeric': 0.1295643592274073, 'fraction_numerical': 0.004652474270407444, 'mean_word_length': 2.887123287671233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7156190', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1850, 'n_words': 451}