<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _iter_service_names():
    '''
    Detect all of the service names available to upstart via init configuration
    files and via classic sysv init scripts
    '''
    found = set()
    for line in glob.glob('/etc/init.d/*'):
        name = os.path.basename(line)
        found.add(name)
        yield name

    # This walk method supports nested services as per the init man page
    # definition 'For example a configuration file /etc/init/rc-sysinit.conf
    # is named rc-sysinit, while a configuration file /etc/init/net/apache.conf
    # is named net/apache'
    init_root = '/etc/init/'
    for root, dirnames, filenames in salt.utils.path.os_walk(init_root):
        relpath = os.path.relpath(root, init_root)
        for filename in fnmatch.filter(filenames, '*.conf'):
            if relpath == '.':
                # service is defined in the root, no need to append prefix.
                name = filename[:-5]
            else:
                # service is nested, append its relative path prefix.
                name = os.path.join(relpath, filename[:-5])
            if name in found:
                continue
            yield name