Skip to content

Instantly share code, notes, and snippets.

@mohan43u
mohan43u / mkdirp.c
Created December 13, 2020 11:44
simple mkdir -p implementation in C
+static void mkdirpath(const char *path, mode_t mode) {
+ char *d = NULL;
+ char *i = NULL;
+
+ if(path == NULL) return;
+ d = strdup(path);
+ i = d;
+ while(i != NULL) {
+ if( *i == '/') i++;
+ i = strchr(i, '/');
@mohan43u
mohan43u / spmc.c
Last active November 23, 2020 15:23
example of single producer multiple consumer in C
/* compile: gcc -pthread -o spmc spmc.c */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <signal.h>

unback

gzip -dc boot/berryboot.img | sudo cpio -iuvdm -D berryboot

repack

(C="${PWD}"; cd berryboot; sudo find . | sudo cpio -ov --format=newc | gzip -9 &gt;"${C}"/berryboot.img)
2020-07-10 17:00:20 +mohan43u-we good evening all
2020-07-10 17:00:37 +mohan43u-we welcome to Day 5 of 'sh' Posix shell Session
2020-07-10 17:01:17 +mohan43u-we I hope all of you who joined #ilugc through webchat followed https://pasteboard.co/JgGXsrf.gif link to disable join/part messages
2020-07-10 17:02:10 +mohan43u-we yesterday we saw variables, if-elif, case, for, while control structures
2020-07-10 17:02:42 +mohan43u-we also we saw how variable get expanded by shell before executing command, different types of variable expansion
2020-07-10 17:02:55 +mohan43u-we we also saw arithmetic expansion, command substitution
2020-07-10 17:03:23 +mohan43u-we we also looked into special built-in variables shell provides like $$, $!, $? etc.,
2020-07-10 17:04:10 +mohan43u-we today, we will look into functions, positional parameters
2020-07-10 17:04:15 +mohan43u-we let see function
2020-07-10 17:04:46 +mohan43u-we a function in shell is nothing but another built-in command which you write, instead of shell providing
2020-07-09 16:58:39 +mohan43u-we #ilugc channel is now in restricted mode
2020-07-09 16:59:51 +mohan43u-we type '/msg mohan43u-we message' if you want to say something important
2020-07-09 17:00:46 +mohan43u-we good evening to all
2020-07-09 17:01:06 +mohan43u-we welcome to Day 4 of sh Posix shell session
2020-07-09 17:01:46 +mohan43u-we we will continue from where we left yesterday
2020-07-09 17:02:09 +mohan43u-we just a rewind, yesterday we looked into redirection, pipes, normal and environment variables
2020-07-09 17:03:10 +mohan43u-we our next topic is control structures, like 'if' elif etc.,
2020-07-09 17:04:08 +mohan43u-we before going into the topic, just want to let you guys how to disable that joined/left messages in the irc chat
2020-07-09 17:05:00 +mohan43u-we if you are joining #ilugc through webchat.freenode.net, follow https://pasteboard.co/JgGXsrf.gif this link to disable join/part messages
2020-07-09 17:05:09 +mohan43u-we now, coming to the topic
2020-07-08 16:58:48 +mohan43u-we good evening to all
2020-07-08 16:58:58 +mohan43u-we welcome to day 3 of 'sh' Posix Shell session
2020-07-08 16:59:27 +mohan43u-we before we begin, if you are using 'webchat.freenode.net' you can hide join/part messages
2020-07-08 16:59:41 +mohan43u-we the instruction is provided in the 'training.ilugc.in' page
2020-07-08 16:59:58 +mohan43u-we also we have a new practice server. IP address got changed
2020-07-08 17:00:17 +mohan43u-we so make sure you login to the correct server to practice
2020-07-08 17:00:29 +mohan43u-we without further delay, lets start
2020-07-08 17:01:18 +mohan43u-we yesterday we learnt about man command, manual pages and howto execute more than one command with ';', '&&' and '||'combination
2020-07-08 17:01:28 +mohan43u-we today, we will start with redirection
2020-07-08 17:02:02 +mohan43u-we as I explained earlier, a command have "--options", "[args]' arguments, as well as it give returncode when it exits
2020-07-07 16:51:06 +mohan43u-we hi, channel switched into restricted mode
2020-07-07 16:52:14 @mohan43u only people who have voice mode enabled can speak
2020-07-07 16:59:41 +mohan43u-we good evening all
2020-07-07 16:59:56 +mohan43u-we welcome to day 2 of 'sh' Posix shell session
2020-07-07 17:00:21 +mohan43u-we today we will be covering the topics which I'm showing in the Presenter Terminal now
2020-07-07 17:01:02 +mohan43u-we I hope all of you will be able to see the presenter terminal
2020-07-07 17:01:36 +mohan43u-we lets begin
2020-07-07 17:01:52 +mohan43u-we lets talk about man pages
2020-07-07 17:02:55 +mohan43u-we yesterday we saw simple unix commands like 'ls'
2020-07-07 17:02:58 +mohan43u-we 'cd'
2020-07-06 17:40:11 +mohan43u-we the first thing you do in a shell is to see where you are
2020-07-06 17:40:50 @mohan43u type pwd command to see in which place you are currently present.
2020-07-06 17:41:37 +mohan43u-we the path /home/trainer is the current working directory
2020-07-06 17:41:54 +mohan43u-we in unix, everything is a file
2020-07-06 17:42:07 +mohan43u-we a directory is also a file
2020-07-06 17:42:35 +mohan43u-we a file in unix is stored in one particular tree
2020-07-06 17:42:56 +mohan43u-we unix filesytem starts from root
2020-07-06 17:43:40 +mohan43u-we as you see in the presenter terminal, 'ls /' command will show the directories inside the root
2020-07-06 17:43:51 +mohan43u-we the command 'ls' means list
2020-07-06 17:44:19 +mohan43u-we here '/' represents the root of the file system

Testing openat2 in systemd-nspawn

Test code

/* openat2_test.c */
/* compile: gcc -O0 -g -static -o openat2_test openat2_test.c */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
2020-06-16 16:00:17 mohan43u-we welcome to ILUGC #irc channel
2020-06-16 16:01:14 mohan43u-we wait for another 5 more mins for people to join
2020-06-16 16:01:46 mohan43u-we I hope everyone can see the presenter terminal
2020-06-16 16:03:09 --> mohan43u-kiwi (~mohan43u-@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:03:43 stof9-9 link please
2020-06-16 16:04:00 mohan43u-we stof9-9: https://training.ilugc.in
2020-06-16 16:04:09 stof9-9 thanks
2020-06-16 16:04:32 --> famubu__1 (~famubu@117.207.224.45) has joined #ilugc
2020-06-16 16:04:57 mohan43u-we lets start the talk
2020-06-16 16:05:23 mohan43u-we this talk is about 'ed' the text editor