1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00
systemd/man/inotify-watch-tmp.c
Zbigniew Jędrzejewski-Szmek 1fe6d37ea5 man: change license of examples to MIT-0
Quoting Richard Fontana in [1]:

  CC0 has been listed by Fedora as a 'good' license for code and content
  (corresponding to allowed and allowed-content under the new system). We plan
  to classify CC0 as allowed-content only, so that CC0 would no longer be
  allowed for code.

  Over a long period of time a consensus has been building in FOSS that
  licenses that preclude any form of patent licensing or patent forbearance
  cannot be considered FOSS. CC0 has a clause that says: "No trademark or
  patent rights held by Affirmer are waived, abandoned, surrendered, licensed
  or otherwise affected by this document." (The trademark side of that clause
  is nonproblematic from a FOSS licensing norms standpoint.) The regular
  Creative Commons licenses have similar clauses.

For the case of our documentation snippets, patent issues do not matter much.
But it is always nicer to have a license that is considerred acceptable without
any further considerations. So let's change the license to the (now recommended
replacement) MIT-0.

[1] https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/NO7KGDNL5GX3KCB7T3XTGFA3QPSUJA6R/

Using 'git blame -b' and 'git log -p --follow', I identified the following
folks as having made non-trivial changes to those snippets:

  Lennart Poettering
  Tom Gundersen
  Luca Bocassi
  Zbigniew Jędrzejewski-Szmek
  Thomas Mühlbacher
  Daan De Meyer

I'll ask for confirmation in the pull request.
2022-10-26 08:39:34 +02:00

59 lines
1.8 KiB
C

/* SPDX-License-Identifier: MIT-0 */
#include <stdio.h>
#include <string.h>
#include <sys/inotify.h>
#include <systemd/sd-event.h>
#define _cleanup_(f) __attribute__((cleanup(f)))
static int inotify_handler(sd_event_source *source,
const struct inotify_event *event,
void *userdata) {
const char *desc = NULL;
sd_event_source_get_description(source, &desc);
if (event->mask & IN_Q_OVERFLOW)
printf("inotify-handler <%s>: overflow\n", desc);
else if (event->mask & IN_CREATE)
printf("inotify-handler <%s>: create on %s\n", desc, event->name);
else if (event->mask & IN_DELETE)
printf("inotify-handler <%s>: delete on %s\n", desc, event->name);
else if (event->mask & IN_MOVED_TO)
printf("inotify-handler <%s>: moved-to on %s\n", desc, event->name);
/* Terminate the program if an "exit" file appears */
if ((event->mask & (IN_CREATE|IN_MOVED_TO)) &&
strcmp(event->name, "exit") == 0)
sd_event_exit(sd_event_source_get_event(source), 0);
return 1;
}
int main(int argc, char **argv) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *source1 = NULL, *source2 = NULL;
const char *path1 = argc > 1 ? argv[1] : "/tmp";
const char *path2 = argc > 2 ? argv[2] : NULL;
/* Note: failure handling is omitted for brevity */
sd_event_default(&event);
sd_event_add_inotify(event, &source1, path1,
IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_TO,
inotify_handler, NULL);
if (path2)
sd_event_add_inotify(event, &source2, path2,
IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_TO,
inotify_handler, NULL);
sd_event_loop(event);
return 0;
}