Great video. Perfect amount of being informative/educational without dragging your feet, and you come up with a practical piece of software by the end of it. Very well done, hope to see more from you!
I spent a few hours trying to solve the dependency problem that other people had in the comments. Apparently there are some dependencies that he uses in the video that other distros don't have by default. What I did was install these dependencies with "sudo apt-get install libgdk-pixbuf2.0-dev" and "sudo apt-get install libglib2.0-dev" and installed the libnotify dependency too, but I dont remember the command anymore. Then I ran the build command as follows: "gcc -Wall -pedantic -std=gnu99 -o build/rolexhound rolexhound.c $(pkg-config - -cflags gdk-pixbuf-2.0 libnotify) -lnotify". Also, I changed the $PKG_CONFIG_PATH environment variable, but I don't know if that helped in any way. It only worked like this on Ubuntu, I hope it works for you too!
This was a cool video on daemons. I've been looking for good resources all morning and this was the best introduction to getting started with it all. Thanks for the video! :D
This cunts a legend bro, keep up the work cuzzy. Showing your knowledge without going through at 100x speed and still having a sense of humour and normality about ya (Sorry for bad language, am from Australia is normal here hahahaha😂😂😂😂)
Great video man! About a month ago I wrote a daemon in Zig also using inotify, although just to be fancy and learn I decided to use io_uring instead of actively polling events.
that's awesome bro Zig looks like a sweet lang just haven't had the time to learn it. How does io_uring work without polling? Does it emit signals, events or something your program can write handlers for?
@@hoff._world You tell the kernel to do IO operations (read, write, readv, writev, etc...) and letting it do them when it has time and tell you when they're ready, making them asynchronous. In the end you only have to check if the "completion queue" has any items in it, if not, your application continues as normal. It's a little overkill for a little program like this but it was interesting getting to work with it.
@@michaelscofield4524 sick thanks for sharing. In essence then you're doing a non-blocking check somewhere in your main loop and if that turns negative your daemon does other work until it's ready. Which is useful for bigger daemons for sure, especially if networking is involved where it could potentially talk to others as well (we might be doing that sometime :)
Randomly had this on my RU-vid homepage and it's perfect! Love this video. Definitely going to try and write some cute little dogs that'll watch my clipboard for some magic later!
once the file is written, the inotify_event watch descriptor is changed, so furthur access or "alterations" of the file won't be notified. also would be neat that if the file were moved, it would show the path it was moved to. btw nice video, the channel will blow up at this rate
@@hoff._world your code from pastebin has the same issue. mayb some platform dependency? im on arch6.7.3+dwm with dunst notify daemon. watch descriptor is being set to IN_MOVE_SELF rather than IN_MODIFY upon modification of the file. i guess when modifying the file it interprets it as "moving" the file, on my system.
@@johntully1414I have actually noticed that if you use vim to edit it generates move events for some reason. Every other editor I've tested doesn't have the issue so no clue why
@@hoff._world yupp, that was it. looks like the vim/neovim saving mechanism uses "swap" or "temporary" files, so when you're modifying the file in the text editor it writes to the temp file (like a buffer) rather than the original file. Then when you :w the file, it renames that temp file to the original filename.. hence generating move events.
Starting my journey in tutorial series, after started watch the last tutorial and not understand anything 😂. It is me, not you. You explain very well and is funny, my problem is keep my mind in english and keep my focus on code 🤣 Let’s go!
No one going to talk about how he is using Kate to write all this? People crying over why VsCode/Vim/Emacs are the best, meanwhile mans been chillin with Kate watching the world bun, Is he a psycho?
Nice vid, one thing tho. When writing in C be very careful with `str*` functions. `strlen` is not safe bcs with a string not null-terminated it accesses memory beyond the buffer. You could use strnlen, or better yet, strnlen_s. Nice vid regardless :) cheers
You are right my friend. Considering we are grabbing the string from argv I am trusting the shell to get it right, but on any other user input that is the way to go :D
You are running it as a regular shell process, can you please make a video on how to run it as actual daemon which can be controlled by systemctl command
hey thanx for the great video (subbed)! Been trying to get back into C ever since I was forced to adopt Java (OOP) to get thru my classes at uni (comp sci major) and this video was a great help. Looking forward to enjoying more of your content and seeing where you take this very cool channel 🙂 I do gotta say though... PLEASE make the font in your text editor bigger in future videos! It will make your content WAY easier to engage with going forward (especially for those of us who generally watch YT on a tv screen as opposed to a laptop screen). Anyways that's my only complaint tho - keep up the good work!
don't stress bro font size will be bigger on the next one! Interesting point about the TV screen, hadn't thought about that before. Thanks for the comment!
This was a really good video. It would have been nice if you had included the part where the daemon detaches from the parent shell and runs in it's own session, and all the logs being written to a separate file. It would also be fun to see how to integrate the daemon with systemd and allow it to be started or stopped from there
31:00 Back in the days this was even how we could read directory entries on a *nix system, because as we know "everything is a file" and even a directory could be "open"-ed like one! A terrible non-portable way of doing it, and totally bound to the internal format of one specific file system. IIRC it probably was on a Venix machine I did this.
Around 34:00 you might want to assure you read at least _(sizeof *watchEvent)_ bytes too, or else you risk accessing invalid buffer content that wasn't actually filled by _read._ It can be done by changing "bufferPointer < buffer+..." to something like "bufferPointer+(sizeof *watchEvent) < buffer+..." in the _for_ condition. Remember the _read_ system call may return less that you ask for, and even 0 bytes!
Hello, after testing with "bufferPointer+(sizeof *watchEvent) < buffer+..." in the for condition, the inotify event is not detected at all. I think adding the actual size of the struct inotify_event could lead to skipping the loop.
@@Ozla102 Yes, but that probably means you have read a few bytes from the file descriptor ("event queue"), but not yet the full size of a watchEvent. Did you check the actual value of that _readLength?_ Then we're also left with another challenge; how to handle whatever data is left in the buffer after the _for_ loop. (The _bufferPointer_ may even point beyond the end of the data read!) You cannot just discard it, because then all the subsequent reads will be out of sync with the event records, and it can be hard to get back in sync again. Probably just move it to the beginning of the buffer and let the _read_ append from there. This requires some adjustments to both the max count to read and the returned _readLength_ though. Some mgmt related to the variable length of the records too, so a bit of things to get right there, unfortunately!
Your cam is in the way of the terminal. I suggest to pipe your webcam output to MPV so that it show in your screen and you can move it around like a normal window.
I like this. Pretty cool :v Edit: I'm a scholar in a research group and watchdog sounded familiar. Maybe youtube recommended this to me because of it. IDK. But anyway, thanks. Now ik what a watchdog is :v
Any good books or tutorials on this? I have a python and JavaScript background and will eventually be taking computer science classes. Wanted to learn C. I know the basics of assembly x86. I was having a hard time really understanding what’s going on with the API
10:45 - One quick thing, I'm not sure if you've mainly done a lot of programming in C++ or something but, in C it's redundant to cast the return value of malloc (or its derivatives). C is very loose about its types and all pointers are really just the same type (void*) when interacting with one another.
damn. only watched first five minutes and already got agitated and intrigued. will watch this for sure. like your delivery. any chance you have discord channel or smth? you seem like a great guy to talk with
Amazing, I already know all this, and I use arch btw, but, still a nice thing to watch in background! Respect for not using VSCode, but I wish you used Vim
Yeah I use vim on the CLI but with this syscall API vim wanted to generate file move events which was really weird, that still works correctly for the intent of seeing if someone edited ur file ig but nano generated the events one would expect so I used that for the demo.
@hoff._world: at 38.53 minutes into the video, you do something based on the command _make_ not producing the output you were looking for; what did you do/type to correct the issue? I cannot proceed any further, because there is no online information that deals with essentially, what the unknown issue is. UPDATE: I have completed the tutorial and it works well, except for the`dialog-information` box. I completed the program on an Android mobile phone IDE; the issue is Java. I do not know how to implement the Java `AlertDialog` box for Android devices; all examples I have seen are very complicated to understand (as I don’t know Java) and difficult to implement. Any chance of some assistance with this issue?
Thanks, useful video. To get it to build correctly I needed to change the order of the gcc command line in Makefile. ``` CFLAGS= -Wall -pedantic -std=gnu99 all: rolexhound rolexhound: gcc $(CFLAGS) rolexhound.c -o rolexhoundd `pkg-config --cflags --libs libnotify` ```
Hey, you can also use glib's gio component for file monitoring. glib is included with almost any linux system since it's a gtk dependency (and as you know gtk apps are very common)
My girl at the time, ex-girl now :P It was a simple Python web-scraping daemon that sent her a notification when a very niche store (no email notifs) had some piece of clothing she wanted back in stock. She ran Manjaro for around 4 yrs but recently swapped it back to Win when it had some issues.
@ihavenoenem1es it's light and responsive while having the features I want (split view, inbuilt term, LSP client, etc) vs. vscode which feels slow. Also integrates nicely with my DE which is plasma since kate is a KDE editor
@@hoff._world assembly language allows you to pretty much directly manipulate the CPU and all its registers. C obfuscates a lot of that to make it more human-readable.
This video was grt, i also want to learn all these stuff, any advise from where can i learn these low level stuff? i cant find any system engineering playist on youtube
Can somebody help with implementing this watchdog on MacOs? I tried to find libraries, there seems to be a fswatch, but i actually do not know how to properly perform linking. I would really appreciate if somebody had me pushed in some direction here. Thank you very much! Tutorial is great!
Dude we’re like the same age but you’ve gotten further than me in c.. and I started programming 6 months ago :( Im slow lol Also BROO WANNA SURF YOU DOGGY 👊 🤣 Love from 🇿🇦 SA
Don't sweat it dude I've been programming for a lot longer than 6 months, that's actually a pretty short amount of time when it comes to getting good at this stuff. Yeah man tell me which beach u wanna hit up and I'll be there sunrise
@CJ1337HF this is true, however if the daemon is started before your desktop env this can cause issues initialising with libnotify. May have to do some playing around, or it might just work, idk hahaha
mentioned in another comment that because this daemon runs forever the OS will release it when it is killed; there is only one allocation so it will never grow. You could implement a signaling method to the main loop to free the memory before the daemon exits but that would be way too complex for this vid, and pointless because it is about to exit where the kernel will just do it.
Bro really be coming up to Tony Hoare - rocking variable declarations at the top of his functions like it's the ANSI C days (as if the flexible array members aren't from C99) - telling him that his billion dollar mistake is fine actually and that the legend himself has a skill issue XD fr tho, nullability is useful, that's why you got `Option`, so you get it only where you need it, oh and it's useful for more than just pointers
That is true, and equivalents exist in almost all langs. However string tokenisation is a very common thing in programming in general so I thought it would be good to go over it using this as an example :)
@@hoff._worldwhat a legend i know this has some security implications, is there now a way around this to hide your program from inode calls? or is this bulletproof
Letter's to small to watch it from the bed, lucky for me today I'll sleep on the desk 🍻 Cool code and walk true!!! Is really solid. What's the prep/improvise ratio? I love to learn C... I should start with it when I've know nothing, now it's harder. What's worry me, why all of it have a perfect sense for me? I don't understand that!!! I just seen artifacts of it in so many places of my os.
Hey thanks for the comment! As mentioned I did write up the program beforehand, took maybe 20-30 minutes? It is quite a basic program; whatever I improvised in the video would come out roughly the same as what I wrote beforehand. I don't film with scripts, at best I have a text file with some dot points which just feels more natural to me. Tbh I think I'm still a bit robotic in places so trying to work on it. C as a language is nice to learn because you can really start to think like a computer. Higher level languages abstract a lot of things away from you, so when you program in C it's like you're having a conversation with the CPU :)
@@hoff._world you do have a good presentation skills, this is something I'm trying to stress myself a bit more. Half scripted? You are good natural. Keep it this way. C... I know... I'm just lazy fuck, sticked with those languages that are doing for us every stupid mistake... and BTW most of new CLI apps do not provide man 🫨 they are 12 fucks apps and forgetting about first one. fuck!!!! RTFM