Sunday, June 8, 2025

DISTCC: client did not provide distcc magic fairy dust

 I get these errors from distccd (in detach mode) everytime distcc client wants to distribute some jobs to do:


istccd[14791] (dcc_create_kids) up to 1 children
distccd[14791] (dcc_create_kids) up to 2 children
distccd[14791] (dcc_create_kids) up to 3 children
distccd[14791] (dcc_create_kids) up to 4 children
distccd[14791] (dcc_create_kids) up to 5 children
distccd[14791] (dcc_create_kids) up to 6 children
distccd[14791] (dcc_create_kids) up to 7 children
distccd[14791] (dcc_create_kids) up to 8 children
distccd[14791] (dcc_create_kids) up to 9 children
distccd[14791] (dcc_create_kids) up to 10 children
distccd[14791] (dcc_create_kids) up to 11 children
distccd[14791] (dcc_create_kids) up to 12 children
distccd[14791] (dcc_create_kids) up to 13 children
distccd[14791] (dcc_create_kids) up to 14 children
distccd[14792] (dcc_check_client) connection from 192.168.100.218:36956
distccd[14792] (check_address_inet) match client 0xda64a8c0, value 0x64a8c0, mask 0xffffff
distccd[14792] (dcc_readx) ERROR: unexpected eof on fd4
distccd[14792] (dcc_r_token_int) ERROR: read failed while waiting for token "DIST"
distccd[14792] (dcc_r_request_header) ERROR: client did not provide distcc magic fairy dust
distccd[14792] (dcc_cleanup_tempfiles_inner) deleted 3 temporary files
distccd[14792] (dcc_job_summary) client: 192.168.100.218:36956 OTHER exit:0 sig:0 core:0 ret:108 time:0ms 
distccd[14793] (dcc_check_client) connection from 192.168.100.218:40390
distccd[14793] (check_address_inet) match client 0xda64a8c0, value 0x64a8c0, mask 0xffffff
distccd[14793] (dcc_readx) ERROR: unexpected eof on fd4
distccd[14793] (dcc_r_token_int) ERROR: read failed while waiting for token "DIST"
distccd[14793] (dcc_r_request_header) ERROR: client did not provide distcc magic fairy dust
distccd[14793] (dcc_cleanup_tempfiles_inner) deleted 3 temporary files
distccd[14793] (dcc_job_summary) client: 192.168.100.218:40390 OTHER exit:0 sig:0 core:0 ret:108 time:0ms 


From distcc source code:

/**
 * Read a token and value.  The receiver always knows what token name
 * is expected next -- indeed the names are really only there as a
 * sanity check and to aid debugging.
 *
 * @param ifd      fd to read from
 * @param expected 4-char token that is expected to come in next
 * @param val      receives the parameter value
 **/
