How can I create a device node from the init_module code of a Linux kernel module?

To have more control over the device numbers and the device creation, you could do the following steps (instead of register_chrdev()): Call alloc_chrdev_region() to get a major number and a range of minor numbers to work with. Create a device class for your devices with class_create(). For each device, call cdev_init() and cdev_add() to add … Read more

Ignore case in glob() on Linux

You can replace each alphabetic character c with [cC], via import glob def insensitive_glob(pattern): def either(c): return ‘[%s%s]’ % (c.lower(), c.upper()) if c.isalpha() else c return glob.glob(”.join(map(either, pattern)))

What does “ulimit -s unlimited” do?

When you call a function, a new “namespace” is allocated on the stack. That’s how functions can have local variables. As functions call functions, which in turn call functions, we keep allocating more and more space on the stack to maintain this deep hierarchy of namespaces. To curb programs using massive amounts of stack space, … Read more

How to set system wide umask?

Both Debian and Ubuntu ship with pam_umask. This allows you to configure umask in /etc/login.defs and have them apply system-wide, regardless of how a user logs in. To enable it, you may need to add a line to /etc/pam.d/common-session reading session optional pam_umask.so or it may already be enabled. Then edit /etc/login.defs and change the … Read more

How do you run a script on login in *nix?

From wikipedia Bash When Bash starts, it executes the commands in a variety of different scripts. When Bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads … Read more

generates same number in Linux, but not in Windows

Here’s what’s going on: default_random_engine in libstdc++ (GCC’s standard library) is minstd_rand0, which is a simple linear congruential engine: typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> minstd_rand0; The way this engine generates random numbers is xi+1 = (16807xi + 0) mod 2147483647. Therefore, if the seeds are different by 1, then most of the time the first … Read more

Creating temporary files in bash

The mktemp(1) man page explains it fairly well: Traditionally, many shell scripts take the name of the program with the pid as a suffix and use that as a temporary file name. This kind of naming scheme is predictable and the race condition it creates is easy for an attacker to win. A safer, though … Read more