int dcc_r_token_int(int ifd, const char *expected, unsigned *val)
{
    char buf[13], *bum;
    int ret;
    if (strlen(expected) != 4) {
        rs_log_error("expected token \"%s\" seems wrong", expected);
        return EXIT_PROTOCOL_ERROR;
    }
    if ((ret = dcc_readx(ifd, buf, 12))) {
        rs_log_error("read failed while waiting for token \"%s\"",
                    expected);
        return ret;
    }


Monday, February 3, 2025

Python script to find duplicate files

Here is a Python script that scans directories for duplicate files by comparing file sizes and MD5 hashes:


import os
import hashlib
from collections import defaultdict
import argparse
def get_file_hash(filepath):
    """Calculate the MD5 hash of a file's content."""
    hasher = hashlib.md5()
    try:
        with open(filepath, 'rb') as f:
            while True:
                chunk = f.read(8192)  # Read in 8KB chunks to handle large files
                if not chunk:
                    break
                hasher.update(chunk)
    except IOError:
        return None  # Skip files that can't be read
    return hasher.hexdigest()
def find_duplicates(start_directory):
    """Find duplicate files in the specified directory and its subdirectories."""
    file_sizes = defaultdict(list)
    
    # First pass: Group files by size
    for root, dirs, files in os.walk(start_directory):
        for filename in files:
            filepath = os.path.join(root, filename)
            try:
                file_size = os.path.getsize(filepath)
            except OSError:
                continue  # Skip inaccessible files
            file_sizes[file_size].append(filepath)
    
    # Second pass: Compare hashes of files with the same size
    duplicates = []
    for size, paths in file_sizes.items():
        if len(paths) < 2:
            continue  # Skip unique file sizes
        
        hashes = defaultdict(list)
        for path in paths:
            file_hash = get_file_hash(path)
            if file_hash is not None:
                hashes[file_hash].append(path)
        
        # Collect all groups of identical files
        for hash_group in hashes.values():
            if len(hash_group) > 1:
                duplicates.append(hash_group)
    
    return duplicates
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Find duplicate files in a directory tree.')
    parser.add_argument('directory', help='Directory to scan for duplicates')
    args = parser.parse_args()
    if not os.path.isdir(args.directory):
        print(f"Error: '{args.directory}' is not a valid directory")
        exit(1)
    duplicate_groups = find_duplicates(args.directory)
    if duplicate_groups:
        print("\nDuplicate files found:")
        for i, group in enumerate(duplicate_groups, 1):
            print(f"\nGroup {i}:")
            for path in group:
                print(f"  {path}")
        print(f"\nFound {len(duplicate_groups)} groups of duplicates")
    else:
        print("\nNo duplicate files found")


Key features:

1. Uses two-pass comparison for efficiency:

   - First groups files by size

   - Then compares MD5 hashes of same-size files

2. Handles large files using chunked reading

3. Skips inaccessible files gracefully

4. Provides clear command-line output

5. Uses MD5 hashing for content comparison


To use:

1. Save as `find_duplicates.py`

2. Run with: `python find_duplicates.py /path/to/directory`


The script will:

1. Scan all subdirectories recursively

2. Identify files with identical content

3. Group duplicates together in the output

4. Show full paths of duplicate files


Note: MD5 is used for speed, but you could modify the script to use SHA-256 for cryptographic-strength hashing by replacing `hashlib.md5()` with `hashlib.sha256()`.

Sunday, December 15, 2024

Some bit manipulations

 This C++ code has bits access routines to get and set some bits:


dataBits.h:




#include <cstdint>
#include <iostream>

template <typename T>
class DataBits
{
public:
DataBits(T v=0) : m_data(v) {};
        
        T get() const { return m_data; }

        void set(T v) { m_data = v; }

        // 0-based
        template <typename TB>
static constexpr TB BitMask(int startpos, int endpos)
{
return TB((1<<(endpos-startpos+1))-1) << startpos;
        }

        constexpr T GetBits(int startpos, int endpos)
        {
            return (m_data & BitMask<T>(startpos, endpos)) >> startpos;
        }

        void SetBits(int startpos, int endpos, T newData)
        {
            auto mask = BitMask<T>(startpos, endpos);
            m_data = (m_data & ~mask) | ((newData << startpos) & mask);
        }

private:
    T  m_data;

};



main.cpp:

#include <iostream>
#include <format>
#include <bitset>
#include <iomanip>
#include "dataBits.h"


int main()
{
    std::cout << std::format("{:#04x}", 0x0e) << std::endl;
    std::cout << "BitMask[1..3] = " << std::hex << "0x" << DataBits<uint32_t>::BitMask<uint32_t>(1,3) << std::endl;

    DataBits bits = 0b1110101001010011;
    std::cout << "bits = " << std::setw(55) << std::bitset<32>(bits.get()) << std::endl;
    auto newbits = 0b010;
    bits.SetBits(13, 15, newbits);
    std::cout << "bits with bits[13..15]=" << std::bitset<3>(newbits) << " -> " << std::bitset<32>(bits.get()) << std::endl;
    std::cout << "BitMask[1..3] = " << std::hex << "0x" << DataBits<uint32_t>::BitMask<uint32_t>(1,3) << std::endl;
    std::cout << "data @bits[13..15] = " << std::bitset<3>(bits.GetBits(13,15)) << std::endl;
    return 0;
}


Saturday, February 5, 2022

Solution to Weak Sound from Maono USB/XLR HD300T Microphone

 I bought a USB/XLR Dynamic Microphone "Maono HD-300T" from Amazon a few months ago and was disappointed with its low or quiet sound made by my Windows 11 when connected through its USB connection.  I tested the microphone through its XLR connection to my Yamaha Audio mixer, no phantom power is needed (as this is a dynamic microphone), but I had to set the preamp gain all the way to its max to get a decent volume.

The volume setting was set to 100%, but I had no luck making it better. I was thinking perhaps it required a special USB driver, but nope, it simply used the stock Windows driver (Maono's official website doesn't mention anything about a special driver for this particular model).

At one point I gave up on using it for my video conferences and meetings and back to just using the built-in microphone on my webcam (Logitech HD 920).  Last week I found an idea to test the microphone using my PC analog microphone input.  I found and bought an XLR-to-3.5mm TRS which is perfect to connect the microphone to my PC.  The good thing with built-in audio from motherboard is that Windows support boost gain to +30 dB, so I was able to make the microphone work properly.

Not being satisfied with that one solution, I googled around and found somebody mentioned about Equalizer APO and its accompanying UI interface, Peace Equalizer APO.  Got them installed and ran, I then connected my Microphone to one of my PC's USB.  After playing around on how to use it (It's a lot of parameter controls and kind of confusing, at least for beginners), I managed to boost the gain of the microphone to + 3- dB. Hooray!

Below is my settings (I saved it as "My Microphone mono" settings.  It is based on the "Microphone mono" preset configuration.):


Set the preamp to gain around +20 dB.  As can be seen, I turn on "Prevent Clipping" down below, so even if set it to the max (+30 dB gain), we shouldn't get the audio clipped.  The downside to crank it up to the max is we'd also get louder noise.









I configure the audio to live play back to its headphone connector (so I can hear my own voice for monitoring purposes):


The level is always set to 100% in this pane:


Saturday, December 18, 2021

2.5 Gbps Ethernet slowing down

 I was having issues again with the unexpected slowness of my internet access.  This time turns out due to failure in ethernet auto-negotiation.  My PC's ethernet interface is 2.5 Gbps, as well MoCA adapter that is connected to it.  It was working fine, until yesterday, where I got only 90's Mbps on SpeedTest.

There is cool PowerShell command to display the link speed: Get-NetAdapter.

We can create a DOS shell wrapper, so invoking this from a regular DOS prompt would work.

For example, I put this command in a file called "getnet.ps1".  I created another DOS script called "getnet.cmd" with the content of it just calling getps1.ps1:


In getnet.ps1:

Get-NetAdapter


In getnet.cmd:

call getnet.ps1


For example:

C:\Users\anon\bin>type getnet.cmd

call getnet.ps1


C:\Users\lshih\bin>getnet


C:\Users\lshih\bin>call getnet.ps1


Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed

----                      --------------------                    ------- ------       ----------             ---------

Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...      27 Disconnected 38-FC-98-13-E9-2A         3 Mbps

2.5 GigE LAN              Realtek Gaming 2.5GbE Family Contr...#2      21 Up           04-42-1A-0C-2C-C4       2.5 Gbps

vEthernet (2.5 GigE LAN)  Hyper-V Virtual Ethernet Adapter             16 Up           00-15-5D-76-F1-69        10 Gbps

vEthernet (1 GigE LAN)    Hyper-V Virtual Ethernet Adapter #3          52 Up           00-15-5D-D2-5B-EB        10 Gbps

1 GigE LAN                Intel(R) I211 Gigabit Network Conn...#2      14 Up           04-42-1A-0C-2C-C3         1 Gbps

vEthernet (VirtualBox ... Hyper-V Virtual Ethernet Adapter #2          40 Up           00-15-5D-F1-53-24        10 Gbps

VirtualBox Host-Only N... VirtualBox Host-Only Ethernet Adapter         7 Up           0A-00-27-00-00-07         1 Gbps

vEthernet (WSL)           Hyper-V Virtual Ethernet Adapter #4          75 Up           00-15-5D-9C-4E-D0        10 Gbps


Friday, December 17, 2021

Chinese Hackers are now the top of the list

 My gateway router has a cool security feature called Intrusive Threat Prevention (ITS).  When I checked the statistics from where most of the attacks occurred to my gateway, majority the attacks come from China